rts-sim-module/entity/singleton.go
walker d3a187e00f 添加创建仿真
完善仿真实体加载
2023-09-28 14:34:00 +08:00

26 lines
603 B
Go

package entity
import (
"time"
"joylink.club/ecs"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
)
// 初始化世界数据
func LoadWorldData(w ecs.World, repo *repository.Repository) {
entry := w.Create(component.WorldDataType)
component.WorldDataType.Set(entry, &component.WorldData{
Repo: repo,
Time: time.Now().UnixMilli(),
EntityMap: make(map[string]*ecs.Entry),
})
}
// 获取世界数据
func GetWorldData(w ecs.World) *component.WorldData {
entry := component.WorldDataType.MustFirst(w)
return component.WorldDataType.Get(entry)
}