This commit is contained in:
Michele Caini
2018-08-05 15:10:56 +02:00
parent d0f20ed2bf
commit b701c9c464
6 changed files with 36 additions and 38 deletions

View File

@@ -12,15 +12,15 @@
namespace entt {
namespace internal {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename...>
struct IsPartOf;
@@ -31,15 +31,15 @@ template<typename Type>
struct IsPartOf<Type>: std::false_type {};
}
/**
* Internal details not to be documented.
* @endcond TURN_OFF_DOXYGEN
*/
}
/**
* @brief Types identifiers.
*

View File

@@ -9,17 +9,13 @@
namespace entt {
namespace internal {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
template<typename Entity>
static constexpr auto null = ~typename entt_traits<Entity>::entity_type{};
namespace internal {
struct Null {
@@ -27,7 +23,8 @@ struct Null {
template<typename Entity>
constexpr operator Entity() const ENTT_NOEXCEPT {
return null<Entity>;
using traits_type = entt_traits<Entity>;
return traits_type::entity_mask | (traits_type::version_mask << traits_type::entity_shift);
}
constexpr bool operator==(Null) const ENTT_NOEXCEPT {
@@ -40,12 +37,12 @@ struct Null {
template<typename Entity>
constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
return entity == null<Entity>;
return entity == static_cast<Entity>(*this);
}
template<typename Entity>
constexpr bool operator!=(const Entity entity) const ENTT_NOEXCEPT {
return entity != null<Entity>;
return entity != static_cast<Entity>(*this);
}
};
@@ -62,15 +59,15 @@ constexpr bool operator!=(const Entity entity, Null null) ENTT_NOEXCEPT {
}
}
/**
* Internal details not to be documented.
* @endcond TURN_OFF_DOXYGEN
*/
}
/**
* @brief Null entity.
*

View File

@@ -36,9 +36,9 @@ struct entt_traits<std::uint16_t> {
using difference_type = std::int32_t;
/*! @brief Mask to use to get the entity number out of an identifier. */
static constexpr auto entity_mask = 0xFFF;
static constexpr std::uint16_t entity_mask = 0xFFF;
/*! @brief Mask to use to get the version out of an identifier. */
static constexpr auto version_mask = 0xF;
static constexpr std::uint16_t version_mask = 0xF;
/*! @brief Extent of the entity number within an identifier. */
static constexpr auto entity_shift = 12;
};
@@ -62,9 +62,9 @@ struct entt_traits<std::uint32_t> {
using difference_type = std::int64_t;
/*! @brief Mask to use to get the entity number out of an identifier. */
static constexpr auto entity_mask = 0xFFFFF;
static constexpr std::uint32_t entity_mask = 0xFFFFF;
/*! @brief Mask to use to get the version out of an identifier. */
static constexpr auto version_mask = 0xFFF;
static constexpr std::uint32_t version_mask = 0xFFF;
/*! @brief Extent of the entity number within an identifier. */
static constexpr auto entity_shift = 20;
};
@@ -88,9 +88,9 @@ struct entt_traits<std::uint64_t> {
using difference_type = std::int64_t;
/*! @brief Mask to use to get the entity number out of an identifier. */
static constexpr auto entity_mask = 0xFFFFFFFF;
static constexpr std::uint64_t entity_mask = 0xFFFFFFFF;
/*! @brief Mask to use to get the version out of an identifier. */
static constexpr auto version_mask = 0xFFFFFFFF;
static constexpr std::uint64_t version_mask = 0xFFFFFFFF;
/*! @brief Extent of the entity number within an identifier. */
static constexpr auto entity_shift = 32;
};

View File

@@ -9,6 +9,7 @@
#include <unordered_map>
#include "../config/config.h"
#include "registry.hpp"
#include "entity.hpp"
namespace entt {
@@ -95,7 +96,7 @@ public:
registry{other.registry},
entity{other.entity}
{
other.entity = ~entity_type{};
other.entity = entt::null;
}
/*! @brief Copying a prototype isn't allowed. @return This Prototype. */

View File

@@ -402,7 +402,7 @@ public:
* @return The version stored along with the given entity identifier.
*/
version_type version(const entity_type entity) const ENTT_NOEXCEPT {
return version_type((entity >> traits_type::entity_shift) & traits_type::version_mask);
return version_type(entity >> traits_type::entity_shift);
}
/**
@@ -425,7 +425,7 @@ public:
version_type current(const entity_type entity) const ENTT_NOEXCEPT {
const auto pos = size_type(entity & traits_type::entity_mask);
assert(pos < entities.size());
return version_type((entities[pos] >> traits_type::entity_shift) & traits_type::version_mask);
return version_type(entities[pos] >> traits_type::entity_shift);
}
/**
@@ -450,9 +450,9 @@ public:
if(available) {
const auto entt = next;
const auto version = entities[entt] & (~traits_type::entity_mask);
entity = entt | version;
const auto version = entities[entt] & (traits_type::version_mask << traits_type::entity_shift);
next = entities[entt] & traits_type::entity_mask;
entity = entt | version;
entities[entt] = entity;
--available;
} else {
@@ -534,7 +534,7 @@ public:
// lengthens the implicit list of destroyed entities
const auto entt = entity & traits_type::entity_mask;
const auto version = (((entity >> traits_type::entity_shift) + 1) & traits_type::version_mask) << traits_type::entity_shift;
const auto version = ((entity >> traits_type::entity_shift) + 1) << traits_type::entity_shift;
const auto node = (available ? next : ((entt + 1) & traits_type::entity_mask)) | version;
entities[entt] = node;
next = entt;
@@ -1550,13 +1550,13 @@ public:
*/
Snapshot<Entity> snapshot() const ENTT_NOEXCEPT {
using follow_fn_type = entity_type(const Registry &, const entity_type);
const entity_type seed = available ? (next | (entities[next] & ~traits_type::entity_mask)) : next;
const entity_type seed = available ? (next | (entities[next] & (traits_type::version_mask << traits_type::entity_shift))) : next;
follow_fn_type *follow = [](const Registry &registry, const entity_type entity) -> entity_type {
const auto &entities = registry.entities;
const auto entt = entity & traits_type::entity_mask;
const auto next = entities[entt] & traits_type::entity_mask;
return (next | (entities[next] & ~traits_type::entity_mask));
return (next | (entities[next] & (traits_type::version_mask << traits_type::entity_shift)));
};
return { *this, seed, follow };
@@ -1596,7 +1596,7 @@ public:
if(destroyed) {
registry.destroy(entity);
const auto version = (entity & (~traits_type::entity_mask));
const auto version = entity & (traits_type::version_mask << traits_type::entity_shift);
entities[entt] = ((entities[entt] & traits_type::entity_mask) | version);
}
};

View File

@@ -11,15 +11,15 @@
namespace entt {
namespace internal {
/**
* @cond TURN_OFF_DOXYGEN
* Internal details not to be documented.
*/
namespace internal {
template<typename, typename>
struct Invoker;
@@ -78,15 +78,15 @@ template<typename Function>
using DefaultCollectorType = typename DefaultCollector<Function>::collector_type;
}
/**
* Internal details not to be documented.
* @endcond TURN_OFF_DOXYGEN
*/
}
/**
* @brief Sink implementation.
*