CmApplication.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmCoreThreadAccessor.h"
  4. #include "CmHighLevelGpuProgram.h"
  5. #include "CmRenderWindow.h"
  6. #include "boost/signal.hpp"
  7. namespace CamelotFramework
  8. {
  9. class RenderWindow;
  10. class Viewport;
  11. class HighLevelGpuProgramManager;
  12. }
  13. namespace CamelotFramework
  14. {
  15. struct START_UP_DESC
  16. {
  17. String renderSystem;
  18. String renderer;
  19. String input;
  20. String sceneManager;
  21. RENDER_WINDOW_DESC primaryWindowDesc;
  22. Vector<String>::type importers;
  23. String resourceCacheDirectory;
  24. };
  25. class CM_EXPORT Application
  26. {
  27. public:
  28. Application();
  29. /**
  30. * @brief Starts the application using the specified options.
  31. * This is how you start the engine.
  32. */
  33. void startUp(START_UP_DESC& desc);
  34. /**
  35. * @brief Executes the main loop. This will cause actually rendering to be performed
  36. * and simulation to be run. Usually called immediately after startUp().
  37. *
  38. * This will run infinitely until stopMainLoop is called (usually from another thread or internally).
  39. */
  40. void runMainLoop();
  41. /**
  42. * @brief Stops a (infinite) main loop from running. The loop will complete its current cycle before stopping.
  43. * You may call this from other threads.
  44. */
  45. void stopMainLoop();
  46. /**
  47. * @brief Frees up all resources allocated during startUp, and while the application was running.
  48. */
  49. void shutDown();
  50. UINT64 getAppWindowId();
  51. RenderWindowPtr getPrimaryWindow() const { return mPrimaryWindow; }
  52. /**
  53. * @brief Loads a plugin.
  54. *
  55. * @param pluginName Name of the plugin to load, without extension.
  56. */
  57. void* loadPlugin(const String& pluginName);
  58. /**
  59. * @brief Called every frame by the main loop, after scene update and before rendering.
  60. */
  61. boost::signal<void()> mainLoopCallback;
  62. private:
  63. friend CM_EXPORT CoreAccessor& gMainCA();
  64. friend CM_EXPORT SyncedCoreAccessor& gMainSyncedCA();
  65. RenderWindowPtr mPrimaryWindow;
  66. CoreAccessorPtr mPrimaryCoreAccessor;
  67. SyncedCoreAccessor* mPrimarySyncedCoreAccessor;
  68. bool mIsFrameRenderingFinished;
  69. CM_MUTEX(mFrameRenderingFinishedMutex);
  70. CM_THREAD_SYNCHRONISER(mFrameRenderingFinishedCondition);
  71. volatile bool mRunMainLoop;
  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. };
  85. CM_EXPORT Application& gApplication();
  86. /**
  87. * @brief A shortcut for accessing the primary core accessor. It may only be accessed safely
  88. * from the main thread.
  89. */
  90. CM_EXPORT CoreAccessor& gMainCA();
  91. /**
  92. * @brief A shortcut for accessing the primary synchronized core accessor. This accessor may be accessed
  93. * from all threads except the core thread. All operations from this accessor will be executed after
  94. * non-synchronized primary accessor has finished executing.
  95. *
  96. * @note It is more efficient to create your own non-synchronized core accessor if you plan on often using it from
  97. * threads other than main.
  98. */
  99. CM_EXPORT SyncedCoreAccessor& gMainSyncedCA();
  100. }