信号机仿真
This commit is contained in:
parent
012e78b078
commit
f82926827e
@ -24,6 +24,7 @@ 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)
|
||||
@ -35,6 +36,10 @@ func main() {
|
||||
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("==>>world 当前时间:", face.WorldTime().GoString())
|
||||
//
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user