add registry::entity_count function

This commit is contained in:
2019-04-10 05:28:42 +07:00
parent 783376c6fc
commit e3358ee2e6
2 changed files with 17 additions and 0 deletions

View File

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

View File

@@ -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") {
{