| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #include "BsApplication.h"
- #include "BsGUIMaterialManager.h"
- #include "BsGUIManager.h"
- #include "BsOverlayManager.h"
- #include "BsShapeMeshes2D.h"
- #include "BsShapeMeshes3D.h"
- #include "BsBuiltinResources.h"
- #include "BsScriptManager.h"
- #include "BsProfilingManager.h"
- #include "BsVirtualInput.h"
- #include "BsSceneManager.h"
- #include "BsSceneObject.h"
- #include "BsCursor.h"
- #include "BsCoreThread.h"
- #include "BsFileSystem.h"
- #include "BsPlainTextImporter.h"
- #include "BsImporter.h"
- #include "BsShortcutManager.h"
- namespace BansheeEngine
- {
- START_UP_DESC createStartUpDesc(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer)
- {
- START_UP_DESC desc;
- desc.renderSystem = renderSystem;
- desc.renderer = renderer;
- desc.primaryWindowDesc = primaryWindowDesc;
- desc.input = "BansheeOISInput";
- desc.importers.push_back("BansheeFreeImgImporter");
- desc.importers.push_back("BansheeFBXImporter");
- desc.importers.push_back("BansheeFontImporter");
- desc.importers.push_back("BansheeSL");
- return desc;
- }
- Application::Application(RENDER_WINDOW_DESC& primaryWindowDesc, RenderSystemPlugin renderSystem, RendererPlugin renderer)
- :CoreApplication(createStartUpDesc(primaryWindowDesc, getLibNameForRenderSystem(renderSystem), getLibNameForRenderer(renderer))),
- mMonoPlugin(nullptr), mSBansheeEnginePlugin(nullptr)
- {
- }
- Application::~Application()
- {
- // Cleanup any new objects queued for destruction by unloaded scripts
- gCoreThread().update();
- gCoreThread().submitAccessors(true);
- Cursor::shutDown();
- GUIMaterialManager::instance().clearMaterials();
- ShortcutManager::shutDown();
- OverlayManager::shutDown();
- GUIManager::shutDown();
- GUIMaterialManager::shutDown();
- BuiltinResources::shutDown();
- ScriptManager::shutDown();
- VirtualInput::shutDown();
- }
- void Application::onStartUp()
- {
- CoreApplication::onStartUp();
- PlainTextImporter* importer = bs_new<PlainTextImporter>();
- Importer::instance()._registerAssetImporter(importer);
- VirtualInput::startUp();
- ScriptManager::startUp();
- BuiltinResources::startUp();
- GUIManager::startUp();
- GUIMaterialManager::startUp();
- OverlayManager::startUp();
- ShortcutManager::startUp();
- Cursor::startUp();
- #if BS_VER == BS_VER_DEV
- loadPlugin("BansheeMono", &mMonoPlugin);
- loadPlugin("SBansheeEngine", &mSBansheeEnginePlugin); // Scripting interface
- #endif
- Cursor::instance().setCursor(CursorType::Arrow);
- }
- void Application::onShutDown()
- {
- // Need to clear all objects before I unload any plugins, as they
- // could have allocated parts or all of those objects.
- SceneManager::instance().clearScene();
- // These plugins must be unloaded before any other script plugins, because
- // they will cause finalizers to trigger and various modules those finalizers
- // might reference must still be active
- #if BS_VER == BS_VER_DEV
- shutdownPlugin(mSBansheeEnginePlugin);
- unloadPlugin(mSBansheeEnginePlugin);
- shutdownPlugin(mMonoPlugin);
- unloadPlugin(mMonoPlugin);
- #endif
- CoreApplication::onShutDown();
- }
- void Application::startUp(RENDER_WINDOW_DESC& primaryWindowDesc, RenderSystemPlugin renderSystem, RendererPlugin renderer)
- {
- CoreApplication::startUp<Application>(primaryWindowDesc, renderSystem, renderer);
- }
- void Application::postUpdate()
- {
- CoreApplication::postUpdate();
- VirtualInput::instance()._update();
- PROFILE_CALL(GUIManager::instance().update(), "GUI");
- }
- ViewportPtr Application::getPrimaryViewport() const
- {
- // TODO - Need a way to determine primary viewport!
- return nullptr;
- }
- Path Application::getEngineAssemblyPath() const
- {
- Path assemblyPath = getBuiltinAssemblyFolder();
- assemblyPath.append(toWString(String(ENGINE_ASSEMBLY)) + L".dll");
-
- return assemblyPath;
- }
- Path Application::getGameAssemblyPath() const
- {
- Path assemblyPath = getScriptAssemblyFolder();
- assemblyPath.append(toWString(String(SCRIPT_GAME_ASSEMBLY)) + L".dll");
- return assemblyPath;
- }
- Path Application::getBuiltinAssemblyFolder() const
- {
- Path assemblyFolder = FileSystem::getWorkingDirectoryPath();
- assemblyFolder.append(ASSEMBLY_PATH);
- return assemblyFolder;
- }
- Path Application::getScriptAssemblyFolder() const
- {
- Path assemblyFolder = FileSystem::getWorkingDirectoryPath();
- assemblyFolder.append(ASSEMBLY_PATH);
- return assemblyFolder;
- }
- const String& Application::getLibNameForRenderSystem(RenderSystemPlugin plugin)
- {
- static String DX11Name = "BansheeD3D11RenderSystem";
- static String DX9Name = "BansheeD3D9RenderSystem";
- static String OpenGLName = "BansheeGLRenderSystem";
- switch (plugin)
- {
- case RenderSystemPlugin::DX11:
- return DX11Name;
- case RenderSystemPlugin::DX9:
- return DX9Name;
- case RenderSystemPlugin::OpenGL:
- return OpenGLName;
- }
- return StringUtil::BLANK;
- }
- const String& Application::getLibNameForRenderer(RendererPlugin plugin)
- {
- static String DefaultName = "BansheeRenderer";
- switch (plugin)
- {
- case RendererPlugin::Default:
- return DefaultName;
- }
-
- return StringUtil::BLANK;
- }
- Application& gApplication()
- {
- return static_cast<Application&>(Application::instance());
- }
- }
|