diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-02-12 17:07:55 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-02-12 17:07:55 -0500 |
commit | 3eccd38e989012ff35ee5376670aabc338c52008 (patch) | |
tree | e245a1db2f737feb0546c8d83e0673ca210b28df /entityx | |
parent | 7189e7d0d5130b7bb37c4d65e595b1608b3c39c8 (diff) |
locked EM.each, arenas
Diffstat (limited to 'entityx')
-rw-r--r-- | entityx/Entity.cc | 4 | ||||
-rw-r--r-- | entityx/Entity.h | 4 |
2 files changed, 7 insertions, 1 deletions
diff --git a/entityx/Entity.cc b/entityx/Entity.cc index ddb8df7..adac3de 100644 --- a/entityx/Entity.cc +++ b/entityx/Entity.cc @@ -31,7 +31,8 @@ std::bitset<entityx::MAX_COMPONENTS> Entity::component_mask() const { return manager_->component_mask(id_); } -EntityManager::EntityManager(EventManager &event_manager) : event_manager_(event_manager) { +EntityManager::EntityManager(EventManager &event_manager) + : event_manager_(event_manager) { } EntityManager::~EntityManager() { @@ -46,6 +47,7 @@ void EntityManager::reset() { for (BaseComponentHelper *helper : component_helpers_) { if (helper) delete helper; } + component_pools_.clear(); component_helpers_.clear(); entity_component_mask_.clear(); diff --git a/entityx/Entity.h b/entityx/Entity.h index 3217ae5..a423f8f 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -16,6 +16,7 @@ #include <new> #include <cstdlib> #include <algorithm> +#include <mutex> #include <bitset> #include <cassert> #include <iostream> @@ -462,8 +463,11 @@ class EntityManager : entityx::help::NonCopyable { template <typename T> struct identity { typedef T type; }; void each(typename identity<std::function<void(Entity entity, Components&...)>>::type f) { + static std::mutex locked; + locked.lock(); for (auto it : *this) f(it, *(it.template component<Components>().get())...); + locked.unlock(); } private: |