BsApplication.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #include "BsApplication.h"
  2. #include "BsGUIMaterialManager.h"
  3. #include "BsGUIManager.h"
  4. #include "BsOverlayManager.h"
  5. #include "BsShapeMeshes2D.h"
  6. #include "BsShapeMeshes3D.h"
  7. #include "BsBuiltinResources.h"
  8. #include "BsScriptManager.h"
  9. #include "BsProfilingManager.h"
  10. #include "BsVirtualInput.h"
  11. #include "BsSceneManager.h"
  12. #include "BsSceneObject.h"
  13. #include "BsCursor.h"
  14. #include "BsCoreThread.h"
  15. #include "BsFileSystem.h"
  16. #include "BsPlainTextImporter.h"
  17. #include "BsImporter.h"
  18. #include "BsShortcutManager.h"
  19. namespace BansheeEngine
  20. {
  21. START_UP_DESC createStartUpDesc(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer)
  22. {
  23. START_UP_DESC desc;
  24. desc.renderSystem = renderSystem;
  25. desc.renderer = renderer;
  26. desc.primaryWindowDesc = primaryWindowDesc;
  27. desc.input = "BansheeOISInput";
  28. desc.importers.push_back("BansheeFreeImgImporter");
  29. desc.importers.push_back("BansheeFBXImporter");
  30. desc.importers.push_back("BansheeFontImporter");
  31. desc.importers.push_back("BansheeSL");
  32. return desc;
  33. }
  34. Application::Application(RENDER_WINDOW_DESC& primaryWindowDesc, RenderSystemPlugin renderSystem, RendererPlugin renderer)
  35. :CoreApplication(createStartUpDesc(primaryWindowDesc, getLibNameForRenderSystem(renderSystem), getLibNameForRenderer(renderer))),
  36. mMonoPlugin(nullptr), mSBansheeEnginePlugin(nullptr)
  37. {
  38. }
  39. Application::~Application()
  40. {
  41. // Cleanup any new objects queued for destruction by unloaded scripts
  42. gCoreThread().update();
  43. gCoreThread().submitAccessors(true);
  44. Cursor::shutDown();
  45. GUIMaterialManager::instance().clearMaterials();
  46. ShortcutManager::shutDown();
  47. OverlayManager::shutDown();
  48. GUIManager::shutDown();
  49. GUIMaterialManager::shutDown();
  50. BuiltinResources::shutDown();
  51. ScriptManager::shutDown();
  52. VirtualInput::shutDown();
  53. }
  54. void Application::onStartUp()
  55. {
  56. CoreApplication::onStartUp();
  57. PlainTextImporter* importer = bs_new<PlainTextImporter>();
  58. Importer::instance()._registerAssetImporter(importer);
  59. VirtualInput::startUp();
  60. ScriptManager::startUp();
  61. BuiltinResources::startUp();
  62. GUIManager::startUp();
  63. GUIMaterialManager::startUp();
  64. OverlayManager::startUp();
  65. ShortcutManager::startUp();
  66. Cursor::startUp();
  67. #if BS_VER == BS_VER_DEV
  68. loadPlugin("BansheeMono", &mMonoPlugin);
  69. loadPlugin("SBansheeEngine", &mSBansheeEnginePlugin); // Scripting interface
  70. #endif
  71. Cursor::instance().setCursor(CursorType::Arrow);
  72. }
  73. void Application::onShutDown()
  74. {
  75. // Need to clear all objects before I unload any plugins, as they
  76. // could have allocated parts or all of those objects.
  77. SceneManager::instance().clearScene();
  78. // These plugins must be unloaded before any other script plugins, because
  79. // they will cause finalizers to trigger and various modules those finalizers
  80. // might reference must still be active
  81. #if BS_VER == BS_VER_DEV
  82. shutdownPlugin(mSBansheeEnginePlugin);
  83. unloadPlugin(mSBansheeEnginePlugin);
  84. shutdownPlugin(mMonoPlugin);
  85. unloadPlugin(mMonoPlugin);
  86. #endif
  87. CoreApplication::onShutDown();
  88. }
  89. void Application::startUp(RENDER_WINDOW_DESC& primaryWindowDesc, RenderSystemPlugin renderSystem, RendererPlugin renderer)
  90. {
  91. CoreApplication::startUp<Application>(primaryWindowDesc, renderSystem, renderer);
  92. }
  93. void Application::postUpdate()
  94. {
  95. CoreApplication::postUpdate();
  96. VirtualInput::instance()._update();
  97. PROFILE_CALL(GUIManager::instance().update(), "GUI");
  98. }
  99. ViewportPtr Application::getPrimaryViewport() const
  100. {
  101. // TODO - Need a way to determine primary viewport!
  102. return nullptr;
  103. }
  104. Path Application::getEngineAssemblyPath() const
  105. {
  106. Path assemblyPath = getBuiltinAssemblyFolder();
  107. assemblyPath.append(toWString(String(ENGINE_ASSEMBLY)) + L".dll");
  108. return assemblyPath;
  109. }
  110. Path Application::getGameAssemblyPath() const
  111. {
  112. Path assemblyPath = getScriptAssemblyFolder();
  113. assemblyPath.append(toWString(String(SCRIPT_GAME_ASSEMBLY)) + L".dll");
  114. return assemblyPath;
  115. }
  116. Path Application::getBuiltinAssemblyFolder() const
  117. {
  118. Path assemblyFolder = FileSystem::getWorkingDirectoryPath();
  119. assemblyFolder.append(ASSEMBLY_PATH);
  120. return assemblyFolder;
  121. }
  122. Path Application::getScriptAssemblyFolder() const
  123. {
  124. Path assemblyFolder = FileSystem::getWorkingDirectoryPath();
  125. assemblyFolder.append(ASSEMBLY_PATH);
  126. return assemblyFolder;
  127. }
  128. const String& Application::getLibNameForRenderSystem(RenderSystemPlugin plugin)
  129. {
  130. static String DX11Name = "BansheeD3D11RenderSystem";
  131. static String DX9Name = "BansheeD3D9RenderSystem";
  132. static String OpenGLName = "BansheeGLRenderSystem";
  133. switch (plugin)
  134. {
  135. case RenderSystemPlugin::DX11:
  136. return DX11Name;
  137. case RenderSystemPlugin::DX9:
  138. return DX9Name;
  139. case RenderSystemPlugin::OpenGL:
  140. return OpenGLName;
  141. }
  142. return StringUtil::BLANK;
  143. }
  144. const String& Application::getLibNameForRenderer(RendererPlugin plugin)
  145. {
  146. static String DefaultName = "BansheeRenderer";
  147. switch (plugin)
  148. {
  149. case RendererPlugin::Default:
  150. return DefaultName;
  151. }
  152. return StringUtil::BLANK;
  153. }
  154. Application& gApplication()
  155. {
  156. return static_cast<Application&>(Application::instance());
  157. }
  158. }