Browse Source

sigh_mixin: support self managed storage classes

Michele Caini 3 years ago
parent
commit
3862184e88
2 changed files with 11 additions and 7 deletions
  1. 7 3
      src/entt/entity/storage_mixin.hpp
  2. 4 4
      test/entt/entity/sigh_mixin.cpp

+ 7 - 3
src/entt/entity/storage_mixin.hpp

@@ -41,9 +41,13 @@ class sigh_mixin final: public Type {
 
     underlying_iterator try_emplace(const typename Type::entity_type entt, const bool force_back, const void *value) final {
         ENTT_ASSERT(owner != nullptr, "Invalid pointer to registry");
-        Type::try_emplace(entt, force_back, value);
-        construction.publish(*owner, entt);
-        return Type::find(entt);
+        const auto it = Type::try_emplace(entt, force_back, value);
+
+        if(it != base_type::end()) {
+            construction.publish(*owner, *it);
+        }
+
+        return it;
     }
 
 public:

+ 4 - 4
test/entt/entity/sigh_mixin.cpp

@@ -244,7 +244,7 @@ TEST(SighMixin, NonDefaultConstructibleType) {
     pool.emplace(entities[1u], 3);
 
     ASSERT_EQ(pool.size(), 1u);
-    ASSERT_EQ(on_construct.value, 2);
+    ASSERT_EQ(on_construct.value, 1);
     ASSERT_EQ(on_destroy.value, 0);
     ASSERT_FALSE(pool.empty());
 
@@ -254,7 +254,7 @@ TEST(SighMixin, NonDefaultConstructibleType) {
     base.erase(entities[1u]);
 
     ASSERT_EQ(pool.size(), 0u);
-    ASSERT_EQ(on_construct.value, 2);
+    ASSERT_EQ(on_construct.value, 1);
     ASSERT_EQ(on_destroy.value, 1);
     ASSERT_TRUE(pool.empty());
 
@@ -267,7 +267,7 @@ TEST(SighMixin, NonDefaultConstructibleType) {
     pool.insert(std::begin(entities), std::end(entities), 3);
 
     ASSERT_EQ(pool.size(), 2u);
-    ASSERT_EQ(on_construct.value, 6);
+    ASSERT_EQ(on_construct.value, 3);
     ASSERT_EQ(on_destroy.value, 1);
     ASSERT_FALSE(pool.empty());
 
@@ -277,7 +277,7 @@ TEST(SighMixin, NonDefaultConstructibleType) {
     pool.erase(std::begin(entities), std::end(entities));
 
     ASSERT_EQ(pool.size(), 0u);
-    ASSERT_EQ(on_construct.value, 6);
+    ASSERT_EQ(on_construct.value, 3);
     ASSERT_EQ(on_destroy.value, 3);
     ASSERT_TRUE(pool.empty());
 }