rts-sim-module/examples/test1/main.go
2023-08-28 16:33:00 +08:00

133 lines
3.7 KiB
Go

package main
import (
"time"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components/cstate"
"joylink.club/rtsssimulation/creator"
"joylink.club/rtsssimulation/examples/test1/tmodel"
"joylink.club/rtsssimulation/examples/test1/tstorages"
"joylink.club/rtsssimulation/operate"
"joylink.club/rtsssimulation/system"
)
// 具体共享模型仓库key
var StorageKeyXaV1 = tstorages.StorageKey{LineId: "xa-1", Version: "0.1"}
func main() {
initShareModels()
// 通过共享仓库生成具体仿真world的模型仓库
woldModelStorage := tstorages.ShareStoragesMapper.CreateWorldStorageWithShare(StorageKeyXaV1, initLinkModels())
//
config := &creator.WorldConfig{
ModelManager: woldModelStorage,
Tick: 300,
InitTime: time.Now(),
Systems: []ecs.ISystem{
system.NewMovableDeviceSystem(),
system.NewPercentageDeviceSystem(),
system.NewSwitchSystem(),
system.NewPsdSystem(),
system.NewTimerSystem(),
system.NewDebugSystem()},
}
world := creator.InitializeWorld(config)
//
world.StartUp()
//
time.Sleep(2 * time.Second)
//
//testPsdOpt(world)
//testPsdCellOpt(world)
testSwitchTurn(world)
//
time.Sleep(120 * time.Second)
}
// 构建具体仿真link模型
func initLinkModels() *tstorages.ModelStorage {
mds := tstorages.NewModelStorage()
//
link1 := tmodel.NewLinkModel("link1")
link2 := tmodel.NewLinkModel("link2")
mds.AddModel(link1)
mds.AddModel(link2)
return mds
}
// 构建模型
func initShareModels() {
mds := tstorages.NewModelStorage()
//
signal1 := tmodel.NewSignalModel("signal1")
signal2 := tmodel.NewSignalModel("signal2")
mds.AddModel(signal1)
mds.AddModel(signal2)
//
switch1 := tmodel.NewSwitchModel("switch1")
switch1.TurnTime = 3000
switch2 := tmodel.NewSwitchModel("switch2")
switch2.TurnTime = 2500
mds.AddModel(switch1)
mds.AddModel(switch2)
//
psd1 := tmodel.NewPsdModel("psd1")
psd1.MoveTime = 5000
psd1Cell1 := tmodel.NewPsdCellModel("psd1Cell1", psd1)
psd1Cell2 := tmodel.NewPsdCellModel("psd1Cell2", psd1)
psd2 := tmodel.NewPsdModel("psd2")
psd2.MoveTime = 6000
psd2Cell1 := tmodel.NewPsdCellModel("psd2Cell1", psd2)
psd2Cell2 := tmodel.NewPsdCellModel("psd2Cell2", psd2)
mds.AddModel(psd1)
mds.AddModel(psd1Cell1)
mds.AddModel(psd1Cell2)
mds.AddModel(psd2)
mds.AddModel(psd2Cell1)
mds.AddModel(psd2Cell2)
//
button1 := tmodel.NewTowPosButtonModel("button1")
mds.AddModel(button1)
//
tstorages.ShareStoragesMapper.AddShareModelStorage(StorageKeyXaV1, mds)
}
////////////////////////////////////////////////////////////////
func testPsdOpt(w ecs.World) {
operate.FirePsdOperation(w, "psd1", true)
time.Sleep(5 * time.Second)
operate.FirePsdOperation(w, "psd1", false)
}
func testPsdCellOpt(w ecs.World) {
operate.FirePsdCellOperation(w, "psd1", "psd1Cell1", 0)
operate.FirePsdCellOperation(w, "psd1", "psd1Cell2", 0)
time.Sleep(10 * time.Second)
operate.FirePsdCellOperation(w, "psd1", "psd1Cell1", 100-20)
operate.FirePsdCellOperation(w, "psd1", "psd1Cell2", 100)
//
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)
}
func testSwitchTurn(w ecs.World) {
operate.FireSwitchFcj(w, "switch1")
time.Sleep(3 * time.Second)
operate.FireSwitchDcj(w, "switch1")
}
func testSignalOpt(w ecs.World) {
operate.SetSignalDisplay(w, "siganl1", cstate.SignalAspect_B)
}
func testButtonOpt(world ecs.World) {
operate.FireTowPositionButtonMoving(world, "button1")
time.Sleep(3 * time.Second)
operate.FireTowPositionButtonArrivedPos1(world, "button1")
time.Sleep(3 * time.Second)
operate.FireTowPositionButtonArrivedPos2(world, "button1")
}