aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlec Thomas <alec@swapoff.org>2015-06-22 15:30:19 +0200
committerAlec Thomas <alec@swapoff.org>2015-06-22 15:32:25 +0200
commitaeac8a52bf226c664fad4f30542658c1b36231e0 (patch)
treec309c908a090bfea075fb61d5cd8addb9babe308
parent9fd3843c3a4c6d21670189071d20fe29ca04fba6 (diff)
Add std::hash<Entity>.
-rw-r--r--entityx/Entity.h13
-rw-r--r--entityx/Event.h4
2 files changed, 15 insertions, 2 deletions
diff --git a/entityx/Entity.h b/entityx/Entity.h
index a19d971..493f948 100644
--- a/entityx/Entity.h
+++ b/entityx/Entity.h
@@ -27,6 +27,7 @@
#include <utility>
#include <vector>
#include <type_traits>
+ #include <functional>
#include "entityx/help/Pool.h"
#include "entityx/config.h"
@@ -44,6 +45,8 @@ class EntityManager;
template <typename C, typename EM = EntityManager>
class ComponentHandle;
+
+
/** A convenience handle around an Entity::Id.
*
* If an entity is destroyed, any copies will be invalidated. Use valid() to
@@ -985,3 +988,13 @@ inline void ComponentHandle<C, EM>::remove() {
} // namespace entityx
+
+
+namespace std {
+template <> struct hash<entityx::Entity> {
+ std::size_t operator () (const entityx::Entity &entity) const {
+ return static_cast<std::size_t>(entity.id().index() ^ entity.id().version());
+ }
+};
+}
+
diff --git a/entityx/Event.h b/entityx/Event.h
index 9e252dc..cb7b3ab 100644
--- a/entityx/Event.h
+++ b/entityx/Event.h
@@ -140,7 +140,7 @@ class EventManager : entityx::help::NonCopyable {
template <typename E, typename Receiver>
void unsubscribe(Receiver &receiver) {
BaseReceiver &base = receiver;
- //Assert that it has been subscribed before
+ // Assert that it has been subscribed before
assert(base.connections_.find(Event<E>::family()) != base.connections_.end());
auto pair = base.connections_[Event<E>::family()];
auto connection = pair.second;
@@ -205,7 +205,7 @@ class EventManager : entityx::help::NonCopyable {
// Functor used as an event signal callback that casts to E.
template <typename E>
struct EventCallbackWrapper {
- EventCallbackWrapper(std::function<void(const E &)> callback) : callback(callback) {}
+ explicit EventCallbackWrapper(std::function<void(const E &)> callback) : callback(callback) {}
void operator()(const void *event) { callback(*(static_cast<const E*>(event))); }
std::function<void(const E &)> callback;
};