BsCoreApplication.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsModule.h"
  4. #include "BsCoreThreadAccessor.h"
  5. #include "BsRenderWindow.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 for the core systems. 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 BS_CORE_EXPORT CoreApplication : public Module<CoreApplication>
  29. {
  30. public:
  31. CoreApplication(START_UP_DESC& desc);
  32. virtual ~CoreApplication();
  33. /**
  34. * @brief Executes the main loop. This will update your components and modules, queue objects
  35. * for rendering and run the simulation. Usually called immediately after startUp().
  36. *
  37. * This will run infinitely until stopMainLoop is called (usually from another thread or internally).
  38. */
  39. void runMainLoop();
  40. /**
  41. * @brief Stops a (infinite) main loop from running. The loop will complete its current cycle before stopping.
  42. */
  43. void stopMainLoop();
  44. /**
  45. * @brief
  46. */
  47. RenderWindowPtr getPrimaryWindow() const { return mPrimaryWindow; }
  48. /**
  49. * @brief Loads a plugin.
  50. *
  51. * @param pluginName Name of the plugin to load, without extension.
  52. * @param [out] library Specify as not null to receive a reference to
  53. * the loaded library.
  54. * @param passThrough Optional parameter that will be passed to the loadPlugin function.
  55. *
  56. * @returns Value returned from the plugin start-up method.
  57. */
  58. void* loadPlugin(const String& pluginName, DynLib** library = nullptr, void* passThrough = nullptr);
  59. /**
  60. * @brief Unloads a previously loaded plugin.
  61. */
  62. void unloadPlugin(DynLib* library);
  63. /**
  64. * @brief Calls the shutdown method on the plugin.
  65. *
  66. * @note This is separate from "unload" method and should be called
  67. * before unload.
  68. */
  69. void shutdownPlugin(DynLib* library);
  70. protected:
  71. /**
  72. * @brief Called for each iteration of the main loop.
  73. */
  74. virtual void update();
  75. private:
  76. /**
  77. * @brief Called when the frame finishes rendering.
  78. */
  79. void frameRenderingFinishedCallback();
  80. /**
  81. * @brief Called by the core thread to begin profiling.
  82. */
  83. void beginCoreProfiling();
  84. /**
  85. * @brief Called by the core thread to end profiling.
  86. */
  87. void endCoreProfiling();
  88. private:
  89. typedef void(*UpdatePluginFunc)();
  90. RenderWindowPtr mPrimaryWindow;
  91. DynLib* mSceneManagerPlugin;
  92. DynLib* mRendererPlugin;
  93. Map<DynLib*, UpdatePluginFunc> mPluginUpdateFunctions;
  94. bool mIsFrameRenderingFinished;
  95. BS_MUTEX(mFrameRenderingFinishedMutex);
  96. BS_THREAD_SYNCHRONISER(mFrameRenderingFinishedCondition);
  97. volatile bool mRunMainLoop;
  98. };
  99. /**
  100. * @brief Provides easy access to primary entry point for the engine.
  101. */
  102. BS_CORE_EXPORT CoreApplication& gCoreApplication();
  103. }