Radium Engine  1.5.0
RadiumEngine.hpp
1 #pragma once
2 #include <Engine/RaEngine.hpp>
3 
4 #include <Core/Tasks/TaskQueue.hpp>
5 #include <Core/Types.hpp>
6 #include <Core/Utils/Singleton.hpp>
7 
8 #include <glbinding/Version.h>
9 #include <globjects/State.h>
10 
11 #include <map>
12 #include <memory>
13 #include <stack>
14 #include <string>
15 #include <vector>
16 
17 namespace Ra {
18 namespace Core {
19 
20 namespace Asset {
21 class FileLoaderInterface;
22 class FileData;
23 } // namespace Asset
24 } // namespace Core
25 
26 namespace Engine {
27 namespace Scene {
28 class System;
29 class Entity;
30 class Component;
31 class EntityManager;
32 class SignalManager;
33 } // namespace Scene
34 
35 namespace Data {
36 class ShaderProgramManager;
37 class Displayable;
38 class TextureManager;
39 } // namespace Data
40 
41 namespace Rendering {
42 class RenderObjectManager;
43 }
44 
49 class RA_ENGINE_API RadiumEngine
50 {
51  RA_SINGLETON_INTERFACE( RadiumEngine );
52 
53  public:
58  void initialize();
59 
68  void initializeGL();
69 
75  glbinding::Version getOpenGLVersion() const;
76 
80  void cleanup();
81 
89  void getTasks( Core::TaskQueue* taskQueue, Scalar dt );
90 
100  bool registerSystem( const std::string& name, Scene::System* system, int priority = 1 );
101 
107  Scene::System* getSystem( const std::string& system ) const;
108 
118  Data::Displayable* getMesh( const std::string& entityName,
119  const std::string& componentName,
120  const std::string& roName = std::string() ) const;
121 
131  bool loadFile( const std::string& file );
132 
140  const Core::Asset::FileData& getFileData() const;
141 
148  void releaseFile();
149 
152  void endFrameSync();
153 
155 
160  Rendering::RenderObjectManager* getRenderObjectManager() const;
166  Scene::EntityManager* getEntityManager() const;
167 
173  Scene::SignalManager* getSignalManager() const;
174 
180  Data::TextureManager* getTextureManager() const;
181 
187  Data::ShaderProgramManager* getShaderProgramManager() const;
188 
193  void registerFileLoader( std::shared_ptr<Core::Asset::FileLoaderInterface> fileLoader );
194 
199  const std::vector<std::shared_ptr<Core::Asset::FileLoaderInterface>>& getFileLoaders() const;
200 
204  Core::Aabb computeSceneAabb() const;
205 
210  void pushFboAndViewport();
211 
217  void popFboAndViewport();
218 
221 
229  void setRealTime( bool realTime );
230 
235  bool isRealTime() const;
236 
241  bool isConstantTime() const;
242 
251  bool setConstantTimeStep( Scalar dt, bool forceConstantTime = false );
252 
263  void setForwardBackward( bool mode );
264 
268  void play( bool isPlaying );
269 
273  void step();
274 
279  void resetTime();
280 
286  void setTime( Scalar t );
287 
294  void setStartTime( Scalar t );
295 
299  Scalar getStartTime() const;
300 
308  void setEndTime( Scalar t );
309 
313  Scalar getEndTime() const;
314 
318  Scalar getTime() const;
319 
323  uint getFrame() const;
325 
326  std::string getResourcesDir() { return m_resourcesRootDir; }
327 
331  void runGpuTasks();
332 
337  Core::TaskQueue::TaskId addGpuTask( std::unique_ptr<Core::Task> );
338 
342  void removeGpuTask( Core::TaskQueue::TaskId taskId );
343 
344  private:
345  RadiumEngine();
346  ~RadiumEngine();
347 
349  glbinding::Version m_glVersion {};
353  void registerDefaultPrograms();
354 
355  using Priority = int;
356  using SystemKey = std::pair<Priority, std::string>;
357  // use transparent functors :
358  // https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-transparent-functors.html
359  using SystemContainer = std::map<SystemKey, std::shared_ptr<Scene::System>, std::greater<>>;
360 
361  SystemContainer::const_iterator findSystem( const std::string& name ) const;
362  SystemContainer::iterator findSystem( const std::string& name );
363 
368  SystemContainer m_systems;
369 
370  std::vector<std::shared_ptr<Core::Asset::FileLoaderInterface>> m_fileLoaders;
371 
372  std::unique_ptr<Rendering::RenderObjectManager> m_renderObjectManager;
373  std::unique_ptr<Scene::EntityManager> m_entityManager;
374  std::unique_ptr<Scene::SignalManager> m_signalManager;
375  std::unique_ptr<Data::TextureManager> m_textureManager;
376  std::unique_ptr<Data::ShaderProgramManager> m_shaderProgramManager;
377  std::unique_ptr<Core::Asset::FileData> m_loadedFile;
378 
379  bool m_loadingState { false };
380 
382  std::string m_resourcesRootDir;
383 
387  class FboAndViewport
388  {
389  public:
390  FboAndViewport( int fbo, std::array<int, 4>&& viewport ) :
391  m_fbo { fbo }, m_viewport { viewport } {}
392  int m_fbo;
393  std::array<int, 4> m_viewport;
394  };
395 
397  std::stack<FboAndViewport> m_fboAndViewportStack;
398 
399  struct TimeData {
404  void updateTime( Scalar dt );
405 
406  Scalar m_dt { 1_ra / 60_ra };
407  Scalar m_startTime { 0_ra };
408  Scalar m_endTime { 1_ra };
409  Scalar m_time { 0_ra };
410  bool m_play { false };
411  bool m_singleStep { true };
412  bool m_realTime { false };
413  bool m_forwardBackward { false };
414  bool m_isBackward { false };
415  };
416 
417  TimeData m_timeData;
418 
421  std::unique_ptr<globjects::State> m_openglState { nullptr };
422  std::unique_ptr<Core::TaskQueue> m_gpuTaskQueue { new Core::TaskQueue( 0 ) };
423 };
424 } // namespace Engine
425 } // namespace Ra
Utils::Index TaskId
Identifier for a task in the task queue.
Definition: TaskQueue.hpp:35
Definition: Cage.cpp:3