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) // initDevicesStatus(world) // initSystems(world) // world.StartUp() time.Sleep(2 * time.Second) //外界与world交互 //testSwitchTurn(world, face) //testSignalOpt(world, face) //testPsdCellOpt(world, face) testPsdOpt(world, face) // fmt.Println("==>>world 当前时间:", face.WorldTime().GoString()) // time.Sleep(40 * time.Second) world.Close() } // ///////////////////////////////////////////////////////////////////////// func testPsdOpt(world ecs.World, face *system.FaceSystem) { face.Call(func(w ecs.World) any { return system.FirePsdMove(w, "psd1", true) }) time.Sleep(5 * time.Second) face.Call(func(w ecs.World) any { return system.FirePsdMove(w, "psd1", false) }) } func testPsdCellOpt(world ecs.World, face *system.FaceSystem) { face.Call(func(w ecs.World) any { return system.FirePsdCellMove(w, "psd1", "psd1Cell1", 0) }) face.Call(func(w ecs.World) any { return system.FirePsdCellMove(w, "psd1", "psd1Cell2", 0) }) time.Sleep(5 * time.Second) face.Call(func(w ecs.World) any { return system.FirePsdCellMove(w, "psd1", "psd1Cell1", 100) }) face.Call(func(w ecs.World) any { return system.FirePsdCellMove(w, "psd1", "psd1Cell2", 100) }) } func testSwitchTurn(world ecs.World, face *system.FaceSystem) { 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) } func testSignalOpt(world ecs.World, face *system.FaceSystem) { face.Call(func(w ecs.World) any { return system.SetSignalDisplay(w, "siganl1", state.SignalAspect_B) }) } // //////////////////////////////////////////////////////////////////////// func initDevicesStatus(world ecs.World) { //当组件未显式set值时,world会初始化组件的零值 switch1Entry := memory.CreateSwitchEntity(world) components.DeviceIdentityComponent.Set(switch1Entry, &state.DeviceIdentity{Id: "switch1"}) components.SwitchStateComponent.Set(switch1Entry, &state.SwitchState{NormalRelay: false, ReverseRelay: false, NormalTable: true, ReverseTable: false}) // signal1Entry := memory.CreateSignalEntity(world) components.DeviceIdentityComponent.Set(signal1Entry, &state.DeviceIdentity{Id: "siganl1"}) components.SignalStateComponent.Set(signal1Entry, &state.SignalState{Display: state.SignalAspect_No}) //psd1两个cell psd1Entry := memory.CreatePsdEntity(world) components.DeviceIdentityComponent.Set(psd1Entry, &state.DeviceIdentity{Id: "psd1"}) components.PsdStateComponent.Set(psd1Entry, &state.PsdState{AllClosed: true, AllOpened: false, InterlockReleased: false}) psd1Cell1Entry := memory.CreatePsdCellEntity(world, psd1Entry) components.DeviceIdentityComponent.Set(psd1Cell1Entry, &state.DeviceIdentity{Id: "psd1Cell1"}) components.PsdCellStateComponent.Set(psd1Cell1Entry, &state.PsdCellState{CloseRate: 100}) psd1Cell2Entry := memory.CreatePsdCellEntity(world, psd1Entry) components.DeviceIdentityComponent.Set(psd1Cell2Entry, &state.DeviceIdentity{Id: "psd1Cell2"}) components.PsdCellStateComponent.Set(psd1Cell2Entry, &state.PsdCellState{CloseRate: 100}) } func initSystems(world ecs.World) { world.AddSystem(system.NewSwitchSystem()) world.AddSystem(system.NewSignalSystem()) world.AddSystem(system.NewPsdSystem()) }