diff --git a/component/signal_2xh1.go b/component/signal_2xh1.go index 7455f63..480e18c 100644 --- a/component/signal_2xh1.go +++ b/component/signal_2xh1.go @@ -1,6 +1,8 @@ package component -import "joylink.club/ecs" +import ( + "joylink.club/ecs" +) // Signal2XH1Electronic 电路状态:**信号机2XH-1(红-绿) 出段(场)信号机 或 **出站区间阻挡信号机 type Signal2XH1Electronic struct { @@ -16,21 +18,7 @@ type Signal2XH1Electronic struct { Z2XH1_H *ecs.Entry } -// Signal2XH1Filament 信号机2XH-1 灯丝状态 -type Signal2XH1Filament struct { - // 物理绿灯,true-灯丝正常 - Lf bool - // 物理红灯,true-灯丝正常 - Hf bool - // 物理绿灯,true-亮 - L bool - // 物理红灯,true-亮 - H bool -} - var ( //Signal2XH1ElectronicType 2XH1信号机电路组件 Signal2XH1ElectronicType = ecs.NewComponentType[Signal2XH1Electronic]() - //Signal2XH1FilamentType 2XH1信号机灯丝组件 - Signal2XH1FilamentType = ecs.NewComponentType[Signal2XH1Filament]() ) diff --git a/entity/signal_2xh1.go b/entity/signal_2xh1.go index bb3cd0c..dd18cd7 100644 --- a/entity/signal_2xh1.go +++ b/entity/signal_2xh1.go @@ -12,9 +12,8 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent if len(elecs) == 3 { //2xh1组合类型包含3个继电器 signalEntry.AddComponent(component.Signal2XH1ElectronicType) - signalEntry.AddComponent(component.Signal2XH1FilamentType) // - elecState := &component.Signal2XH1Electronic{} + elecState := &component.Signal2XH1Electronic{Z2XH1_L: NewLightLEntity(w), Z2XH1_H: NewLightHEntity(w)} for _, elec := range elecs { switch elec.Code() { case consts.SIGNAL_DDJ: @@ -29,7 +28,6 @@ func loadSignal2xh1(w ecs.World, signal *repository.Signal, signalEntry *ecs.Ent } // component.Signal2XH1ElectronicType.Set(signalEntry, elecState) - component.Signal2XH1FilamentType.Set(signalEntry, &component.Signal2XH1Filament{Lf: true, Hf: true, L: false, H: false}) } else { return fmt.Errorf("id=[%s]的信号机2xh1,电子元器件数量须为3", signal.Id()) } diff --git a/examples/signal_2xh1/main.go b/examples/signal_2xh1/main.go index 0e4aa45..f1b7a7c 100644 --- a/examples/signal_2xh1/main.go +++ b/examples/signal_2xh1/main.go @@ -10,8 +10,6 @@ import ( "joylink.club/rtsssimulation/fi" "joylink.club/rtsssimulation/repository" "joylink.club/rtsssimulation/repository/model/proto" - "joylink.club/rtsssimulation/sys/circuit_sys" - "joylink.club/rtsssimulation/sys/device_sys" "log" "time" ) @@ -31,8 +29,6 @@ func main() { loadEntities(sim, repo) sim.SetSpeed(0.1) sim.AddSystem(sigSys.NewSignalDebugSystem()) - sim.AddSystem(device_sys.NewRelaySys()) - sim.AddSystem(circuit_sys.NewSignal2XH1System()) sim.StartUp() // time.Sleep(1 * time.Second) diff --git a/examples/signal_2xh1/sigSys/debug_sys.go b/examples/signal_2xh1/sigSys/debug_sys.go index a7cead5..26f62fd 100644 --- a/examples/signal_2xh1/sigSys/debug_sys.go +++ b/examples/signal_2xh1/sigSys/debug_sys.go @@ -12,7 +12,7 @@ type SignalDebugSystem struct { } func NewSignalDebugSystem() *SignalDebugSystem { - return &SignalDebugSystem{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType, component.Signal2XH1FilamentType))} + return &SignalDebugSystem{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType))} } // Update world 执行 @@ -20,11 +20,12 @@ func (s *SignalDebugSystem) Update(w ecs.World) { s.query.Each(w, func(entry *ecs.Entry) { uid := component.UidType.Get(entry) state := component.Signal2XH1ElectronicType.Get(entry) - filament := component.Signal2XH1FilamentType.Get(entry) + ld := component.BitStateType.Get(state.Z2XH1_L) + hd := component.BitStateType.Get(state.Z2XH1_H) // ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) // - log.Printf("===>> uid = %s ddj = %t lxj = %t , 绿灯 = %t 红灯 = %t,\n", uid.Id, ddj.Val, lxj.Val, filament.L, filament.H) + log.Printf("===>> uid = %s ddj = %t lxj = %t , 绿灯 = %t 红灯 = %t,\n", uid.Id, ddj.Val, lxj.Val, ld.Val, hd.Val) }) } diff --git a/sys/circuit_sys/signal_2xh1.go b/sys/circuit_sys/signal_2xh1.go index a6b6185..4c8684d 100644 --- a/sys/circuit_sys/signal_2xh1.go +++ b/sys/circuit_sys/signal_2xh1.go @@ -11,37 +11,44 @@ type Signal2XH1System struct { } func NewSignal2XH1System() *Signal2XH1System { - return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType, component.Signal2XH1FilamentType))} + return &Signal2XH1System{query: ecs.NewQuery(filter.Contains(component.Signal2XH1ElectronicType))} } // 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(state, filament) + s.calculateL(state) + s.calculateH(state) + s.calculateDJ(state) }) } -func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) { +func (s *Signal2XH1System) calculateL(state *component.Signal2XH1Electronic) { + driveL := component.LightDriveType.Get(state.Z2XH1_L) ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) - isL := !ddj.Val && lxj.Val && filament.Lf - filament.L = isL + isL := !ddj.Val && lxj.Val + if driveL.Td != isL { + driveL.Td = isL + } } -func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) { +func (s *Signal2XH1System) calculateH(state *component.Signal2XH1Electronic) { + driveH := component.LightDriveType.Get(state.Z2XH1_H) ddj := component.BitStateType.Get(state.Z2XH1_DDJ) lxj := component.BitStateType.Get(state.Z2XH1_LXJ) - isH := !ddj.Val && !lxj.Val && filament.Hf - filament.H = isH + isH := !ddj.Val && !lxj.Val + if driveH.Td != isH { + driveH.Td = isH + } } -func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic, filament *component.Signal2XH1Filament) { +func (s *Signal2XH1System) calculateDJ(state *component.Signal2XH1Electronic) { 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 + lf := true + hf := true + isDJ := !ddj.Val && lxj.Val && lf || !ddj.Val && !lxj.Val && hf //通知继电器进行动作 if dj.Val != isDJ { drive := component.RelayDriveType.Get(state.Z2XH1_DJ)