4 return m_Components.
Contains(hComponent);
9 return m_Components.
TryGetValue(hComponent, out_pComponent);
15 bool res = m_Components.
TryGetValue(hComponent, pComponent);
16 out_pComponent = pComponent;
22 return static_cast<plUInt32
>(m_Components.
GetCount());
25template <
typename ComponentType>
31 if (pComponent !=
nullptr)
33 InitializeComponent(pComponent);
36 out_pComponent = plStaticCast<ComponentType*>(pComponent);
42template <
typename T, plBlockStorageType::Enum StorageType>
45 , m_ComponentStorage(GetBlockAllocator(), GetAllocator())
47 static_assert(PL_IS_DERIVED_FROM_STATIC(
plComponent, ComponentType),
"Not a valid component type");
50template <
typename T, plBlockStorageType::Enum StorageType>
53template <
typename T, plBlockStorageType::Enum StorageType>
56 PL_ASSERT_DEV(ComponentType::TypeId() == hComponent.GetInternalID().m_TypeId,
57 "The given component handle is not of the expected type. Expected type id {0}, got type id {1}", ComponentType::TypeId(),
58 hComponent.GetInternalID().m_TypeId);
59 PL_ASSERT_DEV(hComponent.GetInternalID().m_WorldIndex == GetWorldIndex(),
60 "Component does not belong to this world. Expected world id {0} got id {1}", GetWorldIndex(), hComponent.GetInternalID().m_WorldIndex);
64 out_pComponent =
static_cast<ComponentType*
>(pComponent);
68template <
typename T, plBlockStorageType::Enum StorageType>
72 PL_ASSERT_DEV(ComponentType::TypeId() == hComponent.GetInternalID().m_TypeId,
73 "The given component handle is not of the expected type. Expected type id {0}, got type id {1}", ComponentType::TypeId(),
74 hComponent.GetInternalID().m_TypeId);
75 PL_ASSERT_DEV(hComponent.GetInternalID().m_WorldIndex == GetWorldIndex(),
76 "Component does not belong to this world. Expected world id {0} got id {1}", GetWorldIndex(), hComponent.GetInternalID().m_WorldIndex);
80 out_pComponent =
static_cast<const ComponentType*
>(pComponent);
84template <
typename T, plBlockStorageType::Enum StorageType>
87 return m_ComponentStorage.GetIterator(uiStartIndex);
90template <
typename T, plBlockStorageType::Enum StorageType>
94 return m_ComponentStorage.GetIterator(uiStartIndex);
98template <
typename T, plBlockStorageType::Enum StorageType>
104template <
typename T, plBlockStorageType::Enum StorageType>
107 out_allComponents.
Reserve(out_allComponents.
GetCount() + m_ComponentStorage.GetCount());
109 for (
auto it = GetComponents(); it.IsValid(); it.Next())
111 if (!bOnlyActive || it->IsActive())
118template <
typename T, plBlockStorageType::Enum StorageType>
121 out_allComponents.
Reserve(out_allComponents.
GetCount() + m_ComponentStorage.GetCount());
123 for (
auto it = GetComponents(); it.IsValid(); it.Next())
125 if (!bOnlyActive || it->IsActive())
132template <
typename T, plBlockStorageType::Enum StorageType>
135 return m_ComponentStorage.Create();
138template <
typename T, plBlockStorageType::Enum StorageType>
141 T* pMovedComponent =
nullptr;
142 m_ComponentStorage.Delete(
static_cast<T*
>(pComponent), pMovedComponent);
143 out_pMovedComponent = pMovedComponent;
146template <
typename T, plBlockStorageType::Enum StorageType>
150 if (desc.m_uiGranularity != 0)
151 desc.m_uiGranularity =
static_cast<plUInt16
>(
159template <
typename ComponentType, plComponentUpdateType::Enum UpdateType, plBlockStorageType::Enum StorageType>
165template <
typename ComponentType, plComponentUpdateType::Enum UpdateType, plBlockStorageType::Enum StorageType>
171 SimpleUpdateName(functionName);
174 desc.m_bOnlyUpdateWhenSimulating = (UpdateType == plComponentUpdateType::WhenSimulating);
176 this->RegisterUpdateFunction(desc);
179template <
typename ComponentType, plComponentUpdateType::Enum UpdateType, plBlockStorageType::Enum StorageType>
182 for (
auto it = this->m_ComponentStorage.GetIterator(context.m_uiFirstComponentIndex, context.m_uiComponentCount); it.IsValid(); ++it)
184 ComponentType* pComponent = it;
185 if (pComponent->IsActiveAndInitialized())
187 pComponent->Update();
193template <
typename ComponentType, plComponentUpdateType::Enum UpdateType, plBlockStorageType::Enum StorageType>
197 const char* szEnd = sName.FindSubString(
",");
199 if (szEnd !=
nullptr && sName.StartsWith(
"plComponentManagerSimple<class "))
203 PL_ASSERT_DEV(!sChoppedName.IsEmpty(),
"Chopped name is empty: '{0}'", sName);
205 out_sName = sChoppedName;
206 out_sName.
Append(
"::SimpleUpdate");
void PushBack(const T &value)
Pushes value at the end of the array.
Definition ArrayBase_inl.h:333
plUInt32 GetCount() const
Returns the number of active elements in the array.
Definition ArrayBase_inl.h:172
Definition BlockStorage.h:20
Definition BlockStorage.h:45
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
bool IsValidComponent(const plComponentHandle &hComponent) const
Checks whether the given handle references a valid component.
Definition ComponentManager_inl.h:2
plUInt32 GetComponentCount() const
Returns the number of components managed by this manager.
Definition ComponentManager_inl.h:20
plComponentHandle CreateComponent(plGameObject *pOwnerObject)
Create a new component instance and returns a handle to it.
Definition ComponentManager.cpp:18
bool TryGetComponent(const plComponentHandle &hComponent, plComponent *&out_pComponent)
Returns if a component with the given handle exists and if so writes out the corresponding pointer to...
Definition ComponentManager_inl.h:7
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
void Reserve(plUInt32 uiCapacity)
Expands the array so it can at least store the given capacity.
Definition DynamicArray_inl.h:179
Definition DynamicArray.h:81
This class represents an object inside the world.
Definition GameObject.h:32
IndexType GetCount() const
Returns the number of active entries in the table.
Definition IdTable_inl.h:168
bool TryGetValue(const IdType id, ValueType &out_value) const
Returns if an entry with the given id was found and if found writes out the corresponding value to ou...
Definition IdTable_inl.h:267
bool Contains(const IdType id) const
Returns if the table contains an entry corresponding to the given id.
Definition IdTable_inl.h:328
plStringBuilder is a class that is meant for creating and modifying strings.
Definition StringBuilder.h:35
void Append(plUInt32 uiChar)
Appends a single Utf32 character.
Definition StringBuilder_inl.h:94
static constexpr plUInt32 GetStringElementCount(const T *pString)
Returns the number of elements of type T that the string contains, until it hits an element that is z...
Definition StringUtils_inl.h:45
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
void RegisterUpdateFunction(const UpdateFunctionDesc &desc)
Registers the given update function at the world.
Definition WorldModule.cpp:24
double RoundUp(double f, double fMultiple)
Returns a multiple of fMultiple that is larger than f.
Definition MathDouble_inl.h:47
A handle to a component.
Definition Declarations.h:138
This struct represents a block of type T, typically 4kb.
Definition LargeBlockAllocator.h:14
Definition WorldModule.h:33
Description of an update function that can be registered at the world.
Definition WorldModule.h:43