2PL_FORCE_INLINE
void plVisualScriptDataDescription::CheckOffset(DataOffset dataOffset,
const plRTTI* pType)
const
4#if PL_ENABLED(PL_COMPILE_FOR_DEBUG)
5 auto givenDataType = dataOffset.GetType();
6 auto& offsetAndCount = m_PerTypeInfo[givenDataType];
7 PL_ASSERT_DEBUG(offsetAndCount.m_uiCount > 0,
"Invalid data offset");
8 const plUInt32 uiLastOffset = offsetAndCount.m_uiStartOffset + (offsetAndCount.m_uiCount - 1) * plVisualScriptDataType::GetStorageSize(givenDataType);
9 PL_ASSERT_DEBUG(dataOffset.m_uiByteOffset >= offsetAndCount.m_uiStartOffset && dataOffset.m_uiByteOffset <= uiLastOffset,
"Invalid data offset");
13 auto expectedDataType = plVisualScriptDataType::FromRtti(pType);
14 PL_ASSERT_DEBUG(expectedDataType == givenDataType,
"Data type mismatch, expected '{}'({}) but got '{}'", plVisualScriptDataType::GetName(expectedDataType), pType->
GetTypeName(), plVisualScriptDataType::GetName(givenDataType));
21 auto& offsetAndCount = m_PerTypeInfo[dataType];
22 plUInt32 uiByteOffset = plInvalidIndex;
23 if (uiIndex < offsetAndCount.m_uiCount)
25 uiByteOffset = offsetAndCount.m_uiStartOffset + uiIndex * plVisualScriptDataType::GetStorageSize(dataType);
28 return DataOffset(uiByteOffset, dataType, source);
33PL_ALWAYS_INLINE
bool plVisualScriptDataStorage::IsAllocated()
const
39const T& plVisualScriptDataStorage::GetData(DataOffset dataOffset)
const
41 static_assert(!std::is_pointer<T>::value && !std::is_same<T, plTypedPointer>::value,
"Use GetPointerData instead");
43 m_pDesc->CheckOffset(dataOffset, plGetStaticRTTI<T>());
45 return *
reinterpret_cast<const T*
>(m_Storage.
GetByteBlobPtr().
GetPtr() + dataOffset.m_uiByteOffset);
49T& plVisualScriptDataStorage::GetWritableData(DataOffset dataOffset)
51 static_assert(!std::is_pointer<T>::value && !std::is_same<T, plTypedPointer>::value,
"Use GetPointerData instead");
53 m_pDesc->CheckOffset(dataOffset, plGetStaticRTTI<T>());
59void plVisualScriptDataStorage::SetData(DataOffset dataOffset,
const T& value)
61 static_assert(!std::is_pointer<T>::value,
"Use SetPointerData instead");
65 m_pDesc->CheckOffset(dataOffset, plGetStaticRTTI<T>());
69 if constexpr (std::is_same<T, plGameObjectHandle>::value)
72 storedHandle.AssignHandle(value);
74 else if constexpr (std::is_same<T, plComponentHandle>::value)
77 storedHandle.AssignHandle(value);
79 else if constexpr (std::is_same<T, plStringView>::value)
81 *
reinterpret_cast<plString*
>(pData) = value;
85 *
reinterpret_cast<T*
>(pData) = value;
91void plVisualScriptDataStorage::SetPointerData(DataOffset dataOffset, T ptr,
const plRTTI* pType, plUInt32 uiExecutionCounter)
93 static_assert(std::is_pointer<T>::value);
99 if constexpr (std::is_same<T, plGameObject*>::value)
101 m_pDesc->CheckOffset(dataOffset, plGetStaticRTTI<plGameObject>());
104 storedHandle.AssignPtr(ptr, uiExecutionCounter);
106 else if constexpr (std::is_same<T, plComponent*>::value)
108 m_pDesc->CheckOffset(dataOffset, plGetStaticRTTI<plComponent>());
111 storedHandle.AssignPtr(ptr, uiExecutionCounter);
115 PL_ASSERT_DEBUG(!pType || pType->
IsDerivedFrom<
plComponent>() ==
false,
"Component type '{}' is stored as typed pointer, cast to plComponent first to ensure correct storage", pType->
GetTypeName());
117 m_pDesc->CheckOffset(dataOffset, pType);
120 typedPointer.m_pObject = ptr;
121 typedPointer.m_pType = pType;
130 PL_SUCCEED_OR_RETURN(m_DataOffset.Serialize(inout_stream));
131 inout_stream << m_DefaultValue;
137 PL_SUCCEED_OR_RETURN(m_DataOffset.Deserialize(inout_stream));
138 inout_stream >> m_DefaultValue;
plByteBlobPtr GetByteBlobPtr()
Returns a blob pointer to the blob data, or an empty blob pointer if the blob is empty.
Definition Blob.h:366
PL_ALWAYS_INLINE PointerType GetPtr() const
Returns the pointer to the array.
Definition Blob.h:80
PL_ALWAYS_INLINE bool IsEmpty() const
Returns whether the array is empty.
Definition Blob.h:92
PL_ALWAYS_INLINE plUInt64 GetCount() const
Returns the number of elements in the array.
Definition Blob.h:95
Base class of all component types.
Definition Component.h:25
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
PL_ALWAYS_INLINE plStringView GetTypeName() const
Returns the name of this type.
Definition RTTI.h:48
PL_ALWAYS_INLINE bool IsDerivedFrom(const plRTTI *pBaseType) const
Returns true if this type is derived from the given type (or of the same type).
Definition RTTI.h:60
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
A typed raw pointer.
Definition TypedPointer.h:13
Definition VisualScriptDataType.h:99
Definition VisualScriptData.h:10
Definition VisualScriptDataType.h:76