rts-sim-module/sys/circuit_sys/signal_jckxh.go

114 lines
3.7 KiB
Go
Raw Normal View History

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"
"joylink.club/rtsssimulation/entity"
2023-10-09 10:30:44 +08:00
)
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) {
wd := entity.GetWorldData(w)
2023-10-12 17:33:20 +08:00
s.query.Each(w, func(entry *ecs.Entry) {
circuit := component.SignalJCKXHElectronicType.Get(entry)
exciteJckxhByCiDrive(circuit, wd)
//lsq := component.SignalJCKXHLsqType.Get(entry)
//lsc := component.SignalJCKXHLscType.Get(entry)
2023-10-12 17:33:20 +08:00
lights := component.SignalLightsType.Get(entry)
JCKXH_H := lights.GetLightByTag(component.HdTag)
JCKXH_B := lights.GetLightByTag(component.BdTag)
JCKXH_U := lights.GetLightByTag(component.UdTag)
//s.calculateLsq(circuit, lsq)
s.calculateU(circuit, JCKXH_U)
s.calculateB(circuit, JCKXH_B)
s.calculateH(circuit, JCKXH_H)
s.calculateDJ(circuit, JCKXH_H, JCKXH_B, JCKXH_U)
//s.calculateLsc(circuit, lsc)
2023-10-09 10:30:44 +08:00
})
}
func exciteJckxhByCiDrive(circuit *component.SignalJCKXHElectronic, wd *component.WorldData) {
bit, err := wd.QueryQdBit(component.UidType.Get(circuit.JCKXH_LXJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.JCKXH_LXJ).Td = bit
}
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.JCKXH_DXJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.JCKXH_DXJ).Td = bit
}
}
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
}