rearrange Unregister
This commit is contained in:
parent
5ec1a98ae4
commit
9c8417780a
3 changed files with 20 additions and 5 deletions
|
@ -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
|
// to nil. If the number of nil items is greater than half the slice, the slice
|
||||||
// is compacted.
|
// is compacted.
|
||||||
func (c *Container) Unregister(component interface{}) {
|
func (c *Container) Unregister(component interface{}) {
|
||||||
if i, found := c.reverse[component]; found {
|
i, found := c.reverse[component]
|
||||||
c.items[i] = nil
|
if !found {
|
||||||
c.free[i] = struct{}{}
|
return
|
||||||
delete(c.reverse, i)
|
|
||||||
}
|
}
|
||||||
|
c.items[i] = nil
|
||||||
|
c.free[i] = struct{}{}
|
||||||
|
delete(c.reverse, i)
|
||||||
if len(c.free) > len(c.items)/2 {
|
if len(c.free) > len(c.items)/2 {
|
||||||
c.compact()
|
c.compact()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"log"
|
"log"
|
||||||
|
@ -21,6 +22,10 @@ var _ interface {
|
||||||
Updater
|
Updater
|
||||||
} = &DrawDAG{}
|
} = &DrawDAG{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
gob.Register(&DrawDAG{})
|
||||||
|
}
|
||||||
|
|
||||||
// DrawDAG is a DrawLayer that organises DrawBoxer descendants in a directed
|
// DrawDAG is a DrawLayer that organises DrawBoxer descendants in a directed
|
||||||
// acyclic graph (DAG), in order to draw them according to ordering constraints.
|
// 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
|
// It combines a DAG with a spatial index used when updating vertices to reduce
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import "github.com/hajimehoshi/ebiten/v2"
|
import (
|
||||||
|
"encoding/gob"
|
||||||
|
|
||||||
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
)
|
||||||
|
|
||||||
var _ interface {
|
var _ interface {
|
||||||
Drawer
|
Drawer
|
||||||
|
@ -8,6 +12,10 @@ var _ interface {
|
||||||
Scanner
|
Scanner
|
||||||
} = &DrawDFS{}
|
} = &DrawDFS{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
gob.Register(&DrawDFS{})
|
||||||
|
}
|
||||||
|
|
||||||
// DrawDFS is a DrawLayer that does not add any structure. Components are
|
// 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
|
// 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
|
// through the game tree, without any extra sorting based on Z values or
|
||||||
|
|
Loading…
Reference in a new issue