tomato/test/example/custom_identifier.cpp
Green Sky 5c7231b7a3 Squashed 'external/entt/entt/' content from commit fef92113
git-subtree-dir: external/entt/entt
git-subtree-split: fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc
2023-07-25 11:29:51 +02:00

54 lines
1.3 KiB
C++

#include <cstdint>
#include <gtest/gtest.h>
#include <entt/entity/entity.hpp>
#include <entt/entity/registry.hpp>
struct entity_id {
using entity_type = std::uint32_t;
static constexpr auto null = entt::null;
constexpr entity_id(entity_type value = null) noexcept
: entt{value} {}
constexpr entity_id(const entity_id &other) noexcept
: entt{other.entt} {}
constexpr operator entity_type() const noexcept {
return entt;
}
private:
entity_type entt;
};
TEST(Example, CustomIdentifier) {
entt::basic_registry<entity_id> registry{};
entity_id entity{};
ASSERT_FALSE(registry.valid(entity));
ASSERT_TRUE(entity == entt::null);
entity = registry.create();
ASSERT_TRUE(registry.valid(entity));
ASSERT_TRUE(entity != entt::null);
ASSERT_FALSE((registry.all_of<int, char>(entity)));
ASSERT_EQ(registry.try_get<int>(entity), nullptr);
registry.emplace<int>(entity, 42);
ASSERT_TRUE((registry.any_of<int, char>(entity)));
ASSERT_EQ(registry.get<int>(entity), 42);
registry.destroy(entity);
ASSERT_FALSE(registry.valid(entity));
ASSERT_TRUE(entity != entt::null);
entity = registry.create();
ASSERT_TRUE(registry.valid(entity));
ASSERT_TRUE(entity != entt::null);
}