1
0
Эх сурвалжийг харах

accommodate => assign_or_replace (#153)

Michele Caini 7 жил өмнө
parent
commit
d0764d5854

+ 7 - 7
docs/entity.md

@@ -195,21 +195,21 @@ vel.dy = 0.;
 ```
 
 In case users want to assign a component to an entity, but it's unknown whether
-the entity already has it or not, `accommodate` does the work in a single call
-(there is a performance penalty to pay for this mainly due to the fact that it
-has to check if the entity already has the given component or not):
+the entity already has it or not, `assign_or_replace` does the work in a single
+call (there is a performance penalty to pay for this mainly due to the fact that
+it has to check if the entity already has the given component or not):
 
 ```cpp
-registry.accommodate<position>(entity, 0., 0.);
+registry.assign_or_replace<position>(entity, 0., 0.);
 
 // ...
 
-auto &velocity = registry.accommodate<velocity>(entity);
+auto &velocity = registry.assign_or_replace<velocity>(entity);
 vel.dx = 0.;
 vel.dy = 0.;
 ```
 
-Note that `accommodate` is a slightly faster alternative for the following
+Note that `assign_or_replace` is a slightly faster alternative for the following
 `if/else` statement and nothing more:
 
 ```cpp
@@ -716,7 +716,7 @@ Creating an entity from a prototype is straightforward:
 * Finally, to assign or replace all the components for an entity, thus
   overwriting existing ones:
   ```cpp
-  prototype.accommodate(entity);
+  prototype.assign_or_replace(entity);
   ```
 
 In the examples above, the prototype uses its underlying registry to create

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

@@ -98,7 +98,7 @@ struct actor {
      */
     template<typename Component, typename... Args>
     Component & assign(Args &&... args) {
-        return reg->template accommodate<Component>(entt, std::forward<Args>(args)...);
+        return reg->template assign_or_replace<Component>(entt, std::forward<Args>(args)...);
     }
 
     /**

+ 9 - 9
src/entt/entity/prototype.hpp

@@ -45,7 +45,7 @@ class prototype final {
     struct component_wrapper { Component component; };
 
     struct component_handler {
-        basic_fn_type *accommodate;
+        basic_fn_type *assign_or_replace;
         basic_fn_type *assign;
     };
 
@@ -132,9 +132,9 @@ public:
      */
     template<typename Component, typename... Args>
     Component & set(Args &&... args) {
-        basic_fn_type *accommodate = [](const prototype &prototype, registry<Entity> &other, const Entity dst) {
+        basic_fn_type *assign_or_replace = [](const prototype &prototype, registry<Entity> &other, const Entity dst) {
             const auto &wrapper = prototype.reg->template get<component_wrapper<Component>>(prototype.entity);
-            other.template accommodate<Component>(dst, wrapper.component);
+            other.template assign_or_replace<Component>(dst, wrapper.component);
         };
 
         basic_fn_type *assign = [](const prototype &prototype, registry<Entity> &other, const Entity dst) {
@@ -144,8 +144,8 @@ public:
             }
         };
 
-        handlers[reg->template type<Component>()] = component_handler{accommodate, assign};
-        auto &wrapper = reg->template accommodate<component_wrapper<Component>>(entity, Component{std::forward<Args>(args)...});
+        handlers[reg->template type<Component>()] = component_handler{assign_or_replace, assign};
+        auto &wrapper = reg->template assign_or_replace<component_wrapper<Component>>(entity, Component{std::forward<Args>(args)...});
         return wrapper.component;
     }
 
@@ -355,9 +355,9 @@ public:
      * @param other A valid reference to a registry.
      * @param dst A valid entity identifier.
      */
-    void accommodate(registry_type &other, const entity_type dst) const {
+    void assign_or_replace(registry_type &other, const entity_type dst) const {
         for(auto &handler: handlers) {
-            handler.second.accommodate(*this, other, dst);
+            handler.second.assign_or_replace(*this, other, dst);
         }
     }
 
@@ -379,8 +379,8 @@ public:
      *
      * @param dst A valid entity identifier.
      */
-    inline void accommodate(const entity_type dst) const {
-        accommodate(*reg, dst);
+    inline void assign_or_replace(const entity_type dst) const {
+        assign_or_replace(*reg, dst);
     }
 
     /**

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

@@ -771,7 +771,7 @@ public:
      * @return A reference to the newly created component.
      */
     template<typename Component, typename... Args>
-    Component & accommodate(const entity_type entity, Args &&... args) {
+    Component & assign_or_replace(const entity_type entity, Args &&... args) {
         assure<Component>();
         auto &cpool = pool<Component>();
 

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

@@ -500,7 +500,7 @@ public:
     template<typename... Component, typename Archive, typename... Type, typename... Member>
     continuous_loader & component(Archive &archive, Member Type:: *... member) {
         auto apply = [this](const auto entity, const auto &component) {
-            reg.template accommodate<std::decay_t<decltype(component)>>(entity, component);
+            reg.template assign_or_replace<std::decay_t<decltype(component)>>(entity, component);
         };
 
         (reset<Component>(), ...);

+ 2 - 2
test/entt/entity/prototype.cpp

@@ -66,7 +66,7 @@ TEST(Prototype, SameRegistry) {
     ASSERT_EQ(registry.get<char>(e0), '*');
 
     registry.get<char>(e1) = '*';
-    prototype.accommodate(e1);
+    prototype.assign_or_replace(e1);
 
     ASSERT_EQ(registry.get<char>(e1), 'c');
 }
@@ -126,7 +126,7 @@ TEST(Prototype, OtherRegistry) {
     ASSERT_EQ(registry.get<char>(e0), '*');
 
     registry.get<char>(e1) = '*';
-    prototype.accommodate(registry, e1);
+    prototype.assign_or_replace(registry, e1);
 
     ASSERT_EQ(registry.get<char>(e1), 'c');
 }

+ 5 - 5
test/entt/entity/registry.cpp

@@ -96,8 +96,8 @@ TEST(Registry, Functionalities) {
 
     const auto e2 = registry.create();
 
-    registry.accommodate<int>(e2, registry.get<int>(e0));
-    registry.accommodate<char>(e2, registry.get<char>(e0));
+    registry.assign_or_replace<int>(e2, registry.get<int>(e0));
+    registry.assign_or_replace<char>(e2, registry.get<char>(e0));
 
     ASSERT_TRUE(registry.has<int>(e2));
     ASSERT_TRUE(registry.has<char>(e2));
@@ -123,8 +123,8 @@ TEST(Registry, Functionalities) {
     ASSERT_NO_THROW(registry.replace<int>(e0, 0));
     ASSERT_EQ(registry.get<int>(e0), 0);
 
-    ASSERT_NO_THROW(registry.accommodate<int>(e0, 1));
-    ASSERT_NO_THROW(registry.accommodate<int>(e1, 1));
+    ASSERT_NO_THROW(registry.assign_or_replace<int>(e0, 1));
+    ASSERT_NO_THROW(registry.assign_or_replace<int>(e1, 1));
     ASSERT_EQ(static_cast<const entt::registry<> &>(registry).get<int>(e0), 1);
     ASSERT_EQ(static_cast<const entt::registry<> &>(registry).get<int>(e1), 1);
 
@@ -690,7 +690,7 @@ TEST(Registry, SignalsOnAccommodate) {
     const auto view = registry.persistent_view<int, char>();
 
     registry.assign<int>(entity);
-    registry.accommodate<char>(entity);
+    registry.assign_or_replace<char>(entity);
 
     ASSERT_FALSE((view.empty()));
 }

+ 2 - 2
test/mod/mod.cpp

@@ -27,7 +27,7 @@ duk_ret_t set(duk_context *ctx, entt::registry<> &registry) {
     if constexpr(std::is_same_v<Comp, position>) {
         const auto x = duk_require_number(ctx, 2);
         const auto y = duk_require_number(ctx, 3);
-        registry.accommodate<position>(entity, x, y);
+        registry.assign_or_replace<position>(entity, x, y);
     } else if constexpr(std::is_same_v<Comp, duktape_runtime>) {
         const auto type = duk_require_uint(ctx, 1);
 
@@ -41,7 +41,7 @@ duk_ret_t set(duk_context *ctx, entt::registry<> &registry) {
 
         duk_pop(ctx);
     } else {
-        registry.accommodate<Comp>(entity);
+        registry.assign_or_replace<Comp>(entity);
     }
 
     return 0;