126 lines
4.1 KiB
Go
126 lines
4.1 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
)
|
|
|
|
type SignalJDXHSystem struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewSignalJDXHSystem() *SignalJDXHSystem {
|
|
return &SignalJDXHSystem{query: ecs.NewQuery(filter.Contains(
|
|
component.SignalJDXHElectronicType,
|
|
component.SignalJDXHLsqType,
|
|
component.SignalJDXHLscType,
|
|
component.SignalLightsType))}
|
|
}
|
|
|
|
// Update world 执行
|
|
func (s *SignalJDXHSystem) Update(w ecs.World) {
|
|
wd := entity.GetWorldData(w)
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
circuit := component.SignalJDXHElectronicType.Get(entry)
|
|
exciteJdxhByCiDrive(circuit, wd)
|
|
//lsq := component.SignalJDXHLsqType.Get(entry)
|
|
//lsc := component.SignalJDXHLscType.Get(entry)
|
|
lights := component.SignalLightsType.Get(entry)
|
|
JDXH_H := lights.GetLightByTag(component.HdTag)
|
|
JDXH_L := lights.GetLightByTag(component.LdTag)
|
|
JDXH_U := lights.GetLightByTag(component.UdTag)
|
|
|
|
//s.calculateLsq(circuit, lsq)
|
|
s.calculateL(circuit, JDXH_L)
|
|
s.calculateU(circuit, JDXH_U)
|
|
s.calculateH(circuit, JDXH_H)
|
|
s.calculateDJ(circuit, JDXH_L, JDXH_H)
|
|
s.calculate2DJ(circuit, JDXH_U)
|
|
//s.calculateLsc(circuit, lsc)
|
|
})
|
|
}
|
|
|
|
func exciteJdxhByCiDrive(circuit *component.SignalJDXHElectronic, wd *component.WorldData) {
|
|
bit, err := wd.QueryQdBit(component.UidType.Get(circuit.JDXH_LXJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.JDXH_LXJ).Td = bit
|
|
}
|
|
|
|
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.JDXH_YXJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.JDXH_YXJ).Td = bit
|
|
}
|
|
}
|
|
|
|
// 联锁驱
|
|
func (s *SignalJDXHSystem) calculateLsq(state *component.SignalJDXHElectronic, lsq *component.SignalJDXHLsq) {
|
|
lxj := component.RelayDriveType.Get(state.JDXH_LXJ)
|
|
yzhj := component.RelayDriveType.Get(state.JDXH_YZHJ)
|
|
//
|
|
lxjQ := lsq.JDXH_LXJ_Q
|
|
lxj.Td = lxjQ
|
|
lxj.Xq = lxjQ
|
|
//
|
|
yzhjQ := lsq.JDXH_YZHJ_Q
|
|
yzhj.Td = yzhjQ
|
|
yzhj.Xq = yzhjQ
|
|
}
|
|
|
|
// 联锁采
|
|
func (s *SignalJDXHSystem) calculateLsc(state *component.SignalJDXHElectronic, lsc *component.SignalJDXHLsc) {
|
|
edj := component.BitStateType.Get(state.JDXH_2DJ)
|
|
dj := component.BitStateType.Get(state.JDXH_DJ)
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
yxj := component.BitStateType.Get(state.JDXH_YXJ)
|
|
yzhj := component.BitStateType.Get(state.JDXH_YZHJ)
|
|
//
|
|
lsc.JDXH_2DJ_Xq = edj.Val
|
|
lsc.JDXH_DJ_Xq = dj.Val
|
|
lsc.JDXH_LXJ_Xq = lxj.Val
|
|
lsc.JDXH_YZHJ_YXJ_Xq = yxj.Val && yzhj.Val
|
|
}
|
|
func (s *SignalJDXHSystem) calculateU(state *component.SignalJDXHElectronic, JDXH_U *ecs.Entry) {
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
dj := component.BitStateType.Get(state.JDXH_DJ)
|
|
yxj := component.BitStateType.Get(state.JDXH_YXJ)
|
|
isU := !lxj.Val && dj.Val && yxj.Val
|
|
driveU := component.LightDriveType.Get(JDXH_U)
|
|
driveU.Td = isU
|
|
}
|
|
|
|
func (s *SignalJDXHSystem) calculateL(state *component.SignalJDXHElectronic, JDXH_L *ecs.Entry) {
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
isL := lxj.Val
|
|
driveL := component.LightDriveType.Get(JDXH_L)
|
|
driveL.Td = isL
|
|
}
|
|
|
|
func (s *SignalJDXHSystem) calculateH(state *component.SignalJDXHElectronic, JDXH_H *ecs.Entry) {
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
isH := !lxj.Val
|
|
driveH := component.LightDriveType.Get(JDXH_H)
|
|
driveH.Td = isH
|
|
}
|
|
|
|
func (s *SignalJDXHSystem) calculateDJ(state *component.SignalJDXHElectronic, JDXH_L *ecs.Entry, JDXH_H *ecs.Entry) {
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
hd := component.BitStateType.Get(JDXH_H)
|
|
ld := component.BitStateType.Get(JDXH_L)
|
|
isDJ := ld.Val && lxj.Val || hd.Val && !lxj.Val
|
|
drive := component.RelayDriveType.Get(state.JDXH_DJ)
|
|
drive.Td = isDJ
|
|
drive.Xq = isDJ
|
|
}
|
|
func (s *SignalJDXHSystem) calculate2DJ(state *component.SignalJDXHElectronic, JDXH_U *ecs.Entry) {
|
|
lxj := component.BitStateType.Get(state.JDXH_LXJ)
|
|
dj := component.BitStateType.Get(state.JDXH_DJ)
|
|
yxj := component.BitStateType.Get(state.JDXH_YXJ)
|
|
ud := component.BitStateType.Get(JDXH_U)
|
|
is2DJ := ud.Val && !lxj.Val && dj.Val && yxj.Val
|
|
drive := component.RelayDriveType.Get(state.JDXH_2DJ)
|
|
drive.Td = is2DJ
|
|
drive.Xq = is2DJ
|
|
}
|