Plasma Engine  2.0
Loading...
Searching...
No Matches
AssetDocument.h
1#pragma once
2
3#include <EditorFramework/Assets/AssetDocumentInfo.h>
4#include <EditorFramework/Assets/Declarations.h>
5#include <EditorFramework/EditorFrameworkDLL.h>
6#include <EditorFramework/IPC/IPCObjectMirrorEditor.h>
7#include <ToolsFoundation/Document/Document.h>
8#include <ToolsFoundation/Object/DocumentObjectManager.h>
9
14class QImage;
15
17enum class plAssetDocEngineConnection : plUInt8
18{
19 None,
20 Simple,
21 FullObjectMirroring
22};
23
26{
27 enum Enum : plUInt32
28 {
29 Pause = PL_BIT(0),
30 Restart = PL_BIT(1),
31 Loop = PL_BIT(2),
32 SimulationSpeed = PL_BIT(3),
33 Grid = PL_BIT(4),
34 Visualizers = PL_BIT(5),
35 };
36
37 Enum m_State;
38 double m_fValue = 0;
39};
40
41class PL_EDITORFRAMEWORK_DLL plAssetDocument : public plDocument
42{
43 PL_ADD_DYNAMIC_REFLECTION(plAssetDocument, plDocument);
44
45public:
48 class PL_EDITORFRAMEWORK_DLL ThumbnailInfo
49 {
50 public:
51 plResult Deserialize(plStreamReader& inout_reader);
52 plResult Serialize(plStreamWriter& inout_writer) const;
53
55 bool IsThumbnailUpToDate(plUInt64 uiExpectedHash, plUInt16 uiVersion) const { return (m_uiHash == uiExpectedHash && m_uiVersion == uiVersion); }
56
58 void SetFileHashAndVersion(plUInt64 uiHash, plUInt16 v)
59 {
60 m_uiHash = uiHash;
61 m_uiVersion = v;
62 }
63
66 constexpr plUInt32 GetSerializedSize() const { return 19; }
67
68 private:
69 plUInt64 m_uiHash = 0;
70 plUInt16 m_uiVersion = 0;
71 plUInt16 m_uiReserved = 0;
72 };
73
74 plAssetDocument(plStringView sDocumentPath, plDocumentObjectManager* pObjectManager, plAssetDocEngineConnection engineConnectionType);
76
79
80 plAssetDocumentManager* GetAssetDocumentManager() const;
81 const plAssetDocumentInfo* GetAssetDocumentInfo() const;
82
83 plBitflags<plAssetDocumentFlags> GetAssetFlags() const;
84
85 const plAssetDocumentTypeDescriptor* GetAssetDocumentTypeDescriptor() const
86 {
87 return static_cast<const plAssetDocumentTypeDescriptor*>(GetDocumentTypeDescriptor());
88 }
89
96 plTransformStatus TransformAsset(plBitflags<plTransformFlags> transformFlags, const plPlatformProfile* pAssetProfile = nullptr);
97
100 plTransformStatus CreateThumbnail();
101
104 plUInt16 GetAssetTypeVersion() const;
105
109
110 enum class EngineStatus
111 {
112 Unsupported,
113 Disconnected,
114 Initializing,
115 Loaded,
116 };
117
119 EngineStatus GetEngineStatus() const { return m_EngineStatus; }
120
122 virtual plVariant GetCreateEngineMetaData() const { return plVariant(); }
123
125 bool SendMessageToEngine(plEditorEngineDocumentMsg* pMessage) const;
126
128 virtual void HandleEngineMessage(const plEditorEngineDocumentMsg* pMsg);
129
131 plEditorEngineConnection* GetEditorEngineConnection() const { return m_pEngineConnection; }
132
134 void AddSyncObject(plEditorEngineSyncObject* pSync) const;
135
137 void RemoveSyncObject(plEditorEngineSyncObject* pSync) const;
138
140 plEditorEngineSyncObject* FindSyncObject(const plUuid& guid) const;
141
143 plEditorEngineSyncObject* FindSyncObject(const plRTTI* pType) const;
144
146 void SyncObjectsToEngine() const;
147
151 void SendDocumentOpenMessage(bool bOpen);
152
153
155
156 plEvent<const plEditorEngineDocumentMsg*> m_ProcessMessageEvent;
157
158protected:
159 void EngineConnectionEventHandler(const plEditorEngineProcessConnection::Event& e);
160
163
165 plUInt64 GetDocumentHash() const;
166
168 void GetChildHash(const plDocumentObject* pObject, plUInt64& inout_uiHash) const;
169
171 virtual void InternalGetMetaDataHash(const plDocumentObject* pObject, plUInt64& inout_uiHash) const {}
172
176
178 virtual plTaskGroupID InternalSaveDocument(AfterSaveCallback callback) override;
179
181 virtual void InternalAfterSaveDocument() override;
182
183 virtual void InitializeAfterLoading(bool bFirstTimeCreation) override;
184 virtual void InitializeAfterLoadingAndSaving() override;
185
189
194 virtual void UpdateAssetDocumentInfo(plAssetDocumentInfo* pInfo) const;
195
207 const plAssetFileHeader& AssetHeader, plBitflags<plTransformFlags> transformFlags) = 0;
208
214 virtual plTransformStatus InternalTransformAsset(const char* szTargetFile, plStringView sOutputTag, const plPlatformProfile* pAssetProfile,
215 const plAssetFileHeader& AssetHeader, plBitflags<plTransformFlags> transformFlags);
216
217 plStatus RemoteExport(const plAssetFileHeader& header, const char* szOutputTarget) const;
218
222
224 virtual plTransformStatus InternalCreateThumbnail(const ThumbnailInfo& thumbnailInfo);
225
227 plString GetThumbnailFilePath(plStringView sSubAssetName = plStringView()) const;
228
230 void InvalidateAssetThumbnail(plStringView sSubAssetName = plStringView()) const;
231
233 plStatus RemoteCreateThumbnail(const ThumbnailInfo& thumbnailInfo, plArrayPtr<plStringView> viewExclusionTags /*= plStringView("SkyLight")*/) const;
234 plStatus RemoteCreateThumbnail(const ThumbnailInfo& thumbnailInfo) const
235 {
236 plStringView defVal("SkyLight");
237 return RemoteCreateThumbnail(thumbnailInfo, {&defVal, 1});
238 }
239
241 plStatus SaveThumbnail(const plImage& img, const ThumbnailInfo& thumbnailInfo) const;
242
244 plStatus SaveThumbnail(const QImage& img, const ThumbnailInfo& thumbnailInfo) const;
245
247 void AppendThumbnailInfo(plStringView sThumbnailFile, const ThumbnailInfo& thumbnailInfo) const;
248
252
253public:
258 virtual void SetCommonAssetUiState(plCommonAssetUiState::Enum state, double value);
259
261 virtual double GetCommonAssetUiState(plCommonAssetUiState::Enum state) const;
262
265
266protected:
267 plUInt32 m_uiCommonAssetStateFlags = 0;
268
270
271protected:
273 void AddPrefabDependencies(const plDocumentObject* pObject, plAssetDocumentInfo* pInfo) const;
274
277 void AddReferences(const plDocumentObject* pObject, plAssetDocumentInfo* pInfo, bool bInsidePrefab) const;
278
279protected:
281
282 virtual plDocumentInfo* CreateDocumentInfo() override;
283
284 plTransformStatus DoTransformAsset(const plPlatformProfile* pAssetProfile, plBitflags<plTransformFlags> transformFlags);
285
286 EngineStatus m_EngineStatus;
287 plAssetDocEngineConnection m_EngineConnectionType = plAssetDocEngineConnection::None;
288
289 plEditorEngineConnection* m_pEngineConnection;
290
291 mutable plHashTable<plUuid, plEditorEngineSyncObject*> m_AllSyncObjects;
292 mutable plDeque<plEditorEngineSyncObject*> m_SyncObjects;
293
294 mutable plHybridArray<plUuid, 32> m_DeletedObjects;
295};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
The thumbnail info containing the hash of the file is appended to assets. The serialized size of this...
Definition AssetDocument.h:49
void SetFileHashAndVersion(plUInt64 uiHash, plUInt16 v)
Sets the asset file hash.
Definition AssetDocument.h:58
bool IsThumbnailUpToDate(plUInt64 uiExpectedHash, plUInt16 uiVersion) const
Checks whether the stored file contains the same hash.
Definition AssetDocument.h:55
constexpr plUInt32 GetSerializedSize() const
Returns the serialized size of the thumbnail info. Used to seek to the end of the file and find the t...
Definition AssetDocument.h:66
Definition AssetDocument.h:42
EngineStatus
Definition AssetDocument.h:111
virtual void InternalGetMetaDataHash(const plDocumentObject *pObject, plUInt64 &inout_uiHash) const
Computes the hash for transform relevant meta data of the given document object and combines it with ...
Definition AssetDocument.h:171
virtual plVariant GetCreateEngineMetaData() const
Passed into plEngineProcessDocumentContext::Initialize on the engine process side....
Definition AssetDocument.h:122
virtual plTransformStatus InternalTransformAsset(plStreamWriter &stream, plStringView sOutputTag, const plPlatformProfile *pAssetProfile, const plAssetFileHeader &AssetHeader, plBitflags< plTransformFlags > transformFlags)=0
Override this and write the transformed file for the given szOutputTag into the given stream.
plEditorEngineConnection * GetEditorEngineConnection() const
Returns the plEditorEngineConnection for this document.
Definition AssetDocument.h:131
EngineStatus GetEngineStatus() const
Returns the current state of the engine process side of this document.
Definition AssetDocument.h:119
plEvent< const plCommonAssetUiState & > m_CommonAssetUiChangeEvent
Used to broadcast state change events for common asset states.
Definition AssetDocument.h:264
Definition AssetDocumentInfo.h:7
Definition AssetDocumentManager.h:13
Simple class to handle asset file headers (the very first bytes in all transformed asset files)
Definition AssetFileHeader.h:8
Definition Deque.h:270
Definition Document.h:57
virtual void InternalAfterSaveDocument()
A hook to execute additional code after SUCCESSFULLY saving a document. E.g. manual asset transform c...
Definition Document.h:259
Definition Declarations.h:72
Definition DocumentObjectBase.h:11
Represents to content of a document. Every document has exactly one root object under which all objec...
Definition DocumentObjectManager.h:116
Definition EngineProcessConnection.h:108
Base class for all messages that are tied to some document.
Definition EngineProcessMessages.h:151
Definition SyncObject.h:11
Definition Event.h:177
Definition HashTable.h:333
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
A class containing image data and associated meta data.
Definition Image.h:103
Definition PlatformProfile.h:25
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
Interface for binary in (read) streams.
Definition Stream.h:22
Interface for binary out (write) streams.
Definition Stream.h:107
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Given out by plTaskSystem::CreateTaskGroup to identify a task group.
Definition TaskSystemDeclarations.h:103
A Unique ptr manages an object and destroys that object when it goes out of scope....
Definition UniquePtr.h:10
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
Definition Declarations.h:89
The plBitflags class allows you to work with type-safe bitflags.
Definition Bitflags.h:82
Frequently needed asset document states, to prevent code duplication.
Definition AssetDocument.h:26
Definition EngineProcessConnection.h:63
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
An plResult with an additional message for the reason of failure.
Definition Status.h:12
Definition Declarations.h:114