rts-sim-module/sys/circuit_sys/signal_dcxh.go
2023-10-12 17:33:20 +08:00

80 lines
2.3 KiB
Go

package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
type SignalDCXHSystem struct {
query *ecs.Query
}
func NewSignalDCXHSystem() *SignalDCXHSystem {
return &SignalDCXHSystem{query: ecs.NewQuery(filter.Contains(
component.SignalDCXHElectronicType,
component.SignalDCXHLsqType,
component.SignalDCXHLscType,
component.SignalLightsType))}
}
// Update world 执行
func (s *SignalDCXHSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
state := component.SignalDCXHElectronicType.Get(entry)
lsq := component.SignalDCXHLsqType.Get(entry)
lsc := component.SignalDCXHLscType.Get(entry)
lights := component.SignalLightsType.Get(entry)
DCXH_A := lights.GetLightByTag(component.AdTag)
DCXH_B := lights.GetLightByTag(component.BdTag)
//
s.calculateLsq(state, lsq)
s.calculateA(state, DCXH_A)
s.calculateB(state, DCXH_B)
s.calculateDJ(state, DCXH_B, DCXH_A)
s.calculateLsc(state, lsc)
})
}
// 联锁驱
func (s *SignalDCXHSystem) calculateLsq(state *component.SignalDCXHElectronic, lsq *component.SignalDCXHLsq) {
dxj := component.RelayDriveType.Get(state.DCXH_DXJ)
//
dxjQ := lsq.DCXH_DXJ_Q
dxj.Td = dxjQ
dxj.Xq = dxjQ
}
// 联锁采
func (s *SignalDCXHSystem) calculateLsc(state *component.SignalDCXHElectronic, lsc *component.SignalDCXHLsc) {
dxj := component.BitStateType.Get(state.DCXH_DXJ)
dj := component.BitStateType.Get(state.DCXH_DJ)
//
lsc.DCXH_DJ_Xq = dj.Val
lsc.DCXH_DXJ_Xq = dxj.Val
}
func (s *SignalDCXHSystem) calculateB(state *component.SignalDCXHElectronic, DCXH_B *ecs.Entry) {
dxj := component.BitStateType.Get(state.DCXH_DXJ)
isB := dxj.Val
driveB := component.LightDriveType.Get(DCXH_B)
driveB.Td = isB
}
func (s *SignalDCXHSystem) calculateA(state *component.SignalDCXHElectronic, DCXH_A *ecs.Entry) {
dxj := component.BitStateType.Get(state.DCXH_DXJ)
isA := !dxj.Val
driveA := component.LightDriveType.Get(DCXH_A)
driveA.Td = isA
}
func (s *SignalDCXHSystem) calculateDJ(state *component.SignalDCXHElectronic, DCXH_B *ecs.Entry, DCXH_A *ecs.Entry) {
dxj := component.BitStateType.Get(state.DCXH_DXJ)
ad := component.BitStateType.Get(DCXH_A)
bd := component.BitStateType.Get(DCXH_B)
isDJ := bd.Val && dxj.Val || ad.Val && !dxj.Val
drive := component.RelayDriveType.Get(state.DCXH_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}