-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
system_test.go
74 lines (67 loc) · 1.83 KB
/
system_test.go
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
package ecs
import (
"fmt"
"testing"
"time"
)
// // func physicsSystem(id Id, pos *Position, vel *Velocity) {
// 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(world, physicsSystem)
// sys.Run(16 * time.Millisecond)
// }
var lastTime time.Time
func TestSchedulerPhysics(t *testing.T) {
scheduler := NewScheduler()
scheduler.AppendPhysics(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) {
scheduler := NewScheduler()
scheduler.AppendInput(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.AppendPhysics(System{
Name: "TestSystemPhysics",
Func: func(dt time.Duration) {
fmt.Printf("Physics: %v - %v\n", dt, time.Since(lastTimePhysics))
lastTimePhysics = time.Now()
},
})
scheduler.AppendRender(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)
}