interface{} -> any
Because I’m on Go 1.18 now.
This commit is contained in:
parent
ca23e0e06b
commit
b4f7753a00
13 changed files with 70 additions and 70 deletions
|
@ -63,7 +63,7 @@ func (a *Actor) CollidesAt(p geom.Int3) bool {
|
||||||
log.Printf("collision domain %q not found", a.CollisionDomain)
|
log.Printf("collision domain %q not found", a.CollisionDomain)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return errCollision == a.game.Query(cd, ColliderType, nil, func(c interface{}) error {
|
return errCollision == a.game.Query(cd, ColliderType, nil, func(c any) error {
|
||||||
if cl, ok := c.(Collider); ok && cl.CollidesWith(bounds) {
|
if cl, ok := c.(Collider); ok && cl.CollidesWith(bounds) {
|
||||||
return errCollision
|
return errCollision
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ type assetKey struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadGobz gunzips and gob-decodes a component from a file from a FS.
|
// LoadGobz gunzips and gob-decodes a component from a file from a FS.
|
||||||
func LoadGobz(dst interface{}, assets fs.FS, path string) error {
|
func LoadGobz(dst any, assets fs.FS, path string) error {
|
||||||
f, err := assets.Open(path)
|
f, err := assets.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -45,7 +45,7 @@ func LoadGobz(dst interface{}, assets fs.FS, path string) error {
|
||||||
|
|
||||||
// SaveGobz takes an object, gob-encodes it, gzips it, and writes to disk.
|
// SaveGobz takes an object, gob-encodes it, gzips it, and writes to disk.
|
||||||
// This requires running on something with a disk to write to (not JS)
|
// This requires running on something with a disk to write to (not JS)
|
||||||
func SaveGobz(src interface{}, name string) error {
|
func SaveGobz(src any, name string) error {
|
||||||
f, err := os.CreateTemp(".", filepath.Base(name))
|
f, err := os.CreateTemp(".", filepath.Base(name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -39,7 +39,7 @@ func init() {
|
||||||
// Camera models a camera that is viewing something.
|
// Camera models a camera that is viewing something.
|
||||||
type Camera struct {
|
type Camera struct {
|
||||||
ID
|
ID
|
||||||
Child interface{}
|
Child any
|
||||||
Disables
|
Disables
|
||||||
Hides
|
Hides
|
||||||
|
|
||||||
|
|
|
@ -33,15 +33,15 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Container is a component that contains many other components, in order.
|
// Container is a component that contains many other components, in order.
|
||||||
// It can be used as both a component in its own right, or as a ordered set.
|
// It can be used as both a component in its own right, or as an ordered set.
|
||||||
// A nil *Container contains no items and modifications will panic (like a map).
|
// A nil *Container contains no items and modifications will panic (like a map).
|
||||||
type Container struct {
|
type Container struct {
|
||||||
items []interface{}
|
items []any
|
||||||
reverse map[interface{}]int
|
reverse map[any]int
|
||||||
}
|
}
|
||||||
|
|
||||||
// MakeContainer puts the items into a new Container.
|
// MakeContainer puts the items into a new Container.
|
||||||
func MakeContainer(items ...interface{}) *Container {
|
func MakeContainer(items ...any) *Container {
|
||||||
c := &Container{items: items}
|
c := &Container{items: items}
|
||||||
c.rebuildReverse()
|
c.rebuildReverse()
|
||||||
return c
|
return c
|
||||||
|
@ -51,7 +51,7 @@ func (c *Container) rebuildReverse() {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.reverse = make(map[interface{}]int, len(c.items))
|
c.reverse = make(map[any]int, len(c.items))
|
||||||
for i, x := range c.items {
|
for i, x := range c.items {
|
||||||
c.reverse[x] = i
|
c.reverse[x] = i
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ func (c *Container) Scan(visit VisitFunc) error {
|
||||||
// Add adds an item to the end of the container, if not already present.
|
// Add adds an item to the end of the container, if not already present.
|
||||||
// Adding nil, or a component already present in the container, does nothing.
|
// Adding nil, or a component already present in the container, does nothing.
|
||||||
// Add is _not_ safe to call on a nil *Container.
|
// Add is _not_ safe to call on a nil *Container.
|
||||||
func (c *Container) Add(component interface{}) {
|
func (c *Container) Add(component any) {
|
||||||
if component == nil || c.Contains(component) {
|
if component == nil || c.Contains(component) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func (c *Container) Add(component interface{}) {
|
||||||
// half the slice, the slice is compacted (indexes of items will change).
|
// half the slice, the slice is compacted (indexes of items will change).
|
||||||
// Removing an item not in the Container does nothing.
|
// Removing an item not in the Container does nothing.
|
||||||
// Remove is safe to call on a nil *Container.
|
// Remove is safe to call on a nil *Container.
|
||||||
func (c *Container) Remove(component interface{}) {
|
func (c *Container) Remove(component any) {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ func (c *Container) Remove(component interface{}) {
|
||||||
|
|
||||||
// Contains reports if an item exists in the container.
|
// Contains reports if an item exists in the container.
|
||||||
// Contains is safe to call on a nil *Container.
|
// Contains is safe to call on a nil *Container.
|
||||||
func (c *Container) Contains(component interface{}) bool {
|
func (c *Container) Contains(component any) bool {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ func (c *Container) Contains(component interface{}) bool {
|
||||||
// IndexOf reports if an item exists in the container and returns the index if
|
// IndexOf reports if an item exists in the container and returns the index if
|
||||||
// present.
|
// present.
|
||||||
// IndexOf is safe to call on a nil *Container.
|
// IndexOf is safe to call on a nil *Container.
|
||||||
func (c *Container) IndexOf(component interface{}) (int, bool) {
|
func (c *Container) IndexOf(component any) (int, bool) {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ func (c *Container) ItemCount() int {
|
||||||
|
|
||||||
// Element returns the item at index i, or nil for a free slot.
|
// Element returns the item at index i, or nil for a free slot.
|
||||||
// Element is _not_ safe to call on a nil *Container.
|
// Element is _not_ safe to call on a nil *Container.
|
||||||
func (c *Container) Element(i int) interface{} { return c.items[i] }
|
func (c *Container) Element(i int) any { return c.items[i] }
|
||||||
|
|
||||||
// Len returns the number of items plus the number of nil slots in the container.
|
// Len returns the number of items plus the number of nil slots in the container.
|
||||||
// Len is safe to call on a nil *Container.
|
// Len is safe to call on a nil *Container.
|
||||||
|
|
|
@ -24,10 +24,10 @@ import (
|
||||||
|
|
||||||
func TestMakeContainer(t *testing.T) {
|
func TestMakeContainer(t *testing.T) {
|
||||||
c := MakeContainer(69, 420)
|
c := MakeContainer(69, 420)
|
||||||
if want := []interface{}{69, 420}; !cmp.Equal(c.items, want) {
|
if want := []any{69, 420}; !cmp.Equal(c.items, want) {
|
||||||
t.Errorf("c.items = %v, want %v", c.items, want)
|
t.Errorf("c.items = %v, want %v", c.items, want)
|
||||||
}
|
}
|
||||||
if want := map[interface{}]int{69: 0, 420: 1}; !cmp.Equal(c.reverse, want) {
|
if want := map[any]int{69: 0, 420: 1}; !cmp.Equal(c.reverse, want) {
|
||||||
t.Errorf("c.reverse = %v, want %v", c.reverse, want)
|
t.Errorf("c.reverse = %v, want %v", c.reverse, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func init() {
|
||||||
// the number of tests between components.
|
// the number of tests between components.
|
||||||
type DrawDAG struct {
|
type DrawDAG struct {
|
||||||
ChunkSize int
|
ChunkSize int
|
||||||
Child interface{}
|
Child any
|
||||||
Disables
|
Disables
|
||||||
Hides
|
Hides
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ func (d *DrawDAG) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
hidden bool
|
hidden bool
|
||||||
opts ebiten.DrawImageOptions
|
opts ebiten.DrawImageOptions
|
||||||
}
|
}
|
||||||
cache := map[interface{}]state{
|
cache := map[any]state{
|
||||||
d: {
|
d: {
|
||||||
hidden: false,
|
hidden: false,
|
||||||
opts: *opts,
|
opts: *opts,
|
||||||
|
@ -86,7 +86,7 @@ func (d *DrawDAG) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
}
|
}
|
||||||
// Walk up game tree to find the nearest state in cache.
|
// Walk up game tree to find the nearest state in cache.
|
||||||
var st state
|
var st state
|
||||||
stack := []interface{}{x}
|
stack := []any{x}
|
||||||
for p := d.game.Parent(x); p != nil; p = d.game.Parent(p) {
|
for p := d.game.Parent(x); p != nil; p = d.game.Parent(p) {
|
||||||
if s, found := cache[p]; found {
|
if s, found := cache[p]; found {
|
||||||
st = s
|
st = s
|
||||||
|
@ -168,8 +168,8 @@ func (d *DrawDAG) Update() error {
|
||||||
// Register recursively registers compponent and all descendants that are
|
// Register recursively registers compponent and all descendants that are
|
||||||
// DrawBoxers into internal data structures (the DAG, etc) unless they are
|
// DrawBoxers into internal data structures (the DAG, etc) unless they are
|
||||||
// descendants of a different DrawManager.
|
// descendants of a different DrawManager.
|
||||||
func (d *DrawDAG) Register(component, _ interface{}) error {
|
func (d *DrawDAG) Register(component, _ any) error {
|
||||||
return d.game.Query(component, DrawBoxerType, func(c interface{}) error {
|
return d.game.Query(component, DrawBoxerType, func(c any) error {
|
||||||
if db, ok := c.(DrawBoxer); ok {
|
if db, ok := c.(DrawBoxer); ok {
|
||||||
d.registerOne(db)
|
d.registerOne(db)
|
||||||
}
|
}
|
||||||
|
@ -235,8 +235,8 @@ func (d *DrawDAG) registerOne(x DrawBoxer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unregister unregisters the component and all subcomponents.
|
// Unregister unregisters the component and all subcomponents.
|
||||||
func (d *DrawDAG) Unregister(component interface{}) {
|
func (d *DrawDAG) Unregister(component any) {
|
||||||
d.game.Query(component, DrawBoxerType, func(c interface{}) error {
|
d.game.Query(component, DrawBoxerType, func(c any) error {
|
||||||
if db, ok := c.(DrawBoxer); ok {
|
if db, ok := c.(DrawBoxer); ok {
|
||||||
d.unregisterOne(db)
|
d.unregisterOne(db)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ func init() {
|
||||||
// through the game tree using Query, without any extra sorting based on Z
|
// through the game tree using Query, without any extra sorting based on Z
|
||||||
// values or consideration for DrawOrderer.
|
// values or consideration for DrawOrderer.
|
||||||
type DrawDFS struct {
|
type DrawDFS struct {
|
||||||
Child interface{}
|
Child any
|
||||||
Hides
|
Hides
|
||||||
|
|
||||||
game *Game
|
game *Game
|
||||||
|
@ -49,7 +49,7 @@ func (d *DrawDFS) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
stack := []ebiten.DrawImageOptions{*opts}
|
stack := []ebiten.DrawImageOptions{*opts}
|
||||||
d.game.Query(d, DrawerType,
|
d.game.Query(d, DrawerType,
|
||||||
// visitPre
|
// visitPre
|
||||||
func(x interface{}) error {
|
func(x any) error {
|
||||||
if h, ok := x.(Hider); ok && h.Hidden() {
|
if h, ok := x.(Hider); ok && h.Hidden() {
|
||||||
return Skip
|
return Skip
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (d *DrawDFS) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
// visitPost
|
// visitPost
|
||||||
func(x interface{}) error {
|
func(x any) error {
|
||||||
if _, ok := x.(Transformer); ok {
|
if _, ok := x.(Transformer); ok {
|
||||||
stack = stack[:len(stack)-1]
|
stack = stack[:len(stack)-1]
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,10 +60,10 @@ type Game struct {
|
||||||
VoxelScale geom.Float3
|
VoxelScale geom.Float3
|
||||||
|
|
||||||
dbmu sync.RWMutex
|
dbmu sync.RWMutex
|
||||||
byID map[string]Identifier // Named components by ID
|
byID map[string]Identifier // Named components by ID
|
||||||
byAB map[abKey]*Container // paths matching interface
|
byAB map[abKey]*Container // paths matching interface
|
||||||
parent map[interface{}]interface{} // parent[x] is parent of x
|
parent map[any]any // parent[x] is parent of x
|
||||||
children map[interface{}]*Container // children[x] are chilren of x
|
children map[any]*Container // children[x] are children of x
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw draws everything.
|
// Draw draws everything.
|
||||||
|
@ -84,14 +84,14 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (w, h int) {
|
||||||
// not updated.
|
// not updated.
|
||||||
func (g *Game) Update() error {
|
func (g *Game) Update() error {
|
||||||
return g.Query(g.Root, UpdaterType,
|
return g.Query(g.Root, UpdaterType,
|
||||||
func(c interface{}) error {
|
func(c any) error {
|
||||||
if d, ok := c.(Disabler); ok && d.Disabled() {
|
if d, ok := c.(Disabler); ok && d.Disabled() {
|
||||||
// Do not update this component or descendants.
|
// Do not update this component or descendants.
|
||||||
return Skip
|
return Skip
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
func(c interface{}) error {
|
func(c any) error {
|
||||||
if u, ok := c.(Updater); ok {
|
if u, ok := c.(Updater); ok {
|
||||||
return u.Update()
|
return u.Update()
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ func (g *Game) Component(id string) Identifier {
|
||||||
|
|
||||||
// Parent returns the parent of a given component, or nil if there is none.
|
// Parent returns the parent of a given component, or nil if there is none.
|
||||||
// This only returns sensible values for registered components.
|
// This only returns sensible values for registered components.
|
||||||
func (g *Game) Parent(c interface{}) interface{} {
|
func (g *Game) Parent(c any) any {
|
||||||
g.dbmu.RLock()
|
g.dbmu.RLock()
|
||||||
defer g.dbmu.RUnlock()
|
defer g.dbmu.RUnlock()
|
||||||
return g.parent[c]
|
return g.parent[c]
|
||||||
|
@ -122,7 +122,7 @@ func (g *Game) Parent(c interface{}) interface{} {
|
||||||
|
|
||||||
// Children returns the direct subcomponents of the given component, or nil if
|
// Children returns the direct subcomponents of the given component, or nil if
|
||||||
// there are none. This only returns sensible values for registered components.
|
// there are none. This only returns sensible values for registered components.
|
||||||
func (g *Game) Children(c interface{}) *Container {
|
func (g *Game) Children(c any) *Container[any] {
|
||||||
g.dbmu.RLock()
|
g.dbmu.RLock()
|
||||||
defer g.dbmu.RUnlock()
|
defer g.dbmu.RUnlock()
|
||||||
return g.children[c]
|
return g.children[c]
|
||||||
|
@ -130,7 +130,7 @@ func (g *Game) Children(c interface{}) *Container {
|
||||||
|
|
||||||
// PathRegister calls Register on every Registrar in the path between g and
|
// PathRegister calls Register on every Registrar in the path between g and
|
||||||
// parent (top-to-bottom, i.e. game first, component last).
|
// parent (top-to-bottom, i.e. game first, component last).
|
||||||
func (g *Game) PathRegister(component, parent interface{}) error {
|
func (g *Game) PathRegister(component, parent any) error {
|
||||||
for _, p := range g.Path(parent) {
|
for _, p := range g.Path(parent) {
|
||||||
if r, ok := p.(Registrar); ok {
|
if r, ok := p.(Registrar); ok {
|
||||||
if err := r.Register(component, parent); err != nil {
|
if err := r.Register(component, parent); err != nil {
|
||||||
|
@ -143,7 +143,7 @@ func (g *Game) PathRegister(component, parent interface{}) error {
|
||||||
|
|
||||||
// PathUnregister calls Unregister on every Registrar in the path between g and
|
// PathUnregister calls Unregister on every Registrar in the path between g and
|
||||||
// parent (bottom-to-top, i.e. component first, game last).
|
// parent (bottom-to-top, i.e. component first, game last).
|
||||||
func (g *Game) PathUnregister(component interface{}) {
|
func (g *Game) PathUnregister(component any) {
|
||||||
for _, p := range g.ReversePath(component) {
|
for _, p := range g.ReversePath(component) {
|
||||||
if r, ok := p.(Registrar); ok {
|
if r, ok := p.(Registrar); ok {
|
||||||
r.Unregister(component)
|
r.Unregister(component)
|
||||||
|
@ -153,7 +153,7 @@ func (g *Game) PathUnregister(component interface{}) {
|
||||||
|
|
||||||
// Path returns a slice with the path of components to reach component from g
|
// Path returns a slice with the path of components to reach component from g
|
||||||
// (including g and component).
|
// (including g and component).
|
||||||
func (g *Game) Path(component interface{}) []interface{} {
|
func (g *Game) Path(component any) []any {
|
||||||
stack := g.ReversePath(component)
|
stack := g.ReversePath(component)
|
||||||
for i, j := 0, len(stack)-1; i < j; i, j = i+1, j-1 {
|
for i, j := 0, len(stack)-1; i < j; i, j = i+1, j-1 {
|
||||||
stack[i], stack[j] = stack[j], stack[i]
|
stack[i], stack[j] = stack[j], stack[i]
|
||||||
|
@ -163,8 +163,8 @@ func (g *Game) Path(component interface{}) []interface{} {
|
||||||
|
|
||||||
// ReversePath returns the same slice as Path, but reversed. (ReversePath is
|
// ReversePath returns the same slice as Path, but reversed. (ReversePath is
|
||||||
// faster than Path).
|
// faster than Path).
|
||||||
func (g *Game) ReversePath(component interface{}) []interface{} {
|
func (g *Game) ReversePath(component any) []any {
|
||||||
var stack []interface{}
|
var stack []any
|
||||||
g.dbmu.RLock()
|
g.dbmu.RLock()
|
||||||
for p := component; p != nil; p = g.parent[p] {
|
for p := component; p != nil; p = g.parent[p] {
|
||||||
stack = append(stack, p)
|
stack = append(stack, p)
|
||||||
|
@ -194,7 +194,7 @@ func (g *Game) ReversePath(component interface{}) []interface{} {
|
||||||
// Skip when it is returned from a recursive call. Returning Skip from visitPre
|
// Skip when it is returned from a recursive call. Returning Skip from visitPre
|
||||||
// will cause visitPost and the descendants of the component to be skipped (see
|
// will cause visitPost and the descendants of the component to be skipped (see
|
||||||
// the implementation of Update for an example of how to use this).
|
// the implementation of Update for an example of how to use this).
|
||||||
func (g *Game) Query(ancestor interface{}, behaviour reflect.Type, visitPre, visitPost VisitFunc) error {
|
func (g *Game) Query(ancestor any, behaviour reflect.Type, visitPre, visitPost VisitFunc) error {
|
||||||
if visitPre != nil {
|
if visitPre != nil {
|
||||||
if err := visitPre(ancestor); err != nil {
|
if err := visitPre(ancestor); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -208,7 +208,7 @@ func (g *Game) Query(ancestor interface{}, behaviour reflect.Type, visitPre, vis
|
||||||
g.dbmu.RLock()
|
g.dbmu.RLock()
|
||||||
q := g.byAB[abKey{ancestor, behaviour}]
|
q := g.byAB[abKey{ancestor, behaviour}]
|
||||||
g.dbmu.RUnlock()
|
g.dbmu.RUnlock()
|
||||||
if err := q.Scan(func(x interface{}) error {
|
if err := q.Scan(func(x any) error {
|
||||||
if err := g.Query(x, behaviour, visitPre, visitPost); err != nil {
|
if err := g.Query(x, behaviour, visitPre, visitPost); err != nil {
|
||||||
if errors.Is(err, Skip) {
|
if errors.Is(err, Skip) {
|
||||||
return nil
|
return nil
|
||||||
|
@ -232,7 +232,7 @@ func (g *Game) Scan(visit VisitFunc) error {
|
||||||
|
|
||||||
// Load loads a component and all subcomponents recursively.
|
// Load loads a component and all subcomponents recursively.
|
||||||
// Note that this method does not implement Loader itself.
|
// Note that this method does not implement Loader itself.
|
||||||
func (g *Game) Load(component interface{}, assets fs.FS) error {
|
func (g *Game) Load(component any, assets fs.FS) error {
|
||||||
// Query cannot be used for this method because Load might cause
|
// Query cannot be used for this method because Load might cause
|
||||||
// subcomponents to spring into existence.
|
// subcomponents to spring into existence.
|
||||||
if l, ok := component.(Loader); ok {
|
if l, ok := component.(Loader); ok {
|
||||||
|
@ -241,7 +241,7 @@ func (g *Game) Load(component interface{}, assets fs.FS) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if sc, ok := component.(Scanner); ok {
|
if sc, ok := component.(Scanner); ok {
|
||||||
return sc.Scan(func(x interface{}) error {
|
return sc.Scan(func(x any) error {
|
||||||
return g.Load(x, assets)
|
return g.Load(x, assets)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -250,10 +250,10 @@ func (g *Game) Load(component interface{}, assets fs.FS) error {
|
||||||
|
|
||||||
// Prepare prepares a component and all subcomponents recursively.
|
// Prepare prepares a component and all subcomponents recursively.
|
||||||
// Note that this method does not implement Prepper itself.
|
// Note that this method does not implement Prepper itself.
|
||||||
func (g *Game) Prepare(component interface{}) error {
|
func (g *Game) Prepare(component any) error {
|
||||||
// Postorder traversal, in case ancestors depend on descendants being
|
// Postorder traversal, in case ancestors depend on descendants being
|
||||||
// ready to answer queries.
|
// ready to answer queries.
|
||||||
return g.Query(component, PrepperType, nil, func(c interface{}) error {
|
return g.Query(component, PrepperType, nil, func(c any) error {
|
||||||
if p, ok := c.(Prepper); ok {
|
if p, ok := c.(Prepper); ok {
|
||||||
return p.Prepare(g)
|
return p.Prepare(g)
|
||||||
}
|
}
|
||||||
|
@ -300,8 +300,8 @@ func (g *Game) build() error {
|
||||||
defer g.dbmu.Unlock()
|
defer g.dbmu.Unlock()
|
||||||
g.byID = make(map[string]Identifier)
|
g.byID = make(map[string]Identifier)
|
||||||
g.byAB = make(map[abKey]*Container)
|
g.byAB = make(map[abKey]*Container)
|
||||||
g.parent = make(map[interface{}]interface{})
|
g.parent = make(map[any]any)
|
||||||
g.children = make(map[interface{}]*Container)
|
g.children = make(map[any]*Container)
|
||||||
return g.registerRecursive(g, nil)
|
return g.registerRecursive(g, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ func (g *Game) build() error {
|
||||||
// Registering multiple components with the same ID is also an error.
|
// Registering multiple components with the same ID is also an error.
|
||||||
// Registering a component will recursively register all children found via
|
// Registering a component will recursively register all children found via
|
||||||
// Scan.
|
// Scan.
|
||||||
func (g *Game) Register(component, parent interface{}) error {
|
func (g *Game) Register(component, parent any) error {
|
||||||
if component == nil {
|
if component == nil {
|
||||||
return errNilComponent
|
return errNilComponent
|
||||||
}
|
}
|
||||||
|
@ -322,19 +322,19 @@ func (g *Game) Register(component, parent interface{}) error {
|
||||||
return g.registerRecursive(component, parent)
|
return g.registerRecursive(component, parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) registerRecursive(component, parent interface{}) error {
|
func (g *Game) registerRecursive(component, parent any) error {
|
||||||
if err := g.registerOne(component, parent); err != nil {
|
if err := g.registerOne(component, parent); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if sc, ok := component.(Scanner); ok {
|
if sc, ok := component.(Scanner); ok {
|
||||||
return sc.Scan(func(x interface{}) error {
|
return sc.Scan(func(x any) error {
|
||||||
return g.registerRecursive(x, component)
|
return g.registerRecursive(x, component)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) registerOne(component, parent interface{}) error {
|
func (g *Game) registerOne(component, parent any) error {
|
||||||
// register in g.byID if needed
|
// register in g.byID if needed
|
||||||
if i, ok := component.(Identifier); ok {
|
if i, ok := component.(Identifier); ok {
|
||||||
if id := i.Ident(); id != "" {
|
if id := i.Ident(); id != "" {
|
||||||
|
@ -377,7 +377,7 @@ func (g *Game) registerOne(component, parent interface{}) error {
|
||||||
// Unregister removes the component from the component database.
|
// Unregister removes the component from the component database.
|
||||||
// Passing a nil component has no effect. Unregistering a component will
|
// Passing a nil component has no effect. Unregistering a component will
|
||||||
// recursively unregister child components found via Scan.
|
// recursively unregister child components found via Scan.
|
||||||
func (g *Game) Unregister(component interface{}) {
|
func (g *Game) Unregister(component any) {
|
||||||
if component == nil {
|
if component == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -386,15 +386,15 @@ func (g *Game) Unregister(component interface{}) {
|
||||||
g.dbmu.Unlock()
|
g.dbmu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) unregisterRecursive(component interface{}) {
|
func (g *Game) unregisterRecursive(component any) {
|
||||||
g.children[component].Scan(func(x interface{}) error {
|
g.children[component].Scan(func(x any) error {
|
||||||
g.unregisterRecursive(x)
|
g.unregisterRecursive(x)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
g.unregisterOne(component)
|
g.unregisterOne(component)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) unregisterOne(component interface{}) {
|
func (g *Game) unregisterOne(component any) {
|
||||||
parent := g.parent[component]
|
parent := g.parent[component]
|
||||||
|
|
||||||
// unregister from g.byAB
|
// unregister from g.byAB
|
||||||
|
@ -428,7 +428,7 @@ func (g *Game) String() string { return "Game" }
|
||||||
|
|
||||||
// abKey is the key type for game.byAB.
|
// abKey is the key type for game.byAB.
|
||||||
type abKey struct {
|
type abKey struct {
|
||||||
parent interface{}
|
parent any
|
||||||
behaviour reflect.Type
|
behaviour reflect.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,10 +453,10 @@ func concatOpts(a, b ebiten.DrawImageOptions) ebiten.DrawImageOptions {
|
||||||
// For example, Query takes two VisitFuncs that are called for each result, and
|
// For example, Query takes two VisitFuncs that are called for each result, and
|
||||||
// Scan is given a VisitFunc that should be called with each component. For
|
// Scan is given a VisitFunc that should be called with each component. For
|
||||||
// recursive operations, return Skip for components that should be skipped.
|
// recursive operations, return Skip for components that should be skipped.
|
||||||
type VisitFunc func(interface{}) error
|
type VisitFunc func(any) error
|
||||||
|
|
||||||
// Many calls a VisitFunc for multiple args, and returns on first non-nil error.
|
// Many calls a VisitFunc for multiple args, and returns on first non-nil error.
|
||||||
func (v VisitFunc) Many(x ...interface{}) error {
|
func (v VisitFunc) Many(x ...any) error {
|
||||||
for _, c := range x {
|
for _, c := range x {
|
||||||
if err := v(c); err != nil {
|
if err := v(c); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -150,8 +150,8 @@ type Prepper interface {
|
||||||
// into internal data structures). Registrars are expected to automatically
|
// into internal data structures). Registrars are expected to automatically
|
||||||
// register/unregister subcomponents of components (usually recursively).
|
// register/unregister subcomponents of components (usually recursively).
|
||||||
type Registrar interface {
|
type Registrar interface {
|
||||||
Register(component, parent interface{}) error
|
Register(component, parent any) error
|
||||||
Unregister(component interface{})
|
Unregister(component any)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Saver components can be saved to disk.
|
// Saver components can be saved to disk.
|
||||||
|
|
|
@ -39,7 +39,7 @@ func init() {
|
||||||
type Parallax struct {
|
type Parallax struct {
|
||||||
CameraID string
|
CameraID string
|
||||||
Factor float64 // how much to translate in response to the camera
|
Factor float64 // how much to translate in response to the camera
|
||||||
Child interface{}
|
Child any
|
||||||
|
|
||||||
camera *Camera
|
camera *Camera
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ func (g *Game) cmdTree(dst io.Writer, argv []string) {
|
||||||
fmt.Println(dst, "Usage: tree [ID]")
|
fmt.Println(dst, "Usage: tree [ID]")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c := interface{}(g)
|
c := any(g)
|
||||||
if len(argv) == 2 { // subtree
|
if len(argv) == 2 { // subtree
|
||||||
id := argv[1]
|
id := argv[1]
|
||||||
c = g.Component(id)
|
c = g.Component(id)
|
||||||
|
@ -107,7 +107,7 @@ func (g *Game) cmdTree(dst io.Writer, argv []string) {
|
||||||
g.printTreeRecursive(dst, 0, c)
|
g.printTreeRecursive(dst, 0, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) printTreeRecursive(dst io.Writer, depth int, c interface{}) {
|
func (g *Game) printTreeRecursive(dst io.Writer, depth int, c any) {
|
||||||
indent := ""
|
indent := ""
|
||||||
if depth > 0 {
|
if depth > 0 {
|
||||||
indent = strings.Repeat(" ", depth-1) + "↳ "
|
indent = strings.Repeat(" ", depth-1) + "↳ "
|
||||||
|
@ -118,7 +118,7 @@ func (g *Game) printTreeRecursive(dst io.Writer, depth int, c interface{}) {
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(dst, "%s%v\n", indent, c)
|
fmt.Fprintf(dst, "%s%v\n", indent, c)
|
||||||
}
|
}
|
||||||
g.Children(c).Scan(func(x interface{}) error {
|
g.Children(c).Scan(func(x any) error {
|
||||||
g.printTreeRecursive(dst, depth+1, x)
|
g.printTreeRecursive(dst, depth+1, x)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -145,7 +145,7 @@ func (g *Game) cmdQuery(dst io.Writer, argv []string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var ancestor interface{} = g
|
var ancestor any = g
|
||||||
if len(argv) == 3 {
|
if len(argv) == 3 {
|
||||||
c := g.Component(argv[2])
|
c := g.Component(argv[2])
|
||||||
if c == nil {
|
if c == nil {
|
||||||
|
@ -156,7 +156,7 @@ func (g *Game) cmdQuery(dst io.Writer, argv []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
noResults := true
|
noResults := true
|
||||||
g.Query(ancestor, behaviour, func(c interface{}) error {
|
g.Query(ancestor, behaviour, func(c any) error {
|
||||||
if !reflect.TypeOf(c).Implements(behaviour) {
|
if !reflect.TypeOf(c).Implements(behaviour) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ func (g *Game) cmdQuery(dst io.Writer, argv []string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Game) cmdutilComponentArg1(dst io.Writer, argv []string) interface{} {
|
func (g *Game) cmdutilComponentArg1(dst io.Writer, argv []string) any {
|
||||||
if len(argv) != 2 {
|
if len(argv) != 2 {
|
||||||
fmt.Fprintln(dst, "Usage: hide ID")
|
fmt.Fprintln(dst, "Usage: hide ID")
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -49,7 +49,7 @@ func init() {
|
||||||
type Scene struct {
|
type Scene struct {
|
||||||
ID
|
ID
|
||||||
Bounds // world coordinates
|
Bounds // world coordinates
|
||||||
Child interface{}
|
Child any
|
||||||
Disables
|
Disables
|
||||||
Hides
|
Hides
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func (s *Scene) String() string { return "Scene" }
|
||||||
// This is mostly useful for scenes that refer to other scenes, e.g.
|
// This is mostly useful for scenes that refer to other scenes, e.g.
|
||||||
//
|
//
|
||||||
// sc := &Scene{
|
// sc := &Scene{
|
||||||
// Components: []interface{}{
|
// Components: []any{
|
||||||
// &SceneRef{Path: "assets/foo.gob.gz"} // inflated at Load time
|
// &SceneRef{Path: "assets/foo.gob.gz"} // inflated at Load time
|
||||||
// },
|
// },
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -64,7 +64,7 @@ func main() {
|
||||||
ebiten.SetWindowTitle("TODO")
|
ebiten.SetWindowTitle("TODO")
|
||||||
|
|
||||||
// Change to true to rewrite level1.gobz
|
// Change to true to rewrite level1.gobz
|
||||||
lev1 := interface{}(&engine.SceneRef{Path: "assets/level1.gobz"})
|
lev1 := any(&engine.SceneRef{Path: "assets/level1.gobz"})
|
||||||
if hardcodedLevel1 {
|
if hardcodedLevel1 {
|
||||||
lev1 = example.Level1()
|
lev1 = example.Level1()
|
||||||
if rewriteLevel1 && runtime.GOOS != "js" {
|
if rewriteLevel1 && runtime.GOOS != "js" {
|
||||||
|
|
Loading…
Reference in a new issue