|
|
@@ -33,7 +33,6 @@ class dispatcher {
|
|
|
virtual ~basic_pool() = default;
|
|
|
virtual void publish() = 0;
|
|
|
virtual void clear() ENTT_NOEXCEPT = 0;
|
|
|
- virtual id_type type_id() const ENTT_NOEXCEPT = 0;
|
|
|
};
|
|
|
|
|
|
template<typename Event>
|
|
|
@@ -69,10 +68,6 @@ class dispatcher {
|
|
|
events.emplace_back(std::forward<Args>(args)...);
|
|
|
}
|
|
|
|
|
|
- id_type type_id() const ENTT_NOEXCEPT override {
|
|
|
- return type_info<Event>::id();
|
|
|
- }
|
|
|
-
|
|
|
private:
|
|
|
signal_type signal{};
|
|
|
std::vector<Event> events;
|
|
|
@@ -81,14 +76,14 @@ class dispatcher {
|
|
|
template<typename Event>
|
|
|
pool_handler<Event> & assure() {
|
|
|
static_assert(std::is_same_v<Event, std::decay_t<Event>>);
|
|
|
- static std::size_t index{pools.size()};
|
|
|
+ const auto index = type_index<Event>::value();
|
|
|
|
|
|
- if(const auto length = pools.size(); !(index < length) || pools[index]->type_id() != type_info<Event>::id()) {
|
|
|
- for(index = {}; index < length && pools[index]->type_id() != type_info<Event>::id(); ++index);
|
|
|
+ if(!(index < pools.size())) {
|
|
|
+ pools.resize(index+1);
|
|
|
+ }
|
|
|
|
|
|
- if(index == pools.size()) {
|
|
|
- pools.emplace_back(new pool_handler<Event>{});
|
|
|
- }
|
|
|
+ if(!pools[index]) {
|
|
|
+ pools[index].reset(new pool_handler<Event>{});
|
|
|
}
|
|
|
|
|
|
return static_cast<pool_handler<Event> &>(*pools[index]);
|
|
|
@@ -187,7 +182,9 @@ public:
|
|
|
void clear() {
|
|
|
if constexpr(sizeof...(Event) == 0) {
|
|
|
for(auto &&cpool: pools) {
|
|
|
- cpool->clear();
|
|
|
+ if(cpool) {
|
|
|
+ cpool->clear();
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
(assure<Event>().clear(), ...);
|
|
|
@@ -217,7 +214,9 @@ public:
|
|
|
*/
|
|
|
void update() const {
|
|
|
for(auto pos = pools.size(); pos; --pos) {
|
|
|
- pools[pos-1]->publish();
|
|
|
+ if(auto &&cpool = pools[pos-1]; cpool) {
|
|
|
+ cpool->publish();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|