rts-sim-module/memory/init_world.go
2023-08-18 11:23:52 +08:00

63 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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时钟
timeEntry := w.Create(components.SystemTimerComponent)
components.SystemTimerComponent.Set(timeEntry, state.NewSystemTimer(&worldTime))
w.AddSystem(system.NewTimerSystem())
//初始化world与外界交互的门面
faceSystem := system.NewFaceSystem(w)
w.AddSystem(faceSystem)
//添加调试系统
w.AddSystem(system.NewDebugSystem())
//
return faceSystem
}
// 创建道岔实体
func CreateSwitchEntity(w ecs.World) *ecs.Entry {
return w.Create(components.DeviceIdentityComponent, components.SwitchRelayStateComponent, components.PercentageDeviceComponent)
}
// 创建信号机实体
func CreateSignalEntity(w ecs.World) *ecs.Entry {
return w.Create(components.DeviceIdentityComponent, components.SignalStateComponent)
}
// 创建物理区段实体
func CreatePhysicalSectionEntity(w ecs.World) *ecs.Entry {
return w.Create(components.DeviceIdentityComponent, components.PhysicalSectionStateComponent)
}
// 创建站台单侧屏蔽门实体
func CreatePsdEntity(w ecs.World) *ecs.Entry {
e := w.Create(components.DeviceIdentityComponent, components.PsdStateComponent, components.EntityTagHandlerComponent)
components.EntityTagHandlerComponent.Set(e, &state.EntityTagHandler{Tag: ecs.NewComponentType[struct{}]()})
return e
}
// 创建单个屏蔽门实体
func CreatePsdCellEntity(w ecs.World, psdEntry *ecs.Entry) *ecs.Entry {
return w.Create(components.DeviceIdentityComponent, components.PsdCellStateComponent, components.EntityTagHandlerComponent.Get(psdEntry).Tag)
}
// 创建应答器实体
func CreateBaliseEntity(w ecs.World) *ecs.Entry {
return w.Create(components.DeviceIdentityComponent, components.BaliseStateComponent)
}
// 创建列车实体
func CreateTrainEntity(w ecs.World) *ecs.Entry {
return w.Create(components.DeviceIdentityComponent, components.TrainStateComponent)
}