102 lines
3.3 KiB
Go
102 lines
3.3 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
)
|
|
|
|
type Signal2XH1System struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewSignal2XH1System() *Signal2XH1System {
|
|
return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(
|
|
component.Signal2XH1ElectronicType,
|
|
component.Signal2XH1LsqType,
|
|
component.Signal2XH1LscType,
|
|
component.SignalLightsType))}
|
|
}
|
|
|
|
// Update world 执行
|
|
func (s *Signal2XH1System) Update(w ecs.World) {
|
|
wd := entity.GetWorldData(w)
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
circuit := component.Signal2XH1ElectronicType.Get(entry)
|
|
excite2xh1ByCiDrive(circuit, wd)
|
|
//lsq := component.Signal2XH1LsqType.Get(entry)
|
|
//lsc := component.Signal2XH1LscType.Get(entry)
|
|
lights := component.SignalLightsType.Get(entry)
|
|
Z2XH1_L := lights.GetLightByTag(component.LdTag)
|
|
Z2XH1_H := lights.GetLightByTag(component.HdTag)
|
|
//s.calculateLsq(circuit, lsq)
|
|
s.calculateL(circuit, Z2XH1_L)
|
|
s.calculateH(circuit, Z2XH1_H)
|
|
s.calculateDJ(circuit, Z2XH1_L, Z2XH1_H)
|
|
//s.calculateLsc(circuit, lsc)
|
|
})
|
|
}
|
|
|
|
func excite2xh1ByCiDrive(circuit *component.Signal2XH1Electronic, wd *component.WorldData) {
|
|
bit, err := wd.QueryQdBit(component.UidType.Get(circuit.Z2XH1_DDJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.Z2XH1_DDJ).Td = bit
|
|
}
|
|
|
|
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z2XH1_LXJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.Z2XH1_LXJ).Td = bit
|
|
}
|
|
}
|
|
|
|
// 联锁驱
|
|
func (s *Signal2XH1System) calculateLsq(state *component.Signal2XH1Electronic, lsq *component.Signal2XH1Lsq) {
|
|
ddj := component.RelayDriveType.Get(state.Z2XH1_DDJ)
|
|
lxj := component.RelayDriveType.Get(state.Z2XH1_LXJ)
|
|
//
|
|
ddjQ := lsq.Z2XH1_DDJ_Q
|
|
ddj.Td = ddjQ
|
|
ddj.Xq = ddjQ
|
|
//
|
|
lxjQ := lsq.Z2XH1_LXJ_Q
|
|
lxj.Td = lxjQ
|
|
lxj.Xq = lxjQ
|
|
}
|
|
|
|
// 联锁采
|
|
func (s *Signal2XH1System) calculateLsc(state *component.Signal2XH1Electronic, lsc *component.Signal2XH1Lsc) {
|
|
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
|
dj := component.BitStateType.Get(state.Z2XH1_DJ)
|
|
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
|
//
|
|
lsc.Z2XH1_DDJ_Lx = !ddj.Val
|
|
lsc.Z2XH1_DJ_Xq = dj.Val
|
|
lsc.Z2XH1_LXJ_Xq = lxj.Val
|
|
}
|
|
func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic, Z2XH1_L *ecs.Entry) {
|
|
driveL := component.LightDriveType.Get(Z2XH1_L)
|
|
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
|
isL := !ddj.Val && lxj.Val
|
|
driveL.Td = isL
|
|
}
|
|
func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic, Z2XH1_H *ecs.Entry) {
|
|
driveH := component.LightDriveType.Get(Z2XH1_H)
|
|
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
|
isH := !ddj.Val && !lxj.Val
|
|
driveH.Td = isH
|
|
}
|
|
func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic, Z2XH1_L *ecs.Entry, Z2XH1_H *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z2XH1_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z2XH1_LXJ)
|
|
ld := component.BitStateType.Get(Z2XH1_L)
|
|
hd := component.BitStateType.Get(Z2XH1_H)
|
|
isDJ := !ddj.Val && lxj.Val && ld.Val || !ddj.Val && !lxj.Val && hd.Val
|
|
//通知继电器进行动作
|
|
drive := component.RelayDriveType.Get(state.Z2XH1_DJ)
|
|
drive.Td = isDJ
|
|
drive.Xq = isDJ
|
|
}
|