Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
CouplingSystem.hpp
1 #pragma once
2 
3 #include <Engine/RaEngine.hpp> // RA_ENGINE_API
4 #include <Engine/Scene/System.hpp> // System methods declaration
5 #include <memory> // std::unique_ptr
6 #include <type_traits> // std::is_base_of
7 #include <vector> // std::vector
8 
9 namespace Ra {
10 namespace Engine {
11 namespace Scene {
12 
36 template <typename _BaseAbstractSystem>
37 class BaseCouplingSystem : public _BaseAbstractSystem
38 {
39  public:
40  using BaseAbstractSystem = _BaseAbstractSystem;
41 
42  inline BaseCouplingSystem() {
43  static_assert( std::is_base_of<Ra::Engine::Scene::System, BaseAbstractSystem>::value,
44  "BaseAbstractSystem must inherit Ra::Core::System" );
45  }
46  ~BaseCouplingSystem() override = default;
47 
50  operator=( const BaseCouplingSystem<BaseAbstractSystem>& ) = delete;
51 
54  inline void addSystem( BaseAbstractSystem* s ) { m_systems.emplace_back( s ); }
55 
56  inline void generateTasks( Core::TaskQueue* taskQueue,
57  const Engine::FrameInfo& frameInfo ) override {
58  dispatch( [taskQueue, &frameInfo]( const auto& s ) {
59  s->generateTasks( taskQueue, frameInfo );
60  } );
61  }
62  inline void handleAssetLoading( Entity* entity, const Core::Asset::FileData* data ) override {
63  BaseAbstractSystem::handleAssetLoading( entity, data );
64  dispatch( [entity, data]( const auto& s ) { s->handleAssetLoading( entity, data ); } );
65  }
66 
67  protected:
70  template <typename Functor>
71  inline void dispatch( Functor f ) {
72  for ( auto& s : m_systems )
73  f( s );
74  }
75 
78  template <typename Functor>
79  inline void dispatch( Functor f ) const {
80  for ( const auto& s : m_systems )
81  f( s );
82  }
83 
109  template <typename Functor>
110  inline bool conditionnaldispatch( Functor f, bool abortWhenInvalid = true ) {
111  for ( auto& s : m_systems ) {
112  if ( !f( s ) && abortWhenInvalid ) return false;
113  }
114  return true;
115  }
116 
118  template <typename Functor>
119  inline bool conditionnaldispatch( Functor f, bool abortWhenInvalid = true ) const {
120  for ( const auto& s : m_systems ) {
121  if ( !f( s ) && abortWhenInvalid ) return false;
122  }
123  return true;
124  }
125 
126  private:
128  std::vector<std::unique_ptr<BaseAbstractSystem>> m_systems;
129 };
130 
131 } // namespace Scene
132 } // namespace Engine
133 } // namespace Ra
bool conditionnaldispatch(Functor f, bool abortWhenInvalid=true) const
void addSystem(BaseAbstractSystem *s)
bool conditionnaldispatch(Functor f, bool abortWhenInvalid=true)
Definition: Cage.cpp:3
Structure passed to each system before they fill the task queue.
Definition: FrameInfo.hpp:8