1 #ifndef ENTT_ENTITY_ENTITY_HPP
2 #define ENTT_ENTITY_ENTITY_HPP
7 #include "../config/config.h"
19 template<
typename,
typename =
void>
22 template<
typename Type>
23 struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
24 : entt_traits<std::underlying_type_t<Type>> {};
26 template<
typename Type>
27 struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
28 : entt_traits<typename Type::entity_type> {};
31 struct entt_traits<std::uint32_t> {
32 using entity_type = std::uint32_t;
33 using version_type = std::uint16_t;
35 static constexpr entity_type entity_mask = 0xFFFFF;
36 static constexpr entity_type version_mask = 0xFFF;
37 static constexpr std::size_t entity_shift = 20u;
41 struct entt_traits<std::uint64_t> {
42 using entity_type = std::uint64_t;
43 using version_type = std::uint32_t;
45 static constexpr entity_type entity_mask = 0xFFFFFFFF;
46 static constexpr entity_type version_mask = 0xFFFFFFFF;
47 static constexpr std::size_t entity_shift = 32u;
61 template<
typename Type>
63 using base_type = internal::entt_traits<Type>;
73 static constexpr
entity_type reserved = base_type::entity_mask | (base_type::version_mask << base_type::entity_shift);
92 return (
to_integral(value) & base_type::entity_mask);
101 return (
to_integral(value) >> base_type::entity_shift);
129 constexpr
auto mask = (base_type::version_mask << base_type::entity_shift);
130 return value_type{(lhs & base_type::entity_mask) | (rhs & mask)};
138 template<
typename Entity>
147 template<
typename Entity>
156 template<
typename Entity>
168 template<
typename Entity>
169 [[nodiscard]] constexpr
operator Entity() const ENTT_NOEXCEPT {
171 return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
179 [[nodiscard]] constexpr
bool operator==([[maybe_unused]]
const null_t other)
const ENTT_NOEXCEPT {
188 [[nodiscard]] constexpr
bool operator!=([[maybe_unused]]
const null_t other)
const ENTT_NOEXCEPT {
198 template<
typename Entity>
201 return entity_traits::to_entity(
entity) == entity_traits::to_entity(*
this);
210 template<
typename Entity>
212 return !(
entity == *
this);
223 template<
typename Entity>
225 return other.operator==(
entity);
235 template<
typename Entity>
237 return !(other ==
entity);
247 template<
typename Entity>
248 [[nodiscard]] constexpr
operator Entity() const ENTT_NOEXCEPT {
250 return entity_traits::combine(entity_traits::reserved, entity_traits::reserved);
277 template<
typename Entity>
280 return entity_traits::to_version(
entity) == entity_traits::to_version(*
this);
289 template<
typename Entity>
291 return !(
entity == *
this);
302 template<
typename Entity>
304 return other.operator==(
entity);
314 template<
typename Entity>
316 return !(other ==
entity);
static constexpr auto page_size
Page size, default is ENTT_SPARSE_PAGE.
typename base_type::entity_type entity_type
Underlying entity type.
static constexpr entity_type reserved
Reserved identifier.
static constexpr entity_type to_integral(const value_type value)
Converts an entity to its underlying type.
static constexpr entity_type to_entity(const value_type value)
Returns the entity part once converted to the underlying type.
static constexpr value_type construct(const entity_type entity, const version_type version)
Constructs an identifier from its parts.
Type value_type
Value type.
static constexpr value_type combine(const entity_type lhs, const entity_type rhs)
Combines two identifiers in a single one.
typename base_type::version_type version_type
Underlying version type.
static constexpr version_type to_version(const value_type value)
Returns the version part once converted to the underlying type.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs)
Compares two hashed strings.
entity
Default entity identifier.
constexpr tombstone_t tombstone
Compile-time constant for tombstone entities.
constexpr entt_traits< Entity >::entity_type to_integral(const Entity value)
Converts an entity to its underlying type.
constexpr entt_traits< Entity >::entity_type to_entity(const Entity value)
Returns the entity part once converted to the underlying type.
bool operator!=(const basic_any< Len, Align > &lhs, const basic_any< Len, Align > &rhs)
Checks if two wrappers differ in their content.
constexpr entt_traits< Entity >::version_type to_version(const Entity value)
Returns the version part once converted to the underlying type.
Null object for all identifiers.
constexpr bool operator!=([[maybe_unused]] const null_t other) const
Compares two null objects.
constexpr bool operator!=(const Entity entity) const
Compares a null object and an identifier of any type.
constexpr bool operator==(const Entity entity) const
Compares a null object and an identifier of any type.
constexpr bool operator==([[maybe_unused]] const null_t other) const
Compares two null objects.
Tombstone object for all identifiers.
constexpr bool operator==([[maybe_unused]] const tombstone_t other) const
Compares two tombstone objects.
constexpr bool operator==(const Entity entity) const
Compares a tombstone object and an identifier of any type.
constexpr bool operator!=(const Entity entity) const
Compares a tombstone object and an identifier of any type.
constexpr bool operator!=([[maybe_unused]] const tombstone_t other) const
Compares two tombstone objects.