simple ecs system

This commit is contained in:
Tnze
2022-05-23 10:04:01 +08:00
parent a5dd70d1ea
commit d2f7db9d0d
9 changed files with 239 additions and 110 deletions

View File

@ -0,0 +1,27 @@
package ecs
import "testing"
func Test_common(t *testing.T) {
// W
w := NewWorld()
// C
type pos [2]int
type vel [2]int
Register(w, pos{})
Register(w, vel{})
// E
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)
})
// Run
s1.Update(w)
s2.Update(w)
}