132 lines
4.3 KiB
Go
132 lines
4.3 KiB
Go
package circuit_sys
|
|
|
|
import (
|
|
"joylink.club/ecs"
|
|
"joylink.club/ecs/filter"
|
|
"joylink.club/rtsssimulation/component"
|
|
"joylink.club/rtsssimulation/entity"
|
|
)
|
|
|
|
type Signal3XH4System struct {
|
|
query *ecs.Query
|
|
}
|
|
|
|
func NewSignal3XH4System() *Signal3XH4System {
|
|
return &Signal3XH4System{query: ecs.NewQuery(filter.Contains(
|
|
component.Signal3XH4ElectronicType,
|
|
component.Signal3XH4LsqType,
|
|
component.Signal3XH4LscType,
|
|
component.SignalLightsType))}
|
|
}
|
|
|
|
// Update world 执行
|
|
func (s *Signal3XH4System) Update(w ecs.World) {
|
|
wd := entity.GetWorldData(w)
|
|
s.query.Each(w, func(entry *ecs.Entry) {
|
|
circuit := component.Signal3XH4ElectronicType.Get(entry)
|
|
excite3xh4ByCiDrive(circuit, wd)
|
|
//lsq := component.Signal3XH4LsqType.Get(entry)
|
|
//lsc := component.Signal3XH4LscType.Get(entry)
|
|
lights := component.SignalLightsType.Get(entry)
|
|
Z3XH4_H := lights.GetLightByTag(component.HdTag)
|
|
Z3XH4_L := lights.GetLightByTag(component.LdTag)
|
|
Z3XH4_U := lights.GetLightByTag(component.UdTag)
|
|
//
|
|
//s.calculateLsq(circuit, lsq)
|
|
s.calculateU(circuit, Z3XH4_U)
|
|
s.calculateL(circuit, Z3XH4_L)
|
|
s.calculateH(circuit, Z3XH4_H)
|
|
s.calculateDJ(circuit, Z3XH4_H, Z3XH4_L, Z3XH4_U)
|
|
//s.calculateLsc(circuit, lsc)
|
|
})
|
|
}
|
|
|
|
func excite3xh4ByCiDrive(circuit *component.Signal3XH4Electronic, wd *component.WorldData) {
|
|
bit, err := wd.QueryQdBit(component.UidType.Get(circuit.Z3XH4_DDJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.Z3XH4_DDJ).Td = bit
|
|
}
|
|
|
|
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH4_LXJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.Z3XH4_LXJ).Td = bit
|
|
}
|
|
|
|
bit, err = wd.QueryQdBit(component.UidType.Get(circuit.Z3XH4_ZXJ).Id)
|
|
if err == nil {
|
|
component.RelayDriveType.Get(circuit.Z3XH4_ZXJ).Td = bit
|
|
}
|
|
}
|
|
|
|
// 联锁驱
|
|
func (s *Signal3XH4System) calculateLsq(state *component.Signal3XH4Electronic, lsq *component.Signal3XH4Lsq) {
|
|
ddj := component.RelayDriveType.Get(state.Z3XH4_DDJ)
|
|
lxj := component.RelayDriveType.Get(state.Z3XH4_LXJ)
|
|
zxj := component.RelayDriveType.Get(state.Z3XH4_ZXJ)
|
|
//
|
|
ddjQ := lsq.Z3XH4_DDJ_Q
|
|
ddj.Td = ddjQ
|
|
ddj.Xq = ddjQ
|
|
//
|
|
lxjQ := lsq.Z3XH4_LXJ_Q
|
|
lxj.Td = lxjQ
|
|
lxj.Xq = lxjQ
|
|
//
|
|
zxjQ := lsq.Z3XH4_ZXJ_Q
|
|
zxj.Td = zxjQ
|
|
zxj.Xq = zxjQ
|
|
}
|
|
|
|
// 联锁采
|
|
func (s *Signal3XH4System) calculateLsc(state *component.Signal3XH4Electronic, lsc *component.Signal3XH4Lsc) {
|
|
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
|
|
dj := component.BitStateType.Get(state.Z3XH4_DJ)
|
|
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
|
|
//
|
|
lsc.Z3XH4_DJ_Xq = dj.Val
|
|
lsc.Z3XH4_DDJ_Lx = !ddj.Val
|
|
lsc.Z3XH4_LXJ_Xq = lxj.Val
|
|
lsc.Z3XH4_ZXJ_Xq = zxj.Val
|
|
}
|
|
func (s *Signal3XH4System) calculateU(state *component.Signal3XH4Electronic, Z3XH4_U *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
|
|
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
|
|
isU := !ddj.Val && lxj.Val && !zxj.Val
|
|
driveU := component.LightDriveType.Get(Z3XH4_U)
|
|
driveU.Td = isU
|
|
}
|
|
|
|
func (s *Signal3XH4System) calculateL(state *component.Signal3XH4Electronic, Z3XH4_L *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
|
|
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
|
|
isL := !ddj.Val && lxj.Val && zxj.Val
|
|
driveL := component.LightDriveType.Get(Z3XH4_L)
|
|
driveL.Td = isL
|
|
}
|
|
|
|
func (s *Signal3XH4System) calculateH(state *component.Signal3XH4Electronic, Z3XH4_H *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
|
|
isH := !ddj.Val && !lxj.Val
|
|
driveH := component.LightDriveType.Get(Z3XH4_H)
|
|
driveH.Td = isH
|
|
}
|
|
|
|
func (s *Signal3XH4System) calculateDJ(state *component.Signal3XH4Electronic, Z3XH4_H *ecs.Entry, Z3XH4_L *ecs.Entry, Z3XH4_U *ecs.Entry) {
|
|
ddj := component.BitStateType.Get(state.Z3XH4_DDJ)
|
|
lxj := component.BitStateType.Get(state.Z3XH4_LXJ)
|
|
zxj := component.BitStateType.Get(state.Z3XH4_ZXJ)
|
|
hd := component.BitStateType.Get(Z3XH4_H)
|
|
ld := component.BitStateType.Get(Z3XH4_L)
|
|
ud := component.BitStateType.Get(Z3XH4_U)
|
|
isDJ := ud.Val && !ddj.Val && lxj.Val && !zxj.Val ||
|
|
ld.Val && !ddj.Val && lxj.Val && zxj.Val ||
|
|
hd.Val && !ddj.Val && !lxj.Val
|
|
drive := component.RelayDriveType.Get(state.Z3XH4_DJ)
|
|
drive.Td = isDJ
|
|
drive.Xq = isDJ
|
|
}
|