2023-10-09 10:06:01 +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:06:01 +08:00
|
|
|
"joylink.club/rtsssimulation/component"
|
2024-08-01 14:25:45 +08:00
|
|
|
"joylink.club/rtsssimulation/entity"
|
2023-10-09 10:06:01 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type SignalDCXHSystem struct {
|
|
|
|
query *ecs.Query
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewSignalDCXHSystem() *SignalDCXHSystem {
|
2023-10-12 16:59:08 +08:00
|
|
|
return &SignalDCXHSystem{query: ecs.NewQuery(filter.Contains(
|
|
|
|
component.SignalDCXHElectronicType,
|
|
|
|
component.SignalDCXHLsqType,
|
|
|
|
component.SignalDCXHLscType,
|
|
|
|
component.SignalLightsType))}
|
2023-10-09 10:06:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update world 执行
|
|
|
|
func (s *SignalDCXHSystem) Update(w ecs.World) {
|
2024-08-01 14:25:45 +08:00
|
|
|
wd := entity.GetWorldData(w)
|
2023-10-12 16:59:08 +08:00
|
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
2024-08-01 14:25:45 +08:00
|
|
|
circuit := component.SignalDCXHElectronicType.Get(entry)
|
|
|
|
exciteDcxhByCiDrive(circuit, wd)
|
|
|
|
//lsq := component.SignalDCXHLsqType.Get(entry)
|
|
|
|
//lsc := component.SignalDCXHLscType.Get(entry)
|
2023-10-12 16:59:08 +08:00
|
|
|
lights := component.SignalLightsType.Get(entry)
|
|
|
|
DCXH_A := lights.GetLightByTag(component.AdTag)
|
|
|
|
DCXH_B := lights.GetLightByTag(component.BdTag)
|
2024-08-01 14:25:45 +08:00
|
|
|
|
|
|
|
//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)
|
2023-10-09 10:06:01 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-08-01 14:25:45 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-12 16:59:08 +08:00
|
|
|
// 联锁驱
|
|
|
|
func (s *SignalDCXHSystem) calculateLsq(state *component.SignalDCXHElectronic, lsq *component.SignalDCXHLsq) {
|
|
|
|
dxj := component.RelayDriveType.Get(state.DCXH_DXJ)
|
|
|
|
//
|
2023-10-12 17:33:20 +08:00
|
|
|
dxjQ := lsq.DCXH_DXJ_Q
|
|
|
|
dxj.Td = dxjQ
|
|
|
|
dxj.Xq = dxjQ
|
2023-10-12 16:59:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 联锁采
|
|
|
|
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) {
|
2023-10-09 10:06:01 +08:00
|
|
|
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
2023-10-12 16:59:08 +08:00
|
|
|
isB := dxj.Val
|
|
|
|
driveB := component.LightDriveType.Get(DCXH_B)
|
|
|
|
driveB.Td = isB
|
2023-10-09 10:06:01 +08:00
|
|
|
}
|
|
|
|
|
2023-10-12 16:59:08 +08:00
|
|
|
func (s *SignalDCXHSystem) calculateA(state *component.SignalDCXHElectronic, DCXH_A *ecs.Entry) {
|
2023-10-09 10:06:01 +08:00
|
|
|
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
2023-10-12 16:59:08 +08:00
|
|
|
isA := !dxj.Val
|
|
|
|
driveA := component.LightDriveType.Get(DCXH_A)
|
|
|
|
driveA.Td = isA
|
2023-10-09 10:06:01 +08:00
|
|
|
}
|
|
|
|
|
2023-10-12 16:59:08 +08:00
|
|
|
func (s *SignalDCXHSystem) calculateDJ(state *component.SignalDCXHElectronic, DCXH_B *ecs.Entry, DCXH_A *ecs.Entry) {
|
2023-10-09 10:06:01 +08:00
|
|
|
dxj := component.BitStateType.Get(state.DCXH_DXJ)
|
2023-10-12 16:59:08 +08:00
|
|
|
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
|
2023-10-09 10:06:01 +08:00
|
|
|
}
|