BsCoreApplication.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //__________________________ Banshee Project - A modern game development toolkit _________________________________//
  2. //_____________________________________ www.banshee-project.com __________________________________________________//
  3. //________________________ Copyright (c) 2014 Marko Pintera. All rights reserved. ________________________________//
  4. #pragma once
  5. #include "BsCorePrerequisites.h"
  6. #include "BsModule.h"
  7. #include "BsCoreThreadAccessor.h"
  8. #include "BsRenderWindow.h"
  9. #include "BsEvent.h"
  10. namespace BansheeEngine
  11. {
  12. /**
  13. * @brief Structure containing parameters for starting the application.
  14. */
  15. struct START_UP_DESC
  16. {
  17. String renderSystem; /**< Name of the render system plugin to use. */
  18. String renderer; /**< Name of the renderer plugin to use. */
  19. String input; /**< Name of the input plugin to use. */
  20. String sceneManager; /**< Name of the scene manager plugin to use. */
  21. RENDER_WINDOW_DESC primaryWindowDesc; /**< Describes the window to create during start-up. */
  22. Vector<String> importers; /**< A list of importer plugins to load. */
  23. };
  24. /**
  25. * @brief Represents the primary entry point for the core systems. Handles
  26. * start-up, shutdown, primary loop and allows you to load and unload
  27. * plugins.
  28. *
  29. * @note Sim thread only.
  30. */
  31. class BS_CORE_EXPORT CoreApplication : public Module<CoreApplication>
  32. {
  33. public:
  34. CoreApplication(START_UP_DESC& desc);
  35. virtual ~CoreApplication();
  36. /**
  37. * @brief Executes the main loop. This will update your components and modules, queue objects
  38. * for rendering and run the simulation. Usually called immediately after startUp().
  39. *
  40. * This will run infinitely until stopMainLoop is called (usually from another thread or internally).
  41. */
  42. void runMainLoop();
  43. /**
  44. * @brief Stops a (infinite) main loop from running. The loop will complete its current cycle before stopping.
  45. */
  46. void stopMainLoop();
  47. /**
  48. * @brief
  49. */
  50. RenderWindowPtr getPrimaryWindow() const { return mPrimaryWindow; }
  51. /**
  52. * @brief Loads a plugin.
  53. *
  54. * @param pluginName Name of the plugin to load, without extension.
  55. * @param [out] library Specify as not null to receive a reference to
  56. * the loaded library.
  57. * @param passThrough Optional parameter that will be passed to the loadPlugin function.
  58. *
  59. * @returns Value returned from the plugin start-up method.
  60. */
  61. void* loadPlugin(const String& pluginName, DynLib** library = nullptr, void* passThrough = nullptr);
  62. /**
  63. * @brief Unloads a previously loaded plugin.
  64. */
  65. void unloadPlugin(DynLib* library);
  66. protected:
  67. /**
  68. * @brief Called for each iteration of the main loop.
  69. */
  70. virtual void update();
  71. private:
  72. /**
  73. * @brief Called when the frame finishes rendering.
  74. */
  75. void frameRenderingFinishedCallback();
  76. /**
  77. * @brief Called by the core thread to begin profiling.
  78. */
  79. void beginCoreProfiling();
  80. /**
  81. * @brief Called by the core thread to end profiling.
  82. */
  83. void endCoreProfiling();
  84. private:
  85. RenderWindowPtr mPrimaryWindow;
  86. DynLib* mSceneManagerPlugin;
  87. DynLib* mRendererPlugin;
  88. bool mIsFrameRenderingFinished;
  89. BS_MUTEX(mFrameRenderingFinishedMutex);
  90. BS_THREAD_SYNCHRONISER(mFrameRenderingFinishedCondition);
  91. volatile bool mRunMainLoop;
  92. };
  93. /**
  94. * @brief Provides easy access to primary entry point for the engine.
  95. */
  96. BS_CORE_EXPORT CoreApplication& gCoreApplication();
  97. }