![]() |
R-Type
2
Doom but in better
|
A container that provides dense storage for components with a mapping between entity IDs and component indices. More...
#include <DenseArray.hpp>
Public Types | |
using | value_type = Component |
Type aliases for convenience. | |
using | optional_t = std::optional<Component> |
using | reference_type = optional_t& |
using | const_reference_type = const optional_t& |
using | id_type = std::size_t |
using | id_container_t = std::vector<id_type> |
using | component_container_t = std::vector<optional_t, Allocator> |
using | size_type = typename component_container_t::size_type |
using | iterator = typename component_container_t::iterator |
using | const_iterator = typename component_container_t::const_iterator |
Public Member Functions | |
DenseArray ()=default | |
Default constructor. | |
DenseArray (const DenseArray &other)=default | |
Copy constructor. | |
DenseArray (DenseArray &&other) noexcept=default | |
Move constructor. | |
~DenseArray ()=default | |
Destructor. | |
DenseArray & | operator= (const DenseArray &other)=default |
Copy assignment operator. | |
DenseArray & | operator= (DenseArray &&other) noexcept=default |
Move assignment operator. | |
reference_type | operator[] (size_type idx) |
Accesses the component at the given index. | |
const_reference_type | operator[] (size_type idx) const |
Accesses the component at the given index (const version). | |
iterator | begin () |
Returns an iterator to the beginning of the component container. | |
const_iterator | begin () const |
Returns a const iterator to the beginning of the component container. | |
const_iterator | cbegin () const |
Returns a const iterator to the beginning of the component container. | |
iterator | end () |
Returns an iterator to the end of the component container. | |
const_iterator | end () const |
Returns a const iterator to the end of the component container. | |
const_iterator | cend () const |
Returns a const iterator to the end of the component container. | |
size_type | size () const |
Returns the number of components stored in the array. | |
void | insert_at (size_type id, const Component &component) |
Inserts a component at a specific ID. | |
void | insert_at (size_type id, Component &&component) |
Inserts a component at a specific ID (move version). | |
template<typename... Params> | |
void | emplace_at (size_type id, Params &&... params) |
Constructs and inserts a component at a specific ID. | |
void | erase (size_type id) |
Removes the component at a specific ID. | |
A container that provides dense storage for components with a mapping between entity IDs and component indices.
The DenseArray
class is designed for efficient storage and retrieval of components in an ECS (Entity-Component-System) architecture. It maintains a mapping between entity IDs and component indices to support fast lookups and iteration.
Component | The type of the components stored in the array. |
Allocator | The allocator type used for memory management (defaults to std::allocator<Component> ). |
Definition at line 20 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::component_container_t = std::vector<optional_t, Allocator> |
Container type for storing components.
Definition at line 29 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::const_iterator = typename component_container_t::const_iterator |
Const iterator type.
Definition at line 32 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::const_reference_type = const optional_t& |
Const reference to a component.
Definition at line 26 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::id_container_t = std::vector<id_type> |
Container type for storing entity IDs.
Definition at line 28 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::id_type = std::size_t |
Type used for entity IDs.
Definition at line 27 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::iterator = typename component_container_t::iterator |
Iterator type.
Definition at line 31 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::optional_t = std::optional<Component> |
Optional type for components.
Definition at line 24 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::reference_type = optional_t& |
Reference to a component.
Definition at line 25 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::size_type = typename component_container_t::size_type |
Size type for the container.
Definition at line 30 of file DenseArray.hpp.
using DenseArray< Component, Allocator >::value_type = Component |
Type aliases for convenience.
The type of component stored.
Definition at line 23 of file DenseArray.hpp.
|
default |
Default constructor.
|
default |
Copy constructor.
other | The DenseArray to copy from. |
|
defaultnoexcept |
Move constructor.
other | The DenseArray to move from. |
|
default |
Destructor.
|
inline |
Returns an iterator to the beginning of the component container.
Definition at line 100 of file DenseArray.hpp.
|
inline |
Returns a const iterator to the beginning of the component container.
Definition at line 109 of file DenseArray.hpp.
|
inline |
Returns a const iterator to the beginning of the component container.
Definition at line 118 of file DenseArray.hpp.
|
inline |
Returns a const iterator to the end of the component container.
Definition at line 145 of file DenseArray.hpp.
|
inline |
Constructs and inserts a component at a specific ID.
Params | The types of the parameters for the component constructor. |
id | The ID where the component should be inserted. |
params | The parameters for constructing the component. |
Definition at line 190 of file DenseArray.hpp.
|
inline |
Returns an iterator to the end of the component container.
Definition at line 127 of file DenseArray.hpp.
|
inline |
Returns a const iterator to the end of the component container.
Definition at line 136 of file DenseArray.hpp.
|
inline |
Removes the component at a specific ID.
id | The ID of the component to erase. |
Definition at line 201 of file DenseArray.hpp.
|
inline |
Inserts a component at a specific ID (move version).
id | The ID where the component should be inserted. |
component | The component to insert (moved). |
Definition at line 176 of file DenseArray.hpp.
|
inline |
Inserts a component at a specific ID.
id | The ID where the component should be inserted. |
component | The component to insert. |
Definition at line 164 of file DenseArray.hpp.
|
default |
Copy assignment operator.
other | The DenseArray to copy from. |
DenseArray
.
|
defaultnoexcept |
Move assignment operator.
other | The DenseArray to move from. |
DenseArray
.
|
inline |
Accesses the component at the given index.
idx | The index to access. |
Definition at line 80 of file DenseArray.hpp.
|
inline |
Accesses the component at the given index (const version).
idx | The index to access. |
Definition at line 91 of file DenseArray.hpp.
|
inline |
Returns the number of components stored in the array.
Definition at line 154 of file DenseArray.hpp.