Photon Editor Library 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
Editor.ipp
Go to the documentation of this file.
1#pragma once
2
3#include "App/Editor.h"
4
5#include <type_traits>
6
7namespace ph::editor
8{
9
10inline DesignerScene* Editor::getScene(const std::size_t sceneIndex) const
11{
12 return m_scenes.get(sceneIndex);
13}
14
16{
17 return m_activeScene;
18}
19
20inline std::size_t Editor::numScenes() const
21{
22 return m_scenes.size();
23}
24
25inline std::size_t Editor::getSceneIndex(const DesignerScene* scene) const
26{
27 auto optIndex = m_scenes.indexOf(scene);
28 return optIndex ? *optIndex : nullSceneIndex();
29}
30
31inline constexpr std::size_t Editor::nullSceneIndex()
32{
33 return static_cast<std::size_t>(-1);
34}
35
36template<typename EventType>
37inline void Editor::postEvent(const EventType& e, TEditorEventDispatcher<EventType>& eventDispatcher)
38{
39 constexpr bool hasPostTraits = requires (EventType)
40 {
41 { EventType::canPost } -> std::same_as<bool>;
42 };
43
44 if constexpr(hasPostTraits)
45 {
46 static_assert(EventType::canPost,
47 "Attempting to post an event that does not allow event posting.");
48 }
49
50 // Posted event should be captured by value since exceution of queued works are delayed,
51 // there is no guarantee that the original event object still lives by the time we
52 // execute the work.
53 //
54 // Queued work is some event `e` that is going to be posted by `eventDispatcher`. Do not
55 // reference anything that might not live across frames/threads when constructing post work,
56 // as `postEvent()` can get called anywhere in a frame or from any thread and the execution
57 // of post works may be delayed to next multiple frames.
58 m_eventPostQueue.add(
59 [&eventDispatcher, e]()
60 {
61 dispatchPostedEventToListeners(e, eventDispatcher);
62 });
63}
64
65template<typename EventType>
66inline void Editor::dispatchPostedEventToListeners(
67 const EventType& e,
68 TEditorEventDispatcher<EventType>& eventDispatcher)
69{
70 using Listener = typename TEditorEventDispatcher<EventType>::Listener;
71
72 eventDispatcher.dispatch(
73 e,
74 [](const EventType& e, const Listener& listener)
75 {
76 listener(e);
77 });
78}
79
80}// end namespace ph::editor
Definition DesignerScene.h:58
void add(EventUpdateWork work)
Definition EditorEventQueue.h:46
DesignerScene * getScene(std::size_t sceneIndex) const
Definition Editor.ipp:10
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 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
static constexpr std::size_t nullSceneIndex()
Definition Editor.ipp:31
DesignerScene * getActiveScene() const
Definition Editor.ipp:15
std::size_t numScenes() const
Definition Editor.ipp:20
Definition TClassEventDispatcher.h:13
DispatcherType::Listener Listener
Definition TClassEventDispatcher.h:20
Definition ph_editor.h:10