CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
CeresEngine::ComponentStore< C > Class Template Referencefinal

A type-safe component store implementation. More...

#include <CeresEngine/Entity/ComponentStore.hpp>

Inheritance diagram for CeresEngine::ComponentStore< C >:
CeresEngine::AbstractComponentStore

Public Member Functions

 ComponentStore (const size_t chunkSize)
 Creates a new component store with the given chunkSize.
 
 ~ComponentStore () noexcept final=default
 Destroys the component store.
 
template<typename... Args>
Ccreate (const EntityIndex entityIndex, Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >)
 Creates a new component at entityIndex position.
 
Ccreate (const EntityIndex entityIndex) final
 Creates a new component at entityIndex position.
 
void destroy (const EntityIndex entityIndex) final
 Destroys the component located at entityIndex.
 
void copy (const EntityIndex sourceEntityIndex, const EntityIndex targetEntityIndex) final
 Copies the component located at entityIndex
 
Cget (const EntityIndex entityIndex) final
 Gets the component at entityIndex position.
 
const Cget (const EntityIndex entityIndex) const final
 Gets the component at entityIndex position.
 
- Public Member Functions inherited from CeresEngine::AbstractComponentStore
 AbstractComponentStore (const size_t chunkSize, const size_t elementSize)
 
virtual ~AbstractComponentStore () noexcept
 Defaulted virtual destructor.
 
size_t getSize () const noexcept
 
size_t getCapacity () const noexcept
 
size_t getChunkSize () const noexcept
 
size_t getChunkCount () const noexcept
 

Private Member Functions

CgetPointer (const EntityIndex index) noexcept
 Gets a pointer to the the component stored at index.
 
const CgetPointer (const EntityIndex index) const noexcept
 Gets a pointer to the the component stored at index.
 

Additional Inherited Members

- Protected Member Functions inherited from CeresEngine::AbstractComponentStore
voidgetRawPointer (const EntityIndex index) noexcept
 Gets a pointer to the the component stored at index.
 
const voidgetRawPointer (const EntityIndex index) const noexcept
 Gets a pointer to the the component stored at index.
 
void ensureMinimumSize (std::size_t size)
 Ensures that the store size is at least size bytes.
 
void ensureMinimumCapacity (size_t minCapacity)
 Ensures that the store capacity is at least minCapacity bytes.
 
- Protected Attributes inherited from CeresEngine::AbstractComponentStore
size_t mSize = 0
 The current store size (in bytes)
 
size_t mCapacity = 0
 The current store capacity (in bytes)
 
size_t mChunkSize
 The size to be used for each memory chunk (in bytes)
 
size_t mElementSize
 The amount of bytes allocated for each element in the store.
 
Vector< char * > mChunks
 A vector of all allocated memory chunks.
 

Detailed Description

template<CComponent C>
class CeresEngine::ComponentStore< C >

A type-safe component store implementation.

This store uses a chunked memory pool to store the component data semi-contiguous in memory.

Template Parameters
Cthe component type

Constructor & Destructor Documentation

◆ ComponentStore()

template<CComponent C>
CeresEngine::ComponentStore< C >::ComponentStore ( const size_t  chunkSize)
inlineexplicit

Creates a new component store with the given chunkSize.

Parameters
chunkSizeThe chunk size to be used

◆ ~ComponentStore()

template<CComponent C>
CeresEngine::ComponentStore< C >::~ComponentStore ( )
finaldefaultnoexcept

Destroys the component store.

Will destroy all components store in it.

Member Function Documentation

◆ copy()

template<CComponent C>
void CeresEngine::ComponentStore< C >::copy ( const EntityIndex  sourceEntityIndex,
const EntityIndex  targetEntityIndex 
)
inlinefinalvirtual

Copies the component located at entityIndex

Parameters
sourceEntityIndexThe index of the component to copy from
targetEntityIndexThe index of the component to copy to

Implements CeresEngine::AbstractComponentStore.

◆ create() [1/2]

template<CComponent C>
C & CeresEngine::ComponentStore< C >::create ( const EntityIndex  entityIndex)
inlinefinalvirtual

Creates a new component at entityIndex position.

Note
Calling create() on a already created index could lead to a memory leak! The previously constructed component destructor will not be called. The user must manually call `destroy()´ before calling create on the same index.
Parameters
entityIndexThe component position
Returns
A reference to the created component

Implements CeresEngine::AbstractComponentStore.

◆ create() [2/2]

template<CComponent C>
template<typename... Args>
C & CeresEngine::ComponentStore< C >::create ( const EntityIndex  entityIndex,
Args &&...  args 
)
inlinenoexcept

Creates a new component at entityIndex position.

Note
Calling create() on a already created index could lead to a memory leak! The previously constructed component destructor will not be caled. The user must manually call `destroy()´ before calling create on the same index.
Template Parameters
Argsthe component constructor argument types
Parameters
entityIndexThe component position
argsThe component constructor arguments
Returns
A reference to the created component

◆ destroy()

template<CComponent C>
void CeresEngine::ComponentStore< C >::destroy ( const EntityIndex  entityIndex)
inlinefinalvirtual

Destroys the component located at entityIndex.

Parameters
entityIndexThe index of the component to be destroyed

Implements CeresEngine::AbstractComponentStore.

◆ get() [1/2]

template<CComponent C>
const C & CeresEngine::ComponentStore< C >::get ( const EntityIndex  entityIndex) const
inlinefinalvirtual

Gets the component at entityIndex position.

Note
Calling get() on a not allocated/created position will cause a crash. The user must make sure that the component being retrieved has been previously created with a call to create().
Parameters
entityIndexThe component position
Returns
A reference to the stored component

Implements CeresEngine::AbstractComponentStore.

◆ get() [2/2]

template<CComponent C>
C & CeresEngine::ComponentStore< C >::get ( const EntityIndex  entityIndex)
inlinefinalvirtual

Gets the component at entityIndex position.

Note
Calling get() on a not allocated/created position will cause a crash. The user must make sure that the component being retrieved has been previously created with a call to create().
Parameters
entityIndexThe component position
Returns
A reference to the stored component

Implements CeresEngine::AbstractComponentStore.

◆ getPointer() [1/2]

template<CComponent C>
const C * CeresEngine::ComponentStore< C >::getPointer ( const EntityIndex  index) const
inlineprivatenoexcept

Gets a pointer to the the component stored at index.

Parameters
indexThe component position
Returns
A pointer to the the component stored at index.

◆ getPointer() [2/2]

template<CComponent C>
C * CeresEngine::ComponentStore< C >::getPointer ( const EntityIndex  index)
inlineprivatenoexcept

Gets a pointer to the the component stored at index.

Parameters
indexThe component position
Returns
A pointer to the the component stored at index.

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