From 1dc64115db880caacd831dc118868996af6a6bd6 Mon Sep 17 00:00:00 2001 From: walker Date: Mon, 9 Oct 2023 14:24:53 +0800 Subject: [PATCH] =?UTF-8?q?ecs=E6=8E=A5=E5=8F=A3=E5=8F=98=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E5=AE=9E=E4=BD=93=E5=88=9B=E5=BB=BA=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9B=B8=E5=BA=94=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entity/dbq.go | 2 +- entity/relay.go | 2 +- entity/signal.go | 3 ++- entity/singleton.go | 2 +- entity/turnout.go | 4 ++-- examples/main.go | 6 +++++- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/entity/dbq.go b/entity/dbq.go index eaa9ec6..b5bb33c 100644 --- a/entity/dbq.go +++ b/entity/dbq.go @@ -9,7 +9,7 @@ import ( func NewDBQEntity(w ecs.World, uid string, entityMap map[string]*ecs.Entry) *ecs.Entry { entry, ok := entityMap[uid] if !ok { - entry = w.Create(component.DBQTag, component.UidType, component.DBQStateType, component.CounterType) + entry = w.Entry(w.Create(component.DBQTag, component.UidType, component.DBQStateType, component.CounterType)) component.UidType.SetValue(entry, component.Uid{Id: uid}) entityMap[uid] = entry } diff --git a/entity/relay.go b/entity/relay.go index fd2b1dc..44eef0c 100644 --- a/entity/relay.go +++ b/entity/relay.go @@ -15,7 +15,7 @@ func NewRelayEntity(w ecs.World, relay *repository.Relay, entityMap map[string]* model := proto.Relay_Model_name[int32(relay.Model())] entry, ok := entityMap[uid] if !ok { - entry = w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType) + entry = w.Entry(w.Create(component.RelayTag, component.UidType, component.RelayDriveType, component.BitStateType)) component.UidType.SetValue(entry, component.Uid{Id: uid}) if strings.Contains(model, "Y") { // 有极继电器 entry.AddComponent(component.YjRelayTag) diff --git a/entity/signal.go b/entity/signal.go index 335725b..6d63138 100644 --- a/entity/signal.go +++ b/entity/signal.go @@ -2,6 +2,7 @@ package entity import ( "fmt" + "joylink.club/ecs" "joylink.club/rtsssimulation/component" "joylink.club/rtsssimulation/consts" @@ -65,7 +66,7 @@ func LoadSignals(w ecs.World) error { func newSignalEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry { entry, ok := worldData.EntityMap[uid] if !ok { - entry = w.Create(component.UidType) + entry = w.Entry(w.Create(component.UidType)) component.UidType.SetValue(entry, component.Uid{Id: uid}) worldData.EntityMap[uid] = entry } diff --git a/entity/singleton.go b/entity/singleton.go index f88bf7b..54ca42c 100644 --- a/entity/singleton.go +++ b/entity/singleton.go @@ -14,7 +14,7 @@ func LoadWorldData(w ecs.World, repo *repository.Repository) { if repo == nil { panic("repo不能为nil") } - entry := w.Create(component.WorldDataType) + entry := w.Entry(w.Create(component.WorldDataType)) component.WorldDataType.Set(entry, &component.WorldData{ Repo: repo, Time: time.Now().UnixMilli(), diff --git a/entity/turnout.go b/entity/turnout.go index da73d4c..34d7f7e 100644 --- a/entity/turnout.go +++ b/entity/turnout.go @@ -41,7 +41,7 @@ func LoadTurnoutZdj9One(w ecs.World, turnout *repository.Turnout, entry *ecs.Ent // 加载道岔ZDJ9双机转辙机 func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Entry, entityMap map[string]*ecs.Entry) error { // 加载转辙机 - entrys := w.CreateMany(2, component.ZzjStateType, component.TwoPositionTransformType) + entrys := ecs.Entries(w, w.CreateMany(2, component.ZzjStateType, component.TwoPositionTransformType)) // 给道岔添加转辙机引用组件 entry.AddComponent(component.TurnoutZzjType, unsafe.Pointer(&component.TurnoutZzj{ ZzjList: entrys, @@ -144,7 +144,7 @@ func LoadTurnoutZdj9Two(w ecs.World, turnout *repository.Turnout, entry *ecs.Ent func NewTurnoutEntity(w ecs.World, uid string, worldData *component.WorldData) *ecs.Entry { entry, ok := worldData.EntityMap[uid] if !ok { - entry = w.Create(component.TurnoutTag, component.UidType, component.TurnoutPositionType) + entry = w.Entry(w.Create(component.TurnoutTag, component.UidType, component.TurnoutPositionType)) component.UidType.SetValue(entry, component.Uid{Id: uid}) worldData.EntityMap[uid] = entry } diff --git a/examples/main.go b/examples/main.go index f729447..63ecc56 100644 --- a/examples/main.go +++ b/examples/main.go @@ -1,10 +1,14 @@ package main import ( + "fmt" + rtss_simulation "joylink.club/rtsssimulation" "joylink.club/rtsssimulation/repository" ) func main() { - rtss_simulation.NewSimulation(&repository.Repository{}) + sim := rtss_simulation.NewSimulation(&repository.Repository{}) + fmt.Println(sim.Id()) + sim.StartUp() }