3#include <GameEngine/GameEngineDLL.h>
5#include <Foundation/Containers/Blob.h>
6#include <Foundation/Containers/SmallArray.h>
7#include <Foundation/Memory/InstanceDataAllocator.h>
9namespace plStateMachineInternal
14 PL_ALWAYS_INLINE plUInt32 GetBaseOffset()
const {
return m_InstanceDataOffsets.GetUserData<plUInt32>(); }
15 PL_ALWAYS_INLINE plUInt32 GetDataSize()
const {
return m_InstanceDataAllocator.GetTotalDataSize(); }
26 if (m_pOwner !=
nullptr)
28 m_pOwner->m_InstanceDataAllocator.
Destruct(GetBlobPtr());
38 PL_ALWAYS_INLINE
void* GetSubInstanceData(
InstanceData* pData, plUInt32 uiIndex)
const
40 return pData !=
nullptr ? m_InstanceDataAllocator.
GetInstanceData(pData->GetBlobPtr(), m_InstanceDataOffsets[uiIndex]) :
nullptr;
43 PL_FORCE_INLINE
void Initialize(InstanceData* pData)
const
45 if (pData !=
nullptr && pData->m_pOwner ==
nullptr)
47 pData->m_pOwner =
this;
48 m_InstanceDataAllocator.
Construct(pData->GetBlobPtr());
55 m_InstanceDataOffsets.
Clear();
58 plUInt32 uiMaxAlignment = 0;
61 for (T* pSubObject : subObjects)
63 plUInt32 uiOffset = plInvalidIndex;
64 if (pSubObject->GetInstanceDataDesc(instanceDataDesc))
66 uiOffset = m_InstanceDataAllocator.
AddDesc(instanceDataDesc);
67 uiMaxAlignment =
plMath::Max(uiMaxAlignment, instanceDataDesc.m_uiTypeAlignment);
69 m_InstanceDataOffsets.PushBack(uiOffset);
72 if (uiMaxAlignment > 0)
74 out_desc.FillFromType<InstanceData>();
75 out_desc.m_ConstructorFunction =
nullptr;
78 m_InstanceDataOffsets.GetUserData<plUInt32>() = uiBaseOffset;
80 out_desc.m_uiTypeSize = uiBaseOffset + m_InstanceDataAllocator.
GetTotalDataSize();
81 out_desc.m_uiTypeAlignment =
plMath::Max(out_desc.m_uiTypeAlignment, uiMaxAlignment);
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Helper class to manager instance data allocation, construction and destruction.
Definition InstanceDataAllocator.h:35
void ClearDescs()
Resets all internal state.
Definition InstanceDataAllocator.cpp:15
void Construct(plByteBlobPtr blobPtr) const
Constructs the instance data objects, within the pre-allocated memory block.
Definition InstanceDataAllocator.cpp:43
plUInt32 AddDesc(const plInstanceDataDesc &desc)
Adds the given desc to internal list of data that needs to be allocated and returns the byte offset.
Definition InstanceDataAllocator.cpp:5
plUInt32 GetTotalDataSize() const
The total size in bytes taken up by all instance data objects that were added.
Definition InstanceDataAllocator.h:56
void Destruct(plByteBlobPtr blobPtr) const
Destructs the instance data objects.
Definition InstanceDataAllocator.cpp:59
static PL_ALWAYS_INLINE void * GetInstanceData(const plByteBlobPtr &blobPtr, plUInt32 uiOffset)
Retrieves a void pointer to the instance data within the given blob at the given offset,...
Definition InstanceDataAllocator.h:59
static T * AddByteOffset(T *pPtr, std::ptrdiff_t offset)
Returns the address stored in ptr plus the given byte offset iOffset, cast to type T.
static T AlignSize(T uiSize, T uiAlignment)
Aligns the given size uiSize by rounding up to the next multiple of the size.
void Clear()
Clears the array.
Definition SmallArray_inl.h:222
Definition SmallArray.h:219
constexpr PL_ALWAYS_INLINE T Max(T f1, T f2)
Returns the greater value, f1 or f2.
Definition Math_inl.h:39
Structure to describe an instance data type.
Definition InstanceDataAllocator.h:17
Definition StateMachineInstanceData.h:21
Helper class to manage instance data for compound states or transitions.
Definition StateMachineInstanceData.h:13