Radium Engine  1.5.20
Loading...
Searching...
No Matches
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
9namespace Ra {
10namespace Engine {
11namespace Scene {
12
36template <typename _BaseAbstractSystem>
37class BaseCouplingSystem : public _BaseAbstractSystem
38{
39 public:
40 using BaseAbstractSystem = _BaseAbstractSystem;
41
42 inline BaseCouplingSystem() {
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:
129};
130
131} // namespace Scene
132} // namespace Engine
133} // namespace Ra
This class allows tasks to be registered and then executed in parallel on separate threads.
Definition TaskQueue.hpp:48
bool conditionnaldispatch(Functor f, bool abortWhenInvalid=true) const
void addSystem(BaseAbstractSystem *s)
bool conditionnaldispatch(Functor f, bool abortWhenInvalid=true)
T emplace_back(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3
Structure passed to each system before they fill the task queue.
Definition FrameInfo.hpp:8