Explorar el Código

minor changes

Michele Caini hace 7 años
padre
commit
6a3bc37dc1
Se han modificado 3 ficheros con 18 adiciones y 1 borrados
  1. 0 1
      TODO
  2. 16 0
      src/entt/entity/prototype.hpp
  3. 2 0
      test/entt/entity/prototype.cpp

+ 0 - 1
TODO

@@ -9,7 +9,6 @@
 * optimize for empty components, it would be a mid improvement in terms of memory usage (see std::is_empty)
 * deep copy of a registry (or use the snapshot stuff to copy components and keep intact ids at least)
 * is it possible to iterate all the components assigned to an entity through a common base class?
-* prototype should offer a way to retrieve its internal registry
 * can we do more for shared libraries? who knows... see #144
 * work stealing job system (see #100)
 * composable looper so as to pack erased systems, compose runners at different rates and run them at once in the loop

+ 16 - 0
src/entt/entity/prototype.hpp

@@ -451,6 +451,22 @@ public:
         return create(*reg);
     }
 
+    /**
+     * @brief Returns a reference to the underlying registry.
+     * @return A reference to the underlying registry.
+     */
+    inline const registry_type & backend() const ENTT_NOEXCEPT {
+        return *reg;
+    }
+
+    /**
+     * @brief Returns a reference to the underlying registry.
+     * @return A reference to the underlying registry.
+     */
+    inline registry_type & backend() ENTT_NOEXCEPT {
+        return const_cast<registry_type &>(std::as_const(*this).backend());
+    }
+
 private:
     std::unordered_map<component_type, component_handler> handlers;
     registry<Entity> *reg;

+ 2 - 0
test/entt/entity/prototype.cpp

@@ -7,6 +7,8 @@ TEST(Prototype, SameRegistry) {
     entt::prototype prototype{registry};
     const auto &cprototype = prototype;
 
+    ASSERT_EQ(&registry, &prototype.backend());
+    ASSERT_EQ(&registry, &cprototype.backend());
     ASSERT_FALSE(registry.empty());
     ASSERT_FALSE((prototype.has<int, char>()));