Radium Engine  1.5.20
Loading...
Searching...
No Matches
BaseApplication.hpp
1#pragma once
2#include <atomic>
3#include <chrono>
4#include <memory>
5#include <vector>
6
7#include <QApplication>
8
9#include <Core/Utils/Timer.hpp>
10#include <Gui/TimerData/FrameTimerData.hpp>
11#include <PluginBase/RadiumPluginInterface.hpp>
12
13#include <glbinding/Version.h>
14
15class QTimer;
16class QCommandLineParser;
17namespace Ra {
18namespace Engine {
19class RadiumEngine;
20namespace Scene {
21class GeometrySystem;
22struct ItemEntry;
23} // namespace Scene
24} // namespace Engine
25
26namespace Gui {
27class Viewer;
28class MainWindowInterface;
29
31class RA_GUI_API BaseApplication : public QApplication
32{
33 Q_OBJECT
34
35 public:
36 class WindowFactory
37 {
38 public:
39 WindowFactory() = default;
40 virtual ~WindowFactory() = default;
41 virtual Ra::Gui::MainWindowInterface* createMainWindow() const = 0;
42 };
43
54 BaseApplication( int& argc,
55 char** argv,
56 QString applicationName = "RadiumEngine",
57 QString organizationName = "STORM-IRIT" );
58
59 ~BaseApplication() override;
60
96 void initialize( const WindowFactory& factory, const glbinding::Version& glVersion = { 4, 1 } );
97
109 virtual void engineBaseInitialization();
110
123 virtual void addApplicationExtension() {};
124
126 void radiumFrame();
127
128 bool isRunning() const { return !m_isAboutToQuit; }
129
130 const Engine::RadiumEngine* getEngine() const { return m_engine; }
131 Viewer* getViewer() { return m_viewer; }
132
133 uint getFrameCount() const { return m_frameCounter; }
134
135 const std::string& getExportFolderName() const { return m_exportFoldername; }
136
138 void addPluginDirectory( const std::string& pluginDir );
140 void clearPluginDirectories();
141
144 void editSettings();
145
147 virtual std::string getHelpText() const;
148
149 void addRadiumMenu();
150
151 signals:
153 void starting();
154
156 void stopping();
157
159 void sceneChanged( const Core::Aabb& );
160
161 void updateFrameStats( const std::vector<FrameTimerData>& );
162
163 void loadComplete();
164
165 void selectedItem( const Ra::Engine::Scene::ItemEntry& entry );
166
167 public slots:
168
170 virtual void engineOpenGLInitialize();
171
174 virtual void initializeGl();
175
176 void updateRadiumFrameIfNeeded() {
177 // Main loop
178 if ( !m_isAboutToQuit && m_isUpdateNeeded.load() ) radiumFrame();
179 if ( m_continuousUpdateRequest <= 0 ) {
180 m_continuousUpdateRequest.store( 0 );
181 m_isUpdateNeeded.store( false );
182 }
183 if ( m_isAboutToQuit ) { this->exit(); }
184 }
185
186 bool loadFile( QString path );
187 void framesCountForStatsChanged( uint count );
188 void appNeedsToQuit();
189
190 void setRealFrameRate( bool on );
191 void setRecordFrames( bool on );
192 void setRecordTimings( bool on );
193 void setRecordGraph( bool on );
194
195 void recordFrame();
196
197 void onSelectedItem( const Ra::Engine::Scene::ItemEntry& entry ) { emit selectedItem( entry ); }
198
199 void setContinuousUpdate( bool b ) {
200 b ? m_continuousUpdateRequest++ : m_continuousUpdateRequest--;
201 // if continuous update is requested, then we need an update, if not,
202 // let update needed stay in the same state.
203 if ( m_continuousUpdateRequest > 0 ) m_isUpdateNeeded.store( true );
204 }
205 void askForUpdate() { m_isUpdateNeeded.store( true ); }
206
207 protected:
209 void createConnections();
210
215 bool loadPlugins( const std::string& pluginsPath,
216 const QStringList& loadList,
217 const QStringList& ignoreList );
218
219 void setupScene();
220
222 bool isUpdateNeeded() { return m_isUpdateNeeded.load(); }
223
225 void setIsUpdateNeeded( bool b ) { m_isUpdateNeeded.store( b ); }
226
227 // Public variables, accessible through the mainApp singleton.
228 public:
231
234
237
240
241 protected:
244
247
250
253
254 uint m_frameCounter;
255 uint m_frameCountBeforeUpdate;
256 uint m_numFrames;
257 uint m_maxThreads;
258 std::vector<FrameTimerData> m_timerData;
259 std::string m_pluginPath;
260
263
264 // Options to control monitoring and outputs
267
274
277
279 std::atomic_bool m_isUpdateNeeded { true };
280
282 std::atomic<int> m_continuousUpdateRequest { 1 };
283
284 Plugins::Context m_pluginContext;
285 QCommandLineParser* m_parser;
286
289};
290} // namespace Gui
291} // namespace Ra
This class contains the main application logic. It owns the engine and the GUI.
std::unique_ptr< Gui::MainWindowInterface > m_mainWindow
Application main window and GUI root class.
void sceneChanged(const Core::Aabb &)
Fired when the scene has changed.
bool m_recordGraph
If true, print the task graph;.
Engine::RadiumEngine * m_engine
Instance of the radium engine.
bool m_recordFrames
If true, dump each frame to a PNG file.
virtual void addApplicationExtension()
bool isUpdateNeeded()
check wheter someone ask for update
std::unique_ptr< Core::TaskQueue > m_taskQueue
Task queue for processing tasks.
std::map< std::string, std::string > m_loadedPlugins
maps name and paths of already loaded plugins
void setIsUpdateNeeded(bool b)
if b is true, then update anyway. If b is false, update on request only
bool m_recordTimings
If true, print the detailed timings of each frame.
QTimer * m_frameTimer
Timer to wake us up at every frame start.
Core::Utils::TimePoint m_lastFrameStart
Time since the last frame start.
uint m_targetFPS
Number of frames per second to generate.
void stopping()
Fired when the engine is about to stop.
std::vector< Ra::Plugins::RadiumPluginInterface * > m_openGLPlugins
Plugins that need to be initialized once OpenGL is ready.
bool m_realFrameRate
If true, use the wall clock to advance the engine. If false, use a fixed time step.
bool m_isAboutToQuit
True if the applicatioon is about to quit. prevent to use resources that are being released.
Gui::Viewer * m_viewer
Pointer to OpenGL Viewer for render call (belongs to MainWindow).
void starting()
Fired when the engine has just started, before the frame timer is set.
std::string m_exportFoldername
Name of the folder where exported data goes.
Data passed to the plugin constructor.
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3