Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
shkyera::SparseSet< Component > Class Template Reference

#include <SparseSet.hpp>

Inheritance diagram for shkyera::SparseSet< Component >:
[legend]

Classes

class  Iterator
 

Public Types

using iterator = Iterator< false >
 
using const_iterator = Iterator< true >
 

Public Member Functions

 SparseSet ()=default
 
 ~SparseSet ()=default
 
std::unique_ptr< SparseSetBaseclone () const override
 
bool add (Entity entity, Component component)
 
bool remove (Entity entity) override
 
void clear ()
 
bool contains (Entity entity) const
 
Componentget (Entity entity)
 
const Componentget (Entity entity) const
 
std::vector< Component > & getComponents ()
 
const std::vector< Component > & getComponents () const
 
bool empty () const
 
size_t size () const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
- Public Member Functions inherited from shkyera::SparseSetBase
virtual ~SparseSetBase ()=default
 

Private Attributes

std::vector< Entity_entities
 
std::unordered_map< Entity, size_t_entityToComponent
 
std::vector< Component_components
 

Detailed Description

template<typename Component>
class shkyera::SparseSet< Component >

Manages a sparse set of components associated with entities. Allows adding, removing, and accessing components efficiently.

Member Typedef Documentation

◆ const_iterator

template<typename Component >
using shkyera::SparseSet< Component >::const_iterator = Iterator<true>

◆ iterator

Constructor & Destructor Documentation

◆ SparseSet()

template<typename Component >
shkyera::SparseSet< Component >::SparseSet ( )
default

Default constructor.

◆ ~SparseSet()

Default destructor.

Member Function Documentation

◆ add()

template<typename Component >
bool shkyera::SparseSet< Component >::add ( Entity  entity,
Component  component 
)
inline

Adds a component for the specified entity.

Parameters
entityThe entity to associate with the component.
componentThe component to add.

◆ begin() [1/2]

template<typename Component >
iterator shkyera::SparseSet< Component >::begin ( )
inline

◆ begin() [2/2]

template<typename Component >
const_iterator shkyera::SparseSet< Component >::begin ( ) const
inline

◆ clear()

template<typename Component >
void shkyera::SparseSet< Component >::clear ( )
inline

◆ clone()

template<typename Component >
std::unique_ptr< SparseSetBase > shkyera::SparseSet< Component >::clone ( ) const
inlineoverridevirtual

◆ contains()

template<typename Component >
bool shkyera::SparseSet< Component >::contains ( Entity  entity) const
inline

Checks if the specified entity has an associated component.

Parameters
entityThe entity to check.
Returns
True if the entity has an associated component, false otherwise.

◆ empty()

template<typename Component >
bool shkyera::SparseSet< Component >::empty ( ) const
inline

Check if there is at least one entity with a component.

Returns
true if empty

◆ end() [1/2]

template<typename Component >
iterator shkyera::SparseSet< Component >::end ( )
inline

◆ end() [2/2]

template<typename Component >
const_iterator shkyera::SparseSet< Component >::end ( ) const
inline

◆ get() [1/2]

template<typename Component >
Component & shkyera::SparseSet< Component >::get ( Entity  entity)
inline

Retrieves a reference to the component associated with the specified entity.

Parameters
entityThe entity whose component is to be retrieved.
Returns
Reference to the associated component.

◆ get() [2/2]

template<typename Component >
const Component & shkyera::SparseSet< Component >::get ( Entity  entity) const
inline

Retrieves a const reference to the component associated with the specified entity.

Parameters
entityThe entity whose component is to be retrieved.
Returns
Const reference to the associated component.

◆ getComponents() [1/2]

template<typename Component >
std::vector< Component > & shkyera::SparseSet< Component >::getComponents ( )
inline

Retrieves a vector of all components in the sparse set.

Returns
Reference to the vector of components.

◆ getComponents() [2/2]

template<typename Component >
const std::vector< Component > & shkyera::SparseSet< Component >::getComponents ( ) const
inline

Retrieves a const vector of all components in the sparse set.

Returns
Const reference to the vector of components.

◆ remove()

template<typename Component >
bool shkyera::SparseSet< Component >::remove ( Entity  entity)
inlineoverridevirtual

Removes the component associated with the specified entity.

Parameters
entityThe entity whose component is to be removed.
Returns
True if the component was successfully removed, false otherwise.

Implements shkyera::SparseSetBase.

◆ size()

template<typename Component >
size_t shkyera::SparseSet< Component >::size ( ) const
inline

Member Data Documentation

◆ _components

template<typename Component >
std::vector<Component> shkyera::SparseSet< Component >::_components
private

Stores components associated with entities.

◆ _entities

template<typename Component >
std::vector<Entity> shkyera::SparseSet< Component >::_entities
private

Stores entities associated with components.

◆ _entityToComponent

template<typename Component >
std::unordered_map<Entity, size_t> shkyera::SparseSet< Component >::_entityToComponent
private

Maps entities to their component indices.


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