-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsystem_test.go
More file actions
92 lines (82 loc) · 2.24 KB
/
system_test.go
File metadata and controls
92 lines (82 loc) · 2.24 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package ecs
import (
"fmt"
"testing"
"time"
)
// // Note: You can do this to pack more queries in
// type custom struct {
// query1 *View2[position, velocity]
// query2 *View2[position, velocity]
// }
// func (c *custom) initialize(world *World) any {
// return &custom{
// GetInjectable[*View2[position, velocity]](world),
// GetInjectable[*View2[position, velocity]](world),
// }
// }
func physicsSystem(dt time.Duration, query *View2[position, velocity]) {
query.MapId(func(id Id, pos *position, vel *velocity) {
pos.x += vel.x * dt.Seconds()
pos.y += vel.y * dt.Seconds()
pos.z += vel.z * dt.Seconds()
})
}
func TestSystemCreationNew(t *testing.T) {
world := setupPhysics(100)
sys := NewSystem1(physicsSystem).Build(world)
fmt.Println("NAME", sys.Name)
for range 100 {
sys.step(16 * time.Millisecond)
}
}
var lastTime time.Time
func TestSchedulerPhysics(t *testing.T) {
world := NewWorld()
scheduler := NewScheduler(world)
scheduler.AddSystems(StageFixedUpdate, System{
Name: "TestSystem",
Func: func(dt time.Duration) {
fmt.Printf("%v - %v\n", dt, time.Since(lastTime))
lastTime = time.Now()
},
})
lastTime = time.Now()
go scheduler.Run()
time.Sleep(1 * time.Second)
scheduler.SetQuit(true)
}
var lastTimeInput, lastTimePhysics, lastTimeRender time.Time
func TestSchedulerAll(t *testing.T) {
world := NewWorld()
scheduler := NewScheduler(world)
scheduler.AddSystems(StagePreUpdate, System{
Name: "TestSystemInput",
Func: func(dt time.Duration) {
fmt.Printf("Input: %v - %v\n", dt, time.Since(lastTimeInput))
lastTimeInput = time.Now()
time.Sleep(1 * time.Millisecond)
},
})
scheduler.AddSystems(StageFixedUpdate, System{
Name: "TestSystemPhysics",
Func: func(dt time.Duration) {
fmt.Printf("Physics: %v - %v\n", dt, time.Since(lastTimePhysics))
lastTimePhysics = time.Now()
},
})
scheduler.AddSystems(StageUpdate, System{
Name: "TestSystemRender",
Func: func(dt time.Duration) {
fmt.Printf("Render: %v - %v\n", dt, time.Since(lastTimeRender))
lastTimeRender = time.Now()
time.Sleep(100 * time.Millisecond)
},
})
lastTimeInput = time.Now()
lastTimePhysics = time.Now()
lastTimeRender = time.Now()
go scheduler.Run()
time.Sleep(1 * time.Second)
scheduler.SetQuit(true)
}