53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
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.ComSystemTimer)
|
||
components.ComSystemTimer.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.ComDeviceIdentity, components.ComSwitchState)
|
||
}
|
||
|
||
// 创建信号机实体
|
||
func CreateSignalEntity(w ecs.World) *ecs.Entry {
|
||
return w.Create(components.ComDeviceIdentity, components.ComSignalState)
|
||
}
|
||
|
||
// 创建物理区段实体
|
||
func CreatePhysicalSectionEntity(w ecs.World) *ecs.Entry {
|
||
return w.Create(components.ComDeviceIdentity, components.ComPhysicalSectionState)
|
||
}
|
||
|
||
// 创建站台单侧屏蔽门实体
|
||
func CreatePsdEntity(w ecs.World) *ecs.Entry {
|
||
e := w.Create(components.ComDeviceIdentity, components.ComPsdState, components.ComEntityTagHandler)
|
||
components.ComEntityTagHandler.Set(e, &state.EntityTagHandler{Tag: ecs.NewComponentType[any]()})
|
||
return e
|
||
}
|
||
|
||
// 创建单个屏蔽门实体
|
||
func CreatePsdCellEntity(w ecs.World, psdEntry *ecs.Entry) *ecs.Entry {
|
||
return w.Create(components.ComDeviceIdentity, components.ComPsdCellState, components.ComEntityTagHandler.Get(psdEntry).Tag)
|
||
}
|