Return query cache from ecs::container::apply and batch_apply
This commit is contained in:
parent
6a13a06187
commit
2a97a467aa
1 changed files with 16 additions and 6 deletions
|
|
@ -143,10 +143,13 @@ 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 the caller doesn't
|
||||||
|
* supply a query cache, a new query cache is created as if by calling `cache<Components...>()`.
|
||||||
|
* In any case, the (user-provided or newly-created) query cache is returned.
|
||||||
*
|
*
|
||||||
* @param function The function to apply to all entities with the specified components
|
* @param function The function to apply to all entities with the specified components
|
||||||
* @param cache A query cache
|
* @param cache A query cache
|
||||||
|
* @return The query cache, either user-provided, or newly-created
|
||||||
* @pre The query query cache was created with the exact same sequence of component types
|
* @pre The query query cache was created with the exact same sequence of component types
|
||||||
* @warning If any two of the passed component types are equal, the call fails with
|
* @warning If any two of the passed component types are equal, the call fails with
|
||||||
* a compilation error
|
* a compilation error
|
||||||
|
|
@ -156,7 +159,7 @@ namespace psemek::ecs
|
||||||
* behavior is undefined
|
* behavior is undefined
|
||||||
*/
|
*/
|
||||||
template <typename ... Components, typename Function>
|
template <typename ... Components, typename Function>
|
||||||
void apply(Function && function, query_cache cache = {});
|
query_cache apply(Function && function, query_cache cache = {});
|
||||||
|
|
||||||
/** Apply a function to all entities having the specified components,
|
/** Apply a function to all entities having the specified components,
|
||||||
* in unspecified order. Instead of applying the function to each
|
* in unspecified order. Instead of applying the function to each
|
||||||
|
|
@ -175,10 +178,13 @@ namespace psemek::ecs
|
||||||
* the function should use the entity handles array view to compute the number
|
* the function should use the entity handles array view to compute the number
|
||||||
* of visited entities.
|
* of visited entities.
|
||||||
*
|
*
|
||||||
* An optional query cache can be supplied to speed up iteration.
|
* An optional query cache can be supplied to speed up iteration. If the caller doesn't
|
||||||
|
* supply a query cache, a new query cache is created as if by calling `cache<Components...>()`.
|
||||||
|
* In any case, the (user-provided or newly-created) query cache is returned.
|
||||||
*
|
*
|
||||||
* @param function The function to batch-apply to all entities with the specified components
|
* @param function The function to batch-apply to all entities with the specified components
|
||||||
* @param cache A query cache
|
* @param cache A query cache
|
||||||
|
* @return The query cache, either user-provided, or newly-created
|
||||||
* @pre The query query cache was created with the exact same sequence of component types
|
* @pre The query query cache was created with the exact same sequence of component types
|
||||||
* @warning If any two of the passed component types are equal, the call fails with
|
* @warning If any two of the passed component types are equal, the call fails with
|
||||||
* a compilation error
|
* a compilation error
|
||||||
|
|
@ -187,7 +193,7 @@ namespace psemek::ecs
|
||||||
* @warning If the function recursively calls `apply()` or `batch_apply()`, the behavior is undefined
|
* @warning If the function recursively calls `apply()` or `batch_apply()`, the behavior is undefined
|
||||||
*/
|
*/
|
||||||
template <typename ... Components, typename Function>
|
template <typename ... Components, typename Function>
|
||||||
void batch_apply(Function && function, query_cache cache = {});
|
query_cache batch_apply(Function && function, query_cache cache = {});
|
||||||
|
|
||||||
/** Register a constructor. Each time an entity is created that has
|
/** Register a constructor. Each time an entity is created that has
|
||||||
* the specified set of components, the constructor is called for
|
* the specified set of components, the constructor is called for
|
||||||
|
|
@ -413,7 +419,7 @@ namespace psemek::ecs
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ... Components, typename Function>
|
template <typename ... Components, typename Function>
|
||||||
void container::apply(Function && function, query_cache cache)
|
query_cache container::apply(Function && function, query_cache cache)
|
||||||
{
|
{
|
||||||
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||||
|
|
||||||
|
|
@ -452,10 +458,12 @@ namespace psemek::ecs
|
||||||
data.row = row++;
|
data.row = row++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ... Components, typename Function>
|
template <typename ... Components, typename Function>
|
||||||
void container::batch_apply(Function && function, query_cache cache)
|
query_cache container::batch_apply(Function && function, query_cache cache)
|
||||||
{
|
{
|
||||||
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||||
|
|
||||||
|
|
@ -471,6 +479,8 @@ namespace psemek::ecs
|
||||||
|
|
||||||
apply_helper.batch_apply(function);
|
apply_helper.batch_apply(function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue