package circuit_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" ) type SignalJDXHSystem struct { query *ecs.Query } func NewSignalJDXHSystem() *SignalJDXHSystem { return &SignalJDXHSystem{query: ecs.NewQuery(filter.Contains(component.SignalJDXHElectronicType, component.SignalJDXHFilamentType))} } // Update world 执行 func (s *SignalJDXHSystem) Update(w ecs.World) { s.query.Each(w, func(e *ecs.Entry) { state := component.SignalJDXHElectronicType.Get(e) filament := component.SignalJDXHFilamentType.Get(e) // s.calculateL(state, filament) s.calculateU(state, filament) s.calculateH(state, filament) s.calculateDJ(state, filament) s.calculate2DJ(state, filament) }) } func (s *SignalJDXHSystem) calculateU(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) { lxj := component.BitStateType.Get(state.JDXH_LXJ) dj := component.BitStateType.Get(state.JDXH_DJ) yxj := component.BitStateType.Get(state.JDXH_YXJ) isU := filament.Uf && !lxj.Val && dj.Val && yxj.Val filament.U = isU } func (s *SignalJDXHSystem) calculateL(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) { lxj := component.BitStateType.Get(state.JDXH_LXJ) isL := filament.Lf && lxj.Val filament.L = isL } func (s *SignalJDXHSystem) calculateH(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) { lxj := component.BitStateType.Get(state.JDXH_LXJ) isH := filament.Hf && !lxj.Val filament.H = isH } func (s *SignalJDXHSystem) calculateDJ(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) { lxj := component.BitStateType.Get(state.JDXH_LXJ) dj := component.BitStateType.Get(state.JDXH_DJ) isDJ := filament.Lf && lxj.Val || filament.Hf && !lxj.Val if isDJ != dj.Val { drive := component.RelayDriveType.Get(state.JDXH_DJ) drive.Td = isDJ drive.Xq = isDJ } } func (s *SignalJDXHSystem) calculate2DJ(state *component.SignalJDXHElectronic, filament *component.SignalJDXHFilament) { lxj := component.BitStateType.Get(state.JDXH_LXJ) dj := component.BitStateType.Get(state.JDXH_DJ) edj := component.BitStateType.Get(state.JDXH_2DJ) yxj := component.BitStateType.Get(state.JDXH_YXJ) is2DJ := filament.Uf && !lxj.Val && dj.Val && yxj.Val if is2DJ != edj.Val { drive := component.RelayDriveType.Get(state.JDXH_2DJ) drive.Td = is2DJ drive.Xq = is2DJ } }