3#include <Foundation/Containers/HybridArray.h>
4#include <Foundation/Containers/IdTable.h>
5#include <Foundation/Logging/Log.h>
6#include <Foundation/Memory/BlockStorage.h>
7#include <Foundation/Reflection/Reflection.h>
8#include <Foundation/Types/Delegate.h>
10#include <Core/World/Component.h>
11#include <Core/World/Declarations.h>
12#include <Core/World/WorldModule.h>
39 plUInt32 GetComponentCount()
const;
45 template <
typename ComponentType>
75 void DeinitializeComponent(
plComponent* pComponent);
86template <
typename T, plBlockStorageType::Enum StorageType>
90 using ComponentType = T;
110 static plWorldModuleTypeId
TypeId();
116 friend ComponentType;
117 friend class plComponentManagerFactory;
119 virtual plComponent* CreateComponentStorage()
override;
140template <
typename ComponentType, plComponentUpdateType::Enum UpdateType, plBlockStorageType::Enum StorageType = plBlockStorageType::FreeList>
157#define PL_ADD_COMPONENT_FUNCTIONALITY(componentType, baseType, managerType) \
159 using ComponentManagerType = managerType; \
160 virtual plWorldModuleTypeId GetTypeId() const override { return s_TypeId; } \
161 static PL_ALWAYS_INLINE plWorldModuleTypeId TypeId() { return s_TypeId; } \
162 virtual plComponentMode::Enum GetMode() const override; \
163 static plComponentHandle CreateComponent(plGameObject* pOwnerObject, componentType*& pComponent); \
164 static void DeleteComponent(componentType* pComponent); \
165 void DeleteComponent(); \
168 friend managerType; \
169 static plWorldModuleTypeId s_TypeId
171#define PL_ADD_ABSTRACT_COMPONENT_FUNCTIONALITY(componentType, baseType) \
173 virtual plWorldModuleTypeId GetTypeId() const override { return plWorldModuleTypeId(-1); } \
174 static PL_ALWAYS_INLINE plWorldModuleTypeId TypeId() { return plWorldModuleTypeId(-1); }
177#define PL_DECLARE_COMPONENT_TYPE(componentType, baseType, managerType) \
178 PL_ADD_DYNAMIC_REFLECTION(componentType, baseType); \
179 PL_ADD_COMPONENT_FUNCTIONALITY(componentType, baseType, managerType);
182#define PL_DECLARE_ABSTRACT_COMPONENT_TYPE(componentType, baseType) \
183 PL_ADD_DYNAMIC_REFLECTION(componentType, baseType); \
184 PL_ADD_ABSTRACT_COMPONENT_FUNCTIONALITY(componentType, baseType);
190#define PL_BEGIN_COMPONENT_TYPE(componentType, version, mode) \
191 plWorldModuleTypeId componentType::s_TypeId = \
192 plWorldModuleFactory::GetInstance()->RegisterWorldModule<typename componentType::ComponentManagerType, componentType>(); \
193 plComponentMode::Enum componentType::GetMode() const { return mode; } \
194 plComponentHandle componentType::CreateComponent(plGameObject* pOwnerObject, componentType*& out_pComponent) \
196 return pOwnerObject->GetWorld()->GetOrCreateComponentManager<ComponentManagerType>()->CreateComponent(pOwnerObject, out_pComponent); \
198 void componentType::DeleteComponent(componentType* pComponent) { pComponent->GetOwningManager()->DeleteComponent(pComponent->GetHandle()); } \
199 void componentType::DeleteComponent() { GetOwningManager()->DeleteComponent(GetHandle()); } \
200 PL_BEGIN_DYNAMIC_REFLECTED_TYPE(componentType, version, plRTTINoAllocator)
205#define PL_BEGIN_ABSTRACT_COMPONENT_TYPE(componentType, version) PL_BEGIN_ABSTRACT_DYNAMIC_REFLECTED_TYPE(componentType, version)
208#define PL_END_COMPONENT_TYPE PL_END_DYNAMIC_REFLECTED_TYPE
209#define PL_END_ABSTRACT_COMPONENT_TYPE PL_END_ABSTRACT_DYNAMIC_REFLECTED_TYPE
211#include <Core/World/Implementation/ComponentManager_inl.h>
Definition BlockStorage.h:20
Definition BlockStorage.h:45
Definition BlockStorage.h:17
Base class of all component types.
Definition Component.h:25
Base class for all component managers. Do not derive directly from this class, but derive from plComp...
Definition ComponentManager.h:21
virtual void CollectAllComponents(plDynamicArray< plComponent * > &out_allComponents, bool bOnlyActive)=0
Adds all components that this manager handles to the given array (array is not cleared)....
plComponentHandle CreateComponent(plGameObject *pOwnerObject, ComponentType *&out_pComponent)
Create a new component instance and returns a handle to it.
virtual void CollectAllComponents(plDynamicArray< plComponentHandle > &out_allComponents, bool bOnlyActive)=0
Adds all components that this manager handles to the given array (array is not cleared)....
Definition ComponentManager.h:88
plComponentManager(plWorld *pWorld)
Although the constructor is public always use plWorld::CreateComponentManager to create an instance.
Definition ComponentManager_inl.h:43
plBlockStorage< ComponentType, plInternal::DEFAULT_BLOCK_SIZE, StorageType >::Iterator GetComponents(plUInt32 uiStartIndex=0)
Returns an iterator over all components.
Definition ComponentManager_inl.h:85
bool TryGetComponent(const plComponentHandle &hComponent, ComponentType *&out_pComponent)
Returns if a component with the given handle exists and if so writes out the corresponding pointer to...
Definition ComponentManager_inl.h:54
static plWorldModuleTypeId TypeId()
Returns the type id corresponding to the component type managed by this manager.
Definition ComponentManager_inl.h:99
virtual void CollectAllComponents(plDynamicArray< plComponentHandle > &out_allComponents, bool bOnlyActive) override
Adds all components that this manager handles to the given array (array is not cleared)....
Definition ComponentManager_inl.h:105
Simple component manager implementation that calls an update method on all components every frame.
Definition ComponentManager.h:142
virtual void Initialize() override
This method is called after the constructor. A derived type can override this method to do initializa...
Definition ComponentManager_inl.h:166
void SimpleUpdate(const plWorldModule::UpdateContext &context)
A simple update function that iterates over all components and calls Update() on every component.
Definition ComponentManager_inl.h:180
Definition DynamicArray.h:81
This class represents an object inside the world.
Definition GameObject.h:32
Definition WorldData.h:18
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
Definition WorldModule.h:10
virtual void Deinitialize()
This method is called before the destructor. A derived type can override this method to do deinitiali...
Definition WorldModule.h:101
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
A handle to a component.
Definition Declarations.h:138
Definition ComponentManager.h:131
Definition WorldModule.h:33
Description of an update function that can be registered at the world.
Definition WorldModule.h:43