2023-10-26 16:41:18 +08:00
|
|
|
package message_server
|
|
|
|
|
2023-10-27 14:57:37 +08:00
|
|
|
import (
|
2023-12-20 10:37:54 +08:00
|
|
|
"joylink.club/bj-rtsts-server/message_server/ms_api"
|
2023-11-16 16:54:23 +08:00
|
|
|
"joylink.club/bj-rtsts-server/mqtt"
|
2023-10-27 14:57:37 +08:00
|
|
|
"joylink.club/bj-rtsts-server/ts/protos/state"
|
|
|
|
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
2023-10-27 16:51:48 +08:00
|
|
|
"joylink.club/ecs"
|
2023-10-27 14:57:37 +08:00
|
|
|
)
|
|
|
|
|
2023-12-20 10:37:54 +08:00
|
|
|
func NewStateMs(vs *memory.VerifySimulation) ms_api.MsgTask {
|
|
|
|
return ms_api.NewMonitorTask("仿真状态", func() {
|
|
|
|
ecs.WorldStateChangeEvent.Subscribe(vs.World, func(_ ecs.World, e ecs.WorldStateChange) {
|
|
|
|
switch e.NewState {
|
|
|
|
case ecs.WorldClose:
|
|
|
|
mqtt.PubSimulationState(vs.SimulationId, &state.SimulationStatus{
|
|
|
|
SimulationId: vs.SimulationId,
|
|
|
|
State: state.SimulationStatus_DESTROY,
|
|
|
|
})
|
|
|
|
case ecs.WorldError:
|
|
|
|
mqtt.PubSimulationState(vs.SimulationId, &state.SimulationStatus{
|
|
|
|
SimulationId: vs.SimulationId,
|
|
|
|
State: state.SimulationStatus_ERROR,
|
|
|
|
})
|
|
|
|
case ecs.WorldPause:
|
|
|
|
mqtt.PubSimulationState(vs.SimulationId, &state.SimulationStatus{
|
|
|
|
SimulationId: vs.SimulationId,
|
|
|
|
State: state.SimulationStatus_PAUSE,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2023-10-27 16:51:48 +08:00
|
|
|
})
|
2023-10-27 14:57:37 +08:00
|
|
|
}
|