Radium Engine  1.5.0
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 
15 class QTimer;
16 class QCommandLineParser;
17 namespace Ra {
18 namespace Engine {
19 class RadiumEngine;
20 namespace Scene {
21 class GeometrySystem;
22 struct ItemEntry;
23 } // namespace Scene
24 } // namespace Engine
25 
26 namespace Gui {
27 class Viewer;
28 class MainWindowInterface;
29 
31 class 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 
132  uint getFrameCount() const { return m_frameCounter; }
133 
134  const std::string& getExportFolderName() const { return m_exportFoldername; }
135 
137  void addPluginDirectory( const std::string& pluginDir );
139  void clearPluginDirectories();
140 
143  void editSettings();
144 
146  virtual std::string getHelpText() const;
147 
148  void addRadiumMenu();
149 
150  signals:
152  void starting();
153 
155  void stopping();
156 
158  void sceneChanged( const Core::Aabb& );
159 
160  void updateFrameStats( const std::vector<FrameTimerData>& );
161 
162  void loadComplete();
163 
164  void selectedItem( const Ra::Engine::Scene::ItemEntry& entry );
165 
166  public slots:
167 
169  virtual void engineOpenGLInitialize();
170 
173  virtual void initializeGl();
174 
175  void updateRadiumFrameIfNeeded() {
176  // Main loop
177  if ( !m_isAboutToQuit && m_isUpdateNeeded.load() ) radiumFrame();
178  if ( m_continuousUpdateRequest <= 0 ) {
179  m_continuousUpdateRequest.store( 0 );
180  m_isUpdateNeeded.store( false );
181  }
182  if ( m_isAboutToQuit ) { this->exit(); }
183  }
184 
185  bool loadFile( QString path );
186  void framesCountForStatsChanged( uint count );
187  void appNeedsToQuit();
188 
189  void setRealFrameRate( bool on );
190  void setRecordFrames( bool on );
191  void setRecordTimings( bool on );
192  void setRecordGraph( bool on );
193 
194  void recordFrame();
195 
196  void onSelectedItem( const Ra::Engine::Scene::ItemEntry& entry ) { emit selectedItem( entry ); }
197 
198  void setContinuousUpdate( bool b ) {
199  b ? m_continuousUpdateRequest++ : m_continuousUpdateRequest--;
200  // if continuous update is requested, then we need an update, if not,
201  // let update needed stay in the same state.
202  if ( m_continuousUpdateRequest > 0 ) m_isUpdateNeeded.store( true );
203  }
204  void askForUpdate() { m_isUpdateNeeded.store( true ); }
205 
206  protected:
208  void createConnections();
209 
214  bool loadPlugins( const std::string& pluginsPath,
215  const QStringList& loadList,
216  const QStringList& ignoreList );
217 
218  void setupScene();
219 
221  bool isUpdateNeeded() { return m_isUpdateNeeded.load(); }
222 
224  void setIsUpdateNeeded( bool b ) { m_isUpdateNeeded.store( b ); }
225 
226  // Public variables, accessible through the mainApp singleton.
227  public:
229  std::unique_ptr<Gui::MainWindowInterface> m_mainWindow;
230 
233 
235  std::unique_ptr<Core::TaskQueue> m_taskQueue;
236 
239 
240  protected:
242  std::vector<Ra::Plugins::RadiumPluginInterface*> m_openGLPlugins;
243 
246 
248  QTimer* m_frameTimer;
249 
251  Core::Utils::TimePoint m_lastFrameStart;
252 
253  uint m_frameCounter;
254  uint m_frameCountBeforeUpdate;
255  uint m_numFrames;
256  uint m_maxThreads;
257  std::vector<FrameTimerData> m_timerData;
258  std::string m_pluginPath;
259 
262 
263  // Options to control monitoring and outputs
265  std::string m_exportFoldername;
266 
273 
276 
278  std::atomic_bool m_isUpdateNeeded { true };
279 
281  std::atomic<int> m_continuousUpdateRequest { 1 };
282 
283  Plugins::Context m_pluginContext;
284  QCommandLineParser* m_parser;
285 
287  std::map<std::string, std::string> m_loadedPlugins;
288 };
289 } // namespace Gui
290 } // 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.
Definition: Cage.cpp:3