DrawDAG.addRecursive
This commit is contained in:
parent
13ecdc901e
commit
9a7e09195d
1 changed files with 21 additions and 4 deletions
|
@ -110,16 +110,17 @@ func (d *DrawDAG) Prepare(game *Game) error {
|
||||||
d.game = game
|
d.game = game
|
||||||
|
|
||||||
// Because Game.LoadAndPrepare calls Prepare in a post-order walk, all the
|
// Because Game.LoadAndPrepare calls Prepare in a post-order walk, all the
|
||||||
// descendants should be prepared, meaning BoundingBox (and Add) is likely
|
// descendants should be prepared, meaning BoundingBox (hence Add) is likely
|
||||||
// to be a safe call.
|
// to be a safe call.
|
||||||
for db := range game.Query(d, DrawBoxerType) {
|
d.addRecursive(d)
|
||||||
d.Add(db.(DrawBoxer))
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan returns d.Components.
|
||||||
func (d *DrawDAG) Scan() []interface{} { return d.Components }
|
func (d *DrawDAG) Scan() []interface{} { return d.Components }
|
||||||
|
|
||||||
|
// Update checks for any changes to descendants, and updates its internal
|
||||||
|
// data structures accordingly.
|
||||||
func (d *DrawDAG) Update() error {
|
func (d *DrawDAG) Update() error {
|
||||||
// Re-evaluate bounding boxes for all descendants. If a box has changed,
|
// Re-evaluate bounding boxes for all descendants. If a box has changed,
|
||||||
// fix up the edges by removing and re-adding the vertex.
|
// fix up the edges by removing and re-adding the vertex.
|
||||||
|
@ -195,6 +196,22 @@ func (d *DrawDAG) Add(x DrawBoxer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// addRecursive adds x and all descendants that are DrawBoxers unless they are
|
||||||
|
// descendants of a different DrawManager.
|
||||||
|
func (d *DrawDAG) addRecursive(x interface{}) {
|
||||||
|
if db, ok := x.(DrawBoxer); ok {
|
||||||
|
d.Add(db)
|
||||||
|
}
|
||||||
|
if _, ok := x.(DrawManager); ok && x != d {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sc, ok := x.(Scanner); ok {
|
||||||
|
for _, x := range sc.Scan() {
|
||||||
|
d.addRecursive(x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove removes a Drawer and all associated edges and metadata.
|
// Remove removes a Drawer and all associated edges and metadata.
|
||||||
func (d *DrawDAG) Remove(x DrawBoxer) {
|
func (d *DrawDAG) Remove(x DrawBoxer) {
|
||||||
// Remove from chunk map
|
// Remove from chunk map
|
||||||
|
|
Loading…
Reference in a new issue