From 2209ca130e734cfe8d1e4704f77261b6bd903ea3 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 27 Sep 2023 10:05:59 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E9=81=93=E5=B2=94=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E4=BF=AE=E6=94=B9=E3=80=91=E3=80=90=E4=BB=BF=E7=9C=9F?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=B7=BB=E5=8A=A0=E7=B3=BB=E7=BB=9F=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entities/switch_entity.go | 21 +++++++-------------- simulation/world/init.go | 7 ++++--- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/entities/switch_entity.go b/entities/switch_entity.go index 7657934..eaad158 100644 --- a/entities/switch_entity.go +++ b/entities/switch_entity.go @@ -3,7 +3,6 @@ package entities import ( "time" - "github.com/yohamta/donburi/component" "github.com/yohamta/donburi/filter" "joylink.club/ecs" "joylink.club/rtsssimulation/repository" @@ -44,13 +43,7 @@ func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout) []*ec if len(turnout.RelayGroups()) == 0 { continue } - var components []component.IComponentType - components = append(components, system.EntityIdentityComponent) - components = append(components, system.Switch2jZdj9StateComponent) - entry := world.Create(components...) - entries = append(entries, entry) - system.EntityIdentityComponent.Set(entry, &system.EntityIdentity{Id: turnout.Id()}) - system.Switch2jZdj9StateComponent.Set(entry, system.NewSwitch2jZdj9State()) + entries = append(entries, CreateSwitch2jzdj9Entity(world, turnout.Id())) } return entries } @@ -58,22 +51,22 @@ func CreateTurnoutEntries(world ecs.World, turnouts []*repository.Turnout) []*ec func TurnToNormal(worldId ecs.WorldId, turnoutId string) { sim := simulation.FindSimulation(worldId) system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true) - system.Switch2jZdj9DriveFc(sim.World(), turnoutId, true) + system.Switch2jZdj9DriveDc(sim.World(), turnoutId, true) go func() { - <-time.After(1 * time.Second) + <-time.After(5 * time.Second) system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false) - system.Switch2jZdj9DriveFc(sim.World(), turnoutId, false) + system.Switch2jZdj9DriveDc(sim.World(), turnoutId, false) }() } func TurnToReverse(worldId ecs.WorldId, turnoutId string) { sim := simulation.FindSimulation(worldId) system.Switch2jZdj9DriveYc(sim.World(), turnoutId, true) - system.Switch2jZdj9DriveDc(sim.World(), turnoutId, true) + system.Switch2jZdj9DriveFc(sim.World(), turnoutId, true) go func() { - <-time.After(1 * time.Second) + <-time.After(5 * time.Second) system.Switch2jZdj9DriveYc(sim.World(), turnoutId, false) - system.Switch2jZdj9DriveDc(sim.World(), turnoutId, false) + system.Switch2jZdj9DriveFc(sim.World(), turnoutId, false) }() } diff --git a/simulation/world/init.go b/simulation/world/init.go index 1282a67..bee6476 100644 --- a/simulation/world/init.go +++ b/simulation/world/init.go @@ -1,25 +1,26 @@ package world import ( + "time" + "github.com/yohamta/donburi/filter" "joylink.club/ecs" "joylink.club/rtsssimulation/entities" "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/simulation" "joylink.club/rtsssimulation/system" - "time" ) func CreateSimulation(repo *repository.Repository) ecs.WorldId { - var systems []ecs.ISystem wc := &WorldConfig{ - Systems: systems, + Systems: []ecs.ISystem{system.NewTimerSystem(), system.NewPercentageMovableSystem(), system.NewSwitch2jZdj9System(), system.NewRelaySystem()}, Tick: 200, InitTime: time.Now(), } w := InitializeWorld(wc) simulation.CreateSimulation(repo, w) //添加实体 + entities.CreateSystemTimerEntity(w, wc.InitTime) entities.CreateTurnoutEntries(w, repo.TurnoutList()) entities.CreateRelayEntries(w, repo.RelayList()) //初始化组件