Преглед изворни кода

*: combine dense hash map and identity when the key is a hashed string already

Michele Caini пре 4 година
родитељ
комит
8de568c2fc
4 измењених фајлова са 10 додато и 6 уклоњено
  1. 1 0
      TODO
  2. 2 1
      src/entt/entity/organizer.hpp
  3. 3 2
      src/entt/signal/dispatcher.hpp
  4. 4 3
      src/entt/signal/emitter.hpp

+ 1 - 0
TODO

@@ -4,6 +4,7 @@
 * add examples (and credits) from @alanjfs :)
 
 WIP:
+* use identity with dense hash map: cache (review api with hashed string), registry
 * fast-contains for sparse sets (low prio but nice-to-have)
 * runtime components (registry), runtime events (dispatcher/emitter), runtime context variables ...
 * runtime_view/registry, remove reference to basic_sparse_set<E>

+ 2 - 1
src/entt/entity/organizer.hpp

@@ -9,6 +9,7 @@
 #include "../container/dense_hash_map.hpp"
 #include "../core/type_info.hpp"
 #include "../core/type_traits.hpp"
+#include "../core/utility.hpp"
 #include "fwd.hpp"
 #include "helper.hpp"
 
@@ -477,7 +478,7 @@ public:
     }
 
 private:
-    dense_hash_map<id_type, std::vector<std::pair<std::size_t, bool>>> dependencies;
+    dense_hash_map<id_type, std::vector<std::pair<std::size_t, bool>>, identity> dependencies;
     std::vector<vertex_data> vertices;
 };
 

+ 3 - 2
src/entt/signal/dispatcher.hpp

@@ -10,6 +10,7 @@
 #include "../container/dense_hash_map.hpp"
 #include "../core/fwd.hpp"
 #include "../core/type_info.hpp"
+#include "../core/utility.hpp"
 #include "sigh.hpp"
 
 namespace entt {
@@ -85,7 +86,7 @@ class dispatcher {
 
     template<typename Event>
     [[nodiscard]] pool_handler<Event> &assure() {
-        if(auto &&ptr = pools[type_id<Event>().hash()]; !ptr) {
+        if(auto &&ptr = pools[type_hash<Event>::value()]; !ptr) {
             auto *cpool = new pool_handler<Event>{};
             ptr.reset(cpool);
             return *cpool;
@@ -255,7 +256,7 @@ public:
     }
 
 private:
-    dense_hash_map<id_type, std::unique_ptr<basic_pool>> pools;
+    dense_hash_map<id_type, std::unique_ptr<basic_pool>, identity> pools;
 };
 
 } // namespace entt

+ 4 - 3
src/entt/signal/emitter.hpp

@@ -12,6 +12,7 @@
 #include "../container/dense_hash_map.hpp"
 #include "../core/fwd.hpp"
 #include "../core/type_info.hpp"
+#include "../core/utility.hpp"
 
 namespace entt {
 
@@ -120,7 +121,7 @@ class emitter {
 
     template<typename Event>
     [[nodiscard]] pool_handler<Event> *assure() {
-        if(auto &&ptr = pools[type_id<Event>().hash()]; !ptr) {
+        if(auto &&ptr = pools[type_hash<Event>::value()]; !ptr) {
             auto *cpool = new pool_handler<Event>{};
             ptr.reset(cpool);
             return cpool;
@@ -131,7 +132,7 @@ class emitter {
 
     template<typename Event>
     [[nodiscard]] const pool_handler<Event> *assure() const {
-        const auto it = pools.find(type_id<Event>().hash());
+        const auto it = pools.find(type_hash<Event>::value());
         return (it == pools.cend()) ? nullptr : static_cast<const pool_handler<Event> *>(it->second.get());
     }
 
@@ -307,7 +308,7 @@ public:
     }
 
 private:
-    dense_hash_map<id_type, std::unique_ptr<basic_pool>> pools{};
+    dense_hash_map<id_type, std::unique_ptr<basic_pool>, identity> pools{};
 };
 
 } // namespace entt