信号机仿真

This commit is contained in:
xzb 2023-08-16 15:14:03 +08:00
parent 012e78b078
commit f82926827e
3 changed files with 35 additions and 20 deletions

View File

@ -24,17 +24,22 @@ func main() {
world.StartUp() world.StartUp()
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
//外界与world交互 //外界与world交互
reslult, _ := face.Call(func(w ecs.World) any { /*
fmt.Println("==>>1触发转动道岔 ...") reslult, _ := face.Call(func(w ecs.World) any {
return system.FireSwitchTurn(w, "switch1", false) 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()) fmt.Println("==>>world 当前时间:", face.WorldTime().GoString())
// //

View File

@ -18,7 +18,17 @@ func NewDebugSystem() *DebugSystem {
// world 执行 // world 执行
func (me *DebugSystem) Update(w ecs.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) { switchesQuery.Each(w, func(e *ecs.Entry) {
id := components.ComDeviceIdentity.Get(e).Id id := components.ComDeviceIdentity.Get(e).Id
state := components.ComSwitchState.Get(e) 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) { if e.HasComponent(components.ComSwitchNRRelayOperating) {
nrOperation := components.ComSwitchNRRelayOperating.Get(e) nrOperation := components.ComSwitchNRRelayOperating.Get(e)
if nrOperation.Normal { if nrOperation.Normal {

View File

@ -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 执行 // world 执行
func (me *SignalSystem) Update(world ecs.World) { func (me *SignalSystem) Update(world ecs.World) {
@ -24,18 +24,18 @@ func NewSignalSystem() *SignalSystem {
// 设置某个信号机的显示 // 设置某个信号机的显示
// 返回值true-设置成功false-设置失败 // 返回值true-设置成功false-设置失败
func SetSignalDisplay(w ecs.World, signalId string, display state.SignalAspect) bool { func SetSignalDisplay(w ecs.World, signalId string, display state.SignalAspect) bool {
var signalState *state.SignalState var signalEntry *ecs.Entry
// signalQuery.Each(w, func(e *ecs.Entry) {
signalDisplayQuery.Each(w, func(e *ecs.Entry) { if signalId == components.ComDeviceIdentity.Get(e).Id {
if components.ComDeviceIdentity.Get(e).Id == signalId { signalEntry = e
signalState = components.ComSignalState.Get(e)
} }
}) })
// //s
if nil == signalState { if signalEntry == nil {
return false return false
} }
// //
signalState := components.ComSignalState.Get(signalEntry)
signalState.Display = display signalState.Display = display
// //
return true return true