Jelajahi Sumber

ENTT_OPAQUE_TYPE: to_integer -> to_integral

Michele Caini 6 tahun lalu
induk
melakukan
d1a6edad8a

+ 1 - 1
src/entt/core/type_traits.hpp

@@ -178,7 +178,7 @@ constexpr auto is_equality_comparable_v = is_equality_comparable<Type>::value;
  */
 #define ENTT_OPAQUE_TYPE(clazz, type)\
     enum class ENTT_API clazz: type {};\
-    constexpr auto to_integer(const clazz id) ENTT_NOEXCEPT {\
+    constexpr auto to_integral(const clazz id) ENTT_NOEXCEPT {\
         return std::underlying_type_t<clazz>(id);\
     }\
     static_assert(true)

+ 1 - 1
src/entt/entity/entity.hpp

@@ -127,7 +127,7 @@ public:
 
     template<typename Entity>
     constexpr bool operator==(const Entity entity) const ENTT_NOEXCEPT {
-        return (to_integer(entity) & traits_type<Entity>::entity_mask) == to_integer(static_cast<Entity>(*this));
+        return (to_integral(entity) & traits_type<Entity>::entity_mask) == to_integral(static_cast<Entity>(*this));
     }
 
     template<typename Entity>

+ 23 - 23
src/entt/entity/registry.hpp

@@ -187,11 +187,11 @@ class basic_registry {
         if(destroyed == null) {
             entt = entities.emplace_back(entity_type(entities.size()));
             // traits_type::entity_mask is reserved to allow for null identifiers
-            ENTT_ASSERT(to_integer(entt) < traits_type::entity_mask);
+            ENTT_ASSERT(to_integral(entt) < traits_type::entity_mask);
         } else {
-            const auto curr = to_integer(destroyed);
-            const auto version = to_integer(entities[curr]) & (traits_type::version_mask << traits_type::entity_shift);
-            destroyed = entity_type{to_integer(entities[curr]) & traits_type::entity_mask};
+            const auto curr = to_integral(destroyed);
+            const auto version = to_integral(entities[curr]) & (traits_type::version_mask << traits_type::entity_shift);
+            destroyed = entity_type{to_integral(entities[curr]) & traits_type::entity_mask};
             entt = entity_type{curr | version};
             entities[curr] = entt;
         }
@@ -201,9 +201,9 @@ class basic_registry {
 
     void release(const Entity entity) {
         // lengthens the implicit list of destroyed entities
-        const auto entt = to_integer(entity) & traits_type::entity_mask;
-        const auto version = ((to_integer(entity) >> traits_type::entity_shift) + 1) << traits_type::entity_shift;
-        const auto node = to_integer(destroyed) | version;
+        const auto entt = to_integral(entity) & traits_type::entity_mask;
+        const auto version = ((to_integral(entity) >> traits_type::entity_shift) + 1) << traits_type::entity_shift;
+        const auto node = to_integral(destroyed) | version;
         entities[entt] = Entity{node};
         destroyed = Entity{entt};
     }
@@ -304,7 +304,7 @@ public:
         auto curr = destroyed;
 
         for(; curr != null; --sz) {
-            curr = entities[to_integer(curr) & traits_type::entity_mask];
+            curr = entities[to_integral(curr) & traits_type::entity_mask];
         }
 
         return sz;
@@ -433,7 +433,7 @@ public:
      * @return True if the identifier is valid, false otherwise.
      */
     bool valid(const entity_type entity) const {
-        const auto pos = size_type(to_integer(entity) & traits_type::entity_mask);
+        const auto pos = size_type(to_integral(entity) & traits_type::entity_mask);
         return (pos < entities.size() && entities[pos] == entity);
     }
 
@@ -443,7 +443,7 @@ public:
      * @return The entity identifier without the version.
      */
     static entity_type entity(const entity_type entity) ENTT_NOEXCEPT {
-        return entity_type{to_integer(entity) & traits_type::entity_mask};
+        return entity_type{to_integral(entity) & traits_type::entity_mask};
     }
 
     /**
@@ -452,7 +452,7 @@ public:
      * @return The version stored along with the given entity identifier.
      */
     static version_type version(const entity_type entity) ENTT_NOEXCEPT {
-        return version_type(to_integer(entity) >> traits_type::entity_shift);
+        return version_type(to_integral(entity) >> traits_type::entity_shift);
     }
 
     /**
@@ -469,9 +469,9 @@ public:
      * @return Actual version for the given entity identifier.
      */
     version_type current(const entity_type entity) const {
-        const auto pos = size_type(to_integer(entity) & traits_type::entity_mask);
+        const auto pos = size_type(to_integral(entity) & traits_type::entity_mask);
         ENTT_ASSERT(pos < entities.size());
-        return version_type(to_integer(entities[pos]) >> traits_type::entity_shift);
+        return version_type(to_integral(entities[pos]) >> traits_type::entity_shift);
     }
 
     /**
@@ -924,8 +924,8 @@ public:
         } else {
             for(auto pos = entities.size(); pos; --pos) {
                 const auto curr = entity_type(pos - 1);
-                const auto entity = entities[to_integer(curr)];
-                const auto entt = entity_type{to_integer(entity) & traits_type::entity_mask};
+                const auto entity = entities[to_integral(curr)];
+                const auto entt = entity_type{to_integral(entity) & traits_type::entity_mask};
 
                 if(curr == entt) {
                     func(entity);
@@ -1552,14 +1552,14 @@ public:
     entt::basic_snapshot<Entity> snapshot() const {
         using follow_fn_type = entity_type(const basic_registry &, const entity_type);
 
-        const auto head = to_integer(destroyed);
-        const entity_type seed = (destroyed == null) ? destroyed : entity_type{head | (to_integer(entities[head]) & (traits_type::version_mask << traits_type::entity_shift))};
+        const auto head = to_integral(destroyed);
+        const entity_type seed = (destroyed == null) ? destroyed : entity_type{head | (to_integral(entities[head]) & (traits_type::version_mask << traits_type::entity_shift))};
 
         follow_fn_type *follow = [](const basic_registry &reg, const entity_type entity) -> entity_type {
             const auto &others = reg.entities;
-            const auto entt = to_integer(entity) & traits_type::entity_mask;
-            const auto curr = to_integer(others[entt]) & traits_type::entity_mask;
-            return entity_type{curr | (to_integer(others[curr]) & (traits_type::version_mask << traits_type::entity_shift))};
+            const auto entt = to_integral(entity) & traits_type::entity_mask;
+            const auto curr = to_integral(others[entt]) & traits_type::entity_mask;
+            return entity_type{curr | (to_integral(others[curr]) & (traits_type::version_mask << traits_type::entity_shift))};
         };
 
         return { this, seed, follow };
@@ -1584,7 +1584,7 @@ public:
         using force_fn_type = void(basic_registry &, const entity_type, const bool);
 
         force_fn_type *force = [](basic_registry &reg, const entity_type entity, const bool discard) {
-            const auto entt = to_integer(entity) & traits_type::entity_mask;
+            const auto entt = to_integral(entity) & traits_type::entity_mask;
             auto &others = reg.entities;
 
             if(!(entt < others.size())) {
@@ -1600,8 +1600,8 @@ public:
 
             if(discard) {
                 reg.destroy(entity);
-                const auto version = to_integer(entity) & (traits_type::version_mask << traits_type::entity_shift);
-                others[entt] = entity_type{(to_integer(others[entt]) & traits_type::entity_mask) | version};
+                const auto version = to_integral(entity) & (traits_type::version_mask << traits_type::entity_shift);
+                others[entt] = entity_type{(to_integral(others[entt]) & traits_type::entity_mask) | version};
             }
         };
 

+ 2 - 2
src/entt/entity/sparse_set.hpp

@@ -154,11 +154,11 @@ class sparse_set {
     };
 
     auto page(const Entity entt) const ENTT_NOEXCEPT {
-        return std::size_t{(to_integer(entt) & traits_type::entity_mask) / entt_per_page};
+        return std::size_t{(to_integral(entt) & traits_type::entity_mask) / entt_per_page};
     }
 
     auto offset(const Entity entt) const ENTT_NOEXCEPT {
-        return std::size_t{to_integer(entt) & (entt_per_page - 1)};
+        return std::size_t{to_integral(entt) & (entt_per_page - 1)};
     }
 
     Entity * assure(const std::size_t pos) {

+ 1 - 1
test/entt/entity/snapshot.cpp

@@ -253,7 +253,7 @@ TEST(Snapshot, Iterator) {
     ASSERT_EQ(registry.view<another_component>().size(), size);
 
     registry.view<another_component>().each([](const auto entity, const auto &) {
-        ASSERT_TRUE(entt::to_integer(entity) % 2);
+        ASSERT_TRUE(entt::to_integral(entity) % 2);
     });
 }
 

+ 2 - 2
test/lib/registry/main.cpp

@@ -23,7 +23,7 @@ TEST(Lib, Registry) {
     update_position(1, registry);
 
     registry.view<position>().each([](auto entity, auto &position) {
-        ASSERT_EQ(position.x, entt::to_integer(entity) + 2);
-        ASSERT_EQ(position.y, entt::to_integer(entity) + 3);
+        ASSERT_EQ(position.x, entt::to_integral(entity) + 2);
+        ASSERT_EQ(position.y, entt::to_integral(entity) + 3);
     });
 }

+ 2 - 2
test/plugin/registry/main.cpp

@@ -25,8 +25,8 @@ TEST(Lib, Registry) {
     ASSERT_FALSE(registry.empty<velocity>());
 
     registry.view<position>().each([](auto entity, auto &position) {
-        ASSERT_EQ(position.x, entt::to_integer(entity) + 2);
-        ASSERT_EQ(position.y, entt::to_integer(entity) + 3);
+        ASSERT_EQ(position.x, entt::to_integral(entity) + 2);
+        ASSERT_EQ(position.y, entt::to_integral(entity) + 3);
     });
 
     cr_plugin_close(ctx);