From fa87ab4425237b15a26bbe9a87b46680b7592d3f Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 16 Dec 2023 16:35:04 +0300 Subject: [PATCH] Rename ecs::entity_container -> ecs::container --- libs/ecs/include/psemek/ecs/accessor.hpp | 2 +- .../{entity_container.hpp => container.hpp} | 14 +++++----- .../psemek/ecs/detail/apply_helper.hpp | 18 ++++++------ libs/ecs/source/entity_container.cpp | 14 +++++----- libs/ecs/tests/apply.cpp | 28 +++++++++---------- libs/ecs/tests/attach.cpp | 24 ++++++++-------- libs/ecs/tests/cache.cpp | 10 +++---- libs/ecs/tests/component.cpp | 8 +++--- libs/ecs/tests/entity.cpp | 12 ++++---- 9 files changed, 65 insertions(+), 65 deletions(-) rename libs/ecs/include/psemek/ecs/{entity_container.hpp => container.hpp} (97%) diff --git a/libs/ecs/include/psemek/ecs/accessor.hpp b/libs/ecs/include/psemek/ecs/accessor.hpp index 1cd657a5..c5a65af3 100644 --- a/libs/ecs/include/psemek/ecs/accessor.hpp +++ b/libs/ecs/include/psemek/ecs/accessor.hpp @@ -67,7 +67,7 @@ namespace psemek::ecs detail::table * table_ = nullptr; std::uint32_t row_ = 0; - friend struct entity_container; + friend struct container; accessor(detail::table * table, std::uint32_t row); }; diff --git a/libs/ecs/include/psemek/ecs/entity_container.hpp b/libs/ecs/include/psemek/ecs/container.hpp similarity index 97% rename from libs/ecs/include/psemek/ecs/entity_container.hpp rename to libs/ecs/include/psemek/ecs/container.hpp index 119156d6..19bf859b 100644 --- a/libs/ecs/include/psemek/ecs/entity_container.hpp +++ b/libs/ecs/include/psemek/ecs/container.hpp @@ -28,7 +28,7 @@ namespace psemek::ecs // - Index API // - Index implementation - struct entity_container + struct container { /** Create an entity with the specified components. * It is faster to create an entity with all the components at once, than to @@ -223,7 +223,7 @@ namespace psemek::ecs }; template - handle entity_container::create(Components && ... components) + handle container::create(Components && ... components) { static_assert(detail::all_different_types_v, "all component types must be different"); @@ -253,7 +253,7 @@ namespace psemek::ecs } template - void entity_container::attach(handle const & entity, Components && ... components) + void container::attach(handle const & entity, Components && ... components) { static_assert(detail::all_different_types_v, "all component types must be different"); @@ -295,7 +295,7 @@ namespace psemek::ecs } template - void entity_container::detach(handle const & entity) + void container::detach(handle const & entity) { static_assert(detail::all_different_types_v, "all component types must be different"); @@ -335,7 +335,7 @@ namespace psemek::ecs } template - query_cache entity_container::cache() + query_cache container::cache() { detail::component_uuid_helper uuids; @@ -349,7 +349,7 @@ namespace psemek::ecs } template - void entity_container::apply(Function && function, query_cache cache) + void container::apply(Function && function, query_cache cache) { static_assert(detail::all_different_types_v, "all component types must be different"); @@ -391,7 +391,7 @@ namespace psemek::ecs } template - void entity_container::batch_apply(Function && function, query_cache cache) + void container::batch_apply(Function && function, query_cache cache) { static_assert(detail::all_different_types_v, "all component types must be different"); diff --git a/libs/ecs/include/psemek/ecs/detail/apply_helper.hpp b/libs/ecs/include/psemek/ecs/detail/apply_helper.hpp index fce00b3b..a3af84c9 100644 --- a/libs/ecs/include/psemek/ecs/detail/apply_helper.hpp +++ b/libs/ecs/include/psemek/ecs/detail/apply_helper.hpp @@ -8,7 +8,7 @@ namespace psemek::ecs { - struct entity_container; + struct container; } @@ -16,13 +16,13 @@ namespace psemek::ecs::detail { template - void invoke(Function && function, entity_container & parent, handle const & handle, Components & ... components) + void invoke(Function && function, container & parent, handle const & handle, Components & ... components) { - if constexpr (std::invocable) + if constexpr (std::invocable) { function(parent, handle, components...); } - else if constexpr (std::invocable) + else if constexpr (std::invocable) { function(parent, components...); } @@ -37,11 +37,11 @@ namespace psemek::ecs::detail } template - void batch_invoke(Function && function, entity_container & parent, std::size_t count, handle const * handles, Components * ... components) + void batch_invoke(Function && function, container & parent, std::size_t count, handle const * handles, Components * ... components) { util::span handles_span{handles, count}; - if constexpr (std::invocable, util::span ...>) + if constexpr (std::invocable, util::span ...>) { function(parent, handles_span, util::span{components, is_empty_v ? 1 : count} ...); } @@ -49,7 +49,7 @@ namespace psemek::ecs::detail { function(handles_span, util::span{components, is_empty_v ? 1 : count} ...); } - else if constexpr (std::invocable ...>) + else if constexpr (std::invocable ...>) { function(parent, util::span{components, is_empty_v ? 1 : count} ...); } @@ -62,13 +62,13 @@ namespace psemek::ecs::detail template struct static_apply_helper { - entity_container & parent; + container & parent; std::size_t row_count; handle const * entity_handles_pointer; // (+1) to prevent zero-sized array std::uint8_t * pointers[sizeof...(Components) + 1]; - static_apply_helper(entity_container & parent, util::span entity_handles) + static_apply_helper(container & parent, util::span entity_handles) : parent(parent) , row_count(entity_handles.size()) , entity_handles_pointer(entity_handles.data()) diff --git a/libs/ecs/source/entity_container.cpp b/libs/ecs/source/entity_container.cpp index 0d6e057a..31ad5ab2 100644 --- a/libs/ecs/source/entity_container.cpp +++ b/libs/ecs/source/entity_container.cpp @@ -1,26 +1,26 @@ -#include +#include namespace psemek::ecs { - bool entity_container::alive(handle const & entity) const + bool container::alive(handle const & entity) const { return entity_list_.get_entities()[entity.id].epoch == entity.epoch; } - void entity_container::destroy(handle const & entity) + void container::destroy(handle const & entity) { do_destroy(entity); entity_list_.destroy(entity.id); } - accessor entity_container::get(handle const & entity) + accessor container::get(handle const & entity) { auto const data = entity_list_.get_entities()[entity.id]; return {data.table, data.row}; } - detail::table * entity_container::insert_table(std::vector> columns) + detail::table * container::insert_table(std::vector> columns) { auto table = table_container_.insert(std::make_unique(std::move(columns))); @@ -31,7 +31,7 @@ namespace psemek::ecs return table; } - void entity_container::do_destroy(handle const & entity) + void container::do_destroy(handle const & entity) { auto entities = entity_list_.get_entities(); auto & data = entities[entity.id]; @@ -43,7 +43,7 @@ namespace psemek::ecs data.table->push_remove(data.row); } - void entity_container::remove_row(detail::table & table, std::uint32_t row, util::span entities) + void container::remove_row(detail::table & table, std::uint32_t row, util::span entities) { // Swap with the last row in that table auto table_entity_handles = table.entity_handles(); diff --git a/libs/ecs/tests/apply.cpp b/libs/ecs/tests/apply.cpp index e1858ec2..a3ba249b 100644 --- a/libs/ecs/tests/apply.cpp +++ b/libs/ecs/tests/apply.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include #include @@ -29,15 +29,15 @@ namespace test_case(ecs_apply_empty) { - entity_container container; + container container; int const count = 2048; for (int i = 0; i < count; ++i) container.create(); int call_count = 0; - container.apply<>([&](entity_container &, handle const &){ ++call_count; }); - container.apply<>([&](entity_container &){ ++call_count; }); + container.apply<>([&](ecs::container &, handle const &){ ++call_count; }); + container.apply<>([&](ecs::container &){ ++call_count; }); container.apply<>([&](handle const &){ ++call_count; }); container.apply<>([&]{ ++call_count; }); expect_equal(count * 4, call_count); @@ -45,7 +45,7 @@ test_case(ecs_apply_empty) test_case(ecs_apply_components_1) { - entity_container container; + container container; random::generator rng; int const expected_count = 1024 * 1024; @@ -71,7 +71,7 @@ test_case(ecs_apply_components_1) test_case(ecs_apply_components_2) { - entity_container container; + container container; random::generator rng; int const expected_count = 1024*1024; @@ -112,15 +112,15 @@ test_case(ecs_apply_components_2) test_case(ecs_apply_batch_invoke) { - entity_container container; + container container; int const count = 2048; for (int i = 0; i < count; ++i) container.create(component_1{i}); int call_count = 0; - container.batch_apply([&](entity_container &, util::span, util::span components){ call_count += components.size(); }); - container.batch_apply([&](entity_container &, util::span components){ call_count += components.size(); }); + container.batch_apply([&](ecs::container &, util::span, util::span components){ call_count += components.size(); }); + container.batch_apply([&](ecs::container &, util::span components){ call_count += components.size(); }); container.batch_apply([&](util::span, util::span components){ call_count += components.size(); }); container.batch_apply([&](util::span components){ call_count += components.size(); }); expect_equal(count * 4, call_count); @@ -128,7 +128,7 @@ test_case(ecs_apply_batch_invoke) test_case(ecs_apply_batch_components) { - entity_container container; + container container; random::generator rng; int const expected_count = 1024*1024; @@ -172,7 +172,7 @@ test_case(ecs_apply_batch_components) test_case(ecs_apply_remove_forward) { - entity_container container; + container container; std::vector handles; int const count = 1024 * 1024; @@ -193,7 +193,7 @@ test_case(ecs_apply_remove_forward) test_case(ecs_apply_remove_reversed) { - entity_container container; + container container; std::vector handles; int const count = 1024 * 1024; @@ -217,7 +217,7 @@ test_case(ecs_apply_remove_reversed) test_case(ecs_apply_remove_random) { - entity_container container; + container container; random::generator rng; std::vector handles; @@ -242,7 +242,7 @@ test_case(ecs_apply_remove_random) test_case(ecs_apply_create) { - entity_container container; + container container; int const count = 1024 * 1024; for (int i = 0; i < count; ++i) diff --git a/libs/ecs/tests/attach.cpp b/libs/ecs/tests/attach.cpp index 751993a2..f60e17aa 100644 --- a/libs/ecs/tests/attach.cpp +++ b/libs/ecs/tests/attach.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include #include @@ -25,7 +25,7 @@ namespace psemek_ecs_declare_uuid("component_2") }; - void check_impl(entity_container & container, int count0, int count1, int count2, int count12) + void check_impl(container & container, int count0, int count1, int count2, int count12) { int call_count = 0; container.apply<>([&]{ ++call_count; }); @@ -48,7 +48,7 @@ namespace test_case(ecs_attach_empty) { - entity_container container; + container container; auto h = container.create(); @@ -60,7 +60,7 @@ test_case(ecs_attach_empty) test_case(ecs_attach_one) { - entity_container container; + container container; auto h = container.create(); @@ -74,7 +74,7 @@ test_case(ecs_attach_one) test_case(ecs_attach_twice) { - entity_container container; + container container; auto h = container.create(); @@ -89,7 +89,7 @@ test_case(ecs_attach_twice) test_case(ecs_attach_two) { - entity_container container; + container container; auto h = container.create(); @@ -104,7 +104,7 @@ test_case(ecs_attach_two) test_case(ecs_detach_empty) { - entity_container container; + container container; auto h = container.create(); @@ -118,7 +118,7 @@ test_case(ecs_detach_empty) test_case(ecs_detach_nonexistent) { - entity_container container; + container container; auto h = container.create(component_1{10}); @@ -132,7 +132,7 @@ test_case(ecs_detach_nonexistent) test_case(ecs_detach_one) { - entity_container container; + container container; auto h = container.create(component_1{10}, component_2{20}); @@ -146,7 +146,7 @@ test_case(ecs_detach_one) test_case(ecs_detach_two) { - entity_container container; + container container; auto h = container.create(component_1{10}, component_2{20}); @@ -162,7 +162,7 @@ test_case(ecs_detach_two) test_case(ecs_attach_random) { random::generator rng; - entity_container container; + container container; int count0 = 0; int count1 = 0; @@ -203,7 +203,7 @@ test_case(ecs_attach_random) test_case(ecs_detach_random) { random::generator rng; - entity_container container; + container container; int count0 = 0; int count1 = 0; diff --git a/libs/ecs/tests/cache.cpp b/libs/ecs/tests/cache.cpp index 3e558246..ff13b0a2 100644 --- a/libs/ecs/tests/cache.cpp +++ b/libs/ecs/tests/cache.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include @@ -34,7 +34,7 @@ namespace test_case(ecs_cache_empty) { - entity_container container; + container container; container.create(); container.create(component_1{10}); @@ -50,7 +50,7 @@ test_case(ecs_cache_empty) test_case(ecs_cache_components) { - entity_container container; + container container; container.create(); container.create(component_1{10}); @@ -66,7 +66,7 @@ test_case(ecs_cache_components) test_case(ecs_cache_update) { - entity_container container; + container container; auto cache = container.cache(); @@ -93,7 +93,7 @@ test_case(ecs_cache_update) test_case(ecs_cache_apply) { - entity_container container; + container container; auto cache = container.cache(); diff --git a/libs/ecs/tests/component.cpp b/libs/ecs/tests/component.cpp index 29d6189e..4760dbef 100644 --- a/libs/ecs/tests/component.cpp +++ b/libs/ecs/tests/component.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include #include @@ -43,7 +43,7 @@ namespace test_case(ecs_component_order) { - entity_container container; + container container; auto h0 = container.create(component_small{10}, component_big{}); expect(container.alive(h0)); @@ -66,7 +66,7 @@ test_case(ecs_component_order) test_case(ecs_component_noncopyable) { - entity_container container; + container container; auto h0 = container.create(component_noncopyable{std::make_unique(10)}); expect(container.alive(h0)); @@ -87,7 +87,7 @@ test_case(ecs_component_noncopyable) test_case(ecs_component_lifetime) { random::generator rng; - entity_container container; + container container; std::vector entities; diff --git a/libs/ecs/tests/entity.cpp b/libs/ecs/tests/entity.cpp index 274e17b7..714a9e6c 100644 --- a/libs/ecs/tests/entity.cpp +++ b/libs/ecs/tests/entity.cpp @@ -1,6 +1,6 @@ #include -#include +#include #include #include #include @@ -30,7 +30,7 @@ namespace test_case(ecs_entity_empty_single) { - entity_container container; + container container; auto h0 = container.create(); expect(container.alive(h0)); @@ -41,7 +41,7 @@ test_case(ecs_entity_empty_single) test_case(ecs_entity_empty_multiple) { - entity_container container; + container container; auto h0 = container.create(); expect(container.alive(h0)); @@ -64,7 +64,7 @@ test_case(ecs_entity_empty_multiple) test_case(ecs_entity_components_single) { - entity_container container; + container container; auto h0 = container.create(component_1{10}, component_2{20}); expect(container.alive(h0)); @@ -82,7 +82,7 @@ test_case(ecs_entity_components_single) test_case(ecs_entity_components_multiple) { - entity_container container; + container container; auto h0 = container.create(component_1{10}, component_2{20}); expect(container.alive(h0)); @@ -112,7 +112,7 @@ test_case(ecs_entity_components_multiple) test_case(ecs_entity_random) { random::generator rng; - entity_container container; + container container; std::vector> entities;