|
|
@@ -74,7 +74,7 @@ struct entt_traits<std::uint64_t> {
|
|
|
* @tparam Type Type of identifier.
|
|
|
*/
|
|
|
template<typename Type>
|
|
|
-class entt_traits: public internal::entt_traits<Type> {
|
|
|
+class entt_traits: private internal::entt_traits<Type> {
|
|
|
using traits_type = internal::entt_traits<Type>;
|
|
|
|
|
|
public:
|
|
|
@@ -99,7 +99,7 @@ public:
|
|
|
* @param value The value to convert.
|
|
|
* @return The integral representation of the entity part.
|
|
|
*/
|
|
|
- [[nodiscard]] static constexpr auto to_entity(const Type value) {
|
|
|
+ [[nodiscard]] static constexpr auto to_entity(const Type value) ENTT_NOEXCEPT {
|
|
|
return (to_integral(value) & traits_type::entity_mask);
|
|
|
}
|
|
|
|
|
|
@@ -108,7 +108,7 @@ public:
|
|
|
* @param value The value to convert.
|
|
|
* @return The integral representation of the version part.
|
|
|
*/
|
|
|
- [[nodiscard]] static constexpr auto to_version(const Type value) {
|
|
|
+ [[nodiscard]] static constexpr auto to_version(const Type value) ENTT_NOEXCEPT {
|
|
|
constexpr auto mask = (traits_type::version_mask << traits_type::entity_shift);
|
|
|
return ((to_integral(value) & mask) >> traits_type::entity_shift);
|
|
|
}
|
|
|
@@ -119,9 +119,17 @@ public:
|
|
|
* @param version The version part of the identifier.
|
|
|
* @return A properly constructed identifier.
|
|
|
*/
|
|
|
- [[nodiscard]] static constexpr auto to_type(const entity_type entity, const version_type version = {}) {
|
|
|
+ [[nodiscard]] static constexpr auto to_type(const entity_type entity, const version_type version) ENTT_NOEXCEPT {
|
|
|
return Type{(entity & traits_type::entity_mask) | (version << traits_type::entity_shift)};
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Returns the reserved identifer.
|
|
|
+ * @return The reserved identifier.
|
|
|
+ */
|
|
|
+ [[nodiscard]] static constexpr auto reserved() ENTT_NOEXCEPT {
|
|
|
+ return to_type(traits_type::entity_mask, traits_type::version_mask);
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -146,7 +154,7 @@ struct null_t {
|
|
|
*/
|
|
|
template<typename Entity>
|
|
|
[[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
|
|
|
- return Entity{entt_traits<Entity>::entity_mask};
|
|
|
+ return entt_traits<Entity>::reserved();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -173,7 +181,7 @@ struct null_t {
|
|
|
*/
|
|
|
template<typename Entity>
|
|
|
[[nodiscard]] constexpr bool operator==(const Entity &entity) const ENTT_NOEXCEPT {
|
|
|
- return entt_traits<Entity>::to_entity(entity) == static_cast<typename entt_traits<Entity>::entity_type>(*this);
|
|
|
+ return entt_traits<Entity>::to_entity(entity) == entt_traits<Entity>::to_entity(*this);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -215,6 +223,84 @@ template<typename Entity>
|
|
|
}
|
|
|
|
|
|
|
|
|
+/*! @brief Tombstone object for all entity identifiers. */
|
|
|
+struct tombstone_t {
|
|
|
+ /**
|
|
|
+ * @brief Converts the tombstone object to identifiers of any type.
|
|
|
+ * @tparam Entity Type of entity identifier.
|
|
|
+ * @return The tombstone representation for the given identifier.
|
|
|
+ */
|
|
|
+ template<typename Entity>
|
|
|
+ [[nodiscard]] constexpr operator Entity() const ENTT_NOEXCEPT {
|
|
|
+ return entt_traits<Entity>::reserved();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Compares two tombstone objects.
|
|
|
+ * @return True in all cases.
|
|
|
+ */
|
|
|
+ [[nodiscard]] constexpr bool operator==(const tombstone_t &) const ENTT_NOEXCEPT {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Compares two tombstone objects.
|
|
|
+ * @return False in all cases.
|
|
|
+ */
|
|
|
+ [[nodiscard]] constexpr bool operator!=(const tombstone_t &) const ENTT_NOEXCEPT {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Compares a null tombstone and an entity identifier of any type.
|
|
|
+ * @tparam Entity Type of entity identifier.
|
|
|
+ * @param entity Entity identifier with which to compare.
|
|
|
+ * @return False if the two elements differ, true otherwise.
|
|
|
+ */
|
|
|
+ template<typename Entity>
|
|
|
+ [[nodiscard]] constexpr bool operator==(const Entity &entity) const ENTT_NOEXCEPT {
|
|
|
+ return entt_traits<Entity>::to_version(entity) == entt_traits<Entity>::to_version(*this);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @brief Compares a tombstone object and an entity identifier of any type.
|
|
|
+ * @tparam Entity Type of entity identifier.
|
|
|
+ * @param entity Entity identifier with which to compare.
|
|
|
+ * @return True if the two elements differ, false otherwise.
|
|
|
+ */
|
|
|
+ template<typename Entity>
|
|
|
+ [[nodiscard]] constexpr bool operator!=(const Entity &entity) const ENTT_NOEXCEPT {
|
|
|
+ return !(entity == *this);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Compares a tombstone object and an entity identifier of any type.
|
|
|
+ * @tparam Entity Type of entity identifier.
|
|
|
+ * @param entity Entity identifier with which to compare.
|
|
|
+ * @param other A tombstone object yet to be converted.
|
|
|
+ * @return False if the two elements differ, true otherwise.
|
|
|
+ */
|
|
|
+template<typename Entity>
|
|
|
+[[nodiscard]] constexpr bool operator==(const Entity &entity, const tombstone_t &other) ENTT_NOEXCEPT {
|
|
|
+ return other.operator==(entity);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Compares a tombstone object and an entity identifier of any type.
|
|
|
+ * @tparam Entity Type of entity identifier.
|
|
|
+ * @param entity Entity identifier with which to compare.
|
|
|
+ * @param other A tombstone object yet to be converted.
|
|
|
+ * @return True if the two elements differ, false otherwise.
|
|
|
+ */
|
|
|
+template<typename Entity>
|
|
|
+[[nodiscard]] constexpr bool operator!=(const Entity &entity, const tombstone_t &other) ENTT_NOEXCEPT {
|
|
|
+ return !(other == entity);
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @brief Compile-time constant for null entities.
|
|
|
*
|
|
|
@@ -225,6 +311,16 @@ template<typename Entity>
|
|
|
inline constexpr null_t null{};
|
|
|
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Compile-time constant for tombstone entities.
|
|
|
+ *
|
|
|
+ * There exist implicit conversions from this variable to entity identifiers of
|
|
|
+ * any allowed type. Similarly, there exist comparision operators between the
|
|
|
+ * tombstone entity and any other entity identifier.
|
|
|
+ */
|
|
|
+inline constexpr tombstone_t tombstone{};
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|