Better ecs::entity_accessor interface
This commit is contained in:
parent
82682c0317
commit
c59a28433a
1 changed files with 16 additions and 2 deletions
|
|
@ -14,7 +14,7 @@ namespace psemek::ecs
|
|||
{}
|
||||
|
||||
template <typename Component>
|
||||
Component & get()
|
||||
Component * get_if()
|
||||
{
|
||||
util::uuid const uuid = Component::uuid();
|
||||
|
||||
|
|
@ -22,12 +22,26 @@ namespace psemek::ecs
|
|||
|
||||
for (std::size_t i = 0; i < component_uuids.size(); ++i)
|
||||
if (uuid == component_uuids[i])
|
||||
return *reinterpret_cast<Component *>(table_->get_component_pointers()[i].data + detail::stride<Component>() * row_);
|
||||
return reinterpret_cast<Component *>(table_->get_component_pointers()[i].data + detail::stride<Component>() * row_);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename Component>
|
||||
Component & get()
|
||||
{
|
||||
if (auto ptr = get_if<Component>())
|
||||
return *ptr;
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
template <typename Component>
|
||||
bool contains() const
|
||||
{
|
||||
return get_if<Component>() != nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
detail::table * table_;
|
||||
std::uint32_t row_;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue