2023-08-15 16:50:24 +08:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"joylink.club/ecs"
|
|
|
|
|
"joylink.club/rtsssimulation/components"
|
|
|
|
|
"joylink.club/rtsssimulation/memory"
|
|
|
|
|
"joylink.club/rtsssimulation/state"
|
|
|
|
|
"joylink.club/rtsssimulation/system"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
world := ecs.NewWorld(300)
|
|
|
|
|
worlTime := time.Now()
|
|
|
|
|
//外界与world交互的门面
|
|
|
|
|
face := memory.InitializeWorld(world, worlTime)
|
2023-08-15 17:29:11 +08:00
|
|
|
|
//
|
|
|
|
|
initDevicesStatus(world)
|
|
|
|
|
//
|
|
|
|
|
initSystems(world)
|
2023-08-15 16:50:24 +08:00
|
|
|
|
//
|
|
|
|
|
world.StartUp()
|
|
|
|
|
time.Sleep(2 * time.Second)
|
2023-08-15 17:29:11 +08:00
|
|
|
|
//外界与world交互
|
2023-08-18 16:15:19 +08:00
|
|
|
|
//testSwitchTurn(world, face)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
//testSignalOpt(world, face)
|
|
|
|
|
//testPsdCellOpt(world, face)
|
2023-08-18 16:15:19 +08:00
|
|
|
|
testPsdCellOpt(world, face)
|
2023-08-15 16:50:24 +08:00
|
|
|
|
//
|
|
|
|
|
fmt.Println("==>>world 当前时间:", face.WorldTime().GoString())
|
2023-08-15 17:29:11 +08:00
|
|
|
|
//
|
|
|
|
|
time.Sleep(40 * time.Second)
|
2023-08-15 16:50:24 +08:00
|
|
|
|
world.Close()
|
|
|
|
|
}
|
2023-08-15 17:29:11 +08:00
|
|
|
|
|
2023-08-17 14:25:18 +08:00
|
|
|
|
// /////////////////////////////////////////////////////////////////////////
|
|
|
|
|
func testPsdOpt(world ecs.World, face *system.FaceSystem) {
|
|
|
|
|
face.Call(func(w ecs.World) any {
|
2023-08-18 16:15:19 +08:00
|
|
|
|
return system.FirePsdOperation(w, "psd1", true)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
})
|
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
face.Call(func(w ecs.World) any {
|
2023-08-18 16:15:19 +08:00
|
|
|
|
return system.FirePsdOperation(w, "psd1", false)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
func testPsdCellOpt(world ecs.World, face *system.FaceSystem) {
|
|
|
|
|
face.Call(func(w ecs.World) any {
|
2023-08-18 16:15:19 +08:00
|
|
|
|
return system.FirePsdCellOperation(w, "psd1", "psd1Cell1", 0)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
})
|
|
|
|
|
face.Call(func(w ecs.World) any {
|
2023-08-18 16:15:19 +08:00
|
|
|
|
return system.FirePsdCellOperation(w, "psd1", "psd1Cell2", 0)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
})
|
|
|
|
|
time.Sleep(5 * time.Second)
|
|
|
|
|
face.Call(func(w ecs.World) any {
|
2023-08-18 16:15:19 +08:00
|
|
|
|
return system.FirePsdCellOperation(w, "psd1", "psd1Cell1", 100-20)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
})
|
|
|
|
|
face.Call(func(w ecs.World) any {
|
2023-08-18 16:15:19 +08:00
|
|
|
|
return system.FirePsdCellOperation(w, "psd1", "psd1Cell2", 100)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
func testSwitchTurn(world ecs.World, face *system.FaceSystem) {
|
|
|
|
|
reslult, _ := face.Call(func(w ecs.World) any {
|
|
|
|
|
fmt.Println("==>>1触发转动道岔 ...")
|
2023-08-18 14:40:13 +08:00
|
|
|
|
return system.FireSwitchTurn(w, "switch1", system.SwitchReverseRate-40)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
})
|
|
|
|
|
fmt.Println("==>>1触发转动道岔 。。。", reslult)
|
|
|
|
|
time.Sleep(8 * time.Second)
|
|
|
|
|
reslult2, _ := face.Call(func(w ecs.World) any {
|
|
|
|
|
fmt.Println("==>>2触发转动道岔 ...")
|
2023-08-18 14:40:13 +08:00
|
|
|
|
return system.FireSwitchTurn(w, "switch1", system.SwitchNormalRate)
|
2023-08-17 14:25:18 +08:00
|
|
|
|
})
|
|
|
|
|
fmt.Println("==>>2触发转动道岔 。。。", reslult2)
|
|
|
|
|
}
|
|
|
|
|
func testSignalOpt(world ecs.World, face *system.FaceSystem) {
|
|
|
|
|
face.Call(func(w ecs.World) any {
|
|
|
|
|
return system.SetSignalDisplay(w, "siganl1", state.SignalAspect_B)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ////////////////////////////////////////////////////////////////////////
|
2023-08-15 17:29:11 +08:00
|
|
|
|
func initDevicesStatus(world ecs.World) {
|
|
|
|
|
//当组件未显式set值时,world会初始化组件的零值
|
2023-08-16 17:17:20 +08:00
|
|
|
|
switch1Entry := memory.CreateSwitchEntity(world)
|
2023-08-18 10:06:17 +08:00
|
|
|
|
components.DeviceIdentityComponent.Set(switch1Entry, &state.DeviceIdentity{Id: "switch1"})
|
2023-08-18 14:40:13 +08:00
|
|
|
|
components.SwitchRelayStateComponent.Set(switch1Entry, &state.SwitchRelayState{DcJ: false, FcJ: false, DbJ: true, FbJ: false})
|
|
|
|
|
components.PercentageDeviceComponent.Set(switch1Entry, &state.PercentageDeviceState{Rate: system.SwitchNormalRate})
|
2023-08-16 15:00:24 +08:00
|
|
|
|
//
|
2023-08-16 17:17:20 +08:00
|
|
|
|
signal1Entry := memory.CreateSignalEntity(world)
|
2023-08-18 10:06:17 +08:00
|
|
|
|
components.DeviceIdentityComponent.Set(signal1Entry, &state.DeviceIdentity{Id: "siganl1"})
|
|
|
|
|
components.SignalStateComponent.Set(signal1Entry, &state.SignalState{Display: state.SignalAspect_No})
|
2023-08-17 14:25:18 +08:00
|
|
|
|
//psd1两个cell
|
|
|
|
|
psd1Entry := memory.CreatePsdEntity(world)
|
2023-08-18 10:06:17 +08:00
|
|
|
|
components.DeviceIdentityComponent.Set(psd1Entry, &state.DeviceIdentity{Id: "psd1"})
|
|
|
|
|
components.PsdStateComponent.Set(psd1Entry, &state.PsdState{AllClosed: true, AllOpened: false, InterlockReleased: false})
|
2023-08-17 14:25:18 +08:00
|
|
|
|
psd1Cell1Entry := memory.CreatePsdCellEntity(world, psd1Entry)
|
2023-08-18 10:06:17 +08:00
|
|
|
|
components.DeviceIdentityComponent.Set(psd1Cell1Entry, &state.DeviceIdentity{Id: "psd1Cell1"})
|
2023-08-18 16:15:19 +08:00
|
|
|
|
components.PercentageDeviceComponent.Set(psd1Cell1Entry, &state.PercentageDeviceState{Rate: system.PsdCellWholeCloseRate})
|
2023-08-17 14:25:18 +08:00
|
|
|
|
psd1Cell2Entry := memory.CreatePsdCellEntity(world, psd1Entry)
|
2023-08-18 10:06:17 +08:00
|
|
|
|
components.DeviceIdentityComponent.Set(psd1Cell2Entry, &state.DeviceIdentity{Id: "psd1Cell2"})
|
2023-08-18 16:15:19 +08:00
|
|
|
|
components.PercentageDeviceComponent.Set(psd1Cell2Entry, &state.PercentageDeviceState{Rate: system.PsdCellWholeCloseRate})
|
2023-08-15 17:29:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func initSystems(world ecs.World) {
|
|
|
|
|
world.AddSystem(system.NewSwitchSystem())
|
2023-08-16 15:00:24 +08:00
|
|
|
|
world.AddSystem(system.NewSignalSystem())
|
2023-08-17 14:25:18 +08:00
|
|
|
|
world.AddSystem(system.NewPsdSystem())
|
2023-08-18 14:40:13 +08:00
|
|
|
|
world.AddSystem(system.NewPercentageSystem())
|
2023-08-15 17:29:11 +08:00
|
|
|
|
}
|