|
|
@@ -159,8 +159,8 @@ inline constexpr basic_collector<> collector{};
|
|
|
* @tparam Allocator Type of allocator used to manage memory and elements.
|
|
|
*/
|
|
|
template<typename Registry, typename Mask, typename Allocator>
|
|
|
-class basic_observer: private basic_storage<Mask, typename Registry::entity_type, Allocator> {
|
|
|
- using base_type = basic_storage<Mask, typename Registry::entity_type, Allocator>;
|
|
|
+class basic_observer {
|
|
|
+ using storage_type = basic_storage<Mask, typename Registry::entity_type, Allocator>;
|
|
|
|
|
|
template<typename>
|
|
|
struct matcher_handler;
|
|
|
@@ -168,7 +168,7 @@ class basic_observer: private basic_storage<Mask, typename Registry::entity_type
|
|
|
template<typename... Reject, typename... Require, typename AnyOf>
|
|
|
struct matcher_handler<matcher<type_list<Reject...>, type_list<Require...>, AnyOf>> {
|
|
|
template<std::size_t Index>
|
|
|
- static void maybe_valid_if(base_type &obs, Registry ®, const typename Registry::entity_type entt) {
|
|
|
+ static void maybe_valid_if(storage_type &obs, Registry ®, const typename Registry::entity_type entt) {
|
|
|
if(reg.template all_of<Require...>(entt) && !reg.template any_of<Reject...>(entt)) {
|
|
|
if(!obs.contains(entt)) {
|
|
|
obs.emplace(entt);
|
|
|
@@ -179,21 +179,21 @@ class basic_observer: private basic_storage<Mask, typename Registry::entity_type
|
|
|
}
|
|
|
|
|
|
template<std::size_t Index>
|
|
|
- static void discard_if(base_type &obs, Registry &, const typename Registry::entity_type entt) {
|
|
|
+ static void discard_if(storage_type &obs, Registry &, const typename Registry::entity_type entt) {
|
|
|
if(obs.contains(entt) && !(obs.get(entt) &= (~(1 << Index)))) {
|
|
|
obs.erase(entt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
template<std::size_t Index>
|
|
|
- static void connect(base_type &obs, Registry ®) {
|
|
|
+ static void connect(storage_type &obs, Registry ®) {
|
|
|
(reg.template on_destroy<Require>().template connect<&discard_if<Index>>(obs), ...);
|
|
|
(reg.template on_construct<Reject>().template connect<&discard_if<Index>>(obs), ...);
|
|
|
reg.template on_update<AnyOf>().template connect<&maybe_valid_if<Index>>(obs);
|
|
|
reg.template on_destroy<AnyOf>().template connect<&discard_if<Index>>(obs);
|
|
|
}
|
|
|
|
|
|
- static void disconnect(base_type &obs, Registry ®) {
|
|
|
+ static void disconnect(storage_type &obs, Registry ®) {
|
|
|
(reg.template on_destroy<Require>().disconnect(&obs), ...);
|
|
|
(reg.template on_construct<Reject>().disconnect(&obs), ...);
|
|
|
reg.template on_update<AnyOf>().disconnect(&obs);
|
|
|
@@ -204,7 +204,7 @@ class basic_observer: private basic_storage<Mask, typename Registry::entity_type
|
|
|
template<typename... Reject, typename... Require, typename... NoneOf, typename... AllOf>
|
|
|
struct matcher_handler<matcher<type_list<Reject...>, type_list<Require...>, type_list<NoneOf...>, AllOf...>> {
|
|
|
template<std::size_t Index, typename... Ignore>
|
|
|
- static void maybe_valid_if(base_type &obs, Registry ®, const typename Registry::entity_type entt) {
|
|
|
+ static void maybe_valid_if(storage_type &obs, Registry ®, const typename Registry::entity_type entt) {
|
|
|
auto condition = [®, entt]() {
|
|
|
if constexpr(sizeof...(Ignore) == 0) {
|
|
|
return reg.template all_of<AllOf..., Require...>(entt) && !reg.template any_of<NoneOf..., Reject...>(entt);
|
|
|
@@ -223,14 +223,14 @@ class basic_observer: private basic_storage<Mask, typename Registry::entity_type
|
|
|
}
|
|
|
|
|
|
template<std::size_t Index>
|
|
|
- static void discard_if(base_type &obs, Registry &, const typename Registry::entity_type entt) {
|
|
|
+ static void discard_if(storage_type &obs, Registry &, const typename Registry::entity_type entt) {
|
|
|
if(obs.contains(entt) && !(obs.get(entt) &= (~(1 << Index)))) {
|
|
|
obs.erase(entt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
template<std::size_t Index>
|
|
|
- static void connect(base_type &obs, Registry ®) {
|
|
|
+ static void connect(storage_type &obs, Registry ®) {
|
|
|
(reg.template on_destroy<Require>().template connect<&discard_if<Index>>(obs), ...);
|
|
|
(reg.template on_construct<Reject>().template connect<&discard_if<Index>>(obs), ...);
|
|
|
(reg.template on_construct<AllOf>().template connect<&maybe_valid_if<Index>>(obs), ...);
|
|
|
@@ -239,7 +239,7 @@ class basic_observer: private basic_storage<Mask, typename Registry::entity_type
|
|
|
(reg.template on_construct<NoneOf>().template connect<&discard_if<Index>>(obs), ...);
|
|
|
}
|
|
|
|
|
|
- static void disconnect(base_type &obs, Registry ®) {
|
|
|
+ static void disconnect(storage_type &obs, Registry ®) {
|
|
|
(reg.template on_destroy<Require>().disconnect(&obs), ...);
|
|
|
(reg.template on_construct<Reject>().disconnect(&obs), ...);
|
|
|
(reg.template on_construct<AllOf>().disconnect(&obs), ...);
|
|
|
@@ -250,14 +250,14 @@ class basic_observer: private basic_storage<Mask, typename Registry::entity_type
|
|
|
};
|
|
|
|
|
|
template<typename... Matcher>
|
|
|
- static void disconnect(Registry ®, base_type &obs) {
|
|
|
+ static void disconnect(Registry ®, storage_type &obs) {
|
|
|
(matcher_handler<Matcher>::disconnect(obs, reg), ...);
|
|
|
}
|
|
|
|
|
|
template<typename... Matcher, std::size_t... Index>
|
|
|
void connect(Registry ®, std::index_sequence<Index...>) {
|
|
|
static_assert(sizeof...(Matcher) < std::numeric_limits<Mask>::digits, "Too many matchers");
|
|
|
- (matcher_handler<Matcher>::template connect<Index>(static_cast<base_type &>(*this), reg), ...);
|
|
|
+ (matcher_handler<Matcher>::template connect<Index>(storage, reg), ...);
|
|
|
release.template connect<&basic_observer::disconnect<Matcher...>>(reg);
|
|
|
}
|
|
|
|
|
|
@@ -282,8 +282,8 @@ public:
|
|
|
* @param allocator The allocator to use.
|
|
|
*/
|
|
|
explicit basic_observer(const allocator_type &allocator)
|
|
|
- : base_type{allocator},
|
|
|
- release{} {}
|
|
|
+ : release{},
|
|
|
+ storage{allocator} {}
|
|
|
|
|
|
/*! @brief Default copy constructor, deleted on purpose. */
|
|
|
basic_observer(const basic_observer &) = delete;
|
|
|
@@ -304,7 +304,7 @@ public:
|
|
|
}
|
|
|
|
|
|
/*! @brief Default destructor. */
|
|
|
- ~basic_observer() noexcept override = default;
|
|
|
+ ~basic_observer() noexcept = default;
|
|
|
|
|
|
/**
|
|
|
* @brief Default copy assignment operator, deleted on purpose.
|
|
|
@@ -327,13 +327,13 @@ public:
|
|
|
void connect(registry_type ®, basic_collector<Matcher...>) {
|
|
|
disconnect();
|
|
|
connect<Matcher...>(reg, std::index_sequence_for<Matcher...>{});
|
|
|
- base_type::clear();
|
|
|
+ storage.clear();
|
|
|
}
|
|
|
|
|
|
/*! @brief Disconnects an observer from the registry it keeps track of. */
|
|
|
void disconnect() {
|
|
|
if(release) {
|
|
|
- release(static_cast<base_type &>(*this));
|
|
|
+ release(storage);
|
|
|
release.reset();
|
|
|
}
|
|
|
}
|
|
|
@@ -343,7 +343,7 @@ public:
|
|
|
* @return Number of elements.
|
|
|
*/
|
|
|
[[nodiscard]] size_type size() const noexcept {
|
|
|
- return base_type::size();
|
|
|
+ return storage.size();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -351,7 +351,7 @@ public:
|
|
|
* @return True if the observer is empty, false otherwise.
|
|
|
*/
|
|
|
[[nodiscard]] bool empty() const noexcept {
|
|
|
- return base_type::empty();
|
|
|
+ return storage.empty();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -367,7 +367,7 @@ public:
|
|
|
* @return A pointer to the array of entities.
|
|
|
*/
|
|
|
[[nodiscard]] const entity_type *data() const noexcept {
|
|
|
- return base_type::data();
|
|
|
+ return storage.data();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -378,7 +378,7 @@ public:
|
|
|
* @return An iterator to the first entity of the observer.
|
|
|
*/
|
|
|
[[nodiscard]] iterator begin() const noexcept {
|
|
|
- return base_type::base_type::begin();
|
|
|
+ return storage.storage_type::base_type::begin();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -387,12 +387,12 @@ public:
|
|
|
* observer.
|
|
|
*/
|
|
|
[[nodiscard]] iterator end() const noexcept {
|
|
|
- return base_type::base_type::end();
|
|
|
+ return storage.storage_type::base_type::end();
|
|
|
}
|
|
|
|
|
|
/*! @brief Clears the underlying container. */
|
|
|
void clear() noexcept {
|
|
|
- base_type::clear();
|
|
|
+ storage.clear();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -431,7 +431,8 @@ public:
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
- delegate<void(base_type &)> release;
|
|
|
+ delegate<void(storage_type &)> release;
|
|
|
+ storage_type storage;
|
|
|
};
|
|
|
|
|
|
} // namespace entt
|