rts-sim-module/component/singleton/load.go
walker 9401b15142 组件调整
实体加载调整
继电器、断相保护器、道岔转辙机、道岔、道岔电路等系统调整
继电器、道岔对外接口调整
2024-01-12 18:20:21 +08:00

43 lines
1.0 KiB
Go

package singleton
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/modelrepo"
)
// 加载并初始化单例组件
func LoadSingletons(w ecs.World, r modelrepo.Repo) {
loadWorldRepo(w, r)
LoadWorldTime(w)
loadUidEntityIndex(w)
}
var worldRepoQuery = ecs.NewQuery(filter.Contains(WorldRepoType))
var worldTimeQuery = ecs.NewQuery(filter.Contains(WorldTimeType))
var uidEntityIndexQuery = ecs.NewQuery(filter.Contains(EntityUidIndexType))
func GetWorldTime(w ecs.World) *WorldTime {
entry, _ := worldTimeQuery.First(w)
if entry == nil {
panic("不存在世界时间单例组件")
}
return WorldTimeType.Get(entry)
}
func GetWorldRepo(w ecs.World) *WorldRepo {
entry, _ := worldRepoQuery.First(w)
if entry == nil {
panic("不存在世界数据单例组件")
}
return WorldRepoType.Get(entry)
}
func GetEntityUidIndex(w ecs.World) *EntityUidIndex {
entry, _ := uidEntityIndexQuery.First(w)
if entry == nil {
panic("不存在实体Uid索引单例组件")
}
return EntityUidIndexType.Get(entry)
}