some light renaming
This commit is contained in:
parent
c6c7823047
commit
4399f463f4
1 changed files with 11 additions and 11 deletions
|
@ -33,11 +33,11 @@ type Game struct {
|
||||||
Root DrawUpdater // typically a *Scene or SceneRef though
|
Root DrawUpdater // typically a *Scene or SceneRef though
|
||||||
|
|
||||||
dbmu sync.RWMutex
|
dbmu sync.RWMutex
|
||||||
db map[string]Identifier // Named components by ID
|
byID map[string]Identifier // Named components by ID
|
||||||
dex map[dexKey][]interface{} // Ancestor/behaviour index
|
byAB map[abKey][]interface{} // Ancestor/behaviour index
|
||||||
}
|
}
|
||||||
|
|
||||||
type dexKey struct {
|
type abKey struct {
|
||||||
ancestor string
|
ancestor string
|
||||||
behaviour reflect.Type
|
behaviour reflect.Type
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func (g *Game) Ident() string { return "__GAME__" }
|
||||||
func (g *Game) Component(id string) Identifier {
|
func (g *Game) Component(id string) Identifier {
|
||||||
g.dbmu.RLock()
|
g.dbmu.RLock()
|
||||||
defer g.dbmu.RUnlock()
|
defer g.dbmu.RUnlock()
|
||||||
return g.db[id]
|
return g.byID[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query looks for components having both a given ancestor and implementing
|
// Query looks for components having both a given ancestor and implementing
|
||||||
|
@ -80,7 +80,7 @@ func (g *Game) Component(id string) Identifier {
|
||||||
func (g *Game) Query(ancestorID string, behaviour reflect.Type) []interface{} {
|
func (g *Game) Query(ancestorID string, behaviour reflect.Type) []interface{} {
|
||||||
g.dbmu.RLock()
|
g.dbmu.RLock()
|
||||||
defer g.dbmu.RUnlock()
|
defer g.dbmu.RUnlock()
|
||||||
return g.dex[dexKey{ancestorID, behaviour}]
|
return g.byAB[abKey{ancestorID, behaviour}]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan implements Scanner.
|
// Scan implements Scanner.
|
||||||
|
@ -126,8 +126,8 @@ func (g *Game) LoadAndPrepare(assets fs.FS) error {
|
||||||
|
|
||||||
// Build the component databases
|
// Build the component databases
|
||||||
g.dbmu.Lock()
|
g.dbmu.Lock()
|
||||||
g.db = make(map[string]Identifier)
|
g.byID = make(map[string]Identifier)
|
||||||
g.dex = make(map[dexKey][]interface{})
|
g.byAB = make(map[abKey][]interface{})
|
||||||
if err := Walk(g, g.registerComponent); err != nil {
|
if err := Walk(g, g.registerComponent); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -155,8 +155,8 @@ func (g *Game) registerComponent(c interface{}, path []interface{}) error {
|
||||||
if !ok || i.Ident() == "" {
|
if !ok || i.Ident() == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
k := dexKey{i.Ident(), b}
|
k := abKey{i.Ident(), b}
|
||||||
g.dex[k] = append(g.dex[k], c)
|
g.byAB[k] = append(g.byAB[k], c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,9 +169,9 @@ func (g *Game) registerComponent(c interface{}, path []interface{}) error {
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if _, exists := g.db[id]; exists {
|
if _, exists := g.byID[id]; exists {
|
||||||
return fmt.Errorf("duplicate id %q", id)
|
return fmt.Errorf("duplicate id %q", id)
|
||||||
}
|
}
|
||||||
g.db[id] = i
|
g.byID[id] = i
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue