rts-sim-module/entity/singleton.go
walker 0bba8f0934 删除donburi包引用
修改filter导入为从ecs项目导入
整理包结构,将弃用的包放入deprecated文件中
2023-10-09 11:17:25 +08:00

42 lines
963 B
Go

package entity
import (
"time"
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
"joylink.club/rtsssimulation/repository"
)
// 初始化世界数据
func LoadWorldData(w ecs.World, repo *repository.Repository) {
if repo == nil {
panic("repo不能为nil")
}
entry := w.Create(component.WorldDataType)
component.WorldDataType.Set(entry, &component.WorldData{
Repo: repo,
Time: time.Now().UnixMilli(),
EntityMap: make(map[string]*ecs.Entry),
})
}
var worldDataQuery = ecs.NewQuery(filter.Contains(component.WorldDataType))
// 获取世界数据
func GetWorldData(w ecs.World) *component.WorldData {
entry, ok := worldDataQuery.First(w)
if ok {
return component.WorldDataType.Get(entry)
}
panic("不存在世界数据")
}
// 根据uid获取对象实体
func GetEntityByUid(w ecs.World, uid string) (entry *ecs.Entry, ok bool) {
wd := GetWorldData(w)
entry, ok = wd.EntityMap[uid]
return
}