道岔测试

This commit is contained in:
xzb 2023-09-26 18:08:34 +08:00
parent f91a8bca38
commit 421311ede4

View File

@ -1,9 +1,11 @@
package world
import (
"fmt"
"github.com/yohamta/donburi/filter"
"joylink.club/ecs"
"joylink.club/rtsssimulation/entities"
"joylink.club/rtsssimulation/examples/test1/tmodel"
"joylink.club/rtsssimulation/repository"
"joylink.club/rtsssimulation/simulation"
"joylink.club/rtsssimulation/system"
@ -48,7 +50,7 @@ func InitializeWorld(config *WorldConfig) ecs.World {
return world
}
func InitComponent(world ecs.World, repo *repository.Repository) {
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)
@ -188,3 +190,103 @@ func InitComponent(world ecs.World, repo *repository.Repository) {
}
})
}
// 初始化组件状态
func InitComponent(w ecs.World, repo *repository.Repository) {
//双机zdj9道岔相关继电器的状态初始化
switchQuery := ecs.NewQuery(filter.Contains(system.Switch2jZdj9StateComponent))
switchQuery.Each(w, func(e *ecs.Entry) {
swId := system.EntityIdentityComponent.Get(e).Id
swState := system.Switch2jZdj9StateComponent.Get(e)
swMd := system.FindModelStorage(w).FindById(swId).(*tmodel.SwitchModel)
for _, relay := range swMd.Relays {
relayId := relay.Relay.(system.IDeviceModel).Id()
relayEntry := system.FindEntityById(w, relayId)
relayState := system.RelayStateComponent.Get(relayEntry)
relayGroup := relay.RelayGroup
relayName := relay.RelayName
switch relayGroup {
case system.SJZDJ9_TDC:
{
switch relayName {
case system.SJZDJ9_DCJ:
relayState.Xh = swState.DCJ
relayState.ResetNeedXh()
case system.SJZDJ9_FCJ:
relayState.Xh = swState.FCJ
relayState.ResetNeedXh()
case system.SJZDJ9_YCJ:
relayState.Xh = swState.YCJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZDBJ:
relayState.Xh = swState.ZDBJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZFBJ:
relayState.Xh = swState.ZFBJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
case system.SJZDJ9_TDFJ1:
{
switch relayName {
case system.SJZDJ9_1DQJ:
relayState.Xh = swState.J1_1DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_BHJ:
relayState.Xh = swState.J1_BHJ
relayState.ResetNeedXh()
case system.SJZDJ9_2DQJ:
relayState.Xh = swState.J1_2DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_1DQJF:
relayState.Xh = swState.J1_1DQJF
relayState.ResetNeedXh()
case system.SJZDJ9_DBJ:
relayState.Xh = swState.J1_DBJ
relayState.ResetNeedXh()
case system.SJZDJ9_FBJ:
relayState.Xh = swState.J1_FBJ
relayState.ResetNeedXh()
case system.SJZDJ9_QDJ:
relayState.Xh = swState.J1_QDJ
relayState.ResetNeedXh()
case system.SJZDJ9_ZBHJ:
relayState.Xh = swState.J1_ZBHJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
case system.SJZDJ9_TDFJ2:
{
switch relayName {
case system.SJZDJ9_1DQJ:
relayState.Xh = swState.J2_1DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_BHJ:
relayState.Xh = swState.J2_BHJ
relayState.ResetNeedXh()
case system.SJZDJ9_2DQJ:
relayState.Xh = swState.J2_2DQJ
relayState.ResetNeedXh()
case system.SJZDJ9_1DQJF:
relayState.Xh = swState.J2_1DQJF
relayState.ResetNeedXh()
case system.SJZDJ9_DBJ:
relayState.Xh = swState.J2_DBJ
relayState.ResetNeedXh()
case system.SJZDJ9_FBJ:
relayState.Xh = swState.J2_FBJ
relayState.ResetNeedXh()
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器功能名称[%s]无法识别", swId, relayName))
}
}
default:
panic(fmt.Sprintf("SwitchZdj9的模型[%s]中继电器组合类型[%s]无法识别", swId, relayGroup))
}
} //for
})
}