EnTT  3.2.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 
9 
10 namespace entt {
11 
12 
19 template<typename>
20 struct entt_traits;
21 
22 
31 template<>
32 struct entt_traits<std::uint16_t> {
34  using entity_type = std::uint16_t;
36  using version_type = std::uint8_t;
38  using difference_type = std::int32_t;
39 
41  static constexpr std::uint16_t entity_mask = 0xFFF;
43  static constexpr std::uint16_t version_mask = 0xF;
45  static constexpr auto entity_shift = 12;
46 };
47 
48 
57 template<>
58 struct entt_traits<std::uint32_t> {
60  using entity_type = std::uint32_t;
62  using version_type = std::uint16_t;
64  using difference_type = std::int64_t;
65 
67  static constexpr std::uint32_t entity_mask = 0xFFFFF;
69  static constexpr std::uint32_t version_mask = 0xFFF;
71  static constexpr auto entity_shift = 20;
72 };
73 
74 
83 template<>
84 struct entt_traits<std::uint64_t> {
86  using entity_type = std::uint64_t;
88  using version_type = std::uint32_t;
90  using difference_type = std::int64_t;
91 
93  static constexpr std::uint64_t entity_mask = 0xFFFFFFFF;
95  static constexpr std::uint64_t version_mask = 0xFFFFFFFF;
97  static constexpr auto entity_shift = 32;
98 };
99 
100 
107 namespace internal {
108 
109 
110 class null {
111  template<typename Entity>
112  using traits_type = entt_traits<std::underlying_type_t<Entity>>;
113 
114 public:
115  template<typename Entity>
116  constexpr operator Entity() const ENTT_NOEXCEPT {
117  return Entity{traits_type<Entity>::entity_mask};
118  }
119 
120  constexpr bool operator==(null) const ENTT_NOEXCEPT {
121  return true;
122  }
123 
124  constexpr bool operator!=(null) const ENTT_NOEXCEPT {
125  return false;
126  }
127 
128  template<typename Entity>
129  constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
130  return (to_integer(entity) & traits_type<Entity>::entity_mask) == to_integer(static_cast<Entity>(*this));
131  }
132 
133  template<typename Entity>
134  constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
135  return !(entity == *this);
136  }
137 };
138 
139 
140 template<typename Entity>
141 constexpr bool operator==(const Entity entity, null other) ENTT_NOEXCEPT {
142  return other == entity;
143 }
144 
145 
146 template<typename Entity>
147 constexpr bool operator!=(const Entity entity, null other) ENTT_NOEXCEPT {
148  return other != entity;
149 }
150 
151 
152 }
153 
154 
168 constexpr auto null = internal::null{};
169 
170 
171 }
172 
173 
174 #endif // ENTT_ENTITY_ENTITY_HPP
entt::null
constexpr auto null
Compile-time constant for null entities.
Definition: entity.hpp:168
entt::entt_traits< std::uint64_t >::version_type
std::uint32_t version_type
Underlying version type.
Definition: entity.hpp:88
entt::entt_traits< std::uint64_t >::entity_type
std::uint64_t entity_type
Underlying entity type.
Definition: entity.hpp:86
entt::entt_traits< std::uint32_t >::entity_type
std::uint32_t entity_type
Underlying entity type.
Definition: entity.hpp:60
entt::entt_traits< std::uint16_t >::difference_type
std::int32_t difference_type
Difference type.
Definition: entity.hpp:38
entt::entt_traits< std::uint64_t >::difference_type
std::int64_t difference_type
Difference type.
Definition: entity.hpp:90
entt::entt_traits< std::uint16_t >::version_type
std::uint8_t version_type
Underlying version type.
Definition: entity.hpp:36
entt::entt_traits< std::uint16_t >::entity_type
std::uint16_t entity_type
Underlying entity type.
Definition: entity.hpp:34
entt::entt_traits< std::uint32_t >::difference_type
std::int64_t difference_type
Difference type.
Definition: entity.hpp:64
entt
EnTT default namespace.
Definition: algorithm.hpp:12
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:217
entt::entt_traits< std::uint32_t >::version_type
std::uint16_t version_type
Underlying version type.
Definition: entity.hpp:62
entt::entt_traits
Entity traits.
Definition: entity.hpp:20