rearrange Unregister

This commit is contained in:
Josh Deprez 2021-09-23 16:47:43 +10:00
parent 5ec1a98ae4
commit 9c8417780a
3 changed files with 20 additions and 5 deletions

View file

@ -135,11 +135,13 @@ func (c *Container) Register(component, parent interface{}) error {
// to nil. If the number of nil items is greater than half the slice, the slice
// is compacted.
func (c *Container) Unregister(component interface{}) {
if i, found := c.reverse[component]; found {
c.items[i] = nil
c.free[i] = struct{}{}
delete(c.reverse, i)
i, found := c.reverse[component]
if !found {
return
}
c.items[i] = nil
c.free[i] = struct{}{}
delete(c.reverse, i)
if len(c.free) > len(c.items)/2 {
c.compact()
}

View file

@ -1,6 +1,7 @@
package engine
import (
"encoding/gob"
"fmt"
"image"
"log"
@ -21,6 +22,10 @@ var _ interface {
Updater
} = &DrawDAG{}
func init() {
gob.Register(&DrawDAG{})
}
// DrawDAG is a DrawLayer that organises DrawBoxer descendants in a directed
// acyclic graph (DAG), in order to draw them according to ordering constraints.
// It combines a DAG with a spatial index used when updating vertices to reduce

View file

@ -1,6 +1,10 @@
package engine
import "github.com/hajimehoshi/ebiten/v2"
import (
"encoding/gob"
"github.com/hajimehoshi/ebiten/v2"
)
var _ interface {
Drawer
@ -8,6 +12,10 @@ var _ interface {
Scanner
} = &DrawDFS{}
func init() {
gob.Register(&DrawDFS{})
}
// DrawDFS is a DrawLayer that does not add any structure. Components are
// drawn in the order in which they are encountered by a depth-first search
// through the game tree, without any extra sorting based on Z values or