player and dimension loader with ecs system

This commit is contained in:
Tnze
2022-05-27 00:38:46 +08:00
parent d2f7db9d0d
commit 474d6a229b
34 changed files with 956 additions and 795 deletions

34
server/ecs/ecs_test.go Normal file
View File

@ -0,0 +1,34 @@
package ecs
import "testing"
func Test_common(t *testing.T) {
// W
w := NewWorld()
// C
type pos [2]int
type vel [2]int
Register[pos, *HashMapStorage[pos]](w)
Register[vel, *HashMapStorage[vel]](w)
// E
e1 := w.CreateEntity(pos{0, 0})
w.CreateEntity(vel{1, 2})
w.CreateEntity(pos{1, 2}, vel{2, 0})
// S
s1 := FuncSystem(func(p *pos) {
t.Log("system 1", p)
})
s2 := FuncSystem(func(p *pos, v *vel) {
t.Log("system 2", p, v)
})
s3 := FuncSystem(func(p pos, v *vel) {
t.Log("system 2", p, v)
})
// Run
s1.Update(w)
s2.Update(w)
s3.Update(w)
w.DeleteEntity(e1)
s1.Update(w)
}