Add ecs::container::detach_finally/destroy_finally helpers
This commit is contained in:
parent
4a4f680d0a
commit
424bf5f533
2 changed files with 23 additions and 0 deletions
|
|
@ -79,6 +79,9 @@ namespace psemek::ecs
|
||||||
*/
|
*/
|
||||||
void destroy(handle entity);
|
void destroy(handle entity);
|
||||||
|
|
||||||
|
/** Same as destroy(), but via finally() */
|
||||||
|
void destroy_finally(handle entity);
|
||||||
|
|
||||||
/** Get an accessor for an entity, which provides access to the entity's components.
|
/** Get an accessor for an entity, which provides access to the entity's components.
|
||||||
* It is designed to be a single-use object; it cannot be stored as a reference to
|
* It is designed to be a single-use object; it cannot be stored as a reference to
|
||||||
* the entity. Use handle for that instead.
|
* the entity. Use handle for that instead.
|
||||||
|
|
@ -169,6 +172,10 @@ namespace psemek::ecs
|
||||||
template <typename ... Components>
|
template <typename ... Components>
|
||||||
void detach(handle entity);
|
void detach(handle entity);
|
||||||
|
|
||||||
|
/** Same as detach(), but via finally() */
|
||||||
|
template <typename ... Components>
|
||||||
|
void detach_finally(handle entity);
|
||||||
|
|
||||||
/** Create a query cache that can be used to speed up `apply()` calls.
|
/** Create a query cache that can be used to speed up `apply()` calls.
|
||||||
*
|
*
|
||||||
* The constness of the component types is ignored.
|
* The constness of the component types is ignored.
|
||||||
|
|
@ -611,6 +618,15 @@ namespace psemek::ecs
|
||||||
--method_recursion_depth_;
|
--method_recursion_depth_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ... Components>
|
||||||
|
void container::detach_finally(handle entity)
|
||||||
|
{
|
||||||
|
finally([entity](container & world){
|
||||||
|
if (world.alive(entity))
|
||||||
|
world.detach<Components...>(entity);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
template <typename ... Components>
|
template <typename ... Components>
|
||||||
query_cache container::cache()
|
query_cache container::cache()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,13 @@ namespace psemek::ecs
|
||||||
|
|
||||||
--method_recursion_depth_;
|
--method_recursion_depth_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void container::destroy_finally(handle entity)
|
||||||
|
{
|
||||||
|
finally([entity](container & world){
|
||||||
|
if (world.alive(entity))
|
||||||
|
world.destroy(entity);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
accessor container::get(handle entity)
|
accessor container::get(handle entity)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue