1 #ifndef ENTT_ENTITY_ENTITY_HPP
2 #define ENTT_ENTITY_ENTITY_HPP
8 #include "../config/config.h"
23 template<
typename,
typename =
void>
27 template<
typename Type>
28 struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
29 : entt_traits<std::underlying_type_t<Type>>
33 template<
typename Type>
34 struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
35 : entt_traits<typename Type::entity_type>
40 struct entt_traits<std::uint32_t> {
41 using entity_type = std::uint32_t;
42 using version_type = std::uint16_t;
43 using difference_type = std::int64_t;
45 static constexpr entity_type entity_mask = 0xFFFFF;
46 static constexpr entity_type version_mask = 0xFFF;
47 static constexpr std::size_t entity_shift = 20u;
52 struct entt_traits<std::uint64_t> {
53 using entity_type = std::uint64_t;
54 using version_type = std::uint32_t;
55 using difference_type = std::int64_t;
57 static constexpr entity_type entity_mask = 0xFFFFFFFF;
58 static constexpr entity_type version_mask = 0xFFFFFFFF;
59 static constexpr std::size_t entity_shift = 32u;
76 template<
typename Type>
78 using traits_type = internal::entt_traits<Type>;
105 return (
to_integral(value) & traits_type::entity_mask);
114 constexpr
auto mask = (traits_type::version_mask << traits_type::entity_shift);
115 return ((
to_integral(value) & mask) >> traits_type::entity_shift);
140 template<
typename Entity>
153 template<
typename Entity>
154 [[nodiscard]] constexpr
operator Entity() const ENTT_NOEXCEPT {
163 [[nodiscard]] constexpr
bool operator==([[maybe_unused]]
const null_t other)
const ENTT_NOEXCEPT {
172 [[nodiscard]] constexpr
bool operator!=([[maybe_unused]]
const null_t other)
const ENTT_NOEXCEPT {
182 template<
typename Entity>
193 template<
typename Entity>
195 return !(
entity == *
this);
204 template<
typename Entity>
218 template<
typename Entity>
220 return other.operator==(
entity);
231 template<
typename Entity>
233 return !(other ==
entity);
244 template<
typename Entity>
245 [[nodiscard]] constexpr
operator Entity() const ENTT_NOEXCEPT {
273 template<
typename Entity>
284 template<
typename Entity>
286 return !(
entity == *
this);
295 template<
typename Entity>
309 template<
typename Entity>
311 return other.operator==(
entity);
322 template<
typename Entity>
324 return !(other ==
entity);
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.
typename traits_type::version_type version_type
Underlying version type.
typename traits_type::entity_type entity_type
Underlying entity type.
static constexpr value_type construct(const entity_type entity=traits_type::entity_mask, const version_type version=traits_type::version_mask)
Constructs an identifier from its parts.
Type value_type
Value type.
static constexpr version_type to_version(const value_type value)
Returns the version part once converted to the underlying type.
typename traits_type::difference_type difference_type
Difference type.
entity
Default entity identifier.
constexpr auto to_integral(const Entity entity)
Converts an entity to its underlying type.
constexpr tombstone_t tombstone
Compile-time constant for tombstone entities.
bool operator!=(const basic_any< Len, Align > &lhs, const basic_any< Len, Align > &rhs)
Checks if two wrappers differ in their content.
constexpr bool operator==(const Entity entity, const null_t other)
Compares a null object and an entity identifier of any type.
Null object for all entity 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 entity identifier of any type.
constexpr bool operator==(const Entity entity) const
Compares a null object and an entity identifier of any type.
constexpr bool operator==([[maybe_unused]] const null_t other) const
Compares two null objects.
constexpr Entity operator|(const Entity entity) const
Creates a null object from an entity identifier of any type.
Tombstone object for all entity identifiers.
constexpr Entity operator|(const Entity entity) const
Creates a tombstone object from an entity identifier of any type.
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 entity identifier of any type.
constexpr bool operator!=(const Entity entity) const
Compares a tombstone object and an entity identifier of any type.
constexpr bool operator!=([[maybe_unused]] const tombstone_t other) const
Compares two tombstone objects.