![]() |
R-Type
2
Doom but in better
|
Manages a collection of components associated with entities in an ECS (Entity-Component-System) architecture. More...
#include <ComponentContainer.hpp>
Public Types | |
using | value_type = Component |
Type aliases for convenience. | |
using | optional_t = std::optional<Component> |
using | sparse_storage_t = SparseArray<Component, Allocator> |
using | dense_storage_t = DenseArray<Component, Allocator> |
using | size_type = typename sparse_storage_t::size_type |
using | reference = optional_t& |
using | const_reference = const optional_t& |
using | iterator = typename std::vector<optional_t, Allocator>::iterator |
using | const_iterator = typename std::vector<optional_t, Allocator>::const_iterator |
Public Member Functions | |
ComponentContainer () | |
Default constructor. | |
reference | operator[] (size_t idx) |
Accesses the component at a given index. | |
const_reference | operator[] (size_t idx) const |
Accesses the component at a 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. | |
std::optional< Component > | get (const value_type &id) const |
Retrieves a component by its id. | |
void | erase (size_type id) |
Removes a component at a specific ID. | |
void | resize (size_type new_size) |
Resizes the container to a new size. | |
void | optimize_storage (size_type sparse_threshold, size_type dense_threshold) |
Optimizes the storage type based on thresholds for sparse and dense storage. | |
Manages a collection of components associated with entities in an ECS (Entity-Component-System) architecture.
The ComponentContainer
class provides an interface for managing components, offering storage flexibility between sparse and dense arrays, and supports efficient insertion, retrieval, and optimization.
Component | The type of component stored. |
Allocator | The allocator type used for memory management (defaults to std::allocator<Component> ). |
Definition at line 24 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::const_iterator = typename std::vector<optional_t, Allocator>::const_iterator |
Const iterator type.
Definition at line 36 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::const_reference = const optional_t& |
Const reference to a component.
Definition at line 34 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::dense_storage_t = DenseArray<Component, Allocator> |
Dense storage type.
Definition at line 30 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::iterator = typename std::vector<optional_t, Allocator>::iterator |
Iterator type.
Definition at line 35 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::optional_t = std::optional<Component> |
Optional type for components.
Definition at line 28 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::reference = optional_t& |
Reference to a component.
Definition at line 33 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::size_type = typename sparse_storage_t::size_type |
Size type.
Definition at line 31 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::sparse_storage_t = SparseArray<Component, Allocator> |
Sparse storage type.
Definition at line 29 of file ComponentContainer.hpp.
using ComponentContainer< Component, Allocator >::value_type = Component |
Type aliases for convenience.
The type of component stored.
Definition at line 27 of file ComponentContainer.hpp.
|
inline |
Default constructor.
Definition at line 41 of file ComponentContainer.hpp.
|
inline |
Returns an iterator to the beginning of the component container.
Definition at line 68 of file ComponentContainer.hpp.
|
inline |
Returns a const iterator to the beginning of the component container.
Definition at line 83 of file ComponentContainer.hpp.
|
inline |
Returns a const iterator to the beginning of the component container.
Definition at line 98 of file ComponentContainer.hpp.
|
inline |
Returns a const iterator to the end of the component container.
Definition at line 143 of file ComponentContainer.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 208 of file ComponentContainer.hpp.
|
inline |
Returns an iterator to the end of the component container.
Definition at line 113 of file ComponentContainer.hpp.
|
inline |
Returns a const iterator to the end of the component container.
Definition at line 128 of file ComponentContainer.hpp.
|
inline |
Removes a component at a specific ID.
id | The ID of the component to erase. |
Definition at line 249 of file ComponentContainer.hpp.
|
inline |
Retrieves a component by its id.
id | The id value to search for. |
std::nullopt
if not. Definition at line 229 of file ComponentContainer.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 190 of file ComponentContainer.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 174 of file ComponentContainer.hpp.
|
inline |
Accesses the component at a given index.
idx | The index of the component. |
Definition at line 49 of file ComponentContainer.hpp.
|
inline |
Accesses the component at a given index (const version).
idx | The index of the component. |
Definition at line 59 of file ComponentContainer.hpp.
|
inline |
Optimizes the storage type based on thresholds for sparse and dense storage.
sparse_threshold | The threshold for switching to sparse storage. |
dense_threshold | The threshold for switching to dense storage. |
Definition at line 281 of file ComponentContainer.hpp.
|
inline |
Resizes the container to a new size.
new_size | The new size of the container. |
Definition at line 268 of file ComponentContainer.hpp.
|
inline |
Returns the number of components stored in the array.
Definition at line 158 of file ComponentContainer.hpp.