only register if not in lower dm

This commit is contained in:
Josh Deprez 2021-09-22 10:14:44 +10:00
parent 6301c01026
commit d37a26eb70
2 changed files with 12 additions and 3 deletions

View file

@ -139,6 +139,18 @@ func (d *DrawDAG) Update() error {
// DrawBoxers into internal data structures (the DAG, etc) unless they are
// descendants of a different DrawManager.
func (d *DrawDAG) Register(component, _ interface{}) error {
// *Don't* register the component if it is inside a descendant DrawManager.
// These queries work because component should be registered in game before
// this call.
for dm := range d.game.Query(d, DrawManagerType) {
if dm == d {
continue
}
dbs := d.game.Query(dm, DrawBoxerType)
if _, found := dbs[component]; found {
return nil
}
}
if db, ok := component.(DrawBoxer); ok {
d.registerOne(db)
}

View file

@ -114,9 +114,6 @@ func (g *Game) Parent(c interface{}) interface{} {
// PathRegister calls Register on every Registrar in the path between g and
// parent (top-to-bottom, i.e. g first)
func (g *Game) PathRegister(component, parent interface{}) error {
// The only issue with this approach is... component gets registered in
// *every* drawmanager...
// TODO: Way of registering/unregistering from lowest DM only?
rp := g.ReversePath(parent)
for i := len(rp) - 1; i >= 0; i-- {
if r, ok := rp[i].(Registrar); ok {