EntityComponentMetaSystem
An implementation of an EntityComponent System with template meta-programming.
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
EC::Manager< ComponentsList, TagsList, ThreadCount > Struct Template Reference

Manages an EntityComponent system. More...

#include <Manager.hpp>

Classes

struct  TPFnDataStructFive
 Temporary struct used internally by ThreadPool. More...
 
struct  TPFnDataStructFour
 Temporary struct used internally by ThreadPool. More...
 
struct  TPFnDataStructOne
 Temporary struct used internally by ThreadPool. More...
 
struct  TPFnDataStructSeven
 Temporary struct used internally by ThreadPool. More...
 
struct  TPFnDataStructSix
 Temporary struct used internally by ThreadPool. More...
 
struct  TPFnDataStructThree
 Temporary struct used internally by ThreadPool. More...
 
struct  TPFnDataStructTwo
 Temporary struct used internally by ThreadPool. More...
 
struct  TPFnDataStructZero
 Temporary struct used internally by ThreadPool. More...
 

Public Types

using Components = ComponentsList
 
using Tags = TagsList
 
using Combined = EC::Meta::Combine< ComponentsList, TagsList >
 
using BitsetType = EC::Bitset< ComponentsList, TagsList >
 
typedef void ForMatchingFn(std::size_t, Manager< ComponentsList, TagsList > *, void *)
 

Public Member Functions

 Manager ()
 Initializes the manager with a default capacity. More...
 
std::size_t addEntity ()
 Adds an entity to the system, returning the ID of the entity. More...
 
void deleteEntity (std::size_t index)
 Marks an entity for deletion. More...
 
bool hasEntity (const std::size_t &index) const
 Checks if the Entity with the given ID is in the system. More...
 
bool isAlive (const std::size_t &index) const
 Checks if the Entity is not marked as deleted. More...
 
std::size_t getCurrentSize () const
 Returns the current size or number of entities in the system. More...
 
std::size_t getCurrentCapacity () const
 
const EntitiesTupleType & getEntityInfo (const std::size_t &index) const
 Returns a const reference to an Entity's info. More...
 
template<typename Component >
Component * getEntityData (const std::size_t &index)
 Returns a pointer to a component belonging to the given Entity. More...
 
template<typename Component >
Component * getEntityComponent (const std::size_t &index)
 Returns a pointer to a component belonging to the given Entity. More...
 
template<typename Component >
const Component * getEntityData (const std::size_t &index) const
 Returns a const pointer to a component belonging to the given Entity. More...
 
template<typename Component >
const Component * getEntityComponent (const std::size_t &index) const
 Returns a const pointer to a component belonging to the given Entity. More...
 
template<typename Component >
bool hasComponent (const std::size_t &index) const
 Checks whether or not the given Entity has the given Component. More...
 
template<typename Tag >
bool hasTag (const std::size_t &index) const
 Checks whether or not the given Entity has the given Tag. More...
 
template<typename Component , typename... Args>
void addComponent (const std::size_t &entityID, Args &&... args)
 Adds a component to the given Entity. More...
 
template<typename Component >
void removeComponent (const std::size_t &entityID)
 Removes the given Component from the given Entity. More...
 
template<typename Tag >
void addTag (const std::size_t &entityID)
 Adds the given Tag to the given Entity. More...
 
template<typename Tag >
void removeTag (const std::size_t &entityID)
 Removes the given Tag from the given Entity. More...
 
void reset ()
 Resets the Manager, removing all entities. More...
 
template<typename Signature , typename Function >
void forMatchingSignature (Function &&function, void *userData=nullptr, const bool useThreadPool=false)
 Calls the given function on all Entities matching the given Signature. More...
 
template<typename Signature , typename Function >
void forMatchingSignaturePtr (Function *function, void *userData=nullptr, const bool useThreadPool=false)
 Calls the given function on all Entities matching the given Signature. More...
 
template<typename Signature , typename Function >
std::size_t addForMatchingFunction (Function &&function, void *userData=nullptr)
 Stores a function in the manager to be called later. More...
 
void callForMatchingFunctions (const bool useThreadPool=false)
 Call all stored functions. More...
 
bool callForMatchingFunction (std::size_t id, const bool useThreadPool=false)
 Call a specific stored function. More...
 
void clearForMatchingFunctions ()
 Remove all stored functions. More...
 
bool removeForMatchingFunction (std::size_t id)
 Removes a function that has the given id. More...
 
template<typename List >
std::size_t keepSomeMatchingFunctions (List list)
 Removes all functions that do not have the index specified in argument "list". More...
 
std::size_t keepSomeMatchingFunctions (std::initializer_list< std::size_t > list)
 Removes all functions that do not have the index specified in argument "list". More...
 
template<typename List >
std::size_t removeSomeMatchingFunctions (List list)
 Removes all functions that do have the index specified in argument "list". More...
 
std::size_t removeSomeMatchingFunctions (std::initializer_list< std::size_t > list)
 Removes all functions that do have the index specified in argument "list". More...
 
bool changeForMatchingFunctionContext (std::size_t id, void *userData)
 Sets the context pointer of a stored function. More...
 
template<typename SigList , typename FTuple >
void forMatchingSignatures (FTuple fTuple, void *userData=nullptr, const bool useThreadPool=false)
 Call multiple functions with mulitple signatures on all living entities. More...
 
template<typename SigList , typename FTuple >
void forMatchingSignaturesPtr (FTuple fTuple, void *userData=nullptr, const bool useThreadPool=false)
 Call multiple functions with mulitple signatures on all living entities. More...
 
template<typename Signature >
void forMatchingSimple (ForMatchingFn fn, void *userData=nullptr, const bool useThreadPool=false)
 A simple version of forMatchingSignature() More...
 
template<typename Iterable >
void forMatchingIterable (Iterable iterable, ForMatchingFn fn, void *userData=nullptr, const bool useThreadPool=false)
 Similar to forMatchingSimple(), but with a collection of Component/Tag indices. More...
 

Detailed Description

template<typename ComponentsList, typename TagsList, unsigned int ThreadCount = 4>
struct EC::Manager< ComponentsList, TagsList, ThreadCount >

Manages an EntityComponent system.

EC::Manager must be created with a list of all used Components and all used tags.

Note that all components must have a default constructor.

An optional third template parameter may be given, which is the size of the number of threads in the internal ThreadPool, and should be at least 2. If ThreadCount is 1 or less, then the ThreadPool will not be created and it will never be used, even if the "true" parameter is given for functions that enable its usage.

Note that when calling one of the "forMatching" functions that make use of the internal ThreadPool, it is allowed to call addEntity() or deleteEntity() as the functions cache which entities are alive before running (allowing for addEntity()), and the functions defer deletions during concurrent execution (allowing for deleteEntity()).

Example:

EC::Manager<TypeList<C0, C1, C2>, TypeList<T0, T1>> manager;
Manages an EntityComponent system.
Definition: Manager.hpp:70

Constructor & Destructor Documentation

◆ Manager()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
EC::Manager< ComponentsList, TagsList, ThreadCount >::Manager ( )
inline

Initializes the manager with a default capacity.

The default capacity is set with macro EC_INIT_ENTITIES_SIZE, and will grow by amounts of EC_GROW_SIZE_AMOUNT when needed.

Member Function Documentation

◆ addComponent()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Component , typename... Args>
void EC::Manager< ComponentsList, TagsList, ThreadCount >::addComponent ( const std::size_t &  entityID,
Args &&...  args 
)
inline

Adds a component to the given Entity.

Additional parameters given to this function will construct the Component with those parameters.

Note that if the Entity already has the same component, then it will be overwritten by the newly created Component with the given arguments.

If the Entity is not alive or the given Component is not known to the Manager, then nothing will change.

Example:

struct C0
{
// constructor is compatible as a default constructor
C0(int a = 0, char b = 'b') :
a(a), b(b)
{}
int a;
char b;
}
manager.addComponent<C0>(entityID, 10, 'd');

◆ addEntity()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
std::size_t EC::Manager< ComponentsList, TagsList, ThreadCount >::addEntity ( )
inline

Adds an entity to the system, returning the ID of the entity.

Note: The ID of an entity is guaranteed to not change.

◆ addForMatchingFunction()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Signature , typename Function >
std::size_t EC::Manager< ComponentsList, TagsList, ThreadCount >::addForMatchingFunction ( Function &&  function,
void *  userData = nullptr 
)
inline

Stores a function in the manager to be called later.

As an alternative to calling functions directly with forMatchingSignature(), functions can be stored in the manager to be called later with callForMatchingFunctions() and callForMatchingFunction, and removed with clearForMatchingFunctions() and removeForMatchingFunction().

The syntax for the Function is the same as with forMatchingSignature().

Note that functions will be called in the same order they are inserted if called by callForMatchingFunctions() unless the internal functionIndex counter has wrapped around (is a std::size_t). Calling clearForMatchingFunctions() will reset this counter to zero.

Note that the context pointer provided here (default nullptr) will be provided to the stored function when called.

Example:

manager.addForMatchingFunction<TypeList<C0, C1, T0>>([]
(std::size_t ID,
void* context,
C0* component0, C1* component1)
{
// Lambda function contents here
});
// call all stored functions
manager.callForMatchingFunctions();
// remove all stored functions
manager.clearForMatchingFunctions();
Returns
The index of the function, used for deletion with removeForMatchingFunction() or filtering with keepSomeMatchingFunctions() or removeSomeMatchingFunctions(), or calling with callForMatchingFunction().

◆ addTag()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Tag >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::addTag ( const std::size_t &  entityID)
inline

Adds the given Tag to the given Entity.

Example:

manager.addTag<T0>(entityID);

◆ callForMatchingFunction()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
bool EC::Manager< ComponentsList, TagsList, ThreadCount >::callForMatchingFunction ( std::size_t  id,
const bool  useThreadPool = false 
)
inline

Call a specific stored function.

The second parameter can be optionally used to enable the use of the internal ThreadPool to call the stored function in parallel. Using the value false (which is the default) will not use the ThreadPool and run the stored function sequentially on the main thread. Note that multi-threading is based on splitting the task of calling the functions across sections of entities. Thus if there are only a small amount of entities in the manager, then using multiple threads may not have as great of a speed-up.

Example:

std::size_t id =
manager.addForMatchingFunction<TypeList<C0, C1, T0>>(
[] (std::size_t ID, void* context, C0* c0, C1* c1) {
// Lambda function contents here
});
// call the previously added function
manager.callForMatchingFunction(id);
// call the previously added function with ThreadPool enabled
manager.callForMatchingFunction(id, true);
Returns
False if a function with the given id does not exist.

◆ callForMatchingFunctions()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
void EC::Manager< ComponentsList, TagsList, ThreadCount >::callForMatchingFunctions ( const bool  useThreadPool = false)
inline

Call all stored functions.

The first (and only) parameter can be optionally used to enable the use of the internal ThreadPool to call all stored functions in parallel. Using the value false (which is the default) will not use the ThreadPool and run all stored functions sequentially on the main thread. Note that multi-threading is based on splitting the task of calling the functions across sections of entities. Thus if there are only a small amount of entities in the manager, then using multiple threads may not have as great of a speed-up.

Example:

manager.addForMatchingFunction<TypeList<C0, C1, T0>>([]
(std::size_t ID,
void* context,
C0* component0, C1* component1) {
// Lambda function contents here
});
// call all stored functions
manager.callForMatchingFunctions();
// call all stored functions with ThreadPool enabled
manager.callForMatchingFunctions(true);
// remove all stored functions
manager.clearForMatchingFunctions();

◆ changeForMatchingFunctionContext()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
bool EC::Manager< ComponentsList, TagsList, ThreadCount >::changeForMatchingFunctionContext ( std::size_t  id,
void *  userData 
)
inline

Sets the context pointer of a stored function.

Returns
True if id is valid and context was updated

◆ clearForMatchingFunctions()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
void EC::Manager< ComponentsList, TagsList, ThreadCount >::clearForMatchingFunctions ( )
inline

Remove all stored functions.

Also resets the index counter of stored functions to 0.

Example:

manager.addForMatchingFunction<TypeList<C0, C1, T0>>([]
(std::size_t ID,
void* context,
C0* component0, C1* component1)
{
// Lambda function contents here
});
// call all stored functions
manager.callForMatchingFunctions();
// remove all stored functions
manager.clearForMatchingFunctions();

◆ deleteEntity()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
void EC::Manager< ComponentsList, TagsList, ThreadCount >::deleteEntity ( std::size_t  index)
inline

Marks an entity for deletion.

A deleted Entity's id is stored to be reclaimed later when addEntity is called. Thus calling addEntity may return an id of a previously deleted Entity.

◆ forMatchingIterable()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Iterable >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::forMatchingIterable ( Iterable  iterable,
ForMatchingFn  fn,
void *  userData = nullptr,
const bool  useThreadPool = false 
)
inline

Similar to forMatchingSimple(), but with a collection of Component/Tag indices.

This function works like forMatchingSimple(), but instead of providing template types that filter out non-matching entities, an iterable of indices must be provided which correlate to matching Component/Tag indices. The function given must match the previously defined typedef of type ForMatchingFn.

The fourth parameter can be optionally used to enable the use of the internal ThreadPool to call the function in parallel. Using the value false (which is the default) will not use the ThreadPool and run the function sequentially on all entities on the main thread. Note that multi-threading is based on splitting the task of calling the functions across sections of entities. Thus if there are only a small amount of entities in the manager, then using multiple threads may not have as great of a speed-up.

◆ forMatchingSignature()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Signature , typename Function >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::forMatchingSignature ( Function &&  function,
void *  userData = nullptr,
const bool  useThreadPool = false 
)
inline

Calls the given function on all Entities matching the given Signature.

The function object given to this function must accept std::size_t as its first parameter, void* as its second parameter, and Component pointers for the rest of the parameters. Tags specified in the Signature are only used as filters and will not be given as a parameter to the function.

The second parameter is default nullptr and will be passed to the function call as the second parameter as a means of providing context (useful when the function is not a lambda function).

The third parameter is default false (not multi-threaded). Otherwise, if true, then the thread pool will be used to call the given function in parallel across all entities. Note that multi-threading is based on splitting the task of calling the function across sections of entities. Thus if there are only a small amount of entities in the manager, then using multiple threads may not have as great of a speed-up.

Example:

Context c; // some class/struct with data
manager.forMatchingSignature<TypeList<C0, C1, T0>>([]
(std::size_t ID,
void* context,
C0* component0, C1* component1)
{
// Lambda function contents here
},
&c, // "Context" object passed to the function
true // enable use of internal ThreadPool
);

Note, the ID given to the function is not permanent. An entity's ID may change when cleanup() is called.

◆ forMatchingSignaturePtr()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Signature , typename Function >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::forMatchingSignaturePtr ( Function *  function,
void *  userData = nullptr,
const bool  useThreadPool = false 
)
inline

Calls the given function on all Entities matching the given Signature.

The function pointer given to this function must accept std::size_t as its first parameter, void* as its second parameter, and Component pointers for the rest of the parameters. Tags specified in the Signature are only used as filters and will not be given as a parameter to the function.

The second parameter is default nullptr and will be passed to the function call as the second parameter as a means of providing context (useful when the function is not a lambda function).

The third parameter is default false (not multi-threaded). Otherwise, if true, then the thread pool will be used to call the given function in parallel across all entities. Note that multi-threading is based on splitting the task of calling the function across sections of entities. Thus if there are only a small amount of entities in the manager, then using multiple threads may not have as great of a speed-up.

Example:

Context c; // some class/struct with data
auto function = []
(std::size_t ID,
void* context,
C0* component0, C1* component1)
{
// Lambda function contents here
};
manager.forMatchingSignaturePtr<TypeList<C0, C1, T0>>(
&function, // ptr
&c, // "Context" object passed to the function
true // enable use of ThreadPool
);

Note, the ID given to the function is not permanent. An entity's ID may change when cleanup() is called.

◆ forMatchingSignatures()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename SigList , typename FTuple >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::forMatchingSignatures ( FTuple  fTuple,
void *  userData = nullptr,
const bool  useThreadPool = false 
)
inline

Call multiple functions with mulitple signatures on all living entities.

(Living entities as in entities that have not been marked for deletion.)

This function requires the first template parameter to be a EC::Meta::TypeList of signatures. Note that a signature is a EC::Meta::TypeList of components and tags, meaning that SigList is a TypeList of TypeLists.

The second template parameter can be inferred from the function parameter which should be a tuple of functions. The function at any index in the tuple should match with a signature of the same index in the SigList. Behavior is undefined if there are less functions than signatures.

See the Unit Test of this function in src/test/ECTest.cpp for usage examples.

The second parameter (default nullptr) will be provided to every function call as a void* (context).

The third parameter is default false (not multi-threaded). Otherwise, if true, then the thread pool will be used to call the given function in parallel across all entities. Note that multi-threading is based on splitting the task of calling the function across sections of entities. Thus if there are only a small amount of entities in the manager, then using multiple threads may not have as great of a speed-up.

This function was created for the use case where there are many entities in the system which can cause multiple calls to forMatchingSignature to be slow due to the overhead of iterating through the entire list of entities on each invocation. This function instead iterates through all entities once, storing matching entities in a vector of vectors (for each signature and function pair) and then calling functions with the matching list of entities.

Note that multi-threaded or not, functions will be called in order of signatures. The first function signature pair will be called first, then the second, third, and so on. If this function is called with more than 1 thread specified, then the order of entities called is not guaranteed. Otherwise entities will be called in consecutive order by their ID.

◆ forMatchingSignaturesPtr()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename SigList , typename FTuple >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::forMatchingSignaturesPtr ( FTuple  fTuple,
void *  userData = nullptr,
const bool  useThreadPool = false 
)
inline

Call multiple functions with mulitple signatures on all living entities.

(Living entities as in entities that have not been marked for deletion.)

Note that this function requires the tuple of functions to hold pointers to functions, not just functions.

This function requires the first template parameter to be a EC::Meta::TypeList of signatures. Note that a signature is a EC::Meta::TypeList of components and tags, meaning that SigList is a TypeList of TypeLists.

The second template parameter can be inferred from the function parameter which should be a tuple of functions. The function at any index in the tuple should match with a signature of the same index in the SigList. Behavior is undefined if there are less functions than signatures.

See the Unit Test of this function in src/test/ECTest.cpp for usage examples.

The second parameter (default nullptr) will be provided to every function call as a void* (context).

The third parameter is default false (not multi-threaded). Otherwise, if true, then the thread pool will be used to call the given function in parallel across all entities. Note that multi-threading is based on splitting the task of calling the function across sections of entities. Thus if there are only a small amount of entities in the manager, then using multiple threads may not have as great of a speed-up.

This function was created for the use case where there are many entities in the system which can cause multiple calls to forMatchingSignature to be slow due to the overhead of iterating through the entire list of entities on each invocation. This function instead iterates through all entities once, storing matching entities in a vector of vectors (for each signature and function pair) and then calling functions with the matching list of entities.

Note that multi-threaded or not, functions will be called in order of signatures. The first function signature pair will be called first, then the second, third, and so on. If this function is called with more than 1 thread specified, then the order of entities called is not guaranteed. Otherwise entities will be called in consecutive order by their ID.

◆ forMatchingSimple()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Signature >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::forMatchingSimple ( ForMatchingFn  fn,
void *  userData = nullptr,
const bool  useThreadPool = false 
)
inline

A simple version of forMatchingSignature()

This function behaves like forMatchingSignature(), but instead of providing a function with each requested component as a parameter, the function receives a pointer to the manager itself, with which to query component/tag data.

The third parameter can be optionally used to enable the use of the internal ThreadPool to call the function in parallel. Using the value false (which is the default) will not use the ThreadPool and run the function sequentially on all entities on the main thread. Note that multi-threading is based on splitting the task of calling the functions across sections of entities. Thus if there are only a small amount of entities in the manager, then using multiple threads may not have as great of a speed-up.

◆ getCurrentSize()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
std::size_t EC::Manager< ComponentsList, TagsList, ThreadCount >::getCurrentSize ( ) const
inline

Returns the current size or number of entities in the system.

Note this function will only count entities where isAlive() returns true.

◆ getEntityComponent() [1/2]

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Component >
Component * EC::Manager< ComponentsList, TagsList, ThreadCount >::getEntityComponent ( const std::size_t &  index)
inline

Returns a pointer to a component belonging to the given Entity.

Note that this function is the same as getEntityData().

This function will return a pointer to a Component regardless of whether or not the Entity actually owns the Component. If the Entity doesn't own the Component, changes to the Component will not affect any Entity. It is recommended to use hasComponent() to determine if the Entity actually owns that Component.

If the given Component is unknown to the Manager, then this function will return a nullptr.

◆ getEntityComponent() [2/2]

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Component >
const Component * EC::Manager< ComponentsList, TagsList, ThreadCount >::getEntityComponent ( const std::size_t &  index) const
inline

Returns a const pointer to a component belonging to the given Entity.

Note that this function is the same as getEntityData() (const).

This function will return a const pointer to a Component regardless of whether or not the Entity actually owns the Component. If the Entity doesn't own the Component, changes to the Component will not affect any Entity. It is recommended to use hasComponent() to determine if the Entity actually owns that Component.

If the given Component is unknown to the Manager, then this function will return a nullptr.

◆ getEntityData() [1/2]

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Component >
Component * EC::Manager< ComponentsList, TagsList, ThreadCount >::getEntityData ( const std::size_t &  index)
inline

Returns a pointer to a component belonging to the given Entity.

This function will return a pointer to a Component regardless of whether or not the Entity actually owns the Component. If the Entity doesn't own the Component, changes to the Component will not affect any Entity. It is recommended to use hasComponent() to determine if the Entity actually owns that Component.

If the given Component is unknown to the Manager, then this function will return a nullptr.

◆ getEntityData() [2/2]

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Component >
const Component * EC::Manager< ComponentsList, TagsList, ThreadCount >::getEntityData ( const std::size_t &  index) const
inline

Returns a const pointer to a component belonging to the given Entity.

This function will return a const pointer to a Component regardless of whether or not the Entity actually owns the Component. If the Entity doesn't own the Component, changes to the Component will not affect any Entity. It is recommended to use hasComponent() to determine if the Entity actually owns that Component.

If the given Component is unknown to the Manager, then this function will return a nullptr.

◆ getEntityInfo()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
const EntitiesTupleType & EC::Manager< ComponentsList, TagsList, ThreadCount >::getEntityInfo ( const std::size_t &  index) const
inline

Returns a const reference to an Entity's info.

An Entity's info is a std::tuple with a bool, and a bitset.


The bool determines if the Entity is alive.
The bitset shows what Components and Tags belong to the Entity.

◆ hasComponent()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Component >
bool EC::Manager< ComponentsList, TagsList, ThreadCount >::hasComponent ( const std::size_t &  index) const
inline

Checks whether or not the given Entity has the given Component.

Example:

manager.hasComponent<C0>(entityID);

◆ hasEntity()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
bool EC::Manager< ComponentsList, TagsList, ThreadCount >::hasEntity ( const std::size_t &  index) const
inline

Checks if the Entity with the given ID is in the system.

Note that deleted Entities are still considered in the system. Consider using isAlive().

◆ hasTag()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Tag >
bool EC::Manager< ComponentsList, TagsList, ThreadCount >::hasTag ( const std::size_t &  index) const
inline

Checks whether or not the given Entity has the given Tag.

Example:

manager.hasTag<T0>(entityID);

◆ isAlive()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
bool EC::Manager< ComponentsList, TagsList, ThreadCount >::isAlive ( const std::size_t &  index) const
inline

Checks if the Entity is not marked as deleted.

Note that invalid Entities (Entities where calls to hasEntity() returns false) will return false.

◆ keepSomeMatchingFunctions() [1/2]

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename List >
std::size_t EC::Manager< ComponentsList, TagsList, ThreadCount >::keepSomeMatchingFunctions ( List  list)
inline

Removes all functions that do not have the index specified in argument "list".

The given List must be iterable. This is the only requirement, so a set could also be given.

Returns
The number of functions deleted.

◆ keepSomeMatchingFunctions() [2/2]

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
std::size_t EC::Manager< ComponentsList, TagsList, ThreadCount >::keepSomeMatchingFunctions ( std::initializer_list< std::size_t >  list)
inline

Removes all functions that do not have the index specified in argument "list".

This function allows for passing an initializer list.

Returns
The number of functions deleted.

◆ removeComponent()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Component >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::removeComponent ( const std::size_t &  entityID)
inline

Removes the given Component from the given Entity.

If the Entity does not have the Component given, nothing will change.

Example:

manager.removeComponent<C0>(entityID);

◆ removeForMatchingFunction()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
bool EC::Manager< ComponentsList, TagsList, ThreadCount >::removeForMatchingFunction ( std::size_t  id)
inline

Removes a function that has the given id.

Returns
True if a function was erased.

◆ removeSomeMatchingFunctions() [1/2]

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename List >
std::size_t EC::Manager< ComponentsList, TagsList, ThreadCount >::removeSomeMatchingFunctions ( List  list)
inline

Removes all functions that do have the index specified in argument "list".

The given List must be iterable. This is the only requirement, so a set could also be given.

Returns
The number of functions deleted.

◆ removeSomeMatchingFunctions() [2/2]

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
std::size_t EC::Manager< ComponentsList, TagsList, ThreadCount >::removeSomeMatchingFunctions ( std::initializer_list< std::size_t >  list)
inline

Removes all functions that do have the index specified in argument "list".

This function allows for passing an initializer list.

Returns
The number of functions deleted.

◆ removeTag()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
template<typename Tag >
void EC::Manager< ComponentsList, TagsList, ThreadCount >::removeTag ( const std::size_t &  entityID)
inline

Removes the given Tag from the given Entity.

If the Entity does not have the Tag given, nothing will change.

Example:

manager.removeTag<T0>(entityID);

◆ reset()

template<typename ComponentsList , typename TagsList , unsigned int ThreadCount = 4>
void EC::Manager< ComponentsList, TagsList, ThreadCount >::reset ( )
inline

Resets the Manager, removing all entities.

Some data may persist but will be overwritten when new entities are added. Thus, do not depend on data to persist after a call to reset().


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