class ecs::TComponentSparseSet

template<typename ComponentType, bool InPlaceDelete = false, u64 PackedPageSize = 1024>

Storage used for storing components associated with entities.

Template parameters

ComponentType

Type of the component to store. Type must not be empty.

InPlaceDelete

If true, deletion of entities will not erase the entity, but rather just mark it as invalid. Space of invalid entities can be re-used, but iterating such storages is slower. Additionally sorting operations are limited when invalid entities are present in the storage.

PackedPageSize

Size of a single payload page. In order to reduce the impact of array resize, payload array is split into pages of this size.

Public

Constructors

TComponentSparseSet<ComponentType, InPlaceDelete, PackedPageSize>

TComponentSparseSet<ComponentType, InPlaceDelete, PackedPageSize>()

Methods

~TComponentSparseSet<ComponentType, InPlaceDelete, PackedPageSize>

~TComponentSparseSet<ComponentType, InPlaceDelete, PackedPageSize>() override

Get

ComponentType &Get(Entity entity)

Returns the component value for the specified entity.

Caller must ensure storage contains the entity.

Get

const ComponentType &Get(Entity entity) const

Returns the component value for the specified entity.

Caller must ensure storage contains the entity.

Clear

void Clear() override

Removes everything from the set and clears the internal arrays.

ClearInvalid

void ClearInvalid() override

Removes all invalid entities from the set.

Only relevant for sets using in-place deletion policy.

Swap

void Swap(Entity lhs, Entity rhs) override

Swaps the location of the provided entities in the packed array, as well as the relevant payload (data associated with the entities), if any.

Reserve

void Reserve(u64 capacity) override

Reserves internal memory in order to fit entries.

Capacity

u64 Capacity() const override

Returns how many entries can fit into the internal memory.

Shrink

void Shrink() override

Shrinks the memory use of the set to accomodate the currently assigned entries, without any reserve for new entries.

Each

IteratorRange Each()

Allows easy iteration over all components using a range for loop.

Each

ConstIteratorRange Each() const

ReverseEach

ReverseIteratorRange ReverseEach()

Allows easy iteration over all components using a range for loop, in reverse order.

ReverseEach

ConstReverseIteratorRange ReverseEach() const

Cbegin

ConstIterator Cbegin() const

Iterator to the first component in the storage.

Begin

ConstIterator Begin() const

Begin

Iterator Begin()

Cend

ConstIterator Cend() const

Iterator past the last component in the storage.

End

ConstIterator End() const

End

Iterator End()

Crbegin

ConstReverseIterator Crbegin() const

Iterator to the last component in the storage, for reverse iteration.

Rbegin

ConstReverseIterator Rbegin() const

Rbegin

ReverseIterator Rbegin()

Crend

ConstReverseIterator Crend() const

Iterator to before the first component in the storage, for reverse iteration.

Rend

ConstReverseIterator Rend() const

Rend

ReverseIterator Rend()

cbegin

const_iterator cbegin() const

begin

const_iterator begin() const

begin

iterator begin()

cend

const_iterator cend() const

end

const_iterator end() const

end

iterator end()

crbegin

const_reverse_iterator crbegin() const

rbegin

const_reverse_iterator rbegin() const

rbegin

reverse_iterator rbegin()

crend

const_reverse_iterator crend() const

rend

const_reverse_iterator rend() const

rend

reverse_iterator rend()

~TSparseSet<DeletePolicy>

~TSparseSet<DeletePolicy>() override = default

GetDeletePolicy

SparseSetDeletePolicy GetDeletePolicy() const override

Returns the current delete policy.

GetFirstFreeElementPackedIndex

u64 GetFirstFreeElementPackedIndex() const override

When using in-place deletion policy returns the packed index to the first invalid element.

When using swap-only deletion policy returns the number of valid entities in the set. Not relevant if using swap-and-erase deletion policy.

Protected

Methods

AddInternal

Iterator AddInternal(Entity entity, bool forceAddAtEnd) override

Adds a new entity to the set.

entity
Entity to add.
forceAddAtEnd
Only relevant when using in-place deletion policy. When true it will add an entity at the end of the packaged data array, rather than re-using the first available invalid entity entry.

Returns: Iterator to the added entity.

ClearInternal

void ClearInternal()

Same as SparseSet::ClearInternal but also resets the free list head.

Private

Methods

EraseInternal

void EraseInternal(Entity entity) override

Removed an entity from the sparse set.

Entity must be a part of the sparse set.

MoveOrSwapPayload

void MoveOrSwapPayload(u64 fromPackedIndex, u64 toPackedIndex)

Moves the component from to .

ShrinkComponentArray

void ShrinkComponentArray(u64 newComponentCount)

Destroys any excess pages, as long as the internal contain can fit .

GetOrCreateComponentPageFor

ComponentType *GetOrCreateComponentPageFor(u64 packedComponentIndex)

Returns a page in which to store the component with the specified index at.

Internally allocates a page for the provided index if one doesn't exist.

GetOrCreateComponentPointer

ComponentType *GetOrCreateComponentPointer(u64 packedComponentIndex)

Returns a pointer to store the component with the specified index at.

Internally allocates a page for the provided index if one doesn't exist.

GetComponentReference

ComponentType &GetComponentReference(u64 packedComponentIndex)

Returns a reference to store the component with the specified index at.

Internally allocates a page for the provided index if one doesn't exist.

GetComponentReference

const ComponentType &GetComponentReference(u64 packedComponentIndex) const

Returns a reference to store the component with the specified index at.

Internally allocates a page for the provided index if one doesn't exist.

staticGetComponentIndexWithinPage

static constexpr u64 GetComponentIndexWithinPage(u64 packedComponentIndex)

Converts a global packed component index, into an index that's local to the page.

staticGetComponentPage

static constexpr u64 GetComponentPage(u64 packedComponentIndex)

Converts a global packed component index, into a page index.

Fields

mComponents

ComponentContainerType mComponents