2023-08-24 10:34:37 +08:00
|
|
|
|
package system
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2023-09-12 17:07:17 +08:00
|
|
|
|
"github.com/yohamta/donburi/component"
|
2023-08-24 10:34:37 +08:00
|
|
|
|
"github.com/yohamta/donburi/filter"
|
|
|
|
|
"joylink.club/ecs"
|
2023-08-28 15:38:21 +08:00
|
|
|
|
"joylink.club/rtsssimulation/umi"
|
2023-08-24 10:34:37 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-09-12 17:07:17 +08:00
|
|
|
|
// 实体身份定义
|
|
|
|
|
type EntityIdentity struct {
|
|
|
|
|
Id string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 实体身份组件
|
|
|
|
|
var EntityIdentityComponent = ecs.NewComponentType[EntityIdentity]()
|
|
|
|
|
|
2023-08-24 10:34:37 +08:00
|
|
|
|
func FindEntityById(world ecs.World, id string) *ecs.Entry {
|
2023-09-12 17:07:17 +08:00
|
|
|
|
query := ecs.NewQuery(filter.Contains(EntityIdentityComponent))
|
2023-08-24 10:34:37 +08:00
|
|
|
|
return QueryEntityById(world, query, id)
|
|
|
|
|
}
|
|
|
|
|
func QueryEntityById(world ecs.World, q *ecs.Query, id string) *ecs.Entry {
|
|
|
|
|
var entry *ecs.Entry = nil
|
|
|
|
|
func() {
|
|
|
|
|
defer simpleRecover()
|
|
|
|
|
q.Each(world, func(e *ecs.Entry) {
|
2023-09-12 17:07:17 +08:00
|
|
|
|
if id == EntityIdentityComponent.Get(e).Id {
|
2023-08-24 10:34:37 +08:00
|
|
|
|
entry = e
|
|
|
|
|
panic(fmt.Sprintf("找到实体[%s],结束查找", id))
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}()
|
|
|
|
|
//
|
|
|
|
|
return entry
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 18:01:51 +08:00
|
|
|
|
var modelStorageQuery = ecs.NewQuery(filter.Contains(ModelStorageComponent))
|
|
|
|
|
|
|
|
|
|
// 获取模型仓库
|
|
|
|
|
func FindModelStorage(world ecs.World) umi.IModelManager {
|
|
|
|
|
e, _ := modelStorageQuery.First(world)
|
|
|
|
|
return ModelStorageComponent.Get(e).ModelManager
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-24 10:34:37 +08:00
|
|
|
|
// 捕获panic并恢复执行
|
|
|
|
|
func simpleRecover() {
|
|
|
|
|
recover()
|
|
|
|
|
}
|
2023-08-28 15:38:21 +08:00
|
|
|
|
|
2023-09-12 17:07:17 +08:00
|
|
|
|
/////////////////////////////////////////////////////////
|
2023-08-28 15:38:21 +08:00
|
|
|
|
|
2023-09-12 17:07:17 +08:00
|
|
|
|
// 实体标签
|
|
|
|
|
type EntityTag = component.IComponentType
|
2023-08-29 15:00:56 +08:00
|
|
|
|
|
2023-09-12 17:07:17 +08:00
|
|
|
|
type EntityTagHandler struct {
|
|
|
|
|
Tag EntityTag
|
2023-08-29 15:00:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-12 17:07:17 +08:00
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// 模型仓库引用
|
|
|
|
|
// 用于world内使用,查询模型
|
|
|
|
|
type ModelStorageRef struct {
|
|
|
|
|
ModelManager umi.IModelManager
|
2023-08-29 15:00:56 +08:00
|
|
|
|
}
|
2023-09-12 18:01:51 +08:00
|
|
|
|
|
|
|
|
|
// 模型仓库组件
|
|
|
|
|
var ModelStorageComponent = ecs.NewComponentType[ModelStorageRef]()
|