| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- #include "BsApplication.h"
- #include "BsGUIMaterialManager.h"
- #include "BsGUIManager.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"
- #include "BsCoreObjectManager.h"
- #include "BsRendererMaterialManager.h"
- namespace BansheeEngine
- {
- START_UP_DESC createStartUpDesc(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderAPI, const String& renderer)
- {
- START_UP_DESC desc;
- desc.renderAPI = renderAPI;
- 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, RenderAPIPlugin renderAPI, RendererPlugin renderer)
- :CoreApplication(createStartUpDesc(primaryWindowDesc, getLibNameForRenderAPI(renderAPI), getLibNameForRenderer(renderer))),
- mMonoPlugin(nullptr), mSBansheeEnginePlugin(nullptr)
- {
- }
- Application::~Application()
- {
- // Cleanup any new objects queued for destruction by unloaded scripts
- CoreObjectManager::instance().clearDirty();
- gCoreThread().update();
- gCoreThread().submitAccessors(true);
- Cursor::shutDown();
- GUIMaterialManager::instance().clearMaterials();
- ShortcutManager::shutDown();
- GUIManager::shutDown();
- GUIMaterialManager::shutDown();
- BuiltinResources::shutDown();
- RendererMaterialManager::shutDown();
- VirtualInput::shutDown();
- }
- void Application::onStartUp()
- {
- CoreApplication::onStartUp();
- PlainTextImporter* importer = bs_new<PlainTextImporter>();
- Importer::instance()._registerAssetImporter(importer);
- VirtualInput::startUp();
- BuiltinResources::startUp();
- RendererMaterialManager::startUp();
- GUIManager::startUp();
- GUIMaterialManager::startUp();
- ShortcutManager::startUp();
- Cursor::startUp();
- Cursor::instance().setCursor(CursorType::Arrow);
- ScriptManager::startUp();
- loadScriptSystem();
- }
- 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(true);
- ScriptManager::shutDown();
- unloadScriptSystem();
- CoreApplication::onShutDown();
- }
- void Application::startUp(RENDER_WINDOW_DESC& primaryWindowDesc, RenderAPIPlugin renderAPI, RendererPlugin renderer)
- {
- CoreApplication::startUp<Application>(primaryWindowDesc, renderAPI, renderer);
- }
- void Application::preUpdate()
- {
- CoreApplication::preUpdate();
- VirtualInput::instance()._update();
- }
- void Application::postUpdate()
- {
- CoreApplication::postUpdate();
- PROFILE_CALL(GUIManager::instance().update(), "GUI");
- }
- void Application::loadScriptSystem()
- {
- loadPlugin("BansheeMono", &mMonoPlugin);
- loadPlugin("SBansheeEngine", &mSBansheeEnginePlugin);
- ScriptManager::instance().initialize();
- }
- void Application::unloadScriptSystem()
- {
- // 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
- unloadPlugin(mSBansheeEnginePlugin);
- unloadPlugin(mMonoPlugin);
- }
- 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::getLibNameForRenderAPI(RenderAPIPlugin plugin)
- {
- static String DX11Name = "BansheeD3D11RenderAPI";
- static String DX9Name = "BansheeD3D9RenderAPI";
- static String OpenGLName = "BansheeGLRenderAPI";
- switch (plugin)
- {
- case RenderAPIPlugin::DX11:
- return DX11Name;
- case RenderAPIPlugin::DX9:
- return DX9Name;
- case RenderAPIPlugin::OpenGL:
- return OpenGLName;
- }
- return StringUtil::BLANK;
- }
- const String& Application::getLibNameForRenderer(RendererPlugin plugin)
- {
- static String DefaultName = "RenderBeast";
- switch (plugin)
- {
- case RendererPlugin::Default:
- return DefaultName;
- }
-
- return StringUtil::BLANK;
- }
- Application& gApplication()
- {
- return static_cast<Application&>(Application::instance());
- }
- }
|