2023-09-26 10:25:00 +08:00
|
|
|
package world
|
|
|
|
|
|
|
|
import (
|
2023-09-27 10:05:59 +08:00
|
|
|
"time"
|
|
|
|
|
2023-09-26 10:25:00 +08:00
|
|
|
"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{
|
2023-09-27 10:05:59 +08:00
|
|
|
Systems: []ecs.ISystem{system.NewTimerSystem(), system.NewPercentageMovableSystem(), system.NewSwitch2jZdj9System(), system.NewRelaySystem()},
|
2023-09-26 10:25:00 +08:00
|
|
|
Tick: 200,
|
|
|
|
InitTime: time.Now(),
|
|
|
|
}
|
|
|
|
w := InitializeWorld(wc)
|
|
|
|
simulation.CreateSimulation(repo, w)
|
|
|
|
//添加实体
|
2023-09-27 10:05:59 +08:00
|
|
|
entities.CreateSystemTimerEntity(w, wc.InitTime)
|
2023-09-26 10:25:00 +08:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|