Browse Source

registry: context .clear() function - close #1262

skypjack 9 months ago
parent
commit
d7d63b09b7
2 changed files with 12 additions and 0 deletions
  1. 4 0
      src/entt/entity/registry.hpp
  2. 8 0
      test/entt/entity/registry.cpp

+ 4 - 0
src/entt/entity/registry.hpp

@@ -164,6 +164,10 @@ public:
     explicit registry_context(const allocator_type &allocator)
         : ctx{allocator} {}
 
+    void clear() noexcept {
+        ctx.clear();
+    }
+
     template<typename Type, typename... Args>
     Type &emplace_as(const id_type id, Args &&...args) {
         return any_cast<Type &>(ctx.try_emplace(id, std::in_place_type<Type>, std::forward<Args>(args)...).first->second);

+ 8 - 0
test/entt/entity/registry.cpp

@@ -2353,6 +2353,14 @@ TEST(Registry, Context) {
     ASSERT_EQ(ctx.find<const int>(), cctx.find<int>());
     ASSERT_EQ(ctx.get<int>(), cctx.get<const int>());
     ASSERT_EQ(ctx.get<int>(), 0);
+
+    ASSERT_TRUE(ctx.contains<char>());
+    ASSERT_TRUE(ctx.contains<int>());
+
+    ctx.clear();
+
+    ASSERT_FALSE(ctx.contains<char>());
+    ASSERT_FALSE(ctx.contains<int>());
 }
 
 TEST(Registry, ContextHint) {