diff --git a/simulation/examples/main.go b/simulation/examples/main.go index 792df10..b834e23 100644 --- a/simulation/examples/main.go +++ b/simulation/examples/main.go @@ -24,17 +24,22 @@ func main() { world.StartUp() time.Sleep(2 * time.Second) //外界与world交互 - reslult, _ := face.Call(func(w ecs.World) any { - fmt.Println("==>>1触发转动道岔 ...") - return system.FireSwitchTurn(w, "switch1", false) + /* + reslult, _ := face.Call(func(w ecs.World) any { + fmt.Println("==>>1触发转动道岔 ...") + return system.FireSwitchTurn(w, "switch1", false) + }) + fmt.Println("==>>1触发转动道岔 。。。", reslult) + time.Sleep(8 * time.Second) + reslult2, _ := face.Call(func(w ecs.World) any { + fmt.Println("==>>2触发转动道岔 ...") + return system.FireSwitchTurn(w, "switch1", true) + }) + fmt.Println("==>>2触发转动道岔 。。。", reslult2) + */ + face.Call(func(w ecs.World) any { + return system.SetSignalDisplay(w, "siganl1", state.SignalAspect_B) }) - fmt.Println("==>>1触发转动道岔 。。。", reslult) - time.Sleep(8 * time.Second) - reslult2, _ := face.Call(func(w ecs.World) any { - fmt.Println("==>>2触发转动道岔 ...") - return system.FireSwitchTurn(w, "switch1", true) - }) - fmt.Println("==>>2触发转动道岔 。。。", reslult2) // fmt.Println("==>>world 当前时间:", face.WorldTime().GoString()) // diff --git a/simulation/system/debug_system.go b/simulation/system/debug_system.go index bb5ead9..b671aae 100644 --- a/simulation/system/debug_system.go +++ b/simulation/system/debug_system.go @@ -18,7 +18,17 @@ func NewDebugSystem() *DebugSystem { // world 执行 func (me *DebugSystem) Update(w ecs.World) { - debugSwitch(w) + debugSignal(w) +} + +// 显示信号机状态 +func debugSignal(w ecs.World) { + siganlQuery := ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComSignalState)) + siganlQuery.Each(w, func(e *ecs.Entry) { + id := components.ComDeviceIdentity.Get(e).Id + state := components.ComSignalState.Get(e) + fmt.Printf("==>>信号机[%s],显示=%d\n", id, state.Display) + }) } // 显示道岔状态 @@ -27,7 +37,7 @@ func debugSwitch(w ecs.World) { switchesQuery.Each(w, func(e *ecs.Entry) { id := components.ComDeviceIdentity.Get(e).Id state := components.ComSwitchState.Get(e) - fmt.Printf("道岔[%s] ,定操Relay=%t ,反操Relay=%t ,定表Relay=%t ,反表Relay=%t ,", id, state.NormalRelay, state.ReverseRelay, state.NormalTable, state.ReverseTable) + fmt.Printf("==>>道岔[%s] ,定操Relay=%t ,反操Relay=%t ,定表Relay=%t ,反表Relay=%t ,", id, state.NormalRelay, state.ReverseRelay, state.NormalTable, state.ReverseTable) if e.HasComponent(components.ComSwitchNRRelayOperating) { nrOperation := components.ComSwitchNRRelayOperating.Get(e) if nrOperation.Normal { diff --git a/simulation/system/signal_system.go b/simulation/system/signal_system.go index 90ea22a..33917ff 100644 --- a/simulation/system/signal_system.go +++ b/simulation/system/signal_system.go @@ -11,7 +11,7 @@ type SignalSystem struct { } // 信号机显示状态查询 -var signalDisplayQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComSignalState)) +var signalQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ComDeviceIdentity, components.ComSignalState)) // world 执行 func (me *SignalSystem) Update(world ecs.World) { @@ -24,18 +24,18 @@ func NewSignalSystem() *SignalSystem { // 设置某个信号机的显示 // 返回值:true-设置成功,false-设置失败 func SetSignalDisplay(w ecs.World, signalId string, display state.SignalAspect) bool { - var signalState *state.SignalState - // - signalDisplayQuery.Each(w, func(e *ecs.Entry) { - if components.ComDeviceIdentity.Get(e).Id == signalId { - signalState = components.ComSignalState.Get(e) + var signalEntry *ecs.Entry + signalQuery.Each(w, func(e *ecs.Entry) { + if signalId == components.ComDeviceIdentity.Get(e).Id { + signalEntry = e } }) - // - if nil == signalState { + //s + if signalEntry == nil { return false } // + signalState := components.ComSignalState.Get(signalEntry) signalState.Display = display // return true