Skip to content

Commit

Permalink
removed matcher_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Jun 8, 2019
1 parent d3e686f commit 73bb023
Showing 1 changed file with 42 additions and 45 deletions.
87 changes: 42 additions & 45 deletions src/entt/entity/observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,52 +146,21 @@ class basic_observer {
using traits_type = entt_traits<Entity>;
using payload_type = std::uint32_t;

template<std::size_t Index, typename>
struct matcher_handler;

template<std::size_t Index, typename AnyOf>
struct matcher_handler<Index, matcher<AnyOf>> {
static void maybe_valid_if(basic_observer *obs, const basic_registry<Entity> &, const Entity entt) {
(obs->view.has(entt) ? obs->view.get(entt) : obs->view.construct(entt)) |= (1 << Index);
}

static void disconnect(basic_registry<Entity> &reg, const basic_observer &obs) {
(reg.template on_replace<AnyOf>().disconnect(&obs));
(reg.template on_destroy<AnyOf>().disconnect(&obs));
}

static void connect(basic_observer &obs, basic_registry<Entity> &reg) {
reg.template on_replace<AnyOf>().template connect<&maybe_valid_if>(&obs);
reg.template on_destroy<AnyOf>().template connect<&observer::discard_if<Index>>(&obs);
}
};

template<std::size_t Index, typename... AllOf, typename... NoneOf>
struct matcher_handler<Index, matcher<type_list<AllOf...>, type_list<NoneOf...>>> {
static void maybe_valid_if(basic_observer *obs, const basic_registry<Entity> &reg, const Entity entt) {
if(reg.template has<AllOf...>(entt) && !(reg.template has<NoneOf>(entt) || ...)) {
(obs->view.has(entt) ? obs->view.get(entt) : obs->view.construct(entt)) |= (1 << Index);
}
}

static void disconnect(basic_registry<Entity> &reg, const basic_observer &obs) {
((reg.template on_construct<AllOf>().disconnect(&obs)), ...);
((reg.template on_destroy<AllOf>().disconnect(&obs)), ...);
((reg.template on_construct<NoneOf>().disconnect(&obs)), ...);
((reg.template on_destroy<NoneOf>().disconnect(&obs)), ...);
}
template<typename... Matcher>
static void disconnect(basic_registry<Entity> &reg, const basic_observer &obs) {
(obs.disconnect(reg, Matcher{}), ...);
}

static void connect(basic_observer &obs, basic_registry<Entity> &reg) {
(reg.template on_construct<AllOf>().template connect<&maybe_valid_if>(&obs), ...);
(reg.template on_destroy<NoneOf>().template connect<&maybe_valid_if>(&obs), ...);
(reg.template on_destroy<AllOf>().template connect<&observer::discard_if<Index>>(&obs), ...);
(reg.template on_construct<NoneOf>().template connect<&observer::discard_if<Index>>(&obs), ...);
template<std::size_t Index, auto AllOf, typename... NoneOf>
void maybe_valid_if(const basic_registry<Entity> &reg, const Entity entt) {
if((reg.*AllOf)(entt) && !(reg.template has<NoneOf>(entt) || ...)) {
(view.has(entt) ? view.get(entt) : view.construct(entt)) |= (1 << Index);
}
};
}

template<auto... Disconnect>
static void disconnect(basic_registry<Entity> &reg, const basic_observer &obs) {
(Disconnect(reg, obs), ...);
template<std::size_t Index>
void maybe_valid_if(const basic_registry<Entity> &, const Entity entt) {
(view.has(entt) ? view.get(entt) : view.construct(entt)) |= (1 << Index);
}

template<std::size_t Index>
Expand All @@ -201,11 +170,39 @@ class basic_observer {
}
}

template<typename AnyOf>
void disconnect(basic_registry<Entity> &reg, matcher<AnyOf>) const {
(reg.template on_replace<AnyOf>().disconnect(this));
(reg.template on_destroy<AnyOf>().disconnect(this));
}

template<typename... AllOf, typename... NoneOf>
void disconnect(basic_registry<Entity> &reg, matcher<type_list<AllOf...>, type_list<NoneOf...>>) const {
((reg.template on_construct<AllOf>().disconnect(this)), ...);
((reg.template on_destroy<NoneOf>().disconnect(this)), ...);
((reg.template on_destroy<AllOf>().disconnect(this)), ...);
((reg.template on_construct<NoneOf>().disconnect(this)), ...);
}

template<std::size_t Index, typename AnyOf>
void connect(basic_registry<Entity> &reg, matcher<AnyOf>) {
reg.template on_replace<AnyOf>().template connect<&basic_observer::maybe_valid_if<Index>>(this);
reg.template on_destroy<AnyOf>().template connect<&basic_observer::discard_if<Index>>(this);
}

template<std::size_t Index, typename... AllOf, typename... NoneOf>
void connect(basic_registry<Entity> &reg, matcher<type_list<AllOf...>, type_list<NoneOf...>>) {
(reg.template on_construct<AllOf>().template connect<&basic_observer::maybe_valid_if<Index, &basic_registry<Entity>::template has<AllOf...>, NoneOf...>>(this), ...);
(reg.template on_destroy<NoneOf>().template connect<&basic_observer::maybe_valid_if<Index, &basic_registry<Entity>::template has<AllOf...>, NoneOf...>>(this), ...);
(reg.template on_destroy<AllOf>().template connect<&basic_observer::discard_if<Index>>(this), ...);
(reg.template on_construct<NoneOf>().template connect<&basic_observer::discard_if<Index>>(this), ...);
}

template<typename... Matcher, std::size_t... Index>
void connect(basic_registry<Entity> &reg, std::index_sequence<Index...>) {
static_assert(sizeof...(Matcher) < std::numeric_limits<payload_type>::digits);
release = &basic_observer::disconnect<&matcher_handler<Index, Matcher>::disconnect...>;
(matcher_handler<Index, Matcher>::connect(*this, reg), ...);
(connect<Index>(reg, Matcher{}), ...);
release = &disconnect<Matcher...>;
}

public:
Expand Down

0 comments on commit 73bb023

Please sign in to comment.