Pass ecs & species handle to behavior context
This commit is contained in:
parent
ca85b7ee18
commit
9489c1caef
1 changed files with 23 additions and 8 deletions
|
|
@ -19,6 +19,8 @@
|
|||
namespace psemek::util
|
||||
{
|
||||
|
||||
struct ecs;
|
||||
|
||||
namespace ecs_detail
|
||||
{
|
||||
|
||||
|
|
@ -58,8 +60,9 @@ namespace psemek::util
|
|||
|
||||
struct species_base
|
||||
{
|
||||
species_base(std::string name, species_handle id)
|
||||
: name_(std::move(name))
|
||||
species_base(ecs * ecs, std::string name, species_handle id)
|
||||
: ecs_(ecs)
|
||||
, name_(std::move(name))
|
||||
, id_(id)
|
||||
{}
|
||||
|
||||
|
|
@ -111,6 +114,7 @@ namespace psemek::util
|
|||
virtual entity_version const * get_version_list() const = 0;
|
||||
|
||||
protected:
|
||||
ecs * ecs_;
|
||||
std::string name_;
|
||||
species_handle id_;
|
||||
|
||||
|
|
@ -147,7 +151,8 @@ namespace psemek::util
|
|||
if (!std::apply(all_nonzero, cptrs))
|
||||
return;
|
||||
|
||||
typename Behavior::context ctx;
|
||||
typename Behavior::context ctx{*ecs_};
|
||||
ctx.species.value = id_;
|
||||
|
||||
((std::get<Components *>(ctx.components) = get_species_component<Components>()), ...);
|
||||
|
||||
|
|
@ -228,7 +233,11 @@ namespace psemek::util
|
|||
|
||||
((std::get<Is>(cptrs) += entity), ...);
|
||||
|
||||
typename Behavior::context ctx;
|
||||
auto version = get_version_list();
|
||||
|
||||
typename Behavior::context ctx{*ecs_};
|
||||
ctx.species.value = id_;
|
||||
ctx.entity.value = pack(id_, entity, version ? version[entity] : 0);
|
||||
|
||||
((std::get<Components *>(ctx.components) = get_species_component<Components>()), ...);
|
||||
|
||||
|
|
@ -254,8 +263,8 @@ namespace psemek::util
|
|||
struct species_impl_base
|
||||
: species_base
|
||||
{
|
||||
species_impl_base(std::string name, species_handle id, Components && ... components)
|
||||
: species_base(std::move(name), id)
|
||||
species_impl_base(ecs * ecs, std::string name, species_handle id, Components && ... components)
|
||||
: species_base(ecs, std::move(name), id)
|
||||
, species_components_{std::move(components)...}
|
||||
{}
|
||||
|
||||
|
|
@ -485,12 +494,18 @@ namespace psemek::util
|
|||
|
||||
struct context
|
||||
{
|
||||
struct ecs & ecs;
|
||||
species_handle species;
|
||||
entity_handle entity;
|
||||
|
||||
component_ptrs components;
|
||||
|
||||
mutable bool remove = false;
|
||||
|
||||
context(struct ecs & ecs)
|
||||
: ecs(ecs)
|
||||
{}
|
||||
|
||||
template <typename Component>
|
||||
Component & get() const
|
||||
{
|
||||
|
|
@ -630,9 +645,9 @@ namespace psemek::util
|
|||
{
|
||||
auto result = species_.size();
|
||||
if (p == policy::sparse)
|
||||
species_.push_back(std::make_unique<ecs_detail::sparse_species_impl<Components...>>(std::move(name), result, std::move(components)...));
|
||||
species_.push_back(std::make_unique<ecs_detail::sparse_species_impl<Components...>>(this, std::move(name), result, std::move(components)...));
|
||||
else
|
||||
species_.push_back(std::make_unique<ecs_detail::packed_species_impl<Components...>>(std::move(name), result, std::move(components)...));
|
||||
species_.push_back(std::make_unique<ecs_detail::packed_species_impl<Components...>>(this, std::move(name), result, std::move(components)...));
|
||||
return {result};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue