BsApplication.cpp 5.0 KB

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