cubos::core::ecs::DenseTable class final

Stores the dense data associated to entities of a given archetype.

Constructors, destructors, conversion operators

DenseTable() defaulted
Constructs a table without columns.

Public functions

void addColumn(ColumnId id, const reflection::Type& type)
Adds a new column to the table.
void pushBack(uint32_t index)
Inserts a new entity to the end of the table.
void swapErase(uint32_t index)
Removes an entity from the table.
void swapMove(uint32_t index, DenseTable& other)
Moves an entity from this table into another table, effectively calling pushBack() on the other table, and swapErase() on this one.
auto row(uint32_t index) const -> std::size_t
Gets the row which contains the data for the given entity.
auto entity(std::size_t row) const -> uint32_t
Gets the index of the entity which is stored in the given row.
auto size() const -> std::size_t
Gets the number of rows in the table.
auto column(ColumnId id) -> memory::AnyVector&
Gets a reference to the column with the given id.
auto column(ColumnId id) const -> const memory::AnyVector&
Gets a reference to the column with the given id.
auto contains(ColumnId id) const -> bool
Checks if the table has a column with the given id.

Function documentation

void cubos::core::ecs::DenseTable::addColumn(ColumnId id, const reflection::Type& type)

Adds a new column to the table.

Parameters
id Column type identifier.
type Column data type.

The table must still be empty, and the column must not already exist in the table.

void cubos::core::ecs::DenseTable::pushBack(uint32_t index)

Inserts a new entity to the end of the table.

Parameters
index Entity index.

void cubos::core::ecs::DenseTable::swapErase(uint32_t index)

Removes an entity from the table.

Parameters
index Entity index.

If the entity isn't the last one in the table, the last entity will be moved to the position of the removed entity. The data columns will be updated accordingly.

void cubos::core::ecs::DenseTable::swapMove(uint32_t index, DenseTable& other)

Moves an entity from this table into another table, effectively calling pushBack() on the other table, and swapErase() on this one.

Parameters
index Entity index.
other Destination table.

std::size_t cubos::core::ecs::DenseTable::row(uint32_t index) const

Gets the row which contains the data for the given entity.

Parameters
index Entity index.
Returns Row index.

uint32_t cubos::core::ecs::DenseTable::entity(std::size_t row) const

Gets the index of the entity which is stored in the given row.

Parameters
row Row index.
Returns Entity index.

std::size_t cubos::core::ecs::DenseTable::size() const

Gets the number of rows in the table.

Returns Number of rows.

memory::AnyVector& cubos::core::ecs::DenseTable::column(ColumnId id)

Gets a reference to the column with the given id.

Parameters
id Column identifier.
Returns Column reference.

Aborts if the column does not exist in the table.

const memory::AnyVector& cubos::core::ecs::DenseTable::column(ColumnId id) const

Gets a reference to the column with the given id.

Parameters
id Column identifier.
Returns Column reference.

Aborts if the column does not exist in the table.

bool cubos::core::ecs::DenseTable::contains(ColumnId id) const

Checks if the table has a column with the given id.

Parameters
id Column identifier.
Returns Whether the table contains the given column.