CmApplication.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. #include "CmCoreThreadAccessor.h"
  5. #include "CmRenderWindow.h"
  6. #include "BsEvent.h"
  7. namespace BansheeEngine
  8. {
  9. /**
  10. * @brief Structure containing parameters for starting the application.
  11. */
  12. struct START_UP_DESC
  13. {
  14. String renderSystem; /**< Name of the render system plugin to use. */
  15. String renderer; /**< Name of the renderer plugin to use. */
  16. String input; /**< Name of the input plugin to use. */
  17. String sceneManager; /**< Name of the scene manager plugin to use. */
  18. RENDER_WINDOW_DESC primaryWindowDesc; /**< Describes the window to create during start-up. */
  19. Vector<String> importers; /**< A list of importer plugins to load. */
  20. };
  21. /**
  22. * @brief Represents the primary entry point to the engine. Handles
  23. * start-up, shutdown, primary loop and allows you to load and unload
  24. * plugins.
  25. *
  26. * @note Sim thread only.
  27. */
  28. class CM_EXPORT Application
  29. {
  30. public:
  31. Application();
  32. /**
  33. * @brief Starts the application using the specified options.
  34. * This is how you start the engine. Must be called before any other engine method.
  35. */
  36. void startUp(START_UP_DESC& desc);
  37. /**
  38. * @brief Executes the main loop. This will update your components and modules, queue objects
  39. * for rendering and run the simulation. Usually called immediately after startUp().
  40. *
  41. * This will run infinitely until stopMainLoop is called (usually from another thread or internally).
  42. */
  43. void runMainLoop();
  44. /**
  45. * @brief Stops a (infinite) main loop from running. The loop will complete its current cycle before stopping.
  46. */
  47. void stopMainLoop();
  48. /**
  49. * @brief Frees up all resources allocated during startUp, and while the application was running.
  50. */
  51. void shutDown();
  52. /**
  53. * @brief
  54. */
  55. RenderWindowPtr getPrimaryWindow() const { return mPrimaryWindow; }
  56. /**
  57. * @brief Loads a plugin.
  58. *
  59. * @param pluginName Name of the plugin to load, without extension.
  60. * @param [out] library Specify as not null to receive a reference to
  61. * the loaded library.
  62. *
  63. * @returns Value returned from the plugin start-up method.
  64. */
  65. void* loadPlugin(const String& pluginName, DynLib** library = nullptr);
  66. /**
  67. * @brief Unloads a previously loaded plugin.
  68. */
  69. void unloadPlugin(DynLib* library);
  70. /**
  71. * @brief Called every frame by the main loop, after scene update and before rendering.
  72. */
  73. Event<void()> mainLoopCallback;
  74. private:
  75. /**
  76. * @brief Called when the frame finishes rendering.
  77. */
  78. void frameRenderingFinishedCallback();
  79. /**
  80. * @brief Called by the core thread to begin profiling.
  81. */
  82. void beginCoreProfiling();
  83. /**
  84. * @brief Called by the core thread to end profiling.
  85. */
  86. void endCoreProfiling();
  87. private:
  88. RenderWindowPtr mPrimaryWindow;
  89. DynLib* mSceneManagerPlugin;
  90. bool mIsFrameRenderingFinished;
  91. CM_MUTEX(mFrameRenderingFinishedMutex);
  92. CM_THREAD_SYNCHRONISER(mFrameRenderingFinishedCondition);
  93. volatile bool mRunMainLoop;
  94. };
  95. /**
  96. * @brief Provides easy access to primary entry point for the engine.
  97. */
  98. CM_EXPORT Application& gApplication();
  99. }