Rename ecs::entity_container -> ecs::container
This commit is contained in:
parent
1a133f2d3e
commit
fa87ab4425
9 changed files with 65 additions and 65 deletions
|
|
@ -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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 <typename ... Components>
|
||||
handle entity_container::create(Components && ... components)
|
||||
handle container::create(Components && ... components)
|
||||
{
|
||||
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||
|
||||
|
|
@ -253,7 +253,7 @@ namespace psemek::ecs
|
|||
}
|
||||
|
||||
template <typename ... Components>
|
||||
void entity_container::attach(handle const & entity, Components && ... components)
|
||||
void container::attach(handle const & entity, Components && ... components)
|
||||
{
|
||||
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||
|
||||
|
|
@ -295,7 +295,7 @@ namespace psemek::ecs
|
|||
}
|
||||
|
||||
template <typename ... Components>
|
||||
void entity_container::detach(handle const & entity)
|
||||
void container::detach(handle const & entity)
|
||||
{
|
||||
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||
|
||||
|
|
@ -335,7 +335,7 @@ namespace psemek::ecs
|
|||
}
|
||||
|
||||
template <typename ... Components>
|
||||
query_cache entity_container::cache()
|
||||
query_cache container::cache()
|
||||
{
|
||||
detail::component_uuid_helper<Components...> uuids;
|
||||
|
||||
|
|
@ -349,7 +349,7 @@ namespace psemek::ecs
|
|||
}
|
||||
|
||||
template <typename ... Components, typename Function>
|
||||
void entity_container::apply(Function && function, query_cache cache)
|
||||
void container::apply(Function && function, query_cache cache)
|
||||
{
|
||||
static_assert(detail::all_different_types_v<Components...>, "all component types must be different");
|
||||
|
||||
|
|
@ -391,7 +391,7 @@ namespace psemek::ecs
|
|||
}
|
||||
|
||||
template <typename ... Components, typename Function>
|
||||
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<Components...>, "all component types must be different");
|
||||
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
namespace psemek::ecs
|
||||
{
|
||||
|
||||
struct entity_container;
|
||||
struct container;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -16,13 +16,13 @@ namespace psemek::ecs::detail
|
|||
{
|
||||
|
||||
template <typename Function, typename ... Components>
|
||||
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<Function, entity_container &, ecs::handle, Components & ...>)
|
||||
if constexpr (std::invocable<Function, container &, ecs::handle, Components & ...>)
|
||||
{
|
||||
function(parent, handle, components...);
|
||||
}
|
||||
else if constexpr (std::invocable<Function, entity_container &, Components & ...>)
|
||||
else if constexpr (std::invocable<Function, container &, Components & ...>)
|
||||
{
|
||||
function(parent, components...);
|
||||
}
|
||||
|
|
@ -37,11 +37,11 @@ namespace psemek::ecs::detail
|
|||
}
|
||||
|
||||
template <typename Function, typename ... Components>
|
||||
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<handle const> handles_span{handles, count};
|
||||
|
||||
if constexpr (std::invocable<Function, entity_container &, util::span<handle const>, util::span<Components> ...>)
|
||||
if constexpr (std::invocable<Function, container &, util::span<handle const>, util::span<Components> ...>)
|
||||
{
|
||||
function(parent, handles_span, util::span<Components>{components, is_empty_v<Components> ? 1 : count} ...);
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ namespace psemek::ecs::detail
|
|||
{
|
||||
function(handles_span, util::span<Components>{components, is_empty_v<Components> ? 1 : count} ...);
|
||||
}
|
||||
else if constexpr (std::invocable<Function, entity_container &, util::span<Components> ...>)
|
||||
else if constexpr (std::invocable<Function, container &, util::span<Components> ...>)
|
||||
{
|
||||
function(parent, util::span<Components>{components, is_empty_v<Components> ? 1 : count} ...);
|
||||
}
|
||||
|
|
@ -62,13 +62,13 @@ namespace psemek::ecs::detail
|
|||
template <typename ... Components>
|
||||
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<handle const> entity_handles)
|
||||
static_apply_helper(container & parent, util::span<handle const> entity_handles)
|
||||
: parent(parent)
|
||||
, row_count(entity_handles.size())
|
||||
, entity_handles_pointer(entity_handles.data())
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
#include <psemek/ecs/entity_container.hpp>
|
||||
#include <psemek/ecs/container.hpp>
|
||||
|
||||
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<std::unique_ptr<detail::column>> columns)
|
||||
detail::table * container::insert_table(std::vector<std::unique_ptr<detail::column>> columns)
|
||||
{
|
||||
auto table = table_container_.insert(std::make_unique<detail::table>(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<detail::entity_data> entities)
|
||||
void container::remove_row(detail::table & table, std::uint32_t row, util::span<detail::entity_data> entities)
|
||||
{
|
||||
// Swap with the last row in that table
|
||||
auto table_entity_handles = table.entity_handles();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <psemek/test/test.hpp>
|
||||
|
||||
#include <psemek/ecs/entity_container.hpp>
|
||||
#include <psemek/ecs/container.hpp>
|
||||
#include <psemek/ecs/declare_uuid.hpp>
|
||||
#include <psemek/random/generator.hpp>
|
||||
#include <psemek/random/uniform.hpp>
|
||||
|
|
@ -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<component_1>([&](entity_container &, util::span<handle const>, util::span<component_1> components){ call_count += components.size(); });
|
||||
container.batch_apply<component_1>([&](entity_container &, util::span<component_1> components){ call_count += components.size(); });
|
||||
container.batch_apply<component_1>([&](ecs::container &, util::span<handle const>, util::span<component_1> components){ call_count += components.size(); });
|
||||
container.batch_apply<component_1>([&](ecs::container &, util::span<component_1> components){ call_count += components.size(); });
|
||||
container.batch_apply<component_1>([&](util::span<handle const>, util::span<component_1> components){ call_count += components.size(); });
|
||||
container.batch_apply<component_1>([&](util::span<component_1> 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<handle> 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<handle> 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<handle> 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)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <psemek/test/test.hpp>
|
||||
|
||||
#include <psemek/ecs/entity_container.hpp>
|
||||
#include <psemek/ecs/container.hpp>
|
||||
#include <psemek/ecs/declare_uuid.hpp>
|
||||
#include <psemek/random/generator.hpp>
|
||||
#include <psemek/random/uniform.hpp>
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <psemek/test/test.hpp>
|
||||
|
||||
#include <psemek/ecs/entity_container.hpp>
|
||||
#include <psemek/ecs/container.hpp>
|
||||
#include <psemek/random/generator.hpp>
|
||||
#include <psemek/random/uniform.hpp>
|
||||
|
||||
|
|
@ -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<component_1>();
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ test_case(ecs_cache_update)
|
|||
|
||||
test_case(ecs_cache_apply)
|
||||
{
|
||||
entity_container container;
|
||||
container container;
|
||||
|
||||
auto cache = container.cache<component_1>();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <psemek/test/test.hpp>
|
||||
|
||||
#include <psemek/ecs/entity_container.hpp>
|
||||
#include <psemek/ecs/container.hpp>
|
||||
#include <psemek/ecs/declare_uuid.hpp>
|
||||
#include <psemek/random/generator.hpp>
|
||||
#include <psemek/random/uniform.hpp>
|
||||
|
|
@ -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<int>(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<handle> entities;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include <psemek/test/test.hpp>
|
||||
|
||||
#include <psemek/ecs/entity_container.hpp>
|
||||
#include <psemek/ecs/container.hpp>
|
||||
#include <psemek/ecs/declare_uuid.hpp>
|
||||
#include <psemek/random/generator.hpp>
|
||||
#include <psemek/random/uniform.hpp>
|
||||
|
|
@ -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<std::pair<handle, int>> entities;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue