]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Add std::hash<Entity>.
authorAlec Thomas <alec@swapoff.org>
Mon, 22 Jun 2015 13:30:19 +0000 (15:30 +0200)
committerAlec Thomas <alec@swapoff.org>
Mon, 22 Jun 2015 13:32:25 +0000 (15:32 +0200)
entityx/Entity.h
entityx/Event.h

index a19d9711f713d00befce691912d60b391607ba3c..493f948cee0293961842ab687dab665a7e00b057 100644 (file)
@@ -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());
+  }
+};
+}
+
index 9e252dc7a413d111f8cd8ddb64ac4a0b1b1f1711..cb7b3ab46dab2d27031e5c0b0f1afacd946dfd14 100644 (file)
@@ -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;
   };