From c9a4e276309ec176746eb9d35a5966999ee5b07c Mon Sep 17 00:00:00 2001 From: NukeBird Date: Fri, 14 Feb 2025 21:41:36 +0300 Subject: [PATCH] Destroy an entity and ensure it no longer exists --- tests/zecsy.cpp | 11 ++++++++++- zecsy.hpp | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/zecsy.cpp b/tests/zecsy.cpp index faee0e0..3054eb7 100644 --- a/tests/zecsy.cpp +++ b/tests/zecsy.cpp @@ -8,7 +8,16 @@ using namespace zecsy; TEST_CASE("Create a single entity and verify its existence") { world w; - + auto e = w.make_entity(); REQUIRE(w.is_alive(e)); } + +TEST_CASE("Destroy an entity and ensure it no longer exists in the world") +{ + world w; + + auto e = w.make_entity(); + w.destroy_entity(e); + REQUIRE_FALSE(w.is_alive(e)); +} diff --git a/zecsy.hpp b/zecsy.hpp index abefeab..ed7d0f8 100644 --- a/zecsy.hpp +++ b/zecsy.hpp @@ -22,6 +22,7 @@ namespace zecsy world &operator=(world &&) = default; entity_id make_entity(); + void destroy_entity(entity_id e); bool is_alive(entity_id e) const; private: std::bitset entities_bitset; @@ -38,6 +39,11 @@ namespace zecsy return id; } + inline void world::destroy_entity(entity_id e) + { + entities_bitset.reset(e); + } + inline bool world::is_alive(entity_id e) const { return entities_bitset.test(e);