update orderin

This commit is contained in:
Josh Deprez 2021-09-20 16:02:01 +10:00
parent 938fd70921
commit fe40073407
2 changed files with 17 additions and 16 deletions

View file

@ -19,7 +19,7 @@ type DrawDAG struct {
Hides
*dag
boxCache map[DrawBoxer]geom.Box
boxCache map[DrawBoxer]geom.Box // used to find components that moved
chunks map[image.Point]drawerSet // chunk coord -> drawers with bounding rects intersecting chunk
chunksRev map[DrawBoxer]image.Rectangle // comopnent -> rectangle of chunk coords
game *Game
@ -45,6 +45,7 @@ func (d *DrawDAG) DrawAll(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
},
}
// Draw everything in d.dag, where not hidden (itself or any parent)
// TODO: handle descendant DrawLayers
d.dag.topIterate(func(x Drawer) {
// Is d hidden itself?
if h, ok := x.(Hider); ok && h.Hidden() {
@ -88,6 +89,7 @@ func (d *DrawDAG) DrawAll(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
})
}
// Prepare adds all subcomponents to the DAG.
func (d *DrawDAG) Prepare(game *Game) error {
d.dag = newDAG()
d.boxCache = make(map[DrawBoxer]geom.Box)
@ -109,7 +111,8 @@ func (d *DrawDAG) Scan() []interface{} { return d.Components }
func (d *DrawDAG) Update() error {
// Re-evaluate bounding boxes for all descendants. If a box has changed,
// fix up the edges by removing and re-adding the vertex.
// TODO: ensure this happens after updates for the descendants.
// Thanks once again to postorder traversal, this happens after all
// descendant updates.
var readd []DrawBoxer
for db, bb := range d.boxCache {
nbb := db.BoundingBox()

View file

@ -81,17 +81,20 @@ func (g *Game) Update() error {
}
// Update everything that is not disabled.
// TODO: do it in a fixed order? map essentially randomises iteration order
for u := range g.Query(g, UpdaterType) {
return PostorderWalk(g, func(c, _ interface{}) error {
// Skip g (note g satisfies Updater, so this would infinitely recurse)
if u == g {
continue
if c == g {
return nil
}
u, ok := c.(Updater)
if !ok {
return nil
}
// Is u disabled itself?
if d, ok := u.(Disabler); ok && d.Disabled() {
cache[u] = true
continue
return nil
}
// Walk up g.par to find the nearest state in accum.
@ -117,17 +120,12 @@ func (g *Game) Update() error {
// Skip updating if disabled.
if st {
continue
return nil
}
if err := u.(Updater).Update(); err != nil {
return err
}
}
// Sort the draw list (on every frame - this isn't as bad as it sounds)
//g.drawList.topsort(g.Projection)
return nil
// Update
return u.Update()
})
}
// Ident returns "__GAME__".