Plasma Engine  2.0
Loading...
Searching...
No Matches
CustomData.h
1#pragma once
2
3#include <Core/CoreDLL.h>
4
5#include <Core/ResourceManager/Resource.h>
6#include <Core/World/Declarations.h>
7#include <Foundation/Containers/DynamicArray.h>
8#include <Foundation/Reflection/Reflection.h>
9
10
22class PL_CORE_DLL plCustomData : public plReflectedClass
23{
24 PL_ADD_DYNAMIC_REFLECTION(plCustomData, plReflectedClass);
25
26public:
31 virtual void Load(class plAbstractObjectGraph& ref_graph, class plRttiConverterContext& ref_context, const class plAbstractObjectNode* pRootNode);
32};
33
48class PL_CORE_DLL plCustomDataResourceBase : public plResource
49{
50 PL_ADD_DYNAMIC_REFLECTION(plCustomDataResourceBase, plResource);
51
52public:
55
56protected:
57 virtual void CreateAndLoadData(plAbstractObjectGraph& ref_graph, plRttiConverterContext& ref_context, const plAbstractObjectNode* pRootNode) = 0;
58 virtual plResourceLoadDesc UnloadData(Unload WhatToUnload) override;
59 plResourceLoadDesc UpdateContent_Internal(plStreamReader* Stream, const plRTTI& rtti);
60};
61
65template <typename T>
67{
68public:
71
75 const T* GetData() const { return GetLoadingState() == plResourceState::Loaded ? reinterpret_cast<const T*>(m_Data) : nullptr; }
76
77protected:
78 virtual void CreateAndLoadData(plAbstractObjectGraph& graph, plRttiConverterContext& context, const plAbstractObjectNode* pRootNode) override;
79
80 virtual plResourceLoadDesc UnloadData(Unload WhatToUnload) override;
81
82 virtual plResourceLoadDesc UpdateContent(plStreamReader* Stream) override;
83
84 virtual void UpdateMemoryUsage(MemoryUsage& out_NewMemoryUsage) override;
85
86private:
87 struct alignas(PL_ALIGNMENT_OF(T))
88 {
89 plUInt8 m_Data[sizeof(T)];
90 };
91};
92
96#define PL_DECLARE_CUSTOM_DATA_RESOURCE(SELF) \
97 class SELF##Resource : public plCustomDataResource<SELF> \
98 { \
99 PL_ADD_DYNAMIC_REFLECTION(SELF##Resource, plCustomDataResource<SELF>); \
100 PL_RESOURCE_DECLARE_COMMON_CODE(SELF##Resource); \
101 }; \
102 \
103 using SELF##ResourceHandle = plTypedResourceHandle<SELF##Resource>
104
108#define PL_DEFINE_CUSTOM_DATA_RESOURCE(SELF) \
109 PL_BEGIN_DYNAMIC_REFLECTED_TYPE(SELF##Resource, 1, plRTTIDefaultAllocator<SELF##Resource>) \
110 PL_END_DYNAMIC_REFLECTED_TYPE; \
111 \
112 PL_RESOURCE_IMPLEMENT_COMMON_CODE(SELF##Resource)
113
114
115#include <Core/Utils/Implementation/CustomData_inl.h>
Definition AbstractObjectGraph.h:115
Definition AbstractObjectGraph.h:17
A base class for user-defined data assets.
Definition CustomData.h:23
Base class for resources that represent different implementations of plCustomData.
Definition CustomData.h:49
Template resource type for sub-classed plCustomData types.
Definition CustomData.h:67
const T * GetData() const
Provides read access to the custom data type.
Definition CustomData.h:75
virtual void UpdateMemoryUsage(MemoryUsage &out_NewMemoryUsage) override
This function must be overridden by all resource types.
Definition CustomData_inl.h:46
virtual plResourceLoadDesc UnloadData(Unload WhatToUnload) override
Requests the resource to unload another quality level. If bFullUnload is true, the resource should un...
Definition CustomData_inl.h:29
virtual plResourceLoadDesc UpdateContent(plStreamReader *Stream) override
Called whenever more data for the resource is available. The resource must read the stream to update ...
Definition CustomData_inl.h:40
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
The base class for all resources.
Definition Resource.h:10
PL_ALWAYS_INLINE plResourceState GetLoadingState() const
Returns the current state in which this resource is in.
Definition Resource.h:66
Definition RttiConverter.h:33
Interface for binary in (read) streams.
Definition Stream.h:22
Describes in which loading state a resource currently is, and how many different quality levels there...
Definition Declarations.h:102