1#ifndef ENTT_ENTITY_ENTITY_HPP
2#define ENTT_ENTITY_ENTITY_HPP
7#include "../config/config.h"
8#include "../core/bit.hpp"
16template<
typename,
typename =
void>
19template<
typename Type>
20struct entt_traits<Type, std::enable_if_t<std::is_enum_v<Type>>>
21 : entt_traits<std::underlying_type_t<Type>> {
22 using value_type = Type;
25template<
typename Type>
26struct entt_traits<Type, std::enable_if_t<std::is_class_v<Type>>>
27 : entt_traits<typename Type::entity_type> {
28 using value_type = Type;
32struct entt_traits<std::uint32_t> {
33 using value_type = std::uint32_t;
35 using entity_type = std::uint32_t;
36 using version_type = std::uint16_t;
38 static constexpr entity_type entity_mask = 0xFFFFF;
39 static constexpr entity_type version_mask = 0xFFF;
43struct entt_traits<std::uint64_t> {
44 using value_type = std::uint64_t;
46 using entity_type = std::uint64_t;
47 using version_type = std::uint32_t;
49 static constexpr entity_type entity_mask = 0xFFFFFFFF;
50 static constexpr entity_type version_mask = 0xFFFFFFFF;
60template<
typename Traits>
62 static constexpr auto length =
popcount(Traits::entity_mask);
64 static_assert(Traits::entity_mask && ((Traits::entity_mask & (Traits::entity_mask + 1)) == 0),
"Invalid entity mask");
65 static_assert((Traits::version_mask & (Traits::version_mask + 1)) == 0,
"Invalid version mask");
104 if constexpr(Traits::version_mask == 0
u) {
132 if constexpr(Traits::version_mask == 0
u) {
150 if constexpr(Traits::version_mask == 0
u) {
162template<
typename Type>
167 static constexpr std::size_t
page_size = ENTT_SPARSE_PAGE;
176template<
typename Entity>
187template<
typename Entity>
198template<
typename Entity>
210 template<
typename Entity>
213 constexpr auto value = traits_type::construct(traits_type::entity_mask, traits_type::version_mask);
241 template<
typename Entity>
244 return traits_type::to_entity(
entity) == traits_type::to_entity(*
this);
253 template<
typename Entity>
255 return !(
entity == *
this);
266template<
typename Entity>
268 return rhs.operator==(
lhs);
278template<
typename Entity>
290 template<
typename Entity>
293 constexpr auto value = traits_type::construct(traits_type::entity_mask, traits_type::version_mask);
321 template<
typename Entity>
325 if constexpr(traits_type::version_mask == 0
u) {
328 return (traits_type::to_version(
entity) == traits_type::to_version(*
this));
338 template<
typename Entity>
340 return !(
entity == *
this);
351template<
typename Entity>
353 return rhs.operator==(
lhs);
363template<
typename 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 Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
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.
constexpr std::enable_if_t< std::is_unsigned_v< Type >, int > popcount(const Type value) noexcept
Returns the number of set bits in a value (waiting for C++20 and std::popcount).
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.