1#ifndef ENTT_ENTITY_ENTITY_HPP
2#define ENTT_ENTITY_ENTITY_HPP
7#include "../config/config.h"
16template<
typename Type>
17constexpr int popcount(Type value)
noexcept {
18 return value ? (int(value & 1) + popcount(value >> 1)) : 0;
21template<
typename,
typename =
void>
24template<
typename Type>
25struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
26 : entt_traits<std::underlying_type_t<Type>> {
27 using value_type = Type;
30template<
typename Type>
31struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
32 : entt_traits<typename Type::entity_type> {
33 using value_type = Type;
37struct entt_traits<std::uint32_t> {
38 using value_type = std::uint32_t;
40 using entity_type = std::uint32_t;
41 using version_type = std::uint16_t;
43 static constexpr entity_type entity_mask = 0xFFFFF;
44 static constexpr entity_type version_mask = 0xFFF;
48struct entt_traits<std::uint64_t> {
49 using value_type = std::uint64_t;
51 using entity_type = std::uint64_t;
52 using version_type = std::uint32_t;
54 static constexpr entity_type entity_mask = 0xFFFFFFFF;
55 static constexpr entity_type version_mask = 0xFFFFFFFF;
65template<
typename Traits>
67 static constexpr auto length = internal::popcount(Traits::entity_mask);
69 static_assert(Traits::entity_mask && ((
typename Traits::entity_type{1} << length) == (Traits::entity_mask + 1)),
"Invalid entity mask");
70 static_assert((
typename Traits::entity_type{1} << internal::popcount(Traits::version_mask)) == (Traits::version_mask + 1),
"Invalid version mask");
155template<
typename Type>
160 static constexpr std::size_t
page_size = ENTT_SPARSE_PAGE;
169template<
typename Entity>
180template<
typename Entity>
191template<
typename Entity>
203 template<
typename Entity>
204 [[nodiscard]]
constexpr operator Entity() const noexcept {
206 constexpr auto value = traits_type::construct(traits_type::entity_mask, traits_type::version_mask);
215 [[nodiscard]]
constexpr bool operator==([[maybe_unused]]
const null_t other)
const noexcept {
224 [[nodiscard]]
constexpr bool operator!=([[maybe_unused]]
const null_t other)
const noexcept {
234 template<
typename Entity>
237 return traits_type::to_entity(
entity) == traits_type::to_entity(*
this);
246 template<
typename Entity>
248 return !(
entity == *
this);
259template<
typename Entity>
261 return other.operator==(
entity);
271template<
typename Entity>
273 return !(other ==
entity);
283 template<
typename Entity>
284 [[nodiscard]]
constexpr operator Entity() const noexcept {
286 constexpr auto value = traits_type::construct(traits_type::entity_mask, traits_type::version_mask);
314 template<
typename Entity>
317 return traits_type::to_version(
entity) == traits_type::to_version(*
this);
326 template<
typename Entity>
328 return !(
entity == *
this);
339template<
typename Entity>
341 return other.operator==(
entity);
351template<
typename Entity>
353 return !(other ==
entity);
Common basic entity traits implementation.
typename Traits::entity_type entity_type
Underlying entity type.
static constexpr entity_type version_mask
Version mask size.
static constexpr value_type construct(const entity_type entity, const version_type version) noexcept
Constructs an identifier from its parts.
static constexpr value_type next(const value_type value) noexcept
Returns the successor of a given identifier.
static constexpr entity_type to_integral(const value_type value) noexcept
Converts an entity to its underlying type.
static constexpr entity_type entity_mask
Entity mask size.
static constexpr entity_type to_entity(const value_type value) noexcept
Returns the entity part once converted to the underlying type.
typename Traits::value_type value_type
Value type.
typename Traits::version_type version_type
Underlying version type.
static constexpr value_type combine(const entity_type lhs, const entity_type rhs) noexcept
Combines two identifiers in a single one.
static constexpr version_type to_version(const value_type value) noexcept
Returns the version part once converted to the underlying type.
entity
Default entity identifier.
constexpr entt_traits< Entity >::entity_type to_entity(const Entity value) noexcept
Returns the entity part once converted to the underlying type.
constexpr null_t null
Compile-time constant for null entities.
constexpr entt_traits< Entity >::version_type to_version(const Entity value) noexcept
Returns the version part once converted to the underlying type.
constexpr tombstone_t tombstone
Compile-time constant for tombstone entities.
constexpr entt_traits< Entity >::entity_type to_integral(const Entity value) noexcept
Converts an entity to its underlying type.
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
constexpr bool operator==(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) noexcept
Compares two hashed strings.
static constexpr std::size_t page_size
Page size, default is ENTT_SPARSE_PAGE.
Null object for all identifiers.
constexpr bool operator==(const Entity entity) const noexcept
Compares a null object and an identifier of any type.
constexpr bool operator!=(const Entity entity) const noexcept
Compares a null object and an identifier of any type.
constexpr bool operator!=(const null_t other) const noexcept
Compares two null objects.
constexpr bool operator==(const null_t other) const noexcept
Compares two null objects.
Tombstone object for all identifiers.
constexpr bool operator==(const Entity entity) const noexcept
Compares a tombstone object and an identifier of any type.
constexpr bool operator!=(const tombstone_t other) const noexcept
Compares two tombstone objects.
constexpr bool operator!=(const Entity entity) const noexcept
Compares a tombstone object and an identifier of any type.
constexpr bool operator==(const tombstone_t other) const noexcept
Compares two tombstone objects.