1#ifndef ENTT_ENTITY_ENTITY_HPP
2#define ENTT_ENTITY_ENTITY_HPP
4#include "../config/config.h"
5#include "../core/bit.hpp"
6#include "../stl/bit.hpp"
7#include "../stl/concepts.hpp"
8#include "../stl/cstddef.hpp"
9#include "../stl/cstdint.hpp"
10#include "../stl/type_traits.hpp"
21template<
typename Type>
23 requires stl::is_enum_v<Type>;
24 typename internal::entt_traits<stl::underlying_type_t<Type>>::value_type;
26struct entt_traits<Type>: entt_traits<stl::underlying_type_t<Type>> {
27 using value_type = Type;
30template<
typename Type>
31requires requires {
typename Type::entity_type; }
32struct entt_traits<Type>
33 : entt_traits<typename Type::entity_type> {
34 using value_type = Type;
38struct entt_traits<stl::uint32_t> {
39 using value_type = stl::uint32_t;
41 using entity_type = stl::uint32_t;
42 using version_type = stl::uint16_t;
44 static constexpr entity_type entity_mask = 0xFFFFF;
45 static constexpr entity_type version_mask = 0xFFF;
49struct entt_traits<stl::uint64_t> {
50 using value_type = stl::uint64_t;
52 using entity_type = stl::uint64_t;
53 using version_type = stl::uint32_t;
55 static constexpr entity_type entity_mask = 0xFFFFFFFF;
56 static constexpr entity_type version_mask = 0xFFFFFFFF;
66template<
typename Type>
68 typename internal::entt_traits<Type>::value_type;
75template<
typename Traits>
77 static constexpr auto length = stl::popcount(Traits::entity_mask);
107 static_assert(Traits::entity_mask && ((Traits::entity_mask & (Traits::entity_mask + 1)) == 0),
"Invalid entity mask");
117 if constexpr(Traits::version_mask == 0u) {
120 static_assert((Traits::version_mask & (Traits::version_mask + 1)) == 0,
"Invalid version mask");
146 if constexpr(Traits::version_mask == 0u) {
164 if constexpr(Traits::version_mask == 0u) {
176template<entity_like Type>
181 static constexpr stl::size_t
page_size = ENTT_SPARSE_PAGE;
190template<
typename Entity>
201template<
typename Entity>
212template<
typename Entity>
224 template<entity_like Entity>
225 [[nodiscard]]
constexpr operator Entity() const noexcept {
227 return traits_type::construct(traits_type::entity_mask, traits_type::version_mask);
235 [[nodiscard]]
constexpr bool operator==([[maybe_unused]]
const null_t other)
const noexcept {
245 template<entity_like Entity>
248 return traits_type::to_entity(
entity) == traits_type::to_entity(*
this);
259 template<entity_like Entity>
260 [[nodiscard]]
constexpr operator Entity() const noexcept {
262 return traits_type::construct(traits_type::entity_mask, traits_type::version_mask);
280 template<entity_like Entity>
284 if constexpr(traits_type::version_mask == 0u) {
287 return (traits_type::to_version(
entity) == traits_type::to_version(*
this));
Common basic entity traits implementation.
static constexpr entity_type version_mask
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
Traits::entity_type entity_type
Underlying entity type.
static constexpr entity_type to_entity(const value_type value) noexcept
Returns the entity part once converted to the underlying type.
Traits::value_type value_type
Value type.
static constexpr value_type combine(const entity_type lhs, const entity_type rhs) noexcept
Combines two identifiers in a single one.
Traits::version_type version_type
Underlying version type.
static constexpr version_type to_version(const value_type value) noexcept
Returns the version part once converted to the underlying type.
Specifies that a type is an entity-like 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.
static constexpr stl::size_t page_size
basic_entt_traits< internal::entt_traits< Type > > base_type
Base type.
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 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.