rts-sim-module/memory/init_world.go

65 lines
2.2 KiB
Go
Raw Normal View History

2023-08-16 17:17:20 +08:00
package memory
import (
"time"
"joylink.club/ecs"
"joylink.club/rtsssimulation/components"
"joylink.club/rtsssimulation/state"
"joylink.club/rtsssimulation/system"
)
// 初始化world添加一些内置的组件和系统
func InitializeWorld(w ecs.World, worldTime time.Time) *system.FaceSystem {
//初始化world时钟
2023-08-18 10:06:17 +08:00
timeEntry := w.Create(components.SystemTimerComponent)
components.SystemTimerComponent.Set(timeEntry, state.NewSystemTimer(&worldTime))
2023-08-16 17:17:20 +08:00
w.AddSystem(system.NewTimerSystem())
//初始化world与外界交互的门面
faceSystem := system.NewFaceSystem(w)
w.AddSystem(faceSystem)
2023-08-18 16:28:23 +08:00
//添加百分比设备系统
w.AddSystem(system.NewPercentageSystem())
2023-08-16 17:17:20 +08:00
//添加调试系统
w.AddSystem(system.NewDebugSystem())
//
return faceSystem
}
// 创建道岔实体
func CreateSwitchEntity(w ecs.World) *ecs.Entry {
2023-08-18 11:23:52 +08:00
return w.Create(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent)
2023-08-16 17:17:20 +08:00
}
// 创建信号机实体
func CreateSignalEntity(w ecs.World) *ecs.Entry {
2023-08-18 10:06:17 +08:00
return w.Create(components.DeviceIdentityComponent, components.SignalStateComponent)
2023-08-16 17:17:20 +08:00
}
// 创建物理区段实体
func CreatePhysicalSectionEntity(w ecs.World) *ecs.Entry {
2023-08-18 10:06:17 +08:00
return w.Create(components.DeviceIdentityComponent, components.PhysicalSectionStateComponent)
2023-08-16 17:17:20 +08:00
}
// 创建站台单侧屏蔽门实体
func CreatePsdEntity(w ecs.World) *ecs.Entry {
2023-08-18 10:06:17 +08:00
e := w.Create(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent)
components.EntityTagHandlerComponent.Set(e, &state.EntityTagHandler{Tag: ecs.NewComponentType[struct{}]()})
2023-08-16 18:13:18 +08:00
return e
2023-08-16 17:17:20 +08:00
}
2023-08-21 15:12:57 +08:00
// 创建屏蔽门cell实体
2023-08-16 18:13:18 +08:00
func CreatePsdCellEntity(w ecs.World, psdEntry *ecs.Entry) *ecs.Entry {
2023-08-18 16:15:19 +08:00
return w.Create(components.DeviceIdentityComponent, components.PercentageDeviceComponent, components.EntityTagHandlerComponent.Get(psdEntry).Tag)
2023-08-16 17:17:20 +08:00
}
2023-08-17 17:39:57 +08:00
// 创建应答器实体
func CreateBaliseEntity(w ecs.World) *ecs.Entry {
2023-08-18 10:06:17 +08:00
return w.Create(components.DeviceIdentityComponent, components.BaliseStateComponent)
2023-08-17 17:39:57 +08:00
}
// 创建列车实体
func CreateTrainEntity(w ecs.World) *ecs.Entry {
2023-08-18 10:06:17 +08:00
return w.Create(components.DeviceIdentityComponent, components.TrainStateComponent)
2023-08-17 17:39:57 +08:00
}