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

90 lines
2.7 KiB
Go

package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/entity"
)
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) {
wd := entity.GetWorldData(w)
s.query.Each(w, func(entry *ecs.Entry) {
circuit := component.SignalDCXHElectronicType.Get(entry)
exciteDcxhByCiDrive(circuit, wd)
//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(circuit, lsq)
s.calculateA(circuit, DCXH_A)
s.calculateB(circuit, DCXH_B)
s.calculateDJ(circuit, DCXH_B, DCXH_A)
//s.calculateLsc(circuit, lsc)
})
}
func exciteDcxhByCiDrive(circuit *component.SignalDCXHElectronic, wd *component.WorldData) {
bit, err := wd.QueryQdBit(component.UidType.Get(circuit.DCXH_DXJ).Id)
if err == nil {
component.RelayDriveType.Get(circuit.DCXH_DXJ).Td = bit
}
}
// 联锁驱
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
}