Add static asserts in ecs::entity_component::apply/batch_apply to check that all component types are different
This commit is contained in:
parent
f46b3bdc40
commit
85c0c56e03
1 changed files with 8 additions and 0 deletions
|
|
@ -107,6 +107,8 @@ namespace psemek::ecs
|
||||||
* The function is guaranteed not to visit destroyed entities (unless it did
|
* The function is guaranteed not to visit destroyed entities (unless it did
|
||||||
* so before the entity was destroyed).
|
* so before the entity was destroyed).
|
||||||
* An optional query cache can be supplied to speed up iteration.
|
* An optional query cache can be supplied to speed up iteration.
|
||||||
|
* If any two of the passed component types are equal, the call fails with
|
||||||
|
* a compilation error.
|
||||||
* If the query cache wasn't created with the exact sequence of component
|
* If the query cache wasn't created with the exact sequence of component
|
||||||
* types, the behavior is undefined.
|
* types, the behavior is undefined.
|
||||||
* If the function accesses passed components after destroying the
|
* If the function accesses passed components after destroying the
|
||||||
|
|
@ -129,6 +131,8 @@ namespace psemek::ecs
|
||||||
* except for empty component types (i.e. std::is_empty_v<Component> is true),
|
* except for empty component types (i.e. std::is_empty_v<Component> is true),
|
||||||
* each having an unspecified non-zero size.
|
* each having an unspecified non-zero size.
|
||||||
* An optional query cache can be supplied to speed up iteration.
|
* An optional query cache can be supplied to speed up iteration.
|
||||||
|
* If any two of the passed component types are equal, the call fails with
|
||||||
|
* a compilation error.
|
||||||
* If the query cache wasn't created with the exact sequence of component
|
* If the query cache wasn't created with the exact sequence of component
|
||||||
* types, the behavior is undefined.
|
* types, the behavior is undefined.
|
||||||
* If the function creates or destroyes entities, the behavior is undefined.
|
* If the function creates or destroyes entities, the behavior is undefined.
|
||||||
|
|
@ -279,6 +283,8 @@ namespace psemek::ecs
|
||||||
template <typename ... Components, typename Function>
|
template <typename ... Components, typename Function>
|
||||||
void entity_container::apply(Function && function, query_cache cache)
|
void entity_container::apply(Function && function, query_cache cache)
|
||||||
{
|
{
|
||||||
|
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||||
|
|
||||||
if (!cache)
|
if (!cache)
|
||||||
cache = this->cache<Components...>();
|
cache = this->cache<Components...>();
|
||||||
|
|
||||||
|
|
@ -319,6 +325,8 @@ namespace psemek::ecs
|
||||||
template <typename ... Components, typename Function>
|
template <typename ... Components, typename Function>
|
||||||
void entity_container::batch_apply(Function && function, query_cache cache)
|
void entity_container::batch_apply(Function && function, query_cache cache)
|
||||||
{
|
{
|
||||||
|
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||||
|
|
||||||
if (!cache)
|
if (!cache)
|
||||||
cache = this->cache<Components...>();
|
cache = this->cache<Components...>();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue