Cogs.Core
|
Component system template with multiple parallel structures per component stored in separate pools similar to how the components themselves are stored. More...
#include <ComponentSystem.h>
Classes | |
struct | CreateFunctor |
Functor object used to create component data. More... | |
struct | DestroyFunctor |
Functor object used to destroy component data. More... | |
Public Member Functions | |
ComponentSystemWithDataPools (Memory::Allocator *allocator, SizeType size=1024, MemBlockType componentMemType=MemBlockType::Component, MemBlockType dataMemType=MemBlockType::ComponentData) | |
ComponentHandle | createComponent () override |
void | destroyComponent (ComponentHandle component) override |
template<typename T > | |
T & | getData (const ComponentType *component) |
Get the data stored for the given component from the data pool storing objects of the specified template type. | |
template<typename T > | |
const T & | getData (const ComponentType *component) const |
Get the const data stored for the given component from the data pool storing objects of the specified template type. | |
![]() | |
ComponentSystem (Memory::Allocator *allocator, SizeType size=16384, MemBlockType componentMemType=MemBlockType::Component) | |
void | instrumentedPreUpdate () override |
Provided for tagged engine instrumentation. | |
void | instrumentedUpdate () override |
Provided for tagged engine instrumentation. | |
void | instrumentedPostUpdate () override |
Provided for tagged engine instrumentation. | |
ComponentHandle | createComponent () override |
Create a new component instance. | |
void | destroyComponent (ComponentHandle component) override |
Destroy the component held by the given handle. | |
SizeType | getComponentIndex (const Component *component) const |
Get the index of the given component in the component pool. | |
size_t | size () |
Returns the number of active components. | |
void | clearCarryFlags () |
Clear carry flags of all active components. | |
void | resetFlags () |
Reset the flags of all active components. | |
void | prepareUpdate (Context *) override |
void | postUpdate (Context *) override |
ComponentHandle | getHandle (const ComponentType *component) |
Get a handle to the given Component instance. | |
virtual void | addEntitiesWithComponent (std::vector< EntityId > &entities, Reflection::TypeId componentTypeId) override |
Return all entities with a given. | |
![]() | |
virtual | ~ComponentSystemBase () |
Provided for destruction via pointer to base. | |
ComponentSystemBase (Reflection::TypeId componentType) | |
Constructs a ComponentSystemBase to manage components of the given componentType. | |
virtual void | initialize (Context *context) |
Initialize the system. | |
void | preUpdate () |
Run the pre-update method of the system. | |
void | update () |
Updates the system state to that of the current frame. | |
void | postUpdate () |
Perform post update logic in the system. | |
virtual void | preUpdate (Context *) |
Provided for custom pre update logic in derived systems. | |
virtual void | prepareUpdate (Context *) |
Provided for custom update preparation logic in derived systems. | |
virtual void | update (Context *) |
Provided for custom update logic in derived systems. | |
virtual void | postUpdate (Context *) |
Provided for custom post update logic in derived systems. | |
virtual void | instrumentedPreUpdate () |
Provided for tagged engine instrumentation. | |
virtual void | instrumentedUpdate () |
Provided for tagged engine instrumentation. | |
virtual void | instrumentedPostUpdate () |
Provided for tagged engine instrumentation. | |
virtual void | addEntitiesWithComponent (std::vector< EntityId > &, Reflection::TypeId) |
Return all entities with a given. | |
virtual void | cleanup (Context *) |
Provided for custom cleanup logic in derived systems. | |
virtual ComponentHandle | createComponent () |
Create a new component instance. | |
virtual void | destroyComponent (ComponentHandle) |
Destroy the component held by the given handle. | |
Reflection::TypeId | getComponentType () const |
Get the reflected type of the components managed by this system. | |
Private Attributes | |
std::tuple< ComponentModel::ComponentDataPool< DataTypes >... > | datas |
Separate pools for each template data type. | |
Additional Inherited Members | |
![]() | |
typedef ComponentType | component_type |
![]() | |
static Reflection::TypeId | getTypeId () |
Get the type id of the component type used by the system. | |
![]() | |
ComponentPool< ComponentType > | pool |
Pool of components managed by the system. | |
![]() | |
Reflection::TypeId | componentType |
The type of components managed by this instance. | |
Context * | context = nullptr |
Pointer to the Context instance the system lives in. | |
Component system template with multiple parallel structures per component stored in separate pools similar to how the components themselves are stored.
The pools are kept up to date in terms of allocation/deallocation relative to the component pool.
ComponentType | Type of component to manage in this system. Must be derived from Component and registered in the Reflection::TypeDatabase. |
InitialSize | The initial capacity of the system at startup. The capacity determines the size of the component and data pools and is used to preallocate memory, but no initialization is performed. |
DataTypes | Variable number of unique types of which to store one parallel instance per component. |
Definition at line 251 of file ComponentSystem.h.
|
inline |
Definition at line 254 of file ComponentSystem.h.
|
inlineoverridevirtual |
Overridden to update data pool contents in lockstep with the component pool. Any subclass overriding this method should call base class first.
Reimplemented from Cogs::Core::ComponentSystem< ComponentType >.
Reimplemented in Cogs::Core::CurtainView::CurtainViewSystem, Cogs::Core::EchoSounder::UniformGridSystem, Cogs::Core::Image360System, Cogs::Core::OGC3DTilesSystem, Cogs::Core::PotreeSystem, Cogs::Core::SeaCurrentsSystem, Cogs::Core::TerrainSystem, Cogs::Core::VectorField::VectorFieldSystem, Cogs::Core::VideoPlaybackSystem, Cogs::Core::Volumetric::OctSystem, Cogs::Core::CameraSystem, Cogs::Core::SpriteRenderSystem, and Cogs::Core::MarkerPointSetSystem.
Definition at line 285 of file ComponentSystem.h.
References Cogs::Core::ComponentSystemWithDataPools< ComponentType, DataTypes >::datas, Cogs::for_each_in_tuple(), and Cogs::Core::ComponentSystem< ComponentType >::pool.
Referenced by Cogs::Core::Scene::setup(), and Cogs::Core::InstancedModelSystem::update().
|
inlineoverridevirtual |
Overridden to update data pool contents in lockstep with the component pool. Any subclass overriding this method should also call base class.
Reimplemented from Cogs::Core::ComponentSystem< ComponentType >.
Reimplemented in Cogs::Core::GhostSystem, Cogs::Core::RigidBodySystem, Cogs::Core::TriggerSystem, Cogs::Core::EchoSounder::UniformGridSystem, Cogs::Core::Image360System, Cogs::Core::OGC3DTilesSystem, Cogs::Core::PotreeSystem, Cogs::Core::SeaCurrentsSystem, Cogs::Core::OceanSystem, Cogs::Core::TerrainSystem, Cogs::Core::VectorField::VectorFieldSystem, Cogs::Core::VideoCaptureSystem, Cogs::Core::CaptureSystem, Cogs::Core::SpriteRenderSystem, Cogs::Core::MarkerPointSetSystem, Cogs::Core::AudioSystem, and Cogs::Core::VideoPlaybackSystem.
Definition at line 299 of file ComponentSystem.h.
References Cogs::Core::ComponentSystemWithDataPools< ComponentType, DataTypes >::datas, Cogs::for_each_in_tuple(), and Cogs::Core::ComponentSystem< ComponentType >::pool.
|
inline |
Get the data stored for the given component from the data pool storing objects of the specified template type.
T | Type of data structure used to determine which pool to fetch data from. |
component | Pointer to a valid component instance to fetch data for. |
Definition at line 320 of file ComponentSystem.h.
References Cogs::Core::ComponentSystemWithDataPools< ComponentType, DataTypes >::datas, and Cogs::Core::ComponentSystem< ComponentType >::getComponentIndex().
|
inline |
Get the const data stored for the given component from the data pool storing objects of the specified template type.
T | Type of data structure used to determine which pool to fetch data from. |
component | Pointer to a valid component instance to fetch data for. |
Definition at line 341 of file ComponentSystem.h.
References Cogs::Core::ComponentSystemWithDataPools< ComponentType, DataTypes >::datas, and Cogs::Core::ComponentSystem< ComponentType >::getComponentIndex().
|
private |
Separate pools for each template data type.
Definition at line 353 of file ComponentSystem.h.
Referenced by Cogs::Core::ComponentSystemWithDataPools< ComponentType, DataTypes >::createComponent(), Cogs::Core::ComponentSystemWithDataPools< ComponentType, DataTypes >::destroyComponent(), and Cogs::Core::ComponentSystemWithDataPools< ComponentType, DataTypes >::getData().