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" ) func CreateSimulation(repo *repository.Repository) ecs.WorldId { wc := &WorldConfig{ 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()) //初始化组件 InitComponent(w, repo) //添加监听器 system.Switch2jzdj9AddListeners(w) system.RelayAddListeners(w) //启动 w.StartUp() return w.Id() } // InitializeWorld 初始化仿真world func InitializeWorld(config *WorldConfig) ecs.World { world := ecs.NewWorld(config.Tick) // 添加系统 world.AddSystem(system.NewTimerSystem()) world.AddSystem(system.NewPercentageMovableSystem()) for _, sys := range config.Systems { world.AddSystem(sys) } // 添加内置实体 entities.CreateSystemTimerEntity(world, config.InitTime) entities.CreateModelStorageEntity(world, config.ModelManager) // return world } func InitComponent(world ecs.World, repo *repository.Repository) { query := ecs.NewQuery(filter.Contains(system.Switch2jZdj9StateComponent)) query.Each(world, func(turnoutEntry *ecs.Entry) { turnout := repo.FindTurnout(system.EntityIdentityComponent.Get(turnoutEntry).Id) turnoutState := system.Switch2jZdj9StateComponent.Get(turnoutEntry) { relay := turnout.FindRelay("TDC", "DCJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.DCJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDC", "FCJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.FCJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDC", "YCJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.YCJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDC", "ZDBJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.ZDBJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDC", "ZFBJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.ZFBJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ1", "1DQJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J1_1DQJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ1", "BHJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J1_BHJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ1", "2DQJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J1_2DQJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ1", "1DQJF") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J1_1DQJF relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ1", "DBJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J1_DBJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ1", "FBJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J1_FBJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ1", "QDJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J1_QDJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ1", "ZBHJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J1_ZBHJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ2", "1DQJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J2_1DQJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ2", "BHJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J2_BHJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ2", "2DQJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J2_2DQJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ2", "1DQJF") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J2_1DQJF relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ2", "DBJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J2_DBJ relayState.ResetNeedXh() } { relay := turnout.FindRelay("TDFJ2", "FBJ") relayEntry := system.FindEntityById(world, relay.Id()) relayState := system.RelayStateComponent.Get(relayEntry) relayState.Xh = turnoutState.J2_FBJ relayState.ResetNeedXh() } }) }