Plasma Engine  2.0
Loading...
Searching...
No Matches
Scene2Document.h
1#pragma once
2
3#include <EditorPluginScene/Objects/SceneObjectManager.h>
4#include <EditorPluginScene/Scene/SceneDocument.h>
5#include <Foundation/Types/UniquePtr.h>
6#include <ToolsFoundation/Document/DocumentManager.h>
7#include <ToolsFoundation/Object/ObjectCommandAccessor.h>
8
10
12{
13 PL_ADD_DYNAMIC_REFLECTION(plSceneLayerBase, plReflectedClass);
14
15public:
18
19public:
20 mutable plScene2Document* m_pDocument = nullptr;
21};
22
24{
25 PL_ADD_DYNAMIC_REFLECTION(plSceneLayer, plSceneLayerBase);
26
27public:
30
31public:
32 plUuid m_Layer;
33};
34
36{
37 PL_ADD_DYNAMIC_REFLECTION(plSceneDocumentSettings, plSceneDocumentSettingsBase);
38
39public:
42
43public:
45 mutable plScene2Document* m_pDocument = nullptr;
46};
47
49{
50 enum class Type
51 {
52 LayerAdded,
53 LayerRemoved,
54 LayerLoaded,
55 LayerUnloaded,
56 LayerVisible,
57 LayerInvisible,
58 ActiveLayerChanged,
59 };
60
61 Type m_Type;
62 plUuid m_layerGuid;
63};
64
65class PL_EDITORPLUGINSCENE_DLL plScene2Document : public plSceneDocument
66{
67 PL_ADD_DYNAMIC_REFLECTION(plScene2Document, plSceneDocument);
68
69public:
70 plScene2Document(plStringView sDocumentPath);
72
75
76 const plDocumentObjectManager* GetSceneObjectManager() const { return m_pSceneObjectManager.Borrow(); }
77 plDocumentObjectManager* GetSceneObjectManager() { return m_pSceneObjectManager.Borrow(); }
78 plSelectionManager* GetSceneSelectionManager() const { return m_pSceneSelectionManager.Borrow(); }
79 plCommandHistory* GetSceneCommandHistory() const { return m_pSceneCommandHistory.Borrow(); }
80 plObjectAccessorBase* GetSceneObjectAccessor() const { return m_pSceneObjectAccessor.Borrow(); }
81 const plObjectMetaData<plUuid, plDocumentObjectMetaData>* GetSceneDocumentObjectMetaData() const { return m_pSceneDocumentObjectMetaData.Borrow(); }
82 plObjectMetaData<plUuid, plDocumentObjectMetaData>* GetSceneDocumentObjectMetaData() { return m_pSceneDocumentObjectMetaData.Borrow(); }
83 const plObjectMetaData<plUuid, plGameObjectMetaData>* GetSceneGameObjectMetaData() const { return m_pSceneGameObjectMetaData.Borrow(); }
84 plObjectMetaData<plUuid, plGameObjectMetaData>* GetSceneGameObjectMetaData() { return m_pSceneGameObjectMetaData.Borrow(); }
85
89
90 plSelectionManager* GetLayerSelectionManager() const { return m_pLayerSelection.Borrow(); }
91
92 plStatus CreateLayer(const char* szName, plUuid& out_layerGuid);
93 plStatus DeleteLayer(const plUuid& layerGuid);
94
95 const plUuid& GetActiveLayer() const;
96 plStatus SetActiveLayer(const plUuid& layerGuid);
97
98 bool IsLayerLoaded(const plUuid& layerGuid) const;
99 plStatus SetLayerLoaded(const plUuid& layerGuid, bool bLoaded);
100 void GetAllLayers(plDynamicArray<plUuid>& out_layerGuids);
101 void GetLoadedLayers(plDynamicArray<plSceneDocument*>& out_layers) const;
102
103 bool IsLayerVisible(const plUuid& layerGuid) const;
104 plStatus SetLayerVisible(const plUuid& layerGuid, bool bVisible);
105
106 const plDocumentObject* GetLayerObject(const plUuid& layerGuid) const;
107 plSceneDocument* GetLayerDocument(const plUuid& layerGuid) const;
108
109 bool IsAnyLayerModified() const;
110
114
115 virtual void InitializeAfterLoading(bool bFirstTimeCreation) override;
116 virtual void InitializeAfterLoadingAndSaving() override;
117 virtual const plDocumentObject* GetSettingsObject() const override;
118 virtual void HandleEngineMessage(const plEditorEngineDocumentMsg* pMsg) override;
119 virtual plTaskGroupID InternalSaveDocument(AfterSaveCallback callback) override;
120 virtual void SendGameWorldToEngine() override;
121
123
124public:
125 mutable plEvent<const plScene2LayerEvent&> m_LayerEvents;
126
127private:
128 void LayerSelectionEventHandler(const plSelectionManagerEvent& e);
129 void StructureEventHandler(const plDocumentObjectStructureEvent& e);
130 void CommandHistoryEventHandler(const plCommandHistoryEvent& e);
131 void DocumentManagerEventHandler(const plDocumentManager::Event& e);
132 void HandleObjectStateFromEngineMsg2(const plPushObjectStateMsgToEditor* pMsg);
133
134 void UpdateLayers();
135 void SendLayerVisibility();
136 void LayerAdded(const plUuid& layerGuid, const plUuid& layerObjectGuid);
137 void LayerRemoved(const plUuid& layerGuid);
138
139private:
140 friend class plSceneLayer;
141 plCopyOnBroadcastEvent<const plDocumentObjectStructureEvent&>::Unsubscriber m_StructureEventSubscriber;
142 plCopyOnBroadcastEvent<const plSelectionManagerEvent&>::Unsubscriber m_LayerSelectionEventSubscriber;
143 plEvent<const plCommandHistoryEvent&, plMutex>::Unsubscriber m_CommandHistoryEventSubscriber;
144 plCopyOnBroadcastEvent<const plDocumentManager::Event&>::Unsubscriber m_DocumentManagerEventSubscriber;
145
146 // This is used for a flattened list of the plSceneDocumentSettings hierarchy
147 struct LayerInfo
148 {
149 plSceneDocument* m_pLayer = nullptr;
150 plUuid m_objectGuid;
151 bool m_bVisible = true;
152 };
153
154 // Scene document cache
155 plUniquePtr<plDocumentObjectManager> m_pSceneObjectManager;
156 mutable plUniquePtr<plCommandHistory> m_pSceneCommandHistory;
157 mutable plUniquePtr<plSelectionManager> m_pSceneSelectionManager;
158 mutable plUniquePtr<plObjectCommandAccessor> m_pSceneObjectAccessor;
161
162 // Layer state
163 mutable plUniquePtr<plSelectionManager> m_pLayerSelection;
164 plUuid m_ActiveLayerGuid;
166};
virtual plTaskGroupID InternalSaveDocument(AfterSaveCallback callback) override
Overrides the base function to call UpdateAssetDocumentInfo() to update the settings hash.
Definition AssetDocument.cpp:92
Stores the undo / redo stacks of transactions done on a document.
Definition CommandHistory.h:52
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 DynamicArray.h:81
Base class for all messages that are tied to some document.
Definition EngineProcessMessages.h:151
Definition Event.h:177
virtual void SendGameWorldToEngine()
Sends the current state of the scene to the engine process. This is typically done after scene load o...
Definition GameObjectDocument.cpp:797
Definition HashTable.h:333
Definition ObjectAccessorBase.h:8
Stores meta data for document objects that is not part of the object itself. E.g. editor-only states ...
Definition ObjectMetaData.h:16
Definition Messages.h:53
All classes that should be dynamically reflectable, need to be derived from this base class.
Definition DynamicRTTI.h:86
Definition Scene2Document.h:66
Definition SceneDocument.h:22
virtual void HandleEngineMessage(const plEditorEngineDocumentMsg *pMsg) override
Handles all messages received from the corresponding plEngineProcessDocumentContext on the engine pro...
Definition SceneDocument.cpp:1574
Definition SceneObjectManager.h:11
Definition Scene2Document.h:36
Definition Scene2Document.h:12
Definition Scene2Document.h:24
Selection Manager stores a set of selected document objects.
Definition SelectionManager.h:26
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
Definition CommandHistory.h:31
Definition DocumentManager.h:65
Used by plDocumentObjectManager::m_StructureEvents.
Definition DocumentObjectManager.h:45
Definition Scene2Document.h:49
Definition SelectionManager.h:10
An plResult with an additional message for the reason of failure.
Definition Status.h:12