mirror of
https://github.com/BlackMATov/ecs.hpp.git
synced 2025-12-13 10:35:39 +07:00
add registry::entity_count function
This commit is contained in:
5
ecs.hpp
5
ecs.hpp
@@ -1086,6 +1086,7 @@ namespace ecs_hpp
|
||||
|
||||
template < typename T >
|
||||
std::size_t component_count() const noexcept;
|
||||
std::size_t entity_count() const noexcept;
|
||||
std::size_t entity_component_count(const const_uentity& ent) const noexcept;
|
||||
|
||||
template < typename F >
|
||||
@@ -1855,6 +1856,10 @@ namespace ecs_hpp
|
||||
: 0u;
|
||||
}
|
||||
|
||||
inline std::size_t registry::entity_count() const noexcept {
|
||||
return entity_ids_.size();
|
||||
}
|
||||
|
||||
inline std::size_t registry::entity_component_count(const const_uentity& ent) const noexcept {
|
||||
assert(valid_entity(ent));
|
||||
std::size_t component_count = 0u;
|
||||
|
||||
@@ -411,6 +411,18 @@ TEST_CASE("registry") {
|
||||
// entity index overflow
|
||||
REQUIRE_THROWS_AS(w.create_entity(), std::logic_error);
|
||||
}
|
||||
{
|
||||
ecs::registry w;
|
||||
REQUIRE_FALSE(w.entity_count());
|
||||
auto e1 = w.create_entity();
|
||||
REQUIRE(w.entity_count() == 1u);
|
||||
auto e2 = w.create_entity();
|
||||
REQUIRE(w.entity_count() == 2u);
|
||||
e1.destroy();
|
||||
REQUIRE(w.entity_count() == 1u);
|
||||
e2.destroy();
|
||||
REQUIRE_FALSE(w.entity_count());
|
||||
}
|
||||
}
|
||||
SECTION("components") {
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user