Destroy an entity and ensure it no longer exists

This commit is contained in:
NukeBird 2025-02-14 21:41:36 +03:00
parent 1962e97cf9
commit c9a4e27630
2 changed files with 16 additions and 1 deletions

View file

@ -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));
}

View file

@ -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<MAX_ZECSY_ENTITIES> 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);