Compare commits

...

7 Commits

Author SHA1 Message Date
Michele Caini
344e03ac64 update single include file to v3.12.2 2023-06-23 10:36:30 +02:00
Michele Caini
da56665b03 registry: make ::valid backward compatible 2023-06-22 10:29:42 +02:00
Michele Caini
f6f01ef1bc snapshot: avoid warnings due to deprecated functions 2023-06-21 13:31:21 +02:00
Michele Caini
0ed514628c now working on v3.12.2 2023-06-21 11:48:04 +02:00
Michele Caini
a41421d867 update single include file to v3.12.1 2023-06-19 16:22:38 +02:00
Michele Caini
c1f6b11f7d snapshot: reintroduce support to storage listeners 2023-06-17 22:45:02 +02:00
Michele Caini
b2233064a0 now working on version v3.12.1 2023-06-15 16:44:43 +02:00
6 changed files with 14797 additions and 8912 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@
#define ENTT_VERSION_MAJOR 3 #define ENTT_VERSION_MAJOR 3
#define ENTT_VERSION_MINOR 12 #define ENTT_VERSION_MINOR 12
#define ENTT_VERSION_PATCH 0 #define ENTT_VERSION_PATCH 2
#define ENTT_VERSION \ #define ENTT_VERSION \
ENTT_XSTR(ENTT_VERSION_MAJOR) \ ENTT_XSTR(ENTT_VERSION_MAJOR) \

View File

@@ -527,7 +527,7 @@ public:
* @return True if the identifier is valid, false otherwise. * @return True if the identifier is valid, false otherwise.
*/ */
[[nodiscard]] bool valid(const entity_type entt) const { [[nodiscard]] bool valid(const entity_type entt) const {
return entities.contains(entt); return entities.contains(entt) && (entities.index(entt) < entities.in_use());
} }
/** /**

View File

@@ -211,7 +211,9 @@ public:
basic_snapshot_loader(registry_type &source) noexcept basic_snapshot_loader(registry_type &source) noexcept
: reg{&source} { : reg{&source} {
// restoring a snapshot as a whole requires a clean registry // restoring a snapshot as a whole requires a clean registry
ENTT_ASSERT(reg->empty(), "Registry must be empty"); for([[maybe_unused]] auto elem: source.storage()) {
ENTT_ASSERT(elem.second.empty(), "Registry must be empty");
}
} }
/*! @brief Default move constructor. */ /*! @brief Default move constructor. */
@@ -259,7 +261,9 @@ public:
if constexpr(Registry::template storage_for_type<Type>::traits_type::page_size == 0u) { if constexpr(Registry::template storage_for_type<Type>::traits_type::page_size == 0u) {
storage.emplace(entity); storage.emplace(entity);
} else { } else {
archive(storage.emplace(entity)); Type elem{};
archive(elem);
storage.emplace(entity, std::move(elem));
} }
} }
} }
@@ -466,7 +470,9 @@ public:
if constexpr(Registry::template storage_for_type<Type>::traits_type::page_size == 0u) { if constexpr(Registry::template storage_for_type<Type>::traits_type::page_size == 0u) {
storage.emplace(map(entt)); storage.emplace(map(entt));
} else { } else {
archive(storage.emplace(map(entt))); Type elem{};
archive(elem);
storage.emplace(map(entt), std::move(elem));
} }
} }
} }
@@ -523,9 +529,10 @@ public:
if constexpr(std::remove_reference_t<decltype(storage)>::traits_type::page_size == 0u) { if constexpr(std::remove_reference_t<decltype(storage)>::traits_type::page_size == 0u) {
storage.emplace(map(entt)); storage.emplace(map(entt));
} else { } else {
auto &elem = storage.emplace(map(entt)); typename std::remove_reference_t<decltype(storage)>::value_type elem{};
archive(elem); archive(elem);
(update(elem, member), ...); (update(elem, member), ...);
storage.emplace(map(entt), std::move(elem));
} }
} }
} }

View File

@@ -576,8 +576,8 @@ TEST(Registry, CreateWithHint) {
auto e2 = registry.create(entt::entity{3}); auto e2 = registry.create(entt::entity{3});
ASSERT_EQ(e2, entt::entity{1}); ASSERT_EQ(e2, entt::entity{1});
ASSERT_TRUE(registry.valid(entt::entity{0})); ASSERT_FALSE(registry.valid(entt::entity{0}));
ASSERT_TRUE(registry.valid(entt::entity{2})); ASSERT_FALSE(registry.valid(entt::entity{2}));
ASSERT_EQ(e3, entt::entity{3}); ASSERT_EQ(e3, entt::entity{3});
registry.release(e2); registry.release(e2);

View File

@@ -11,11 +11,16 @@
#include <entt/entity/entity.hpp> #include <entt/entity/entity.hpp>
#include <entt/entity/registry.hpp> #include <entt/entity/registry.hpp>
#include <entt/entity/snapshot.hpp> #include <entt/entity/snapshot.hpp>
#include <entt/signal/sigh.hpp>
struct empty {}; struct empty {};
struct shadow { struct shadow {
entt::entity target{entt::null}; entt::entity target{entt::null};
static void listener(entt::entity &elem, entt::registry &registry, const entt::entity entt) {
elem = registry.get<shadow>(entt).target;
}
}; };
TEST(BasicSnapshot, Constructors) { TEST(BasicSnapshot, Constructors) {
@@ -265,7 +270,7 @@ TEST(BasicSnapshotLoader, GetEntityType) {
ASSERT_TRUE(registry.valid(entities[0u])); ASSERT_TRUE(registry.valid(entities[0u]));
ASSERT_TRUE(registry.valid(entities[1u])); ASSERT_TRUE(registry.valid(entities[1u]));
ASSERT_TRUE(registry.valid(entities[2u])); ASSERT_FALSE(registry.valid(entities[2u]));
ASSERT_EQ(storage.size(), 3u); ASSERT_EQ(storage.size(), 3u);
ASSERT_EQ(storage.in_use(), 2u); ASSERT_EQ(storage.in_use(), 2u);
@@ -417,6 +422,33 @@ TEST(BasicSnapshotLoader, GetTypeSparse) {
ASSERT_EQ(storage.get(entities[1u]), values[1u]); ASSERT_EQ(storage.get(entities[1u]), values[1u]);
} }
TEST(BasicSnapshotLoader, GetTypeWithListener) {
using traits_type = entt::entt_traits<entt::entity>;
entt::registry registry;
entt::basic_snapshot_loader loader{registry};
entt::entity check{entt::null};
std::vector<entt::any> data{};
auto archive = [&data, pos = 0u](auto &value) mutable { value = entt::any_cast<std::remove_reference_t<decltype(value)>>(data[pos++]); };
const auto entity{traits_type::construct(1u, 1u)};
const shadow value{entity};
ASSERT_FALSE(registry.valid(entity));
ASSERT_EQ(check, static_cast<entt::entity>(entt::null));
registry.on_construct<shadow>().connect<&shadow::listener>(check);
data.emplace_back(static_cast<typename traits_type::entity_type>(1u));
data.emplace_back(entity);
data.emplace_back(value);
loader.get<shadow>(archive);
ASSERT_TRUE(registry.valid(entity));
ASSERT_EQ(check, entity);
}
TEST(BasicSnapshotLoader, Orphans) { TEST(BasicSnapshotLoader, Orphans) {
using namespace entt::literals; using namespace entt::literals;
using traits_type = entt::entt_traits<entt::entity>; using traits_type = entt::entt_traits<entt::entity>;
@@ -823,6 +855,33 @@ TEST(BasicContinuousLoader, GetTypeSparse) {
ASSERT_EQ(storage.get(loader.map(entities[1u])), values[1u]); ASSERT_EQ(storage.get(loader.map(entities[1u])), values[1u]);
} }
TEST(BasicContinuousLoader, GetTypeWithListener) {
using traits_type = entt::entt_traits<entt::entity>;
entt::registry registry;
entt::basic_continuous_loader loader{registry};
entt::entity check{entt::null};
std::vector<entt::any> data{};
auto archive = [&data, pos = 0u](auto &value) mutable { value = entt::any_cast<std::remove_reference_t<decltype(value)>>(data[pos++]); };
const auto entity{traits_type::construct(1u, 1u)};
const shadow value{entity};
ASSERT_FALSE(registry.valid(loader.map(entity)));
ASSERT_EQ(check, static_cast<entt::entity>(entt::null));
registry.on_construct<shadow>().connect<&shadow::listener>(check);
data.emplace_back(static_cast<typename traits_type::entity_type>(1u));
data.emplace_back(entity);
data.emplace_back(value);
loader.get<shadow>(archive);
ASSERT_TRUE(registry.valid(loader.map(entity)));
ASSERT_EQ(check, entity);
}
TEST(BasicContinuousLoader, Shrink) { TEST(BasicContinuousLoader, Shrink) {
entt::registry registry; entt::registry registry;
entt::basic_continuous_loader loader{registry}; entt::basic_continuous_loader loader{registry};