package circuit_sys import ( "github.com/yohamta/donburi/filter" "joylink.club/ecs" "joylink.club/rtsssimulation/component" ) type Signal2XH1System struct { query *ecs.Query } func NewSignal2XH1System() *Signal2XH1System { return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType, component.Signal2XH1FilamentType))} } // Update world 执行 func (s *Signal2XH1System) Update(w ecs.World) { s.query.Each(w, func(entry *ecs.Entry) { state := component.Signal2XH1ElectronicType.Get(entry) filament := component.Signal2XH1FilamentType.Get(entry) s.calculateL(state, filament) s.calculateH(state, filament) s.calculateDJ(w, entry, state, filament) }) } func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) { ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) isL := !ddj.Val && lxj.Val && filament.Lf filament.L = isL } func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) { ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) isH := !ddj.Val && !lxj.Val && filament.Hf filament.H = isH } func (s *Signal2XH1System) calculateDJ(w ecs.World, e *ecs.Entry, state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) { ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) dj := component.BitStateType.Get(state.Z2XH1_DJ) isDJ := !ddj.Val && lxj.Val && filament.Lf || !ddj.Val && !lxj.Val && filament.Hf //通知继电器进行动作 if dj.Val != isDJ { drive := component.RelayDriveType.Get(state.Z2XH1_DJ) drive.Td = isDJ drive.Xq = isDJ } }