2023-08-24 10:34:37 +08:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/yohamta/donburi/filter"
|
|
|
|
"joylink.club/ecs"
|
|
|
|
"joylink.club/rtsssimulation/components"
|
2023-08-28 15:38:21 +08:00
|
|
|
"joylink.club/rtsssimulation/umi"
|
2023-08-24 10:34:37 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func FindEntityById(world ecs.World, id string) *ecs.Entry {
|
|
|
|
query := ecs.NewQuery(filter.Contains(components.DeviceIdentityComponent))
|
|
|
|
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 == components.DeviceIdentityComponent.Get(e).Id {
|
|
|
|
entry = e
|
|
|
|
panic(fmt.Sprintf("找到实体[%s],结束查找", id))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
//
|
|
|
|
return entry
|
|
|
|
}
|
|
|
|
|
|
|
|
// 捕获panic并恢复执行
|
|
|
|
func simpleRecover() {
|
|
|
|
recover()
|
|
|
|
}
|
2023-08-28 15:38:21 +08:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
var worldModelStorageQuery *ecs.Query = ecs.NewQuery(filter.Contains(components.ModelStorageRefComponent))
|
|
|
|
|
|
|
|
func WorldModelStorage(world ecs.World) umi.IModelManager {
|
|
|
|
e, ok := worldModelStorageQuery.First(world)
|
|
|
|
if ok {
|
|
|
|
return components.ModelStorageRefComponent.Get(e).ModelManager
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|