EnTT  3.3.2
entity.hpp
1 #ifndef ENTT_ENTITY_ENTITY_HPP
2 #define ENTT_ENTITY_ENTITY_HPP
3 
4 
5 #include <cstdint>
6 #include <type_traits>
7 #include "../config/config.h"
8 #include "../core/type_traits.hpp"
9 
10 
11 namespace entt {
12 
13 
20 template<typename>
21 struct entt_traits;
22 
23 
32 template<>
33 struct entt_traits<std::uint16_t> {
35  using entity_type = std::uint16_t;
37  using version_type = std::uint8_t;
39  using difference_type = std::int32_t;
40 
42  static constexpr std::uint16_t entity_mask = 0xFFF;
44  static constexpr std::uint16_t version_mask = 0xF;
46  static constexpr auto entity_shift = 12;
47 };
48 
49 
58 template<>
59 struct entt_traits<std::uint32_t> {
61  using entity_type = std::uint32_t;
63  using version_type = std::uint16_t;
65  using difference_type = std::int64_t;
66 
68  static constexpr std::uint32_t entity_mask = 0xFFFFF;
70  static constexpr std::uint32_t version_mask = 0xFFF;
72  static constexpr auto entity_shift = 20;
73 };
74 
75 
84 template<>
85 struct entt_traits<std::uint64_t> {
87  using entity_type = std::uint64_t;
89  using version_type = std::uint32_t;
91  using difference_type = std::int64_t;
92 
94  static constexpr std::uint64_t entity_mask = 0xFFFFFFFF;
96  static constexpr std::uint64_t version_mask = 0xFFFFFFFF;
98  static constexpr auto entity_shift = 32;
99 };
100 
101 
108 namespace internal {
109 
110 
111 class null {
112  template<typename Entity>
113  using traits_type = entt_traits<std::underlying_type_t<Entity>>;
114 
115 public:
116  template<typename Entity>
117  constexpr operator Entity() const ENTT_NOEXCEPT {
118  return Entity{traits_type<Entity>::entity_mask};
119  }
120 
121  constexpr bool operator==(null) const ENTT_NOEXCEPT {
122  return true;
123  }
124 
125  constexpr bool operator!=(null) const ENTT_NOEXCEPT {
126  return false;
127  }
128 
129  template<typename Entity>
130  constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
131  return (to_integral(entity) & traits_type<Entity>::entity_mask) == to_integral(static_cast<Entity>(*this));
132  }
133 
134  template<typename Entity>
135  constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
136  return !(entity == *this);
137  }
138 };
139 
140 
141 template<typename Entity>
142 constexpr bool operator==(const Entity entity, null other) ENTT_NOEXCEPT {
143  return other == entity;
144 }
145 
146 
147 template<typename Entity>
148 constexpr bool operator!=(const Entity entity, null other) ENTT_NOEXCEPT {
149  return other != entity;
150 }
151 
152 
153 }
154 
155 
169 constexpr auto null = internal::null{};
170 
171 
172 }
173 
174 
175 #endif
entt::null
constexpr auto null
Compile-time constant for null entities.
Definition: entity.hpp:169
entt::entt_traits< std::uint64_t >::version_type
std::uint32_t version_type
Underlying version type.
Definition: entity.hpp:89
entt::entt_traits< std::uint64_t >::entity_type
std::uint64_t entity_type
Underlying entity type.
Definition: entity.hpp:87
entt::entt_traits< std::uint32_t >::entity_type
std::uint32_t entity_type
Underlying entity type.
Definition: entity.hpp:61
entt::entt_traits< std::uint16_t >::difference_type
std::int32_t difference_type
Difference type.
Definition: entity.hpp:39
entt::entt_traits< std::uint64_t >::difference_type
std::int64_t difference_type
Difference type.
Definition: entity.hpp:91
entt::entt_traits< std::uint16_t >::version_type
std::uint8_t version_type
Underlying version type.
Definition: entity.hpp:37
entt::entt_traits< std::uint16_t >::entity_type
std::uint16_t entity_type
Underlying entity type.
Definition: entity.hpp:35
entt::entt_traits< std::uint32_t >::difference_type
std::int64_t difference_type
Difference type.
Definition: entity.hpp:65
entt
EnTT default namespace.
Definition: algorithm.hpp:13
entt::operator!=
constexpr bool operator!=(const basic_hashed_string< Char > &lhs, const basic_hashed_string< Char > &rhs) ENTT_NOEXCEPT
Compares two hashed strings.
Definition: hashed_string.hpp:226
entt::entt_traits< std::uint32_t >::version_type
std::uint16_t version_type
Underlying version type.
Definition: entity.hpp:63
entt::entt_traits
Entity traits.
Definition: entity.hpp:21