Plasma Engine  2.0
Loading...
Searching...
No Matches
SceneContext.h
1#pragma once
2
3#include <EditorEngineProcessFramework/EngineProcess/EngineProcessDocumentContext.h>
4#include <EnginePluginScene/EnginePluginSceneDLL.h>
5#include <RendererCore/Pipeline/Declarations.h>
6#include <SharedPluginScene/Common/Messages.h>
7
10class plGameStateBase;
19class plWorldWriter;
21class plLayerContext;
23
24class PL_ENGINEPLUGINSCENE_DLL plSceneContext : public plEngineProcessDocumentContext
25{
26 PL_ADD_DYNAMIC_REFLECTION(plSceneContext, plEngineProcessDocumentContext);
27
28public:
31
32 virtual void HandleMessage(const plEditorEngineDocumentMsg* pMsg) override;
33
34 const plDeque<plGameObjectHandle>& GetSelection() const { return m_Selection; }
35 const plDeque<plGameObjectHandle>& GetSelectionWithChildren() const { return m_SelectionWithChildren; }
36 bool GetRenderSelectionOverlay() const { return m_bRenderSelectionOverlay; }
37 bool GetRenderShapeIcons() const { return m_bRenderShapeIcons; }
38 bool GetRenderSelectionBoxes() const { return m_bRenderSelectionBoxes; }
39 float GetGridDensity() const { return plMath::Abs(m_fGridDensity); }
40 bool IsGridInGlobalSpace() const { return m_fGridDensity >= 0.0f; }
41 plTransform GetGridTransform() const { return m_GridTransform; }
42
43 plGameStateBase* GetGameState() const;
44 bool IsPlayTheGameActive() const { return GetGameState() != nullptr; }
45
46 plUInt32 RegisterLayer(plLayerContext* pLayer);
47 void UnregisterLayer(plLayerContext* pLayer);
48 void AddLayerIndexTag(const plEntityMsgToEngine& msg, plWorldRttiConverterContext& ref_context, const plTag& layerTag);
49 const plArrayPtr<const plTag> GetInvisibleLayerTags() const;
50
51 plEngineProcessDocumentContext* GetActiveDocumentContext();
52 const plEngineProcessDocumentContext* GetActiveDocumentContext() const;
53 plWorldRttiConverterContext& GetActiveContext();
54 const plWorldRttiConverterContext& GetActiveContext() const;
55 plWorldRttiConverterContext* GetContextForLayer(const plUuid& layerGuid);
57
58protected:
59 virtual void OnInitialize() override;
60 virtual void OnDeinitialize() override;
61
63 virtual void DestroyViewContext(plEngineProcessViewContext* pContext) override;
64 virtual plStatus ExportDocument(const plExportDocumentMsgToEngine* pMsg) override;
65 void ExportExposedParameters(const plWorldWriter& ww, plDeferredFileWriter& file) const;
66
67 virtual bool UpdateThumbnailViewContext(plEngineProcessViewContext* pThumbnailViewContext) override;
68 virtual void OnThumbnailViewContextCreated() override;
69 virtual void OnDestroyThumbnailViewContext() override;
70 virtual void UpdateDocumentContext() override;
71 virtual plGameObjectHandle ResolveStringToGameObjectHandle(const void* pString, plComponentHandle hThis, plStringView sProperty) const override;
72
73private:
74 struct TagGameObject
75 {
76 plGameObjectHandle m_hObject;
77 plTag m_Tag;
78 };
79
80 void AddAmbientLight(bool bSetEditorTag, bool bForce);
81 void RemoveAmbientLight();
82
83 void HandleViewRedrawMsg(const plViewRedrawMsgToEngine* pMsg);
84 void HandleSelectionMsg(const plObjectSelectionMsgToEngine* pMsg);
85 void HandleGameModeMsg(const plGameModeMsgToEngine* pMsg);
86 void HandleSimulationSettingsMsg(const plSimulationSettingsMsgToEngine* msg);
87 void HandleGridSettingsMsg(const plGridSettingsMsgToEngine* msg);
88 void HandleWorldSettingsMsg(const plWorldSettingsMsgToEngine* msg);
89 void HandleObjectsForDebugVisMsg(const plObjectsForDebugVisMsgToEngine* pMsg);
90 void ComputeHierarchyBounds(plGameObject* pObj, plBoundingBoxSphere& bounds);
91 void HandleExposedPropertiesMsg(const plExposedDocumentObjectPropertiesMsgToEngine* pMsg);
92 void HandleSceneGeometryMsg(const plExportSceneGeometryMsgToEngine* pMsg);
93 void HandlePullObjectStateMsg(const plPullObjectStateMsgToEngine* pMsg);
94 void AnswerObjectStatePullRequest(const plViewRedrawMsgToEngine* pMsg);
95 void HandleActiveLayerChangedMsg(const plActiveLayerChangedMsgToEngine* pMsg);
96 void HandleTagMsgToEngineMsg(const plObjectTagMsgToEngine* pMsg);
97 void HandleLayerVisibilityChangedMsgToEngineMsg(const plLayerVisibilityChangedMsgToEngine* pMsg);
98
99 void DrawSelectionBounds(const plViewHandle& hView);
100
101 void UpdateInvisibleLayerTags();
102 void InsertSelectedChildren(const plGameObject* pObject);
103 void QuerySelectionBBox(const plEditorEngineDocumentMsg* pMsg);
104 void OnSimulationEnabled();
105 void OnSimulationDisabled();
106 void OnPlayTheGameModeStarted(const plTransform* pStartPosition);
107
108 void OnResourceManagerEvent(const plResourceManagerEvent& e);
109 void GameApplicationEventHandler(const plGameApplicationExecutionEvent& e);
110
111 bool m_bUpdateAllLocalBounds = false;
112 bool m_bRenderSelectionOverlay;
113 bool m_bRenderShapeIcons;
114 bool m_bRenderSelectionBoxes;
115 float m_fGridDensity;
116 plTransform m_GridTransform;
117
118 plDeque<plGameObjectHandle> m_Selection;
119 plDeque<plGameObjectHandle> m_SelectionWithChildren;
120 plSet<plGameObjectHandle> m_SelectionWithChildrenSet;
121 plGameObjectHandle m_hSkyLight;
122 plGameObjectHandle m_hDirectionalLight;
123 plDynamicArray<plExposedSceneProperty> m_ExposedSceneProperties;
124
125 plPushObjectStateMsgToEditor m_PushObjectStateMsg;
126
127 plUuid m_ActiveLayer;
130
131 // We use tags in the form of Layer_4 (Layer_Scene for the scene itself) to not pollute the tag registry with hundreds of unique tags. The tags do not need to be unique across documents so we can just use the layer index but that requires the Tags to be recomputed whenever we remove / add layers.
132 // By caching the guids we do not need to send another message each time a layer is loaded as we send also guids of unloaded layers.
133 plTag m_LayerTag;
134 plHybridArray<plUuid, 1> m_InvisibleLayers;
135 bool m_bInvisibleLayersDirty = true;
136 plHybridArray<plTag, 1> m_InvisibleLayerTags;
137
138 plDynamicArray<TagGameObject> m_ObjectsToTag;
139};
Definition Messages.h:61
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
A file writer that caches all written data and only opens and writes to the output file when everythi...
Definition DeferredFileWriter.h:9
Definition Deque.h:270
Definition DynamicArray.h:81
Base class for all messages that are tied to some document.
Definition EngineProcessMessages.h:151
A document context is the counter part to an editor document on the engine side.
Definition EngineProcessDocumentContext.h:42
virtual void OnThumbnailViewContextCreated()
Called after a thumbnail context was created. Allows to insert code before the thumbnail is generated...
Definition EngineProcessDocumentContext.cpp:609
virtual plStatus ExportDocument(const plExportDocumentMsgToEngine *pMsg)
Exports to current document resource to file. Make sure to write plAssetFileHeader at the start of it...
Definition EngineProcessDocumentContext.cpp:506
virtual plEngineProcessViewContext * CreateViewContext()=0
Needs to be implemented to create a view context used for windows and thumbnails rendering.
virtual plGameObjectHandle ResolveStringToGameObjectHandle(const void *pString, plComponentHandle hThis, plStringView sProperty) const
Tries to resolve a 'reference' (given in pData) to an plGameObject.
Definition EngineProcessDocumentContext.cpp:747
virtual void DestroyViewContext(plEngineProcessViewContext *pContext)=0
Needs to be implemented to destroy the view context created in CreateViewContext.
virtual void OnDestroyThumbnailViewContext()
Called before a thumbnail context is destroyed. Used for cleanup of what was done in OnThumbnailViewC...
Definition EngineProcessDocumentContext.cpp:610
virtual void UpdateDocumentContext()
A tick functions that allows each document context to do processing that continues over multiple fram...
Definition EngineProcessDocumentContext.cpp:410
virtual bool UpdateThumbnailViewContext(plEngineProcessViewContext *pThumbnailViewContext)
Overwrite this function to apply the thumbnail render settings to the given context.
Definition EngineProcessDocumentContext.cpp:603
Represents the view/window on the engine process side, holds all data necessary for rendering.
Definition EngineProcessViewContext.h:54
Definition EngineProcessMessages.h:299
Definition EngineProcessMessages.h:307
Definition Messages.h:25
Definition EngineProcessMessages.h:538
This class represents an object inside the world.
Definition GameObject.h:32
plGameState is the base class to build custom game logic upon. It works closely together with plGameA...
Definition GameStateBase.h:38
Definition EngineProcessMessages.h:508
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
Layers that are loaded as sub-documents of a scene share the plWorld with their main document scene....
Definition LayerContext.h:12
Definition Messages.h:69
Definition EngineProcessMessages.h:491
Definition EngineProcessMessages.h:474
Send by the editor scene document to the runtime scene document, to tell it about the poll results (s...
Definition EngineProcessMessages.h:607
Definition Messages.h:36
Definition Messages.h:53
Definition RenderContext.h:30
Definition SceneContext.h:25
Definition Set.h:238
Definition EngineProcessMessages.h:499
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
The tag class stores the necessary lookup information for a single tag which can be used in conjuncti...
Definition Tag.h:16
This data type is the abstraction for 128-bit Uuid (also known as GUID) instances.
Definition Uuid.h:11
Definition Declarations.h:64
Definition EngineProcessMessages.h:257
The world rtti converter context tracks created objects and is capable of also handling components / ...
Definition WorldRttiConverterContext.h:14
Definition EngineProcessMessages.h:527
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
constexpr PL_ALWAYS_INLINE T Abs(T f)
Returns the absolute value of f.
Definition Math_inl.h:21
A handle to a component.
Definition Declarations.h:138
Definition GameApplicationBase.h:32
A handle to a game object.
Definition Declarations.h:76
Events sent by the plResourceManager.
Definition Declarations.h:42
An plResult with an additional message for the reason of failure.
Definition Status.h:12