co_ecs 0.9.0
Cobalt ECS
Loading...
Searching...
No Matches
co_ecs::archetype Class Reference

Archetype groups entities that share the same types of components. Archetype has a list of fixed size chunks where entities and their components are stored in a packed arrays, in a so called SoA fashion. More...

#include <archetype.hpp>

Public Types

using chunks_storage_t = std::vector<chunk>
 Chunks storage type.
 

Public Member Functions

 archetype ()=default
 Construct a new archetype object without components.
 
 archetype (component_meta_set components)
 Construct a new archetype object.
 
auto components () const noexcept -> const component_meta_set &
 Return components set.
 
auto chunks () noexcept -> chunks_storage_t &
 Return reference to chunks vector.
 
auto chunks () const noexcept -> const chunks_storage_t &
 Return const reference to chunks vector.
 
template<component... Components>
auto emplace (entity ent, Components &&... components) -> entity_location
 Emplace new entity and assign given components to it, return entities location.
 
auto swap_erase (const entity_location &location) noexcept -> std::optional< entity >
 Swap erase an entity at given location, returns an entity that has been moved as a result of this operation or std::nullopt if no entities were moved.
 
auto move (const entity_location &location, archetype &other) -> std::pair< entity_location, std::optional< entity > >
 Move entity and its components to a different archetype and returns a pair where the first element is moved entity location in a new archetype and the second is the entity that has been moved in this archetype or std::nullopt if no entities were moved.
 
auto copy (const entity_location &location, archetype &other) -> entity_location
 Copy entity and its components to a different archetype.
 
void visit (const entity_location &location, auto &&func)
 Visit all components of an entity.
 
void visit (const entity_location &location, auto &&func) const
 Visit all components of an entity (const variant).
 
template<component C>
auto get (entity_location location) -> C &
 Get component data.
 
template<component C>
auto get (entity_location location) const -> const C &
 Get component data, const variant.
 
template<component C>
auto contains () const noexcept -> bool
 Check if archetype has component C.
 

Detailed Description

Archetype groups entities that share the same types of components. Archetype has a list of fixed size chunks where entities and their components are stored in a packed arrays, in a so called SoA fashion.

Member Typedef Documentation

◆ chunks_storage_t

Chunks storage type.

Constructor & Destructor Documentation

◆ archetype() [1/2]

co_ecs::archetype::archetype ( )
default

Construct a new archetype object without components.

◆ archetype() [2/2]

co_ecs::archetype::archetype ( component_meta_set components)
inlineexplicit

Construct a new archetype object.

Parameters
componentsComponents

Member Function Documentation

◆ chunks() [1/2]

auto co_ecs::archetype::chunks ( ) const -> const chunks_storage_t&
inlinenoexcept

Return const reference to chunks vector.

Returns
const chunks_storage_t&

◆ chunks() [2/2]

auto co_ecs::archetype::chunks ( ) -> chunks_storage_t&
inlinenoexcept

Return reference to chunks vector.

Returns
chunks_storage_t&

◆ components()

auto co_ecs::archetype::components ( ) const -> const component_meta_set&
inlinenoexcept

Return components set.

Returns
const component_meta_set&

◆ contains()

template<component C>
auto co_ecs::archetype::contains ( ) const -> bool
inlinenoexcept

Check if archetype has component C.

Template Parameters
CComponent type
Returns
true If this archetype has component C
false If this archetype does not have component C

◆ copy()

auto co_ecs::archetype::copy ( const entity_location & location,
archetype & other ) -> entity_location
inline

Copy entity and its components to a different archetype.

Parameters
locationEntity location
otherArchetype to copy entity and its components to
Returns
entity_location

◆ emplace()

template<component... Components>
auto co_ecs::archetype::emplace ( entity ent,
Components &&... components ) -> entity_location
inline

Emplace new entity and assign given components to it, return entities location.

Template Parameters
ComponentsComponents types
Parameters
entEntity
componentsComponents parameter pack
Returns
entity_location

◆ get() [1/2]

template<component C>
auto co_ecs::archetype::get ( entity_location location) -> C&
inline

Get component data.

Template Parameters
CComponent type
Parameters
locationEntity location
Returns
C& Component reference

◆ get() [2/2]

template<component C>
auto co_ecs::archetype::get ( entity_location location) const -> const C&
inline

Get component data, const variant.

Template Parameters
CComponent type
Parameters
locationEntity location
Returns
const C& Component reference

◆ move()

auto co_ecs::archetype::move ( const entity_location & location,
archetype & other ) -> std::pair<entity_location, std::optional<entity>>
inline

Move entity and its components to a different archetype and returns a pair where the first element is moved entity location in a new archetype and the second is the entity that has been moved in this archetype or std::nullopt if no entities were moved.

Parameters
locationEntity location
otherArchetype to move entity and its components to
Returns
std::pair<entity_location, std::optional<entity>>

◆ swap_erase()

auto co_ecs::archetype::swap_erase ( const entity_location & location) -> std::optional<entity>
inlinenoexcept

Swap erase an entity at given location, returns an entity that has been moved as a result of this operation or std::nullopt if no entities were moved.

Parameters
locationEntity location
Returns
std::optional<entity>

◆ visit() [1/2]

void co_ecs::archetype::visit ( const entity_location & location,
auto && func )
inline

Visit all components of an entity.

Parameters
locationEntity location
funcFunction, a visitor, to apply components to.

◆ visit() [2/2]

void co_ecs::archetype::visit ( const entity_location & location,
auto && func ) const
inline

Visit all components of an entity (const variant).

Parameters
locationEntity location
funcFunction, a visitor, to apply components to.

The documentation for this class was generated from the following file: