added Registry::entity
This commit is contained in:
2
TODO
2
TODO
@@ -6,8 +6,8 @@
|
||||
* define systems as composable mixins (initializazion, reactive, update, whatever) with flexible auto-detected arguments (registry, views, etc)
|
||||
* create dedicated flat map based on types implementation (sort of "type map") for types to use within the registry and so on...
|
||||
* registry::create with a "hint" on the entity identifier to use, it should ease combining multiple registries
|
||||
* add a member function aside current and version to get the actual identifier without its version
|
||||
* can we do more for shared libraries? who knows... see #144
|
||||
* filtered views (has, hasn't and so on)
|
||||
* work stealing job system (see #100)
|
||||
* reflection system (maybe)
|
||||
* C++17. That's all.
|
||||
|
||||
@@ -387,10 +387,19 @@ public:
|
||||
return (entities[pos] == entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the entity identifier without the version.
|
||||
* @param entity An entity identifier, either valid or not.
|
||||
* @return The entity identifier without the version.
|
||||
*/
|
||||
entity_type entity(const entity_type entity) const ENTT_NOEXCEPT {
|
||||
return entity & traits_type::entity_mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the version stored along with an entity identifier.
|
||||
* @param entity An entity identifier, either valid or not.
|
||||
* @return Version stored along with the given entity identifier.
|
||||
* @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);
|
||||
@@ -442,7 +451,6 @@ public:
|
||||
if(available) {
|
||||
const auto entt = next;
|
||||
const auto version = entities[entt] & (~traits_type::entity_mask);
|
||||
|
||||
entity = entt | version;
|
||||
next = entities[entt] & traits_type::entity_mask;
|
||||
entities[entt] = entity;
|
||||
@@ -524,10 +532,10 @@ public:
|
||||
// just a way to protect users from listeners that attach components
|
||||
assert(orphan(entity));
|
||||
|
||||
// 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 node = (available ? next : ((entt + 1) & traits_type::entity_mask)) | version;
|
||||
|
||||
entities[entt] = node;
|
||||
next = entt;
|
||||
++available;
|
||||
|
||||
@@ -198,6 +198,22 @@ TEST(DefaultRegistry, Functionalities) {
|
||||
ASSERT_TRUE(registry.empty<int>());
|
||||
}
|
||||
|
||||
TEST(DefaultRegistry, Identifiers) {
|
||||
entt::DefaultRegistry registry;
|
||||
const auto pre = registry.create();
|
||||
|
||||
ASSERT_EQ(pre, registry.entity(pre));
|
||||
|
||||
registry.destroy(pre);
|
||||
const auto post = registry.create();
|
||||
|
||||
ASSERT_NE(pre, post);
|
||||
ASSERT_EQ(registry.entity(pre), registry.entity(post));
|
||||
ASSERT_NE(registry.version(pre), registry.version(post));
|
||||
ASSERT_NE(registry.version(pre), registry.current(pre));
|
||||
ASSERT_EQ(registry.version(post), registry.current(post));
|
||||
}
|
||||
|
||||
TEST(DefaultRegistry, RawData) {
|
||||
entt::DefaultRegistry registry;
|
||||
const entt::DefaultRegistry &cregistry = registry;
|
||||
|
||||
Reference in New Issue
Block a user