-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample_test.go
More file actions
47 lines (40 loc) · 1.21 KB
/
Copy pathexample_test.go
File metadata and controls
47 lines (40 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package akara_test
import (
"fmt"
"time"
"github.com/gravestench/akara"
)
type examplePosition struct{ X, Y float64 }
type exampleVelocity struct{ X, Y float64 }
func ExampleRegister() {
world := akara.NewWorld()
defer func() { _ = world.Close() }()
positions := akara.Register[examplePosition](world)
entity := world.MustCreateEntity()
position, _ := positions.Set(entity, examplePosition{X: 12, Y: 4})
fmt.Println(position.X, position.Y)
// Output: 12 4
}
func ExampleWorld_Subscribe() {
world := akara.NewWorld()
defer func() { _ = world.Close() }()
positions := akara.Register[examplePosition](world)
velocities := akara.Register[exampleVelocity](world)
moving, _ := world.Subscribe(akara.All(positions, velocities))
defer func() { _ = moving.Close() }()
entity := world.MustCreateEntity()
_, _ = positions.Add(entity)
_, _ = velocities.Set(entity, exampleVelocity{X: 2})
fmt.Println(moving.Entities())
// Output: [1]
}
func ExampleWorld_Update() {
world := akara.NewWorld()
defer func() { _ = world.Close() }()
_, _ = world.AddSystem(akara.SystemFunc(func(_ *akara.World, delta time.Duration) error {
fmt.Println(delta)
return nil
}))
_ = world.Update(16 * time.Millisecond)
// Output: 16ms
}