Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Editor.h
Go to the documentation of this file.
1#pragma once
2
19#include "App/EditContext.h"
21
22#include <Common/assertion.h>
23#include <Common/primitive_type.h>
24#include <Utility/TFunction.h>
25#include <Utility/TUniquePtrVector.h>
26#include <Utility/INoCopyAndMove.h>
27
28#include <cstddef>
29#include <list>
30#include <string>
31#include <memory>
32
33namespace ph { class Path; }
34
35namespace ph::editor
36{
37
38class DesignerScene;
39class MainThreadUpdateContext;
40class MainThreadRenderUpdateContext;
41class RenderThreadCaller;
42class EditorSettings;
43
44class Editor final : private INoCopyAndMove
45{
46public:
51
53 ~Editor();
54
57 void start();
58
59 void update(const MainThreadUpdateContext& ctx);
62 void beforeUpdateStage();
63 void afterUpdateStage();
64 void beforeRenderStage();
65 void afterRenderStage();
66
69 void stop();
70
72 void cleanup();
73
78 std::size_t createScene(const Path& workingDirectory, const std::string& name = "");
79
81 const Path& workingDirectory,
82 const Path& sceneDescription,
83 const std::string& name = "",
84 const std::string& descName = "");
85
89 std::size_t loadScene(const Path& sceneFile);
90
93 void saveScene();
94
97 void saveScene(std::size_t sceneIndex);
98
99 DesignerScene* getScene(std::size_t sceneIndex) const;
101 void setActiveScene(std::size_t sceneIndex);
102 void removeScene(std::size_t sceneIndex);
103 std::size_t numScenes() const;
104
110 std::size_t getSceneIndex(const DesignerScene* scene) const;
111
113
114 static constexpr std::size_t nullSceneIndex();
115
116private:
117 struct PendingRemovalScene
118 {
119 std::unique_ptr<DesignerScene> scene;
120 bool hasRenderCleanupDone = false;
121 bool hasCleanupDone = false;
122 };
123
124 TUniquePtrVector<DesignerScene> m_scenes;
125 std::list<PendingRemovalScene> m_removingScenes;
126 DesignerScene* m_activeScene = nullptr;
127 bool m_isActiveScenePaused = false;
128
132 std::size_t newScene();
133
134 void loadDefaultScene();
135 void cleanupRemovingScenes();
136 void renderCleanupRemovingScenes(RenderThreadCaller& caller);
137
138// Event System
139public:
140 template<typename EventType>
142
172
178 template<typename EventType>
179 void postEvent(const EventType& e, TEditorEventDispatcher<EventType>& eventDispatcher);
180
181private:
182 template<typename EventType>
183 static void dispatchPostedEventToListeners(
184 const EventType& e,
185 TEditorEventDispatcher<EventType>& eventDispatcher);
186
187 void flushAllEvents();
188
189 EditorEventQueue m_eventPostQueue;
190
191 // TODO: may require obj/entity add/remove event queue to support concurrent event
192 // (to avoid invalidating Listener on addListener())
193// End Event System
194
195public:
196 void loadSettings(const Path& settingsFile);
197 void saveSettings(const Path& settingsFile) const;
199
200private:
201 std::shared_ptr<EditorSettings> m_settings;
202};
203
204}// end namespace ph::editor
205
206#include "App/Editor.ipp"
Definition DesignerScene.h:58
Size reference of various common UI elements. Unless otherwise noted, unit is in pixel (raster coordi...
Definition DimensionHints.h:12
Definition EditContext.h:9
Definition EditorEventQueue.h:16
Definition Editor.h:45
TEditorEventDispatcher< SceneFramebufferResizedEvent > onSceneFramebufferResized
Definition Editor.h:163
std::size_t createScene(const Path &workingDirectory, const std::string &name="")
Create a new scene. The scene will be made active automatically. This method is for a scene that is b...
Definition Editor.cpp:265
TEditorEventDispatcher< ActiveDesignerSceneChangedEvent > onActiveDesignerSceneChanged
Definition Editor.h:170
void saveScene()
Save the active scene.
Definition Editor.cpp:510
DimensionHints dimensionHints
Definition Editor.h:48
void stop()
Called once after the update loop ends.
Definition Editor.cpp:163
DesignerScene * getScene(std::size_t sceneIndex) const
Definition Editor.ipp:10
EditorSettings & getSettings() const
Definition Editor.cpp:714
void afterUpdateStage()
Definition Editor.cpp:133
TEditorEventDispatcher< DisplayClosedEvent > onDisplayClosed
Definition Editor.h:164
TEditorEventDispatcher< KeyPressedEvent > onKeyPressed
Editor events. Subscribe to editor event by adding listener to the corresponding dispatcher....
Definition Editor.h:160
void saveSettings(const Path &settingsFile) const
Definition Editor.cpp:696
void renderCleanup(RenderThreadCaller &caller)
Definition Editor.cpp:249
void loadSettings(const Path &settingsFile)
Definition Editor.cpp:679
void beforeRenderStage()
Definition Editor.cpp:143
std::size_t getSceneIndex(const DesignerScene *scene) const
Get index of the scene. Most scene operations in the editor take scene index as input,...
Definition Editor.ipp:25
void afterRenderStage()
Definition Editor.cpp:153
void beforeUpdateStage()
Definition Editor.cpp:123
void update(const MainThreadUpdateContext &ctx)
Definition Editor.cpp:80
void removeScene(std::size_t sceneIndex)
Definition Editor.cpp:636
TEditorEventDispatcher< DesignerSceneRemovalEvent > onDesignerSceneRemoval
Definition Editor.h:169
EditorStats editorStats
Definition Editor.h:49
TEditorEventDispatcher< DisplayFramebufferResizedEvent > onDisplayFramebufferResized
Definition Editor.h:162
void renderUpdate(const MainThreadRenderUpdateContext &ctx)
Definition Editor.cpp:101
void postEvent(const EventType &e, TEditorEventDispatcher< EventType > &eventDispatcher)
Specify an event that is going to be dispatched by the dispatcher. The event will not be dispatched i...
Definition Editor.ipp:37
void cleanup()
Definition Editor.cpp:257
TEditorEventDispatcher< AppModuleActionEvent > onAppModuleAction
Definition Editor.h:166
static constexpr std::size_t nullSceneIndex()
Definition Editor.ipp:31
EditContext getEditContext() const
Definition Editor.cpp:729
FileSystemExplorer fileExplorer
Definition Editor.h:50
~Editor()
Definition Editor.cpp:47
void start()
Called once before the update loop begins.
Definition Editor.cpp:54
std::size_t createSceneFromDescription(const Path &workingDirectory, const Path &sceneDescription, const std::string &name="", const std::string &descName="")
Definition Editor.cpp:299
TEditorEventDispatcher< DisplayFocusChangedEvent > onDisplayFocusChanged
Definition Editor.h:165
DesignerScene * getActiveScene() const
Definition Editor.ipp:15
void setActiveScene(std::size_t sceneIndex)
Definition Editor.cpp:598
TEditorEventDispatcher< DesignerSceneAddedEvent > onDesignerSceneAdded
Definition Editor.h:168
void createRenderCommands(RenderThreadCaller &caller)
Definition Editor.cpp:111
TEditorEventDispatcher< KeyReleasedEvent > onKeyReleased
Definition Editor.h:161
TEditorEventDispatcher< EditContextUpdatedEvent > onEditContextUpdated
Definition Editor.h:167
std::size_t loadScene(const Path &sceneFile)
Load a scene. The scene will be made active automatically.
Definition Editor.cpp:424
HelpMenu helpMenu
Definition Editor.h:47
std::size_t numScenes() const
Definition Editor.ipp:20
Definition EditorSettings.h:11
Definition EditorStats.h:9
Definition FileSystemExplorer.h:53
Definition HelpMenu.h:9
Definition MainThreadRenderUpdateContext.h:11
Definition MainThreadUpdateContext.h:11
Thin wrapper for render thread interactions from another thread. Mainly to hide unrelated render thre...
Definition RenderThreadCaller.h:16
Definition TClassEventDispatcher.h:13
Definition ph_editor.h:10
Definition ph_editor.h:5