add function to remove all components of the same type #30

This commit is contained in:
2019-07-19 01:01:02 +07:00
parent f08594b11f
commit e776c74412
2 changed files with 50 additions and 0 deletions

View File

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