2023-10-09 10:30:44 +08:00
|
|
|
package circuit_sys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"joylink.club/ecs"
|
2023-10-09 13:23:34 +08:00
|
|
|
"joylink.club/ecs/filter"
|
2023-10-09 10:30:44 +08:00
|
|
|
"joylink.club/rtsssimulation/component"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SignalJCKXHSystem struct {
|
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSignalJCKXHSystem() *SignalJCKXHSystem {
|
2023-10-12 17:33:20 +08:00
|
|
|
return &SignalJCKXHSystem{query: ecs.NewQuery(filter.Contains(
|
|
|
|
component.SignalJCKXHElectronicType,
|
|
|
|
component.SignalJCKXHLsqType,
|
|
|
|
component.SignalJCKXHLscType,
|
|
|
|
component.SignalLightsType))}
|
2023-10-09 10:30:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update world 执行
|
|
|
|
func (s *SignalJCKXHSystem) Update(w ecs.World) {
|
2023-10-12 17:33:20 +08:00
|
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
|
|
state := component.SignalJCKXHElectronicType.Get(entry)
|
|
|
|
lsq := component.SignalJCKXHLsqType.Get(entry)
|
|
|
|
lsc := component.SignalJCKXHLscType.Get(entry)
|
|
|
|
lights := component.SignalLightsType.Get(entry)
|
|
|
|
JCKXH_H := lights.GetLightByTag(component.HdTag)
|
|
|
|
JCKXH_B := lights.GetLightByTag(component.BdTag)
|
|
|
|
JCKXH_U := lights.GetLightByTag(component.UdTag)
|
2023-10-09 10:30:44 +08:00
|
|
|
//
|
2023-10-12 17:33:20 +08:00
|
|
|
s.calculateLsq(state, lsq)
|
|
|
|
s.calculateU(state, JCKXH_U)
|
|
|
|
s.calculateB(state, JCKXH_B)
|
|
|
|
s.calculateH(state, JCKXH_H)
|
|
|
|
s.calculateDJ(state, JCKXH_H, JCKXH_B, JCKXH_U)
|
|
|
|
s.calculateLsc(state, lsc)
|
2023-10-09 10:30:44 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-12 17:33:20 +08:00
|
|
|
// 联锁驱
|
|
|
|
func (s *SignalJCKXHSystem) calculateLsq(state *component.SignalJCKXHElectronic, lsq *component.SignalJCKXHLsq) {
|
|
|
|
dxj := component.RelayDriveType.Get(state.JCKXH_DXJ)
|
|
|
|
lxj := component.RelayDriveType.Get(state.JCKXH_LXJ)
|
|
|
|
//
|
|
|
|
dxjQ := lsq.JCKXH_DXJ_Q
|
|
|
|
dxj.Td = dxjQ
|
|
|
|
dxj.Xq = dxjQ
|
|
|
|
//
|
|
|
|
lxjQ := lsq.JCKXH_LXJ_Q
|
|
|
|
lxj.Td = lxjQ
|
|
|
|
lxj.Xq = lxjQ
|
|
|
|
}
|
|
|
|
|
|
|
|
// 联锁采
|
|
|
|
func (s *SignalJCKXHSystem) calculateLsc(state *component.SignalJCKXHElectronic, lsc *component.SignalJCKXHLsc) {
|
|
|
|
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
|
|
|
|
dj := component.BitStateType.Get(state.JCKXH_DJ)
|
2023-10-09 10:30:44 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
2023-10-12 17:33:20 +08:00
|
|
|
//
|
|
|
|
lsc.JCKXH_DJ_Xq = dj.Val
|
|
|
|
lsc.JCKXH_LXJ_Xq = lxj.Val
|
|
|
|
lsc.JCKXH_DXJ_Xq = dxj.Val
|
|
|
|
}
|
|
|
|
func (s *SignalJCKXHSystem) calculateU(state *component.SignalJCKXHElectronic, JCKXH_U *ecs.Entry) {
|
|
|
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
|
|
|
isU := lxj.Val
|
|
|
|
driveU := component.LightDriveType.Get(JCKXH_U)
|
|
|
|
driveU.Td = isU
|
2023-10-09 10:30:44 +08:00
|
|
|
}
|
|
|
|
|
2023-10-12 17:33:20 +08:00
|
|
|
func (s *SignalJCKXHSystem) calculateB(state *component.SignalJCKXHElectronic, JCKXH_B *ecs.Entry) {
|
2023-10-09 10:30:44 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
|
|
|
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
|
2023-10-12 17:33:20 +08:00
|
|
|
isB := !lxj.Val && dxj.Val
|
|
|
|
driveB := component.LightDriveType.Get(JCKXH_B)
|
|
|
|
driveB.Td = isB
|
2023-10-09 10:30:44 +08:00
|
|
|
}
|
|
|
|
|
2023-10-12 17:33:20 +08:00
|
|
|
func (s *SignalJCKXHSystem) calculateH(state *component.SignalJCKXHElectronic, JCKXH_H *ecs.Entry) {
|
2023-10-09 10:30:44 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
|
|
|
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
|
2023-10-12 17:33:20 +08:00
|
|
|
isH := !lxj.Val && dxj.Val
|
|
|
|
driveH := component.LightDriveType.Get(JCKXH_H)
|
|
|
|
driveH.Td = isH
|
2023-10-09 10:30:44 +08:00
|
|
|
}
|
|
|
|
|
2023-10-12 17:33:20 +08:00
|
|
|
func (s *SignalJCKXHSystem) calculateDJ(state *component.SignalJCKXHElectronic, JCKXH_H *ecs.Entry, JCKXH_B *ecs.Entry, JCKXH_U *ecs.Entry) {
|
2023-10-09 10:30:44 +08:00
|
|
|
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
|
|
|
|
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
|
2023-10-12 17:33:20 +08:00
|
|
|
hd := component.BitStateType.Get(JCKXH_H)
|
|
|
|
bd := component.BitStateType.Get(JCKXH_B)
|
|
|
|
ud := component.BitStateType.Get(JCKXH_U)
|
|
|
|
isDJ := ud.Val && lxj.Val || bd.Val && !lxj.Val && dxj.Val || hd.Val && !lxj.Val && dxj.Val
|
|
|
|
drive := component.RelayDriveType.Get(state.JCKXH_DJ)
|
|
|
|
drive.Td = isDJ
|
|
|
|
drive.Xq = isDJ
|
2023-10-09 10:30:44 +08:00
|
|
|
}
|