Rename ecs::entity_accessor -> ecs::accessor
This commit is contained in:
parent
95b26d890e
commit
1a133f2d3e
3 changed files with 13 additions and 14 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <psemek/ecs/detail/table.hpp>
|
#include <psemek/ecs/detail/table.hpp>
|
||||||
#include <psemek/ecs/entity_accessor.hpp>
|
|
||||||
#include <psemek/util/span.hpp>
|
#include <psemek/util/span.hpp>
|
||||||
#include <psemek/util/range.hpp>
|
#include <psemek/util/range.hpp>
|
||||||
#include <psemek/util/exception.hpp>
|
#include <psemek/util/exception.hpp>
|
||||||
|
|
@ -37,10 +36,10 @@ namespace psemek::ecs
|
||||||
ecs::handle handle_;
|
ecs::handle handle_;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct entity_accessor
|
struct accessor
|
||||||
{
|
{
|
||||||
entity_accessor() = default;
|
accessor() = default;
|
||||||
entity_accessor(entity_accessor const &) = default;
|
accessor(accessor const &) = default;
|
||||||
|
|
||||||
explicit operator bool() const;
|
explicit operator bool() const;
|
||||||
|
|
||||||
|
|
@ -70,16 +69,16 @@ namespace psemek::ecs
|
||||||
|
|
||||||
friend struct entity_container;
|
friend struct entity_container;
|
||||||
|
|
||||||
entity_accessor(detail::table * table, std::uint32_t row);
|
accessor(detail::table * table, std::uint32_t row);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline entity_accessor::operator bool() const
|
inline accessor::operator bool() const
|
||||||
{
|
{
|
||||||
return table_ != nullptr;
|
return table_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Component>
|
template <typename Component>
|
||||||
Component * entity_accessor::get_if()
|
Component * accessor::get_if()
|
||||||
{
|
{
|
||||||
util::uuid const uuid = Component::uuid();
|
util::uuid const uuid = Component::uuid();
|
||||||
|
|
||||||
|
|
@ -91,7 +90,7 @@ namespace psemek::ecs
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Component>
|
template <typename Component>
|
||||||
Component & entity_accessor::get()
|
Component & accessor::get()
|
||||||
{
|
{
|
||||||
if (auto ptr = get_if<Component>())
|
if (auto ptr = get_if<Component>())
|
||||||
return *ptr;
|
return *ptr;
|
||||||
|
|
@ -99,12 +98,12 @@ namespace psemek::ecs
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Component>
|
template <typename Component>
|
||||||
bool entity_accessor::contains() const
|
bool accessor::contains() const
|
||||||
{
|
{
|
||||||
return get_if<Component>() != nullptr;
|
return get_if<Component>() != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline entity_accessor::entity_accessor(detail::table * table, std::uint32_t row)
|
inline accessor::accessor(detail::table * table, std::uint32_t row)
|
||||||
: table_(table)
|
: table_(table)
|
||||||
, row_(row)
|
, row_(row)
|
||||||
{}
|
{}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
#include <psemek/ecs/detail/apply_helper.hpp>
|
#include <psemek/ecs/detail/apply_helper.hpp>
|
||||||
#include <psemek/ecs/detail/all_different_types.hpp>
|
#include <psemek/ecs/detail/all_different_types.hpp>
|
||||||
#include <psemek/ecs/detail/component_uuid_helper.hpp>
|
#include <psemek/ecs/detail/component_uuid_helper.hpp>
|
||||||
#include <psemek/ecs/entity_accessor.hpp>
|
#include <psemek/ecs/accessor.hpp>
|
||||||
#include <psemek/util/span.hpp>
|
#include <psemek/util/span.hpp>
|
||||||
#include <psemek/util/range.hpp>
|
#include <psemek/util/range.hpp>
|
||||||
#include <psemek/util/exception.hpp>
|
#include <psemek/util/exception.hpp>
|
||||||
|
|
@ -68,7 +68,7 @@ namespace psemek::ecs
|
||||||
* If the handle wasn't previously obtained by a `create()` call, or
|
* If the handle wasn't previously obtained by a `create()` call, or
|
||||||
* the referred entity was already destroyed, the behavior is undefined.
|
* the referred entity was already destroyed, the behavior is undefined.
|
||||||
*/
|
*/
|
||||||
entity_accessor get(handle const & entity);
|
accessor get(handle const & entity);
|
||||||
|
|
||||||
/** Attach new components to an existing entity, or update existing
|
/** Attach new components to an existing entity, or update existing
|
||||||
* components with new values. Other components of this entity
|
* components with new values. Other components of this entity
|
||||||
|
|
@ -244,7 +244,7 @@ namespace psemek::ecs
|
||||||
|
|
||||||
auto id = entity_list_.create(table, table->row_count());
|
auto id = entity_list_.create(table, table->row_count());
|
||||||
handle handle{id, entity_list_.get_entities()[id].epoch};
|
handle handle{id, entity_list_.get_entities()[id].epoch};
|
||||||
[[maybe_unused]] entity_accessor accessor = get(handle);
|
[[maybe_unused]] accessor accessor = get(handle);
|
||||||
|
|
||||||
table->push_row(handle);
|
table->push_row(handle);
|
||||||
((accessor.get<Components>() = std::move(components)), ...);
|
((accessor.get<Components>() = std::move(components)), ...);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace psemek::ecs
|
||||||
entity_list_.destroy(entity.id);
|
entity_list_.destroy(entity.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
entity_accessor entity_container::get(handle const & entity)
|
accessor entity_container::get(handle const & entity)
|
||||||
{
|
{
|
||||||
auto const data = entity_list_.get_entities()[entity.id];
|
auto const data = entity_list_.get_entities()[entity.id];
|
||||||
return {data.table, data.row};
|
return {data.table, data.row};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue