diff --git a/TODO b/TODO index 105f203fd..d1ed7e5e0 100644 --- a/TODO +++ b/TODO @@ -20,8 +20,8 @@ * travis + windows is now available, try it * events on replace, so that one can track updated components? indagate impact * tags revenge: if it's possible, reintroduce them but without a link to entities (see #169 for more details) +* optimize reset (and some others?), direct call on pool in case of no listeners +* provide create with a pack of default constructible components to assign Ready to go: -* (even more) optimized standard views are possible! -* add on-the-fly sort functionality -* introduce induce-respect policy +* policy based views diff --git a/src/entt/entity/snapshot.hpp b/src/entt/entity/snapshot.hpp index 581c5aa84..f9d76b281 100644 --- a/src/entt/entity/snapshot.hpp +++ b/src/entt/entity/snapshot.hpp @@ -11,6 +11,7 @@ #include #include "../config/config.h" #include "entt_traits.hpp" +#include "entity.hpp" namespace entt { @@ -567,19 +568,18 @@ public: /** * @brief Returns the identifier to which an entity refers. - * - * @warning - * Attempting to use an entity that isn't managed by the loader results in - * undefined behavior.
- * An assertion will abort the execution at runtime in debug mode if the - * loader doesn't knows about the entity. - * * @param entity An entity identifier. - * @return The identifier to which `entity` refers in the target registry. + * @return The local identifier if any, the null entity otherwise. */ entity_type map(entity_type entity) const ENTT_NOEXCEPT { - assert(has(entity)); - return remloc.find(entity)->second.first; + const auto it = remloc.find(entity); + entity_type other = null; + + if(it != remloc.cend()) { + other = it->second.first; + } + + return other; } private: diff --git a/test/entt/entity/snapshot.cpp b/test/entt/entity/snapshot.cpp index bd578d47c..e3757f43e 100644 --- a/test/entt/entity/snapshot.cpp +++ b/test/entt/entity/snapshot.cpp @@ -3,6 +3,7 @@ #include #include #include +#include template struct output_archive { @@ -427,7 +428,7 @@ TEST(Snapshot, Continuous) { ASSERT_EQ(dst.size(), a_component_cnt); } -TEST(Snapshot, ContinuousMoreOnShrink) { +TEST(Snapshot, MoreOnShrink) { using entity_type = entt::registry<>::entity_type; entt::registry<> src; @@ -480,15 +481,20 @@ TEST(Snapshot, SyncDataMembers) { auto parent = src.create(); auto child = src.create(); + src.assign(parent, entt::null); src.assign(child, parent).quux.push_back(child); + src.snapshot().entities(output).component(output); loader.entities(input).component(input, &what_a_component::bar, &what_a_component::quux); ASSERT_FALSE(dst.valid(parent)); ASSERT_FALSE(dst.valid(child)); + ASSERT_TRUE(dst.has(loader.map(parent))); ASSERT_TRUE(dst.has(loader.map(child))); + ASSERT_EQ(dst.get(loader.map(parent)).bar, static_cast(entt::null)); + const auto &component = dst.get(loader.map(child)); ASSERT_EQ(component.bar, loader.map(parent));