package circuit_sys import ( "joylink.club/ecs" "joylink.club/ecs/filter" "joylink.club/rtsssimulation/component" ) type SignalJCKXHSystem struct { query *ecs.Query } func NewSignalJCKXHSystem() *SignalJCKXHSystem { return &SignalJCKXHSystem{query: ecs.NewQuery(filter.Contains(component.SignalJCKXHElectronicType, component.SignalJCKXHFilamentType))} } // Update world 执行 func (s *SignalJCKXHSystem) Update(w ecs.World) { s.query.Each(w, func(e *ecs.Entry) { state := component.SignalJCKXHElectronicType.Get(e) filament := component.SignalJCKXHFilamentType.Get(e) // s.calculateU(state, filament) s.calculateB(state, filament) s.calculateH(state, filament) s.calculateDJ(state, filament) }) } func (s *SignalJCKXHSystem) calculateU(state *component.SignalJCKXHElectronic, filament *component.SignalJCKXHFilament) { lxj := component.BitStateType.Get(state.JCKXH_LXJ) isU := filament.Uf && lxj.Val filament.U = isU } func (s *SignalJCKXHSystem) calculateB(state *component.SignalJCKXHElectronic, filament *component.SignalJCKXHFilament) { lxj := component.BitStateType.Get(state.JCKXH_LXJ) dxj := component.BitStateType.Get(state.JCKXH_DXJ) isB := filament.Bf && !lxj.Val && dxj.Val filament.B = isB } func (s *SignalJCKXHSystem) calculateH(state *component.SignalJCKXHElectronic, filament *component.SignalJCKXHFilament) { lxj := component.BitStateType.Get(state.JCKXH_LXJ) dxj := component.BitStateType.Get(state.JCKXH_DXJ) isH := filament.Bf && !lxj.Val && dxj.Val filament.H = isH } func (s *SignalJCKXHSystem) calculateDJ(state *component.SignalJCKXHElectronic, filament *component.SignalJCKXHFilament) { lxj := component.BitStateType.Get(state.JCKXH_LXJ) dxj := component.BitStateType.Get(state.JCKXH_DXJ) dj := component.BitStateType.Get(state.JCKXH_DJ) isDJ := filament.Uf && lxj.Val || filament.Bf && !lxj.Val && dxj.Val || filament.Bf && !lxj.Val && dxj.Val if isDJ != dj.Val { drive := component.RelayDriveType.Get(state.JCKXH_DJ) drive.Td = isDJ drive.Xq = isDJ } }