rts-sim-module/examples/test1/main.go

135 lines
3.7 KiB
Go
Raw Normal View History

2023-08-22 14:37:30 +08:00
package main
import (
"time"
"joylink.club/ecs"
2023-08-23 15:13:06 +08:00
"joylink.club/rtsssimulation/components/cstate"
2023-08-24 10:27:50 +08:00
"joylink.club/rtsssimulation/creator"
"joylink.club/rtsssimulation/examples/test1/tmodel"
"joylink.club/rtsssimulation/examples/test1/tstorages"
2023-08-23 16:01:01 +08:00
"joylink.club/rtsssimulation/operate"
2023-08-22 14:37:30 +08:00
"joylink.club/rtsssimulation/system"
)
2023-08-24 10:30:42 +08:00
// 具体共享模型仓库key
2023-08-24 10:27:50 +08:00
var StorageKeyXaV1 = tstorages.StorageKey{LineId: "xa-1", Version: "0.1"}
2023-08-22 14:37:30 +08:00
2023-08-24 10:27:50 +08:00
func init() {
initShareModels()
}
2023-08-22 14:37:30 +08:00
func main() {
2023-08-24 10:27:50 +08:00
// 通过共享仓库生成具体仿真world的模型仓库
woldModelStorage := tstorages.ShareStoragesMapper.CreateWorldStorageWithShare(StorageKeyXaV1, initLinkModels())
2023-08-22 14:37:30 +08:00
//
2023-08-24 10:27:50 +08:00
config := &creator.WorldConfig{
ModelManager: woldModelStorage,
Tick: 300,
InitTime: time.Now(),
2023-08-25 17:36:12 +08:00
Systems: []ecs.ISystem{
system.NewMovableDeviceSystem(),
system.NewPercentageDeviceSystem(),
2023-08-28 13:51:17 +08:00
system.NewSwitchSystem(),
2023-08-25 17:36:12 +08:00
system.NewPsdSystem(),
system.NewTimerSystem(),
system.NewDebugSystem()},
2023-08-24 10:27:50 +08:00
}
world := creator.InitializeWorld(config)
2023-08-22 14:37:30 +08:00
//
2023-08-24 10:27:50 +08:00
world.StartUp()
2023-08-22 14:37:30 +08:00
//
2023-08-25 10:50:39 +08:00
time.Sleep(2 * time.Second)
//
2023-08-25 13:26:23 +08:00
//testPsdOpt(world)
2023-08-25 17:36:12 +08:00
//testPsdCellOpt(world)
2023-08-25 13:26:23 +08:00
testSwitchTurn(world)
2023-08-22 14:37:30 +08:00
//
2023-08-24 10:27:50 +08:00
time.Sleep(120 * time.Second)
2023-08-22 14:37:30 +08:00
}
2023-08-24 10:27:50 +08:00
// 构建具体仿真link模型
func initLinkModels() *tstorages.ModelStorage {
mds := tstorages.NewModelStorage()
2023-08-22 14:37:30 +08:00
//
2023-08-24 10:27:50 +08:00
link1 := tmodel.NewLinkModel("link1")
link2 := tmodel.NewLinkModel("link2")
mds.AddModel(link1)
mds.AddModel(link2)
return mds
2023-08-22 14:37:30 +08:00
}
// 构建模型
2023-08-24 10:27:50 +08:00
func initShareModels() {
mds := tstorages.NewModelStorage()
2023-08-22 14:37:30 +08:00
//
2023-08-24 10:27:50 +08:00
signal1 := tmodel.NewSignalModel("signal1")
signal2 := tmodel.NewSignalModel("signal2")
2023-08-22 14:37:30 +08:00
mds.AddModel(signal1)
mds.AddModel(signal2)
//
2023-08-24 10:27:50 +08:00
switch1 := tmodel.NewSwitchModel("switch1")
2023-08-22 14:37:30 +08:00
switch1.TurnTime = 3000
2023-08-24 10:27:50 +08:00
switch2 := tmodel.NewSwitchModel("switch2")
2023-08-22 14:37:30 +08:00
switch2.TurnTime = 2500
mds.AddModel(switch1)
mds.AddModel(switch2)
//
2023-08-24 10:27:50 +08:00
psd1 := tmodel.NewPsdModel("psd1")
2023-08-22 14:37:30 +08:00
psd1.MoveTime = 5000
2023-08-24 10:27:50 +08:00
psd1Cell1 := tmodel.NewPsdCellModel("psd1Cell1", psd1)
psd1Cell2 := tmodel.NewPsdCellModel("psd1Cell2", psd1)
psd2 := tmodel.NewPsdModel("psd2")
2023-08-22 14:37:30 +08:00
psd2.MoveTime = 6000
2023-08-24 10:27:50 +08:00
psd2Cell1 := tmodel.NewPsdCellModel("psd2Cell1", psd2)
psd2Cell2 := tmodel.NewPsdCellModel("psd2Cell2", psd2)
2023-08-22 14:37:30 +08:00
mds.AddModel(psd1)
mds.AddModel(psd1Cell1)
mds.AddModel(psd1Cell2)
mds.AddModel(psd2)
mds.AddModel(psd2Cell1)
mds.AddModel(psd2Cell2)
//
2023-08-24 10:27:50 +08:00
button1 := tmodel.NewTowPosButtonModel("button1")
2023-08-22 17:21:21 +08:00
mds.AddModel(button1)
2023-08-24 10:27:50 +08:00
//
tstorages.ShareStoragesMapper.AddShareModelStorage(StorageKeyXaV1, mds)
2023-08-22 14:37:30 +08:00
}
////////////////////////////////////////////////////////////////
2023-08-24 10:27:50 +08:00
func testPsdOpt(w ecs.World) {
operate.FirePsdOperation(w, "psd1", true)
2023-08-22 14:37:30 +08:00
time.Sleep(5 * time.Second)
2023-08-24 10:27:50 +08:00
operate.FirePsdOperation(w, "psd1", false)
2023-08-22 14:37:30 +08:00
}
2023-08-24 10:27:50 +08:00
func testPsdCellOpt(w ecs.World) {
operate.FirePsdCellOperation(w, "psd1", "psd1Cell1", 0)
operate.FirePsdCellOperation(w, "psd1", "psd1Cell2", 0)
2023-08-22 14:37:30 +08:00
time.Sleep(10 * time.Second)
2023-08-24 10:27:50 +08:00
operate.FirePsdCellOperation(w, "psd1", "psd1Cell1", 100-20)
operate.FirePsdCellOperation(w, "psd1", "psd1Cell2", 100)
2023-08-28 13:51:17 +08:00
//
time.Sleep(10 * time.Second)
operate.FirePsdCellOperation(w, "psd2", "psd2Cell1", 0)
operate.FirePsdCellOperation(w, "psd2", "psd2Cell2", 0)
time.Sleep(10 * time.Second)
operate.FirePsdCellOperation(w, "psd2", "psd2Cell1", 100-20)
operate.FirePsdCellOperation(w, "psd2", "psd2Cell2", 100)
2023-08-22 14:37:30 +08:00
}
2023-08-24 10:27:50 +08:00
func testSwitchTurn(w ecs.World) {
2023-08-25 17:36:12 +08:00
operate.FireSwitchFcj(w, "switch1")
2023-08-22 14:37:30 +08:00
time.Sleep(8 * time.Second)
2023-08-25 17:36:12 +08:00
operate.FireSwitchDcj(w, "switch1")
2023-08-24 10:27:50 +08:00
2023-08-22 14:37:30 +08:00
}
2023-08-24 10:27:50 +08:00
func testSignalOpt(w ecs.World) {
operate.SetSignalDisplay(w, "siganl1", cstate.SignalAspect_B)
2023-08-22 14:37:30 +08:00
}
2023-08-24 10:27:50 +08:00
func testButtonOpt(world ecs.World) {
operate.FireTowPositionButtonMoving(world, "button1")
2023-08-22 17:21:21 +08:00
time.Sleep(3 * time.Second)
2023-08-24 10:27:50 +08:00
operate.FireTowPositionButtonArrivedPos1(world, "button1")
2023-08-22 17:21:21 +08:00
time.Sleep(3 * time.Second)
2023-08-24 10:27:50 +08:00
operate.FireTowPositionButtonArrivedPos2(world, "button1")
2023-08-22 17:21:21 +08:00
}