rts-sim-module/sys/circuit_sys/signal_dcxh.go
2023-10-09 13:23:34 +08:00

52 lines
1.5 KiB
Go

package circuit_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
type SignalDCXHSystem struct {
query *ecs.Query
}
func NewSignalDCXHSystem() *SignalDCXHSystem {
return &SignalDCXHSystem{query: ecs.NewQuery(filter.Contains(component.SignalDCXHElectronicType, component.SignalDCXHFilamentType))}
}
// Update world 执行
func (s *SignalDCXHSystem) Update(w ecs.World) {
s.query.Each(w, func(e *ecs.Entry) {
state := component.SignalDCXHElectronicType.Get(e)
filament := component.SignalDCXHFilamentType.Get(e)
//
s.calculateA(state, filament)
s.calculateB(state, filament)
s.calculateDJ(state, filament)
})
}
func (s *SignalDCXHSystem) calculateB(state *component.SignalDCXHElectronic, filament *component.SignalDCXHFilament) {
dxj := component.BitStateType.Get(state.DCXH_DXJ)
isB := filament.Bf && dxj.Val
filament.B = isB
}
func (s *SignalDCXHSystem) calculateA(state *component.SignalDCXHElectronic, filament *component.SignalDCXHFilament) {
dxj := component.BitStateType.Get(state.DCXH_DXJ)
isA := filament.Af && !dxj.Val
filament.A = isA
}
func (s *SignalDCXHSystem) calculateDJ(state *component.SignalDCXHElectronic, filament *component.SignalDCXHFilament) {
dxj := component.BitStateType.Get(state.DCXH_DXJ)
dj := component.BitStateType.Get(state.DCXH_DJ)
isDJ := filament.Bf && dxj.Val || filament.Af && !dxj.Val
if isDJ != dj.Val {
drive := component.RelayDriveType.Get(state.DCXH_DJ)
drive.Td = isDJ
drive.Xq = isDJ
}
}