Radium Engine  1.5.0
SignalManager.hpp
1 #pragma once
2 
3 #include <Engine/RaEngine.hpp>
4 
5 #include <mutex>
6 
7 #include <Core/Utils/Observable.hpp>
8 
9 #include <Engine/Scene/ItemEntry.hpp>
10 
11 namespace Ra {
12 namespace Engine {
13 namespace Scene {
14 
29 class RA_ENGINE_API SignalManager
30 {
31 
32  public:
34  void fireEntityCreated( const ItemEntry& entity ) const;
36  void fireEntityDestroyed( const ItemEntry& entity ) const;
37 
39  void fireComponentAdded( const ItemEntry& component ) const;
41  void fireComponentRemoved( const ItemEntry& component ) const;
42 
44  void fireRenderObjectAdded( const ItemEntry& ro ) const;
46  void fireRenderObjectRemoved( const ItemEntry& ro ) const;
47 
49  void fireFrameEnded() const;
50 
52  void setOn( bool on ) { m_isOn = on; }
53 
58 
61  ItemObservable& getEntityCreatedNotifier();
62  ItemObservable& getEntityDestroyedNotifier();
63  ItemObservable& getComponentCreatedNotifier();
64  ItemObservable& getComponentDestroyedNotifier();
65  ItemObservable& getRenderObjectCreatedNotifier();
66  ItemObservable& getRenderObjectDestroyedNotifier();
67  FrameObservable& getEndFrameNotifier();
69 
70  private:
72  mutable std::mutex m_mutex;
73 
75  bool m_isOn { true };
76 
79  ItemObservable m_entityCreatedCallbacks;
80  ItemObservable m_entityDestroyedCallbacks;
81  ItemObservable m_componentAddedCallbacks;
82  ItemObservable m_componentRemovedCallbacks;
83  ItemObservable m_roAddedCallbacks;
84  ItemObservable m_roRemovedCallbacks;
86 
89  FrameObservable m_frameEndCallbacks;
91 
93  template <typename... TArgs>
94  void notify( const Ra::Core::Utils::Observable<TArgs...>& o, TArgs... args ) const {
95  if ( m_isOn ) {
96  std::lock_guard<std::mutex> lock( m_mutex );
97  o.notify( args... );
98  }
99  }
100 };
101 } // namespace Scene
102 } // namespace Engine
103 } // namespace Ra
void notify(Args... p) const
Notify (i.e. call) each attached observer with argument p.
Definition: Observable.hpp:67
void setOn(bool on)
Enable/disable the notification of observers.
Definition: Cage.cpp:3