* drop utility.hpp
* turn get_t/exclude_t into aliases for type_list
* updated api for basic_registry<...>::group/group_if_exists
* doc review to reflect all the changes above
This commit is contained in:
Michele Caini
2022-04-13 17:19:02 +02:00
parent c134ea3098
commit 803db476bb
10 changed files with 51 additions and 79 deletions

View File

@@ -146,7 +146,6 @@ if(ENTT_INCLUDE_HEADERS)
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/snapshot.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/sparse_set.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/storage.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/utility.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/entity/view.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/locator/locator.hpp>
$<BUILD_INTERFACE:${EnTT_SOURCE_DIR}/src/entt/meta/adl_pointer.hpp>

View File

@@ -1732,7 +1732,7 @@ auto group = registry.group<position, velocity>();
Filtering entities by components is also supported:
```cpp
auto group = registry.group<position, velocity>(entt::exclude<renderable>);
auto group = registry.group<position, velocity>({}, entt::exclude<renderable>);
```
Once created, the group gets the ownership of all the components specified in
@@ -1841,7 +1841,7 @@ nested groups, an excluded component type `T` is treated as being an observed
type `not_T`. Therefore, consider these two definitions:
* `registry.group<sprite, transform>()`.
* `registry.group<sprite, transform>(entt::exclude<rotation>)`.
* `registry.group<sprite, transform>({}, entt::exclude<rotation>)`.
They are treated as if users were defining the following groups:

View File

@@ -3,7 +3,7 @@
#include <memory>
#include "../core/fwd.hpp"
#include "utility.hpp"
#include "../core/type_traits.hpp"
namespace entt {
@@ -43,6 +43,48 @@ class basic_snapshot_loader;
template<typename>
class basic_continuous_loader;
/**
* @brief Alias for exclusion lists.
* @tparam Type List of types.
*/
template<typename... Type>
using exclude_t = type_list<Type...>;
/**
* @brief Variable template for exclusion lists.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr exclude_t<Type...> exclude{};
/**
* @brief Alias for lists of observed components.
* @tparam Type List of types.
*/
template<typename... Type>
using get_t = type_list<Type...>;
/**
* @brief Variable template for lists of observed components.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr get_t<Type...> get{};
/**
* @brief Alias for lists of owned components.
* @tparam Type List of types.
*/
template<typename... Type>
using owned_t = type_list<Type...>;
/**
* @brief Variable template for lists of owned components.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr owned_t<Type...> owned{};
/*! @brief Default entity identifier. */
enum class entity : id_type {};

View File

@@ -12,7 +12,6 @@
#include "fwd.hpp"
#include "sparse_set.hpp"
#include "storage.hpp"
#include "utility.hpp"
namespace entt {

View File

@@ -13,7 +13,6 @@
#include "fwd.hpp"
#include "registry.hpp"
#include "storage.hpp"
#include "utility.hpp"
namespace entt {

View File

@@ -25,7 +25,6 @@
#include "runtime_view.hpp"
#include "sparse_set.hpp"
#include "storage.hpp"
#include "utility.hpp"
#include "view.hpp"
namespace entt {
@@ -1261,7 +1260,7 @@ public:
* @return A newly created group.
*/
template<typename... Owned, typename... Get, typename... Exclude>
[[nodiscard]] basic_group<entity_type, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> group(get_t<Get...>, exclude_t<Exclude...> = {}) {
[[nodiscard]] basic_group<entity_type, owned_t<Owned...>, get_t<Get...>, exclude_t<Exclude...>> group(get_t<Get...> = {}, exclude_t<Exclude...> = {}) {
static_assert(sizeof...(Owned) + sizeof...(Get) > 0, "Exclusion-only groups are not supported");
static_assert(sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude) > 1, "Single component groups are not allowed");
@@ -1343,7 +1342,7 @@ public:
/*! @copydoc group */
template<typename... Owned, typename... Get, typename... Exclude>
[[nodiscard]] basic_group<entity_type, owned_t<std::add_const_t<Owned>...>, get_t<std::add_const_t<Get>...>, exclude_t<Exclude...>> group_if_exists(get_t<Get...>, exclude_t<Exclude...> = {}) const {
[[nodiscard]] basic_group<entity_type, owned_t<std::add_const_t<Owned>...>, get_t<std::add_const_t<Get>...>, exclude_t<Exclude...>> group_if_exists(get_t<Get...> = {}, exclude_t<Exclude...> = {}) const {
auto it = std::find_if(groups.cbegin(), groups.cend(), [](const auto &gdata) {
return gdata.size == (sizeof...(Owned) + sizeof...(Get) + sizeof...(Exclude))
&& (gdata.owned(type_hash<std::remove_const_t<Owned>>::value()) && ...)
@@ -1359,18 +1358,6 @@ public:
}
}
/*! @copydoc group */
template<typename... Owned, typename... Exclude>
[[nodiscard]] basic_group<entity_type, owned_t<Owned...>, get_t<>, exclude_t<Exclude...>> group(exclude_t<Exclude...> = {}) {
return group<Owned...>(get_t<>{}, exclude<Exclude...>);
}
/*! @copydoc group */
template<typename... Owned, typename... Exclude>
[[nodiscard]] basic_group<entity_type, owned_t<std::add_const_t<Owned>...>, get_t<>, exclude_t<Exclude...>> group_if_exists(exclude_t<Exclude...> = {}) const {
return group_if_exists<std::add_const_t<Owned>...>(get_t<>{}, exclude<Exclude...>);
}
/**
* @brief Checks whether the given components belong to any group.
* @tparam Component Types of components in which one is interested.

View File

@@ -1,52 +0,0 @@
#ifndef ENTT_ENTITY_UTILITY_HPP
#define ENTT_ENTITY_UTILITY_HPP
#include "../core/type_traits.hpp"
namespace entt {
/**
* @brief Alias for exclusion lists.
* @tparam Type List of types.
*/
template<typename... Type>
struct exclude_t: type_list<Type...> {};
/**
* @brief Variable template for exclusion lists.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr exclude_t<Type...> exclude{};
/**
* @brief Alias for lists of observed components.
* @tparam Type List of types.
*/
template<typename... Type>
struct get_t: type_list<Type...> {};
/**
* @brief Variable template for lists of observed components.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr get_t<Type...> get{};
/**
* @brief Alias for lists of owned components.
* @tparam Type List of types.
*/
template<typename... Type>
struct owned_t: type_list<Type...> {};
/**
* @brief Variable template for lists of owned components.
* @tparam Type List of types.
*/
template<typename... Type>
inline constexpr owned_t<Type...> owned{};
} // namespace entt
#endif

View File

@@ -15,7 +15,6 @@
#include "fwd.hpp"
#include "sparse_set.hpp"
#include "storage.hpp"
#include "utility.hpp"
namespace entt {

View File

@@ -31,7 +31,6 @@
#include "entity/snapshot.hpp"
#include "entity/sparse_set.hpp"
#include "entity/storage.hpp"
#include "entity/utility.hpp"
#include "entity/view.hpp"
#include "locator/locator.hpp"
#include "meta/adl_pointer.hpp"

View File

@@ -1026,7 +1026,7 @@ TEST(OwningGroup, SortUnordered) {
TEST(OwningGroup, SortWithExclusionList) {
entt::registry registry;
auto group = registry.group<boxed_int>(entt::exclude<char>);
auto group = registry.group<boxed_int>({}, entt::exclude<char>);
entt::entity entities[5]{};
registry.create(std::begin(entities), std::end(entities));
@@ -1192,7 +1192,7 @@ TEST(OwningGroup, ExcludedComponents) {
registry.emplace<int>(e1, 1);
registry.emplace<char>(e1);
const auto group = registry.group<int>(entt::exclude<char, double>);
const auto group = registry.group<int>({}, entt::exclude<char, double>);
const auto e2 = registry.create();
registry.emplace<int>(e2, 2);
@@ -1263,8 +1263,8 @@ TEST(OwningGroup, EmptyAndNonEmptyTypes) {
TEST(OwningGroup, TrackEntitiesOnComponentDestruction) {
entt::registry registry;
const auto group = registry.group<int>(entt::exclude<char>);
const auto cgroup = std::as_const(registry).group_if_exists<const int>(entt::exclude<char>);
const auto group = registry.group<int>({}, entt::exclude<char>);
const auto cgroup = std::as_const(registry).group_if_exists<const int>({}, entt::exclude<char>);
const auto entity = registry.create();
registry.emplace<int>(entity);