|
|
@@ -155,9 +155,9 @@ inline constexpr basic_collector<> collector{};
|
|
|
* from the registry before being destroyed to avoid crashes due to dangling
|
|
|
* pointers.
|
|
|
*
|
|
|
- * @tparam Type Basic registry type.
|
|
|
+ * @tparam Registry Basic registry type.
|
|
|
*/
|
|
|
-template<typename Type>
|
|
|
+template<typename Registry>
|
|
|
class basic_observer {
|
|
|
using payload_type = std::uint32_t;
|
|
|
|
|
|
@@ -167,7 +167,7 @@ class basic_observer {
|
|
|
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(basic_observer &obs, Type ®, const typename Type::entity_type entt) {
|
|
|
+ static void maybe_valid_if(basic_observer &obs, Registry ®, const typename Registry::entity_type entt) {
|
|
|
if(reg.template all_of<Require...>(entt) && !reg.template any_of<Reject...>(entt)) {
|
|
|
if(!obs.storage.contains(entt)) {
|
|
|
obs.storage.emplace(entt);
|
|
|
@@ -178,21 +178,21 @@ class basic_observer {
|
|
|
}
|
|
|
|
|
|
template<std::size_t Index>
|
|
|
- static void discard_if(basic_observer &obs, Type &, const typename Type::entity_type entt) {
|
|
|
+ static void discard_if(basic_observer &obs, Registry &, const typename Registry::entity_type entt) {
|
|
|
if(obs.storage.contains(entt) && !(obs.storage.get(entt) &= (~(1 << Index)))) {
|
|
|
obs.storage.erase(entt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
template<std::size_t Index>
|
|
|
- static void connect(basic_observer &obs, Type ®) {
|
|
|
+ static void connect(basic_observer &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(basic_observer &obs, Type ®) {
|
|
|
+ static void disconnect(basic_observer &obs, Registry ®) {
|
|
|
(reg.template on_destroy<Require>().disconnect(obs), ...);
|
|
|
(reg.template on_construct<Reject>().disconnect(obs), ...);
|
|
|
reg.template on_update<AnyOf>().disconnect(obs);
|
|
|
@@ -203,7 +203,7 @@ class basic_observer {
|
|
|
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(basic_observer &obs, Type ®, const typename Type::entity_type entt) {
|
|
|
+ static void maybe_valid_if(basic_observer &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);
|
|
|
@@ -222,14 +222,14 @@ class basic_observer {
|
|
|
}
|
|
|
|
|
|
template<std::size_t Index>
|
|
|
- static void discard_if(basic_observer &obs, Type &, const typename Type::entity_type entt) {
|
|
|
+ static void discard_if(basic_observer &obs, Registry &, const typename Registry::entity_type entt) {
|
|
|
if(obs.storage.contains(entt) && !(obs.storage.get(entt) &= (~(1 << Index)))) {
|
|
|
obs.storage.erase(entt);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
template<std::size_t Index>
|
|
|
- static void connect(basic_observer &obs, Type ®) {
|
|
|
+ static void connect(basic_observer &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), ...);
|
|
|
@@ -238,7 +238,7 @@ class basic_observer {
|
|
|
(reg.template on_construct<NoneOf>().template connect<&discard_if<Index>>(obs), ...);
|
|
|
}
|
|
|
|
|
|
- static void disconnect(basic_observer &obs, Type ®) {
|
|
|
+ static void disconnect(basic_observer &obs, Registry ®) {
|
|
|
(reg.template on_destroy<Require>().disconnect(obs), ...);
|
|
|
(reg.template on_construct<Reject>().disconnect(obs), ...);
|
|
|
(reg.template on_construct<AllOf>().disconnect(obs), ...);
|
|
|
@@ -249,12 +249,12 @@ class basic_observer {
|
|
|
};
|
|
|
|
|
|
template<typename... Matcher>
|
|
|
- static void disconnect(Type ®, basic_observer &obs) {
|
|
|
+ static void disconnect(Registry ®, basic_observer &obs) {
|
|
|
(matcher_handler<Matcher>::disconnect(obs, reg), ...);
|
|
|
}
|
|
|
|
|
|
template<typename... Matcher, std::size_t... Index>
|
|
|
- void connect(Type ®, std::index_sequence<Index...>) {
|
|
|
+ void connect(Registry ®, std::index_sequence<Index...>) {
|
|
|
static_assert(sizeof...(Matcher) < std::numeric_limits<payload_type>::digits, "Too many matchers");
|
|
|
(matcher_handler<Matcher>::template connect<Index>(*this, reg), ...);
|
|
|
release.template connect<&basic_observer::disconnect<Matcher...>>(reg);
|
|
|
@@ -262,7 +262,7 @@ class basic_observer {
|
|
|
|
|
|
public:
|
|
|
/*! Basic registry type. */
|
|
|
- using registry_type = Type;
|
|
|
+ using registry_type = Registry;
|
|
|
/*! @brief Underlying entity identifier. */
|
|
|
using entity_type = typename registry_type::entity_type;
|
|
|
/*! @brief Unsigned integer type. */
|