world resolve function

This commit is contained in:
2019-05-24 02:45:52 +07:00
parent 27a92fc3ad
commit cc739d6bd2
5 changed files with 22 additions and 3 deletions

View File

@@ -38,6 +38,9 @@ namespace e2d
gobject_iptr instantiate();
gobject_iptr instantiate(const prefab& prefab);
void destroy_instance(const gobject_iptr& inst) noexcept;
gobject_iptr resolve(ecs::entity_id ent) const noexcept;
gobject_iptr resolve(const ecs::const_entity& ent) const noexcept;
private:
ecs::registry registry_;
hash_map<ecs::entity_id, gobject_iptr> gobjects_;

View File

@@ -94,4 +94,20 @@ namespace e2d
gobjects_.erase(inst->entity().id());
}
}
gobject_iptr world::resolve(ecs::entity_id ent) const noexcept {
E2D_ASSERT(registry_.valid_entity(ent));
const auto iter = gobjects_.find(ent);
return iter != gobjects_.end()
? iter->second
: nullptr;
}
gobject_iptr world::resolve(const ecs::const_entity& ent) const noexcept {
E2D_ASSERT(registry_.valid_entity(ent));
const auto iter = gobjects_.find(ent.id());
return iter != gobjects_.end()
? iter->second
: nullptr;
}
}