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

114 lines
3.7 KiB
Go

package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
type SignalJCKXHSystem struct {
query *ecs.Query
}
func NewSignalJCKXHSystem() *SignalJCKXHSystem {
return &SignalJCKXHSystem{query: ecs.NewQuery(filter.Contains(
component.SignalJCKXHElectronicType,
component.SignalJCKXHLsqType,
component.SignalJCKXHLscType,
component.SignalLightsType))}
}
// Update world 执行
func (s *SignalJCKXHSystem) Update(w ecs.World) {
wd := entity.GetWorldData(w)
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)
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)
})
}
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
}
}
// 联锁驱
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)
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
//
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
}
func (s *SignalJCKXHSystem) calculateB(state *component.SignalJCKXHElectronic, JCKXH_B *ecs.Entry) {
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
isB := !lxj.Val && dxj.Val
driveB := component.LightDriveType.Get(JCKXH_B)
driveB.Td = isB
}
func (s *SignalJCKXHSystem) calculateH(state *component.SignalJCKXHElectronic, JCKXH_H *ecs.Entry) {
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
isH := !lxj.Val && dxj.Val
driveH := component.LightDriveType.Get(JCKXH_H)
driveH.Td = isH
}
func (s *SignalJCKXHSystem) calculateDJ(state *component.SignalJCKXHElectronic, JCKXH_H *ecs.Entry, JCKXH_B *ecs.Entry, JCKXH_U *ecs.Entry) {
lxj := component.BitStateType.Get(state.JCKXH_LXJ)
dxj := component.BitStateType.Get(state.JCKXH_DXJ)
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
}