4#include "Platform/Instrumentation.h"
5#include "Utilities/Tuple.h"
7#include "Foundation/ComponentModel/ComponentPool.h"
8#include "Foundation/ComponentModel/ComponentDataPool.h"
9#include "Foundation/ComponentModel/Entity.h"
10#include "Foundation/Reflection/TypeDatabase.h"
67 prepareUpdate(context);
142 template<
typename ComponentType>
146 typedef ComponentType component_type;
150 pool(allocator,
size, componentMemType)
158 return Reflection::TypeDatabase::getType<ComponentType>().getTypeId();
164 CpuInstrumentationScope_(SCOPE_SYSTEMS, scope.c_str());
171 CpuInstrumentationScope_(SCOPE_SYSTEMS, scope.c_str());
178 CpuInstrumentationScope_(SCOPE_SYSTEMS, scope.c_str());
197 for (
auto & component :
pool) {
205 for (
auto & component :
pool) {
206 component.resetChanged();
226 for (
auto & comp :
pool) {
227 if (comp.getTypeId() == componentTypeId) {
228 entities.push_back(comp.getContainer()->getId());
250 template<
typename ComponentType,
typename... DataTypes>
264 template<
typename Type>
265 void operator()(Type && data)
267 data.create(component);
276 template<
typename Type>
277 void operator()(Type && data)
279 data.destroy(component);
287 auto component = this->
pool.allocateComponent();
306 this->
pool.deallocateComponent(component);
325 auto & data = Cogs::get<ComponentModel::ComponentDataPool<T>>(
datas);
341 const T &
getData(
const ComponentType * component)
const
346 auto & data = Cogs::get<ComponentModel::ComponentDataPool<T>>(
datas);
353 std::tuple<ComponentModel::ComponentDataPool<DataTypes>...>
datas;
363 template<
typename ComponentType,
typename DataType>
371 DataType & getData(
const ComponentType * component) {
return Base::template getData<DataType>(component); }
373 const DataType & getData(
const ComponentType * component)
const {
return Base::template getData<DataType>(component); }
Typed data pool for storing data in parallel to a component pool.
Base class for Component instances.
Base class for component systems.
virtual void cleanup(Context *)
Provided for custom cleanup logic in derived systems.
virtual ComponentHandle createComponent()
Create a new component instance.
void postUpdate()
Perform post update logic in the system.
virtual void initialize(Context *context)
Initialize the system.
Reflection::TypeId getComponentType() const
Get the reflected type of the components managed by this system.
virtual void destroyComponent(ComponentHandle)
Destroy the component held by the given handle.
void update()
Updates the system state to that of the current frame.
virtual void instrumentedPreUpdate()
Provided for tagged engine instrumentation.
Reflection::TypeId componentType
The type of components managed by this instance.
virtual ~ComponentSystemBase()
Provided for destruction via pointer to base.
virtual void update(Context *)
Provided for custom update logic in derived systems.
ComponentSystemBase(Reflection::TypeId componentType)
Constructs a ComponentSystemBase to manage components of the given componentType.
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 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 postUpdate(Context *)
Provided for custom post update logic in derived systems.
void preUpdate()
Run the pre-update method of the system.
Component system with parallel data per component stored in a pool similar to how the components them...
Component system template with multiple parallel structures per component stored in separate pools si...
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...
T & getData(const ComponentType *component)
Get the data stored for the given component from the data pool storing objects of the specified templ...
ComponentHandle createComponent() override
std::tuple< ComponentModel::ComponentDataPool< DataTypes >... > datas
Separate pools for each template data type.
void destroyComponent(ComponentHandle component) override
Typed component system managing a pool of components with the given ComponentType.
void instrumentedPostUpdate() override
Provided for tagged engine instrumentation.
void postUpdate(Context *) override
void prepareUpdate(Context *) override
ComponentHandle createComponent() override
Create a new component instance.
void instrumentedPreUpdate() override
Provided for tagged engine instrumentation.
size_t size()
Returns the number of active components.
void clearCarryFlags()
Clear carry flags of all active components.
static Reflection::TypeId getTypeId()
Get the type id of the component type used by the system.
void resetFlags()
Reset the flags of all active components.
SizeType getComponentIndex(const Component *component) const
Get the index of the given component in the component pool.
ComponentPool< ComponentType > pool
Pool of components managed by the system.
ComponentHandle getHandle(const ComponentType *component)
Get a handle to the given Component instance.
void instrumentedUpdate() override
Provided for tagged engine instrumentation.
virtual void addEntitiesWithComponent(std::vector< EntityId > &entities, Reflection::TypeId componentTypeId) override
Return all entities with a given.
void destroyComponent(ComponentHandle component) override
Destroy the component held by the given handle.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Base allocator implementation.
static const Type & getType()
Get the Type of the given template argument.
constexpr const Name & getName() const
Get the unique name of the type.
Contains code for composing and managing entities built from components.
uint16_t TypeId
Built in type used to uniquely identify a single type instance.
Contains all Cogs related functionality.
void for_each_in_tuple(std::tuple< Ts... > &t, F f)
Utility method for executing the given function over all members in a tuple.
ComponentIndex SizeType
Type used to track the size of pools.
Handle to a Component instance.
@ AllowGrow
Allows the component pool to grow on demand.
Functor object used to create component data.
Functor object used to destroy component data.
const std::string & getName() const
Get the string name. This can be empty, even in valid instances of Name.