CmApplication.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCoreThreadAccessor.h"
  4. #include "CmRenderWindow.h"
  5. #include "BsEvent.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Structure containing parameters for starting the application.
  10. */
  11. struct START_UP_DESC
  12. {
  13. String renderSystem; /**< Name of the render system plugin to use. */
  14. String renderer; /**< Name of the renderer plugin to use. */
  15. String input; /**< Name of the input plugin to use. */
  16. String sceneManager; /**< Name of the scene manager plugin to use. */
  17. RENDER_WINDOW_DESC primaryWindowDesc; /**< Describes the window to create during start-up. */
  18. Vector<String> importers; /**< A list of importer plugins to load. */
  19. };
  20. /**
  21. * @brief Represents the primary entry point to the engine. Handles
  22. * start-up, shutdown, primary loop and allows you to load and unload
  23. * plugins.
  24. *
  25. * @note Sim thread only.
  26. */
  27. class CM_EXPORT Application
  28. {
  29. public:
  30. Application();
  31. /**
  32. * @brief Starts the application using the specified options.
  33. * This is how you start the engine. Must be called before any other engine method.
  34. */
  35. void startUp(START_UP_DESC& desc);
  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 Frees up all resources allocated during startUp, and while the application was running.
  49. */
  50. void shutDown();
  51. // DEPRECATED
  52. UINT64 getAppWindowId();
  53. /**
  54. * @brief
  55. */
  56. RenderWindowPtr getPrimaryWindow() const { return mPrimaryWindow; }
  57. /**
  58. * @brief Loads a plugin.
  59. *
  60. * @param pluginName Name of the plugin to load, without extension.
  61. * @param [out] library Specify as not null to receive a reference to
  62. * the loaded library.
  63. *
  64. * @returns Value returned from the plugin start-up method.
  65. */
  66. void* loadPlugin(const String& pluginName, DynLib** library = nullptr);
  67. /**
  68. * @brief Unloads a previously loaded plugin.
  69. */
  70. void unloadPlugin(DynLib* library);
  71. /**
  72. * @brief Called every frame by the main loop, after scene update and before rendering.
  73. */
  74. Event<void()> mainLoopCallback;
  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. RenderWindowPtr mPrimaryWindow;
  90. DynLib* mSceneManagerPlugin;
  91. bool mIsFrameRenderingFinished;
  92. CM_MUTEX(mFrameRenderingFinishedMutex);
  93. CM_THREAD_SYNCHRONISER(mFrameRenderingFinishedCondition);
  94. volatile bool mRunMainLoop;
  95. };
  96. /**
  97. * @brief Provides easy access to primary entry point for the engine.
  98. */
  99. CM_EXPORT Application& gApplication();
  100. }