160 return *
new(component)
C(std::forward<Args>(args)...);
165 if constexpr(std::is_default_constructible_v<C>) {
168 return *
new(component)
C();
170 throw RuntimeError(
"The component C is not default constructible!");
182 if constexpr(std::is_copy_constructible_v<C>) {
186 new(target)
C(*source);
The component store class is responsible for managing and organizing component data storage in memory...
Definition ComponentStore.hpp:28
virtual ~AbstractComponentStore() noexcept
Defaulted virtual destructor.
const void * getRawPointer(const EntityIndex index) const noexcept
Gets a pointer to the the component stored at index.
Definition ComponentStore.hpp:114
virtual AbstractComponent & get(EntityIndex entityIndex)=0
Gets the component at entityIndex position.
size_t getChunkCount() const noexcept
Definition ComponentStore.hpp:103
Vector< char * > mChunks
A vector of all allocated memory chunks.
Definition ComponentStore.hpp:43
size_t mElementSize
The amount of bytes allocated for each element in the store.
Definition ComponentStore.hpp:40
void * getRawPointer(const EntityIndex index) noexcept
Gets a pointer to the the component stored at index.
Definition ComponentStore.hpp:109
size_t mChunkSize
The size to be used for each memory chunk (in bytes)
Definition ComponentStore.hpp:37
size_t mSize
The current store size (in bytes)
Definition ComponentStore.hpp:31
AbstractComponentStore(const size_t chunkSize, const size_t elementSize)
Definition ComponentStore.hpp:46
size_t getCapacity() const noexcept
Definition ComponentStore.hpp:97
size_t mCapacity
The current store capacity (in bytes)
Definition ComponentStore.hpp:34
size_t getSize() const noexcept
Definition ComponentStore.hpp:94
size_t getChunkSize() const noexcept
Definition ComponentStore.hpp:100
void ensureMinimumCapacity(size_t minCapacity)
Ensures that the store capacity is at least minCapacity bytes.
virtual void destroy(EntityIndex entityIndex)=0
Destroys the component located at entityIndex.
virtual AbstractComponent & create(EntityIndex entityIndex)=0
Creates a new component at entityIndex position.
virtual void copy(EntityIndex sourceEntityIndex, EntityIndex targetEntityIndex)=0
Copies the component located at entityIndex
void ensureMinimumSize(std::size_t size)
Ensures that the store size is at least size bytes.
A type-safe component store implementation.
Definition ComponentStore.hpp:135
const C * getPointer(const EntityIndex index) const noexcept
Gets a pointer to the the component stored at index.
Definition ComponentStore.hpp:207
~ComponentStore() noexcept final=default
Destroys the component store.
C & get(const EntityIndex entityIndex) final
Gets the component at entityIndex position.
Definition ComponentStore.hpp:193
void copy(const EntityIndex sourceEntityIndex, const EntityIndex targetEntityIndex) final
Copies the component located at entityIndex
Definition ComponentStore.hpp:181
C & create(const EntityIndex entityIndex, Args &&... args) noexcept(std::is_nothrow_constructible_v< C, Args... >)
Creates a new component at entityIndex position.
Definition ComponentStore.hpp:157
C * getPointer(const EntityIndex index) noexcept
Gets a pointer to the the component stored at index.
Definition ComponentStore.hpp:202
void destroy(const EntityIndex entityIndex) final
Destroys the component located at entityIndex.
Definition ComponentStore.hpp:175
ComponentStore(const size_t chunkSize)
Creates a new component store with the given chunkSize.
Definition ComponentStore.hpp:139
const C & get(const EntityIndex entityIndex) const final
Gets the component at entityIndex position.
Definition ComponentStore.hpp:196
C & create(const EntityIndex entityIndex) final
Creates a new component at entityIndex position.
Definition ComponentStore.hpp:164
Definition Exception.hpp:115
Definition Application.hpp:19
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
UInt32 EntityIndex
Definition EntityID.hpp:22
A abstract class that provides a trait that allows checking for component implementations.
Definition Component.hpp:39