CmApplication.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCoreThreadAccessor.h"
  4. #include "CmRenderWindow.h"
  5. #include "BsEvent.h"
  6. namespace BansheeEngine
  7. {
  8. class RenderWindow;
  9. class Viewport;
  10. class GpuProgramManager;
  11. }
  12. namespace BansheeEngine
  13. {
  14. struct START_UP_DESC
  15. {
  16. String renderSystem;
  17. String renderer;
  18. String input;
  19. String sceneManager;
  20. RENDER_WINDOW_DESC primaryWindowDesc;
  21. Vector<String> importers;
  22. };
  23. class CM_EXPORT Application
  24. {
  25. public:
  26. Application();
  27. /**
  28. * @brief Starts the application using the specified options.
  29. * This is how you start the engine.
  30. */
  31. void startUp(START_UP_DESC& desc);
  32. /**
  33. * @brief Executes the main loop. This will cause actually rendering to be performed
  34. * and simulation to be run. Usually called immediately after startUp().
  35. *
  36. * This will run infinitely until stopMainLoop is called (usually from another thread or internally).
  37. */
  38. void runMainLoop();
  39. /**
  40. * @brief Stops a (infinite) main loop from running. The loop will complete its current cycle before stopping.
  41. * You may call this from other threads.
  42. */
  43. void stopMainLoop();
  44. /**
  45. * @brief Frees up all resources allocated during startUp, and while the application was running.
  46. */
  47. void shutDown();
  48. UINT64 getAppWindowId();
  49. RenderWindowPtr getPrimaryWindow() const { return mPrimaryWindow; }
  50. /**
  51. * @brief Loads a plugin.
  52. *
  53. * @param pluginName Name of the plugin to load, without extension.
  54. */
  55. void* loadPlugin(const String& pluginName, DynLib** library = nullptr);
  56. /**
  57. * @brief Unloads a plugin.
  58. */
  59. void unloadPlugin(DynLib* library);
  60. /**
  61. * @brief Called every frame by the main loop, after scene update and before rendering.
  62. */
  63. Event<void()> mainLoopCallback;
  64. private:
  65. RenderWindowPtr mPrimaryWindow;
  66. DynLib* mSceneManagerPlugin;
  67. bool mIsFrameRenderingFinished;
  68. CM_MUTEX(mFrameRenderingFinishedMutex);
  69. CM_THREAD_SYNCHRONISER(mFrameRenderingFinishedCondition);
  70. volatile bool mRunMainLoop;
  71. /**
  72. * @brief Called when the frame finishes rendering.
  73. */
  74. void frameRenderingFinishedCallback();
  75. /**
  76. * @brief Called by the core thread to begin profiling.
  77. */
  78. void beginCoreProfiling();
  79. /**
  80. * @brief Called by the core thread to end profiling.
  81. */
  82. void endCoreProfiling();
  83. };
  84. CM_EXPORT Application& gApplication();
  85. }