31 lines
874 B
C++
31 lines
874 B
C++
#include <psemek/ecs/entity_container.hpp>
|
|
|
|
namespace psemek::ecs
|
|
{
|
|
|
|
bool entity_container::alive(entity_handle const & entity) const
|
|
{
|
|
return entity_list_.get_entities()[entity.id].epoch == entity.epoch;
|
|
}
|
|
|
|
void entity_container::destroy(entity_handle const & entity)
|
|
{
|
|
// Swap with the last row in that table
|
|
auto entities = entity_list_.get_entities();
|
|
auto & data = entities[entity.id];
|
|
auto table_entity_ids = data.table->get_entity_ids();
|
|
data.table->swap_rows(data.row, table_entity_ids.size() - 1);
|
|
data.table->pop_row();
|
|
auto swap_id = table_entity_ids[data.row];
|
|
auto & swap_data = entities[swap_id];
|
|
swap_data.row = data.row;
|
|
entity_list_.destroy(entity.id);
|
|
}
|
|
|
|
entity_accessor entity_container::get(entity_handle const & entity)
|
|
{
|
|
auto const & data = entity_list_.get_entities()[entity.id];
|
|
return {data.table, data.row};
|
|
}
|
|
|
|
}
|