mirror of
https://github.com/BlackMATov/ecs.hpp.git
synced 2025-12-13 02:26:27 +07:00
@@ -679,6 +679,12 @@ namespace ecs_hpp
|
||||
return components_.unordered_erase(id);
|
||||
}
|
||||
|
||||
std::size_t remove_all() noexcept {
|
||||
const std::size_t count = components_.size();
|
||||
components_.clear();
|
||||
return count;
|
||||
}
|
||||
|
||||
T* find(entity_id id) noexcept {
|
||||
return components_.find(id);
|
||||
}
|
||||
@@ -744,6 +750,12 @@ namespace ecs_hpp
|
||||
return components_.unordered_erase(id);
|
||||
}
|
||||
|
||||
std::size_t remove_all() noexcept {
|
||||
const std::size_t count = components_.size();
|
||||
components_.clear();
|
||||
return count;
|
||||
}
|
||||
|
||||
T* find(entity_id id) noexcept {
|
||||
return components_.has(id)
|
||||
? &empty_value_
|
||||
@@ -1260,6 +1272,9 @@ namespace ecs_hpp
|
||||
|
||||
std::size_t remove_all_components(const uentity& ent) noexcept;
|
||||
|
||||
template < typename T >
|
||||
std::size_t remove_all_components() noexcept;
|
||||
|
||||
template < typename T >
|
||||
T& get_component(const uentity& ent);
|
||||
template < typename T >
|
||||
@@ -2190,6 +2205,14 @@ namespace ecs_hpp
|
||||
return removed_count;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
std::size_t registry::remove_all_components() noexcept {
|
||||
detail::component_storage<T>* storage = find_storage_<T>();
|
||||
return storage
|
||||
? storage->remove_all()
|
||||
: 0u;
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
T& registry::get_component(const uentity& ent) {
|
||||
assert(valid_entity(ent));
|
||||
|
||||
@@ -565,6 +565,33 @@ TEST_CASE("registry") {
|
||||
REQUIRE_FALSE(c2);
|
||||
REQUIRE_FALSE(as_const(c2));
|
||||
}
|
||||
{
|
||||
ecs::registry w;
|
||||
|
||||
ecs::entity e1 = w.create_entity();
|
||||
e1.assign_component<position_c>();
|
||||
|
||||
ecs::entity e2 = w.create_entity();
|
||||
e2.assign_component<position_c>();
|
||||
e2.assign_component<velocity_c>();
|
||||
|
||||
ecs::entity e3 = w.create_entity();
|
||||
e3.assign_component<position_c>();
|
||||
e3.assign_component<velocity_c>();
|
||||
|
||||
REQUIRE(w.component_count<position_c>() == 3u);
|
||||
REQUIRE(w.component_count<velocity_c>() == 2u);
|
||||
|
||||
REQUIRE(w.remove_all_components<position_c>() == 3u);
|
||||
REQUIRE(w.component_count<position_c>() == 0u);
|
||||
REQUIRE(w.component_count<velocity_c>() == 2u);
|
||||
|
||||
REQUIRE(w.remove_all_components<velocity_c>() == 2u);
|
||||
REQUIRE(w.component_count<position_c>() == 0u);
|
||||
REQUIRE(w.component_count<velocity_c>() == 0u);
|
||||
|
||||
REQUIRE(w.remove_all_components<movable_c>() == 0u);
|
||||
}
|
||||
}
|
||||
SECTION("prototypes") {
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user