BsApplication.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. return desc;
  32. }
  33. Application::Application(RENDER_WINDOW_DESC& primaryWindowDesc, RenderSystemPlugin renderSystem, RendererPlugin renderer)
  34. :CoreApplication(createStartUpDesc(primaryWindowDesc, getLibNameForRenderSystem(renderSystem), getLibNameForRenderer(renderer))),
  35. mMonoPlugin(nullptr), mSBansheeEnginePlugin(nullptr)
  36. {
  37. PlainTextImporter* importer = bs_new<PlainTextImporter>();
  38. Importer::instance()._registerAssetImporter(importer);
  39. VirtualInput::startUp();
  40. ScriptManager::startUp();
  41. BuiltinResources::startUp(renderSystem);
  42. GUIManager::startUp();
  43. GUIMaterialManager::startUp();
  44. OverlayManager::startUp();
  45. ShortcutManager::startUp();
  46. Cursor::startUp();
  47. }
  48. Application::~Application()
  49. {
  50. // Need to clear all objects before I unload any plugins, as they
  51. // could have allocated parts or all of those objects.
  52. SceneManager::instance().clearScene();
  53. #if BS_VER == BS_VER_DEV
  54. shutdownPlugin(mSBansheeEnginePlugin);
  55. unloadPlugin(mSBansheeEnginePlugin);
  56. shutdownPlugin(mMonoPlugin);
  57. unloadPlugin(mMonoPlugin);
  58. #endif
  59. // Cleanup any new objects queued for destruction by unloaded scripts
  60. gCoreThread().update();
  61. gCoreThread().submitAccessors(true);
  62. Cursor::shutDown();
  63. GUIMaterialManager::instance().clearMaterials();
  64. ShortcutManager::shutDown();
  65. OverlayManager::shutDown();
  66. GUIManager::shutDown();
  67. GUIMaterialManager::shutDown();
  68. BuiltinResources::shutDown();
  69. ScriptManager::shutDown();
  70. VirtualInput::shutDown();
  71. }
  72. void Application::onStartUp()
  73. {
  74. #if BS_VER == BS_VER_DEV
  75. loadPlugin("BansheeMono", &mMonoPlugin);
  76. loadPlugin("SBansheeEngine", &mSBansheeEnginePlugin); // Scripting interface
  77. #endif
  78. CoreApplication::onStartUp();
  79. Cursor::instance().setCursor(CursorType::Arrow);
  80. }
  81. void Application::startUp(RENDER_WINDOW_DESC& primaryWindowDesc, RenderSystemPlugin renderSystem, RendererPlugin renderer)
  82. {
  83. CoreApplication::startUp<Application>(primaryWindowDesc, renderSystem, renderer);
  84. }
  85. void Application::postUpdate()
  86. {
  87. CoreApplication::postUpdate();
  88. VirtualInput::instance()._update();
  89. PROFILE_CALL(GUIManager::instance().update(), "GUI");
  90. }
  91. ViewportPtr Application::getPrimaryViewport() const
  92. {
  93. // TODO - Need a way to determine primary viewport!
  94. return nullptr;
  95. }
  96. Path Application::getEngineAssemblyPath() const
  97. {
  98. Path assemblyPath = getBuiltinAssemblyFolder();
  99. assemblyPath.append(toWString(String(ENGINE_ASSEMBLY)) + L".dll");
  100. return assemblyPath;
  101. }
  102. Path Application::getGameAssemblyPath() const
  103. {
  104. Path assemblyPath = getScriptAssemblyFolder();
  105. assemblyPath.append(toWString(String(SCRIPT_GAME_ASSEMBLY)) + L".dll");
  106. return assemblyPath;
  107. }
  108. Path Application::getBuiltinAssemblyFolder() const
  109. {
  110. Path assemblyFolder = FileSystem::getWorkingDirectoryPath();
  111. assemblyFolder.append(ASSEMBLY_PATH);
  112. return assemblyFolder;
  113. }
  114. Path Application::getScriptAssemblyFolder() const
  115. {
  116. Path assemblyFolder = FileSystem::getWorkingDirectoryPath();
  117. assemblyFolder.append(ASSEMBLY_PATH);
  118. return assemblyFolder;
  119. }
  120. const String& Application::getLibNameForRenderSystem(RenderSystemPlugin plugin)
  121. {
  122. static String DX11Name = "BansheeD3D11RenderSystem";
  123. static String DX9Name = "BansheeD3D9RenderSystem";
  124. static String OpenGLName = "BansheeGLRenderSystem";
  125. switch (plugin)
  126. {
  127. case RenderSystemPlugin::DX11:
  128. return DX11Name;
  129. case RenderSystemPlugin::DX9:
  130. return DX9Name;
  131. case RenderSystemPlugin::OpenGL:
  132. return OpenGLName;
  133. }
  134. return StringUtil::BLANK;
  135. }
  136. const String& Application::getLibNameForRenderer(RendererPlugin plugin)
  137. {
  138. static String DefaultName = "BansheeRenderer";
  139. switch (plugin)
  140. {
  141. case RendererPlugin::Default:
  142. return DefaultName;
  143. }
  144. return StringUtil::BLANK;
  145. }
  146. Application& gApplication()
  147. {
  148. return static_cast<Application&>(Application::instance());
  149. }
  150. }