package main import ( "fmt" "time" "joylink.club/ecs" "joylink.club/rtsssimulation/components" "joylink.club/rtsssimulation/memory" "joylink.club/rtsssimulation/model" "joylink.club/rtsssimulation/state" "joylink.club/rtsssimulation/system" ) func testModel() { link1 := model.NewLinkModel("link1") link2 := model.NewLinkModel("link2") memory.AddModel(link1) memory.AddModel(link2) memory.ForEachModelsByType(state.DeviceType_Link, func(md memory.ModelData) { link := md.(*model.LinkModel) fmt.Println("==>>", link.Id) }) } 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) testPsdCellOpt(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.FirePsdOperation(w, "psd1", true) }) time.Sleep(5 * time.Second) face.Call(func(w ecs.World) any { return system.FirePsdOperation(w, "psd1", false) }) } func testPsdCellOpt(world ecs.World, face *system.FaceSystem) { face.Call(func(w ecs.World) any { return system.FirePsdCellOperation(w, "psd1", "psd1Cell1", 0) }) face.Call(func(w ecs.World) any { return system.FirePsdCellOperation(w, "psd1", "psd1Cell2", 0) }) time.Sleep(10 * time.Second) face.Call(func(w ecs.World) any { return system.FirePsdCellOperation(w, "psd1", "psd1Cell1", 100-20) }) face.Call(func(w ecs.World) any { return system.FirePsdCellOperation(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", system.SwitchReverseRate-40) }) 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", system.SwitchNormalRate) }) 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.SwitchRelayStateComponent.Set(switch1Entry, &state.SwitchRelayState{DcJ: false, FcJ: false, DbJ: true, FbJ: false}) components.PercentageDeviceComponent.Set(switch1Entry, &state.PercentageDeviceState{Rate: system.SwitchNormalRate}) // 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.PercentageDeviceComponent.Set(psd1Cell1Entry, &state.PercentageDeviceState{Rate: system.PsdCellWholeCloseRate}) psd1Cell2Entry := memory.CreatePsdCellEntity(world, psd1Entry) components.DeviceIdentityComponent.Set(psd1Cell2Entry, &state.DeviceIdentity{Id: "psd1Cell2"}) components.PercentageDeviceComponent.Set(psd1Cell2Entry, &state.PercentageDeviceState{Rate: system.PsdCellWholeCloseRate}) } func initSystems(world ecs.World) { world.AddSystem(system.NewSwitchSystem()) world.AddSystem(system.NewSignalSystem()) world.AddSystem(system.NewPsdSystem()) }