update orderin
This commit is contained in:
parent
938fd70921
commit
fe40073407
2 changed files with 17 additions and 16 deletions
|
@ -19,7 +19,7 @@ type DrawDAG struct {
|
||||||
Hides
|
Hides
|
||||||
|
|
||||||
*dag
|
*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
|
chunks map[image.Point]drawerSet // chunk coord -> drawers with bounding rects intersecting chunk
|
||||||
chunksRev map[DrawBoxer]image.Rectangle // comopnent -> rectangle of chunk coords
|
chunksRev map[DrawBoxer]image.Rectangle // comopnent -> rectangle of chunk coords
|
||||||
game *Game
|
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)
|
// Draw everything in d.dag, where not hidden (itself or any parent)
|
||||||
|
// TODO: handle descendant DrawLayers
|
||||||
d.dag.topIterate(func(x Drawer) {
|
d.dag.topIterate(func(x Drawer) {
|
||||||
// Is d hidden itself?
|
// Is d hidden itself?
|
||||||
if h, ok := x.(Hider); ok && h.Hidden() {
|
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 {
|
func (d *DrawDAG) Prepare(game *Game) error {
|
||||||
d.dag = newDAG()
|
d.dag = newDAG()
|
||||||
d.boxCache = make(map[DrawBoxer]geom.Box)
|
d.boxCache = make(map[DrawBoxer]geom.Box)
|
||||||
|
@ -109,7 +111,8 @@ func (d *DrawDAG) Scan() []interface{} { return d.Components }
|
||||||
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.
|
||||||
// TODO: ensure this happens after updates for the descendants.
|
// Thanks once again to postorder traversal, this happens after all
|
||||||
|
// descendant updates.
|
||||||
var readd []DrawBoxer
|
var readd []DrawBoxer
|
||||||
for db, bb := range d.boxCache {
|
for db, bb := range d.boxCache {
|
||||||
nbb := db.BoundingBox()
|
nbb := db.BoundingBox()
|
||||||
|
|
|
@ -81,17 +81,20 @@ func (g *Game) Update() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update everything that is not disabled.
|
// Update everything that is not disabled.
|
||||||
// TODO: do it in a fixed order? map essentially randomises iteration order
|
return PostorderWalk(g, func(c, _ interface{}) error {
|
||||||
for u := range g.Query(g, UpdaterType) {
|
|
||||||
// Skip g (note g satisfies Updater, so this would infinitely recurse)
|
// Skip g (note g satisfies Updater, so this would infinitely recurse)
|
||||||
if u == g {
|
if c == g {
|
||||||
continue
|
return nil
|
||||||
|
}
|
||||||
|
u, ok := c.(Updater)
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is u disabled itself?
|
// Is u disabled itself?
|
||||||
if d, ok := u.(Disabler); ok && d.Disabled() {
|
if d, ok := u.(Disabler); ok && d.Disabled() {
|
||||||
cache[u] = true
|
cache[u] = true
|
||||||
continue
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk up g.par to find the nearest state in accum.
|
// Walk up g.par to find the nearest state in accum.
|
||||||
|
@ -117,17 +120,12 @@ func (g *Game) Update() error {
|
||||||
|
|
||||||
// Skip updating if disabled.
|
// Skip updating if disabled.
|
||||||
if st {
|
if st {
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
return u.Update()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ident returns "__GAME__".
|
// Ident returns "__GAME__".
|
||||||
|
|
Loading…
Reference in a new issue