#include #include #include #include struct clazz { void func(entt::registry &, entt::entity curr) { entt = curr; } entt::entity entt{entt::null}; }; struct stable_type { static constexpr auto in_place_delete = true; int value; }; void sigh_callback(int &value) { ++value; } TEST(Helper, AsView) { entt::registry registry; const entt::registry cregistry; ([](entt::view>) {})(entt::as_view{registry}); ([](entt::view, entt::exclude_t>) {})(entt::as_view{registry}); ([](entt::view, entt::exclude_t>) {})(entt::as_view{registry}); ([](entt::view, entt::exclude_t>) {})(entt::as_view{cregistry}); } TEST(Helper, AsGroup) { entt::registry registry; const entt::registry cregistry; ([](entt::group, entt::get_t, entt::exclude_t>) {})(entt::as_group{registry}); ([](entt::group, entt::get_t, entt::exclude_t>) {})(entt::as_group{registry}); ([](entt::group, entt::get_t, entt::exclude_t>) {})(entt::as_group{cregistry}); } TEST(Helper, Invoke) { entt::registry registry; const auto entity = registry.create(); registry.on_construct().connect>(); registry.emplace(entity); ASSERT_EQ(entity, registry.get(entity).entt); } TEST(Helper, ToEntity) { entt::registry registry; const entt::entity null = entt::null; constexpr auto page_size = entt::storage_type_t::traits_type::page_size; const int value = 42; ASSERT_EQ(entt::to_entity(registry, 42), null); ASSERT_EQ(entt::to_entity(registry, value), null); const auto entity = registry.create(); auto &&storage = registry.storage(); storage.emplace(entity); while(storage.size() < (page_size - 1u)) { storage.emplace(registry.create(), value); } const auto other = registry.create(); const auto next = registry.create(); registry.emplace(other); registry.emplace(next); ASSERT_EQ(entt::to_entity(registry, registry.get(entity)), entity); ASSERT_EQ(entt::to_entity(registry, registry.get(other)), other); ASSERT_EQ(entt::to_entity(registry, registry.get(next)), next); ASSERT_EQ(®istry.get(entity) + page_size - 1u, ®istry.get(other)); registry.destroy(other); ASSERT_EQ(entt::to_entity(registry, registry.get(entity)), entity); ASSERT_EQ(entt::to_entity(registry, registry.get(next)), next); ASSERT_EQ(®istry.get(entity) + page_size - 1u, ®istry.get(next)); ASSERT_EQ(entt::to_entity(registry, 42), null); ASSERT_EQ(entt::to_entity(registry, value), null); } TEST(Helper, ToEntityStableType) { entt::registry registry; const entt::entity null = entt::null; constexpr auto page_size = entt::storage_type_t::traits_type::page_size; const stable_type value{42}; ASSERT_EQ(entt::to_entity(registry, stable_type{42}), null); ASSERT_EQ(entt::to_entity(registry, value), null); const auto entity = registry.create(); auto &&storage = registry.storage(); registry.emplace(entity); while(storage.size() < (page_size - 2u)) { storage.emplace(registry.create(), value); } const auto other = registry.create(); const auto next = registry.create(); registry.emplace(other); registry.emplace(next); ASSERT_EQ(entt::to_entity(registry, registry.get(entity)), entity); ASSERT_EQ(entt::to_entity(registry, registry.get(other)), other); ASSERT_EQ(entt::to_entity(registry, registry.get(next)), next); ASSERT_EQ(®istry.get(entity) + page_size - 2u, ®istry.get(other)); registry.destroy(other); ASSERT_EQ(entt::to_entity(registry, registry.get(entity)), entity); ASSERT_EQ(entt::to_entity(registry, registry.get(next)), next); ASSERT_EQ(®istry.get(entity) + page_size - 1u, ®istry.get(next)); ASSERT_EQ(entt::to_entity(registry, stable_type{42}), null); ASSERT_EQ(entt::to_entity(registry, value), null); } TEST(Helper, SighHelper) { using namespace entt::literals; entt::registry registry{}; const auto entt = registry.create(); entt::sigh_helper helper{registry}; int counter{}; ASSERT_EQ(&helper.registry(), ®istry); helper.with() .on_construct<&sigh_callback>(counter) .on_update<&sigh_callback>(counter) .on_destroy<&sigh_callback>(counter); ASSERT_EQ(counter, 0); registry.emplace(entt); registry.replace(entt); registry.erase(entt); ASSERT_EQ(counter, 3); helper.with("other"_hs) .on_construct<&sigh_callback>(counter) .on_update<&sigh_callback>(counter) .on_destroy<&sigh_callback>(counter); registry.emplace(entt); registry.replace(entt); registry.erase(entt); ASSERT_EQ(counter, 3); registry.storage("other"_hs).emplace(entt); registry.storage("other"_hs).patch(entt); registry.storage("other"_hs).erase(entt); ASSERT_EQ(counter, 6); }