From 3c3dd9f40887d4774c5f7d4a4a5404f73421f53f Mon Sep 17 00:00:00 2001 From: walker Date: Mon, 14 Aug 2023 14:48:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=80=9A=E7=94=A8=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E8=B0=83=E6=95=B4example=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common_component.go | 9 --------- examples/rtss/component/basic.go | 7 +++++++ examples/rtss/main.go | 5 +++-- examples/rtss/sys/trunout.sys.go | 7 ++++--- 4 files changed, 14 insertions(+), 14 deletions(-) delete mode 100644 common_component.go create mode 100644 examples/rtss/component/basic.go diff --git a/common_component.go b/common_component.go deleted file mode 100644 index 9fa0d4b..0000000 --- a/common_component.go +++ /dev/null @@ -1,9 +0,0 @@ -package ecs - -type Id string - -var IdComp = NewComponentType[Id]() - -// func IdComp() *ComponentType[Id] { -// return NewComponentType[Id]() -// } diff --git a/examples/rtss/component/basic.go b/examples/rtss/component/basic.go new file mode 100644 index 0000000..90772c8 --- /dev/null +++ b/examples/rtss/component/basic.go @@ -0,0 +1,7 @@ +package component + +import "joylink.club/ecs" + +type Id string + +var IdComp = ecs.NewComponentType[Id]() diff --git a/examples/rtss/main.go b/examples/rtss/main.go index e23fdf9..2ec07d9 100644 --- a/examples/rtss/main.go +++ b/examples/rtss/main.go @@ -5,6 +5,7 @@ import ( "time" "joylink.club/ecs" + "joylink.club/ecs/examples/rtss/component" system "joylink.club/ecs/examples/rtss/sys" ) @@ -15,10 +16,10 @@ func main() { w := ecs.NewWorld(20) turnoutSys := system.NewTurnoutSys() w.AddSystem(turnoutSys) - idcomp := ecs.IdComp + idcomp := component.IdComp entities := w.CreateMany(10, idcomp, system.TurnoutStateComp) for i, entry := range entities { - idcomp.SetValue(entry, ecs.Id(fmt.Sprintf("%d", i))) + idcomp.SetValue(entry, component.Id(fmt.Sprintf("%d", i))) var db bool var fb bool if i%2 == 0 { diff --git a/examples/rtss/sys/trunout.sys.go b/examples/rtss/sys/trunout.sys.go index 2f6134e..bfca4bf 100644 --- a/examples/rtss/sys/trunout.sys.go +++ b/examples/rtss/sys/trunout.sys.go @@ -5,6 +5,7 @@ import ( "github.com/yohamta/donburi/filter" "joylink.club/ecs" + "joylink.club/ecs/examples/rtss/component" ) type TurnoutState struct { @@ -40,11 +41,11 @@ func (sys *TurnoutSys) Update(w ecs.World) { // 道岔定操 func DingCao(w ecs.World, id string) { - query := ecs.NewQuery(filter.Contains(ecs.IdComp, TurnoutStateComp)) + query := ecs.NewQuery(filter.Contains(component.IdComp, TurnoutStateComp)) query.Each(w, func(entry *ecs.Entry) { // log.Println("存在id组件") - idcomp := ecs.IdComp.Get(entry) - if *idcomp == ecs.Id(id) { + idcomp := component.IdComp.Get(entry) + if *idcomp == component.Id(id) { ts := TurnoutStateComp.Get(entry) ts.Dc = true log.Println("id=", w.Id(), "的仿真", "道岔定操: id=", id)