diff --git a/tests/zecsy.cpp b/tests/zecsy.cpp index 9f654cb..9d2ef9d 100644 --- a/tests/zecsy.cpp +++ b/tests/zecsy.cpp @@ -1,10 +1,8 @@ #include -#include #include #define CATCH_CONFIG_MAIN #include -//#define MAX_ZECSY_ENTITIES 4 #include "../zecsy.hpp" using namespace zecsy; @@ -168,3 +166,20 @@ TEST_CASE("Addresses of removed components should be reused") entities.clear(); } } + +TEST_CASE("Attach multiple components to an entity and verify all are correctly stored and retrievable") +{ + world w; + + auto e = w.make_entity(); + e.set(ChoosenOne{}); + e.set(Name{"zecsy"}); + + REQUIRE(e.has()); + REQUIRE(w.has(e)); + + e.remove(); + + REQUIRE_FALSE(e.has()); + REQUIRE_FALSE(w.has(e)); +} diff --git a/zecsy.hpp b/zecsy.hpp index a314799..e222d32 100644 --- a/zecsy.hpp +++ b/zecsy.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -30,7 +31,7 @@ namespace zecsy bool is_alive() const; - template + template bool has() const; template @@ -54,6 +55,10 @@ namespace zecsy template bool has(entity_id e) const; + template + requires(sizeof...(Rest) >= 0) + bool has(entity_id e) const; + template T& get(entity_id e); @@ -95,7 +100,7 @@ namespace zecsy void destroy_entity(entity_id e); bool is_alive(entity_id e) const; - template + template bool has(entity_id e) const; template @@ -151,12 +156,6 @@ namespace zecsy return entities_bitset.test(e); } - template - inline bool world::has(entity_id e) const - { - return storage.has(e); - } - template inline bool component_storage::has(entity_id e) const { @@ -184,10 +183,10 @@ namespace zecsy return *ptr; } - template + template inline bool entity::has() const { - return w->has(id); + return w->has(id); } template @@ -269,4 +268,17 @@ namespace zecsy { w->remove(id); } + + template + inline bool world::has(entity_id e) const + { + return storage.has(e); + } + + template + requires(sizeof...(Rest) >= 0) + inline bool component_storage::has(entity_id e) const + { + return has(e) && has(e) && (has(e) && ...); + } };