60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package system
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/yohamta/donburi/component"
|
||
"github.com/yohamta/donburi/filter"
|
||
"joylink.club/ecs"
|
||
"joylink.club/rtsssimulation/umi"
|
||
)
|
||
|
||
// 实体身份定义
|
||
type EntityIdentity struct {
|
||
Id string
|
||
}
|
||
|
||
// 实体身份组件
|
||
var EntityIdentityComponent = ecs.NewComponentType[EntityIdentity]()
|
||
|
||
func FindEntityById(world ecs.World, id string) *ecs.Entry {
|
||
query := ecs.NewQuery(filter.Contains(EntityIdentityComponent))
|
||
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) {
|
||
if id == EntityIdentityComponent.Get(e).Id {
|
||
entry = e
|
||
panic(fmt.Sprintf("找到实体[%s],结束查找", id))
|
||
}
|
||
})
|
||
}()
|
||
//
|
||
return entry
|
||
}
|
||
|
||
// 捕获panic并恢复执行
|
||
func simpleRecover() {
|
||
recover()
|
||
}
|
||
|
||
/////////////////////////////////////////////////////////
|
||
|
||
// 实体标签
|
||
type EntityTag = component.IComponentType
|
||
|
||
type EntityTagHandler struct {
|
||
Tag EntityTag
|
||
}
|
||
|
||
/////////////////////////////////////////////////////////
|
||
|
||
// 模型仓库引用
|
||
// 用于world内使用,查询模型
|
||
type ModelStorageRef struct {
|
||
ModelManager umi.IModelManager
|
||
}
|