瀏覽代碼

Refactored how are Application classes structured (they now derive from each other)

Marko Pintera 11 年之前
父節點
當前提交
bb73926921
共有 38 個文件被更改,包括 364 次插入360 次删除
  1. 2 2
      BansheeCore/BansheeCore.vcxproj
  2. 6 6
      BansheeCore/BansheeCore.vcxproj.filters
  3. 12 20
      BansheeCore/Include/BsCoreApplication.h
  4. 1 1
      BansheeCore/Include/CmMeshBaseRTTI.h
  5. 2 2
      BansheeCore/Include/CmPixelUtil.h
  6. 1 1
      BansheeCore/Include/CmTextureRTTI.h
  7. 74 65
      BansheeCore/Source/BsCoreApplication.cpp
  8. 1 1
      BansheeCore/Source/CmMeshManager.cpp
  9. 1 1
      BansheeCore/Source/CmMeshRTTI.h
  10. 1 1
      BansheeCore/Source/CmPixelUtil.cpp
  11. 7 7
      BansheeCore/Source/Win32/CmPlatformImpl.cpp
  12. 2 2
      BansheeCore/Source/Win32/CmPlatformWndProc.cpp
  13. 27 8
      BansheeEditor/Include/BsEditorApplication.h
  14. 1 1
      BansheeEditor/Source/BsDockManager.cpp
  15. 148 154
      BansheeEditor/Source/BsEditorApplication.cpp
  16. 2 2
      BansheeEditor/Source/BsEditorWindowBase.cpp
  17. 1 1
      BansheeEditor/Source/BsGUIWindowDropArea.cpp
  18. 1 1
      BansheeEditor/Source/BsGUIWindowFrame.cpp
  19. 3 3
      BansheeEditor/Source/DbgEditorWidget2.cpp
  20. 10 21
      BansheeEngine/Include/BsApplication.h
  21. 1 1
      BansheeEngine/Include/BsCursor.h
  22. 32 35
      BansheeEngine/Source/BsApplication.cpp
  23. 1 1
      BansheeEngine/Source/BsBuiltinResources.cpp
  24. 4 4
      BansheeEngine/Source/BsCursor.cpp
  25. 2 2
      BansheeEngine/Source/BsDragAndDropManager.cpp
  26. 1 1
      BansheeEngine/Source/BsDrawHelper2D.cpp
  27. 1 1
      BansheeEngine/Source/BsDrawHelper3D.cpp
  28. 1 1
      BansheeEngine/Source/BsDrawHelperTemplate.cpp
  29. 1 1
      BansheeEngine/Source/BsGUIManager.cpp
  30. 1 1
      BansheeEngine/Source/BsGUIWidget.cpp
  31. 1 1
      BansheeFBXImporter/Source/CmFBXImporter.cpp
  32. 1 1
      BansheeFontImporter/Source/CmFontImporter.cpp
  33. 1 1
      BansheeFreeImgImporter/Source/CmFreeImgImporter.cpp
  34. 2 3
      BansheeOISInput/Source/CmOISPlugin.cpp
  35. 1 1
      BansheeRenderer/Source/BsBansheeRenderer.cpp
  36. 1 0
      BansheeUtility/Source/CmTime.cpp
  37. 4 4
      ExampleProject/Main/Main.cpp
  38. 5 1
      Polish.txt

+ 2 - 2
BansheeCore/BansheeCore.vcxproj

@@ -312,7 +312,7 @@
     <ClInclude Include="Include\CmResourceManifest.h" />
     <ClInclude Include="Include\CmResourceManifestRTTI.h" />
     <ClInclude Include="Include\CmSceneObjectRTTI.h" />
-    <ClInclude Include="Include\CmApplication.h" />
+    <ClInclude Include="Include\BsCoreApplication.h" />
     <ClInclude Include="Include\CmBlendStateRTTI.h" />
     <ClInclude Include="Include\CmCommandQueue.h" />
     <ClInclude Include="Include\BsCommonTypes.h" />
@@ -427,7 +427,7 @@
     <ClCompile Include="Source\CmEventQuery.cpp" />
     <ClCompile Include="Source\CmGameObjectHandle.cpp" />
     <ClCompile Include="Source\CmGameObject.cpp" />
-    <ClCompile Include="Source\CmApplication.cpp" />
+    <ClCompile Include="Source\BsCoreApplication.cpp" />
     <ClCompile Include="Source\CmBlendState.cpp" />
     <ClCompile Include="Source\CmCommandQueue.cpp" />
     <ClCompile Include="Source\CmCoreObject.cpp" />

+ 6 - 6
BansheeCore/BansheeCore.vcxproj.filters

@@ -90,9 +90,6 @@
     </Filter>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="Include\CmApplication.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
     <ClInclude Include="Include\CmViewport.h">
       <Filter>Header Files</Filter>
     </ClInclude>
@@ -519,11 +516,11 @@
     <ClInclude Include="Include\BsCommonTypes.h">
       <Filter>Header Files\Utility</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsCoreApplication.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="Source\CmApplication.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\CmViewport.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
@@ -821,5 +818,8 @@
     <ClCompile Include="Source\Win32\CmWin32FolderMonitor.cpp">
       <Filter>Source Files\Platform</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsCoreApplication.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 12 - 20
BansheeCore/Include/CmApplication.h → BansheeCore/Include/BsCoreApplication.h

@@ -25,22 +25,17 @@ namespace BansheeEngine
 	};
 
 	/**
-	 * @brief	Represents the primary entry point to the engine. Handles
+	 * @brief	Represents the primary entry point for the core systems. Handles
 	 *			start-up, shutdown, primary loop and allows you to load and unload
 	 *			plugins.
 	 *
 	 * @note	Sim thread only.
 	 */
-	class BS_CORE_EXPORT Application
+	class BS_CORE_EXPORT CoreApplication : public Module<CoreApplication>
 	{
 		public:
-			Application();
-
-			/**
-			 * @brief	Starts the application using the specified options. 
-			 * 			This is how you start the engine. Must be called before any other engine method.
-			 */
-			void startUp(START_UP_DESC& desc);
+			CoreApplication(START_UP_DESC& desc);
+			virtual ~CoreApplication();
 
 			/**
 			 * @brief	Executes the main loop. This will update your components and modules, queue objects 
@@ -55,11 +50,6 @@ namespace BansheeEngine
 			 */
 			void stopMainLoop();
 
-			/**
-			 * @brief	Frees up all resources allocated during startUp, and while the application was running.
-			 */
-			void shutDown();
-
 			/**
 			 * @brief	
 			 */
@@ -71,20 +61,22 @@ namespace BansheeEngine
 			 * @param	pluginName		Name of the plugin to load, without extension.
 			 * @param	[out] library	Specify as not null to receive a reference to 
 			 *							the loaded library.
+			 * @param	passThrough		Optional parameter that will be passed to the loadPlugin function.
 			 * 
 			 * @returns	Value returned from the plugin start-up method.
 			 */
-			void* loadPlugin(const String& pluginName, DynLib** library = nullptr);
+			void* loadPlugin(const String& pluginName, DynLib** library = nullptr, void* passThrough = nullptr);
 
 			/**
 			 * @brief	Unloads a previously loaded plugin. 
 			 */
 			void unloadPlugin(DynLib* library);
 
-			/**
-			 * @brief	Called every frame by the main loop, after scene update and before rendering.
-			 */
-			Event<void()> mainLoopCallback;
+	protected:
+		/**
+		 * @brief	Called for each iteration of the main loop.
+		 */
+		virtual void update();
 
 	private:
 		/**
@@ -117,5 +109,5 @@ namespace BansheeEngine
 	/**
 	 * @brief	Provides easy access to primary entry point for the engine.
 	 */
-	BS_CORE_EXPORT Application& gApplication();
+	BS_CORE_EXPORT CoreApplication& gCoreApplication();
 }

+ 1 - 1
BansheeCore/Include/CmMeshBaseRTTI.h

@@ -2,7 +2,7 @@
 
 #include "CmPrerequisites.h"
 #include "CmRTTIType.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmMeshBase.h"
 #include "CmException.h"
 

+ 2 - 2
BansheeCore/Include/CmPixelUtil.h

@@ -17,7 +17,7 @@ namespace BansheeEngine
 		enum Filter
 		{
 			FILTER_NEAREST,
-			FILTER_BILINEAR
+			FILTER_LINEAR
 		};
 
 		/**
@@ -176,7 +176,7 @@ namespace BansheeEngine
 		 *			Provided pixel data objects must have previously allocated buffers of adequate size. You may
 		 *			also provided a filtering method to use when scaling.
 		 */
-		static void scale(const PixelData& src, const PixelData& dst, Filter filter = FILTER_BILINEAR);
+		static void scale(const PixelData& src, const PixelData& dst, Filter filter = FILTER_LINEAR);
 
 		/**
 		 * @brief	Applies gamma correction to the pixels in the provided buffer.

+ 1 - 1
BansheeCore/Include/CmTextureRTTI.h

@@ -5,7 +5,7 @@
 #include "CmTexture.h"
 #include "CmManagedDataBlock.h"
 #include "CmMath.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmCoreThread.h"
 #include "CmRenderSystem.h"
 #include "CmTextureManager.h"

+ 74 - 65
BansheeCore/Source/CmApplication.cpp → BansheeCore/Source/BsCoreApplication.cpp

@@ -1,4 +1,4 @@
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 
 #include "CmRenderSystem.h"
 #include "CmRenderSystemManager.h"
@@ -45,13 +45,8 @@
 
 namespace BansheeEngine
 {
-	Application::Application()
+	CoreApplication::CoreApplication(START_UP_DESC& desc)
 		:mPrimaryWindow(nullptr), mIsFrameRenderingFinished(true), mRunMainLoop(false), mSceneManagerPlugin(nullptr)
-	{
-		
-	}
-
-	void Application::startUp(START_UP_DESC& desc)
 	{
 		UINT32 numWorkerThreads = CM_THREAD_HARDWARE_CONCURRENCY - 1; // Number of cores while excluding current thread.
 
@@ -90,13 +85,48 @@ namespace BansheeEngine
 
 		Importer::startUp();
 
-		for(auto& importerName : desc.importers)
+		for (auto& importerName : desc.importers)
 			loadPlugin(importerName);
 
-		loadPlugin(desc.input);
+		loadPlugin(desc.input, nullptr, mPrimaryWindow.get());
+	}
+
+	CoreApplication::~CoreApplication()
+	{
+		mPrimaryWindow->destroy();
+		mPrimaryWindow = nullptr;
+
+		Importer::shutDown();
+		FontManager::shutDown();
+		MaterialManager::shutDown();
+		MeshManager::shutDown();
+
+		unloadPlugin(mSceneManagerPlugin);
+
+		RendererManager::shutDown();
+		RenderSystemManager::shutDown();
+		Input::shutDown();
+
+		GpuProgramManager::shutDown();
+		Resources::shutDown();
+		GameObjectManager::shutDown();
+		CoreObjectManager::shutDown(); // Must shut down before DynLibManager to ensure all objects are destroyed before unloading their libraries
+		DynLibManager::shutDown();
+		Time::shutDown();
+		DeferredCallManager::shutDown();
+		StringTable::shutDown();
+
+		CoreThread::shutDown();
+		TaskScheduler::shutDown();
+		ThreadPool::shutDown();
+		Profiler::shutDown();
+		UUIDGenerator::shutDown();
+
+		MemStack::endThread();
+		Platform::_shutDown();
 	}
 
-	void Application::runMainLoop()
+	void CoreApplication::runMainLoop()
 	{
 		mRunMainLoop = true;
 
@@ -109,14 +139,14 @@ namespace BansheeEngine
 			DeferredCallManager::instance()._update();
 			RenderWindowManager::instance()._update();
 			gInput()._update();
+			gTime().update();
 
 			PROFILE_CALL(gSceneManager()._update(), "SceneManager");
 
-			gCoreThread().queueCommand(std::bind(&Application::beginCoreProfiling, this));
+			gCoreThread().queueCommand(std::bind(&CoreApplication::beginCoreProfiling, this));
 			gCoreThread().queueCommand(std::bind(&QueryManager::_update, QueryManager::instancePtr()));
 
-			if(!mainLoopCallback.empty())
-				mainLoopCallback();
+			update();
 
 			PROFILE_CALL(RendererManager::instance().getActive()->renderAll(), "Render");
 
@@ -139,23 +169,26 @@ namespace BansheeEngine
 
 			gCoreThread().queueCommand(&Platform::_coreUpdate);
 			gCoreThread().submitAccessors();
-			gCoreThread().queueCommand(std::bind(&Application::endCoreProfiling, this));
-			gCoreThread().queueCommand(std::bind(&Application::frameRenderingFinishedCallback, this));
-
-			gTime().update();
+			gCoreThread().queueCommand(std::bind(&CoreApplication::endCoreProfiling, this));
+			gCoreThread().queueCommand(std::bind(&CoreApplication::frameRenderingFinishedCallback, this));
 
 			gProfiler().endThread();
 			gProfiler()._update();
 		}
 	}
 
-	void Application::stopMainLoop()
+	void CoreApplication::update()
+	{
+		// Do nothing
+	}
+
+	void CoreApplication::stopMainLoop()
 	{
 		mRunMainLoop = false; // No sync primitives needed, in that rare case of 
 		// a race condition we might run the loop one extra iteration which is acceptable
 	}
 
-	void Application::frameRenderingFinishedCallback()
+	void CoreApplication::frameRenderingFinishedCallback()
 	{
 		CM_LOCK_MUTEX(mFrameRenderingFinishedMutex);
 
@@ -163,53 +196,18 @@ namespace BansheeEngine
 		CM_THREAD_NOTIFY_ONE(mFrameRenderingFinishedCondition);
 	}
 
-	void Application::beginCoreProfiling()
+	void CoreApplication::beginCoreProfiling()
 	{
 		gProfiler().beginThread("Core");
 	}
 
-	void Application::endCoreProfiling()
+	void CoreApplication::endCoreProfiling()
 	{
 		gProfiler().endThread();
 		gProfiler()._updateCore();
 	}
 
-	void Application::shutDown()
-	{
-		mPrimaryWindow->destroy();
-		mPrimaryWindow = nullptr;
-
-		Importer::shutDown();
-		FontManager::shutDown();
-		MaterialManager::shutDown();
-		MeshManager::shutDown();
-
-		unloadPlugin(mSceneManagerPlugin);
-
-		RendererManager::shutDown();
-		RenderSystemManager::shutDown();
-		Input::shutDown();
-
-		GpuProgramManager::shutDown();
-		Resources::shutDown();
-		GameObjectManager::shutDown();
-		CoreObjectManager::shutDown(); // Must shut down before DynLibManager to ensure all objects are destroyed before unloading their libraries
-		DynLibManager::shutDown();
-		Time::shutDown();
-		DeferredCallManager::shutDown();
-		StringTable::shutDown();
-
-		CoreThread::shutDown();
-		TaskScheduler::shutDown();
-		ThreadPool::shutDown();
-		Profiler::shutDown();
-		UUIDGenerator::shutDown();
-
-		MemStack::endThread();
-		Platform::_shutDown();
-	}
-
-	void* Application::loadPlugin(const String& pluginName, DynLib** library)
+	void* CoreApplication::loadPlugin(const String& pluginName, DynLib** library, void* passThrough)
 	{
 		String name = pluginName;
 #if CM_PLATFORM == CM_PLATFORM_LINUX
@@ -233,18 +231,30 @@ namespace BansheeEngine
 
 		if(loadedLibrary != nullptr)
 		{
-			typedef void* (*LoadPluginFunc)();
+			if (passThrough == nullptr)
+			{
+				typedef void* (*LoadPluginFunc)();
 
-			LoadPluginFunc loadPluginFunc = (LoadPluginFunc)loadedLibrary->getSymbol("loadPlugin");
+				LoadPluginFunc loadPluginFunc = (LoadPluginFunc)loadedLibrary->getSymbol("loadPlugin");
 
-			if(loadPluginFunc != nullptr)
-				return loadPluginFunc();
+				if (loadPluginFunc != nullptr)
+					return loadPluginFunc();
+			}
+			else
+			{
+				typedef void* (*LoadPluginFunc)(void*);
+
+				LoadPluginFunc loadPluginFunc = (LoadPluginFunc)loadedLibrary->getSymbol("loadPlugin");
+
+				if (loadPluginFunc != nullptr)
+					return loadPluginFunc(passThrough);
+			}
 		}
 
 		return nullptr;
 	}
 
-	void Application::unloadPlugin(DynLib* library)
+	void CoreApplication::unloadPlugin(DynLib* library)
 	{
 		typedef void (*UnloadPluginFunc)();
 
@@ -256,9 +266,8 @@ namespace BansheeEngine
 		gDynLibManager().unload(library);
 	}
 
-	Application& gApplication()
+	CoreApplication& gCoreApplication()
 	{
-		static Application application;
-		return application;
+		return CoreApplication::instance();
 	}
 }

+ 1 - 1
BansheeCore/Source/CmMeshManager.cpp

@@ -1,6 +1,6 @@
 #include "CmMeshManager.h"
 #include "CmCoreThreadAccessor.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmVector3.h"
 #include "CmMesh.h"
 #include "CmVertexDataDesc.h"

+ 1 - 1
BansheeCore/Source/CmMeshRTTI.h

@@ -2,7 +2,7 @@
 
 #include "CmPrerequisites.h"
 #include "CmRTTIType.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmMesh.h"
 #include "CmMeshManager.h"
 #include "CmCoreThread.h"

+ 1 - 1
BansheeCore/Source/CmPixelUtil.cpp

@@ -1318,7 +1318,7 @@ namespace BansheeEngine
 
 			break;
 
-		case FILTER_BILINEAR:
+		case FILTER_LINEAR:
 			switch (src.getFormat()) 
 			{
 			case PF_R8G8:

+ 7 - 7
BansheeCore/Source/Win32/CmPlatformImpl.cpp

@@ -1,7 +1,7 @@
 #include "CmPlatform.h"
 #include "CmRenderWindow.h"
 #include "CmPixelUtil.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmDebug.h"
 #include "Win32/CmWin32Defs.h"
 #include "Win32/CmWin32DropTarget.h"
@@ -93,7 +93,7 @@ namespace BansheeEngine
 
 	void Platform::captureMouse(const RenderWindow& window)
 	{
-		RenderWindowPtr primaryWindow = gApplication().getPrimaryWindow();
+		RenderWindowPtr primaryWindow = gCoreApplication().getPrimaryWindow();
 		HWND hwnd;
 		primaryWindow->getCustomAttribute("WINDOW", &hwnd);
 		
@@ -102,7 +102,7 @@ namespace BansheeEngine
 
 	void Platform::releaseMouseCapture()
 	{
-		RenderWindowPtr primaryWindow = gApplication().getPrimaryWindow();
+		RenderWindowPtr primaryWindow = gCoreApplication().getPrimaryWindow();
 		HWND hwnd;
 		primaryWindow->getCustomAttribute("WINDOW", &hwnd);
 
@@ -111,7 +111,7 @@ namespace BansheeEngine
 
 	bool Platform::isPointOverWindow(const RenderWindow& window, const Vector2I& screenPos)
 	{
-		RenderWindowPtr primaryWindow = gApplication().getPrimaryWindow();
+		RenderWindowPtr primaryWindow = gCoreApplication().getPrimaryWindow();
 
 		POINT point;
 		point.x = screenPos.x;
@@ -131,7 +131,7 @@ namespace BansheeEngine
 		// ShowCursor(FALSE) doesn't work. Presumably because we're in the wrong thread, and using
 		// WM_SETCURSOR in message loop to hide the cursor is smarter solution anyway.
 
-		RenderWindowPtr primaryWindow = gApplication().getPrimaryWindow();
+		RenderWindowPtr primaryWindow = gCoreApplication().getPrimaryWindow();
 		HWND hwnd;
 		primaryWindow->getCustomAttribute("WINDOW", &hwnd);
 
@@ -145,7 +145,7 @@ namespace BansheeEngine
 		// ShowCursor(FALSE) doesn't work. Presumably because we're in the wrong thread, and using
 		// WM_SETCURSOR in message loop to hide the cursor is smarter solution anyway.
 
-		RenderWindowPtr primaryWindow = gApplication().getPrimaryWindow();
+		RenderWindowPtr primaryWindow = gCoreApplication().getPrimaryWindow();
 		HWND hwnd;
 		primaryWindow->getCustomAttribute("WINDOW", &hwnd);
 
@@ -252,7 +252,7 @@ namespace BansheeEngine
 		DeleteObject(hMonoBitmap);
 
 		// Make sure we notify the message loop to perform the actual cursor update
-		RenderWindowPtr primaryWindow = gApplication().getPrimaryWindow();
+		RenderWindowPtr primaryWindow = gCoreApplication().getPrimaryWindow();
 		HWND hwnd;
 		primaryWindow->getCustomAttribute("WINDOW", &hwnd);
 

+ 2 - 2
BansheeCore/Source/Win32/CmPlatformWndProc.cpp

@@ -1,6 +1,6 @@
 #include "Win32/CmPlatformWndProc.h"
 #include "CmRenderWindow.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmInput.h"
 #include "CmDebug.h"
 #include "CmRenderWindowManager.h"
@@ -187,7 +187,7 @@ namespace BansheeEngine
 		case WM_CLOSE:
 			{
 				// TODO - Only stop main loop if primary window is closed!!
-				gApplication().stopMainLoop();
+				gCoreApplication().stopMainLoop();
 
 				return 0;
 			}

+ 27 - 8
BansheeEditor/Include/BsEditorApplication.h

@@ -1,7 +1,7 @@
 #pragma once
 
 #include "BsEditorPrerequisites.h"
-#include "CmModule.h"
+#include "BsApplication.h"
 #include "CmPath.h"
 
 namespace BansheeEngine
@@ -13,27 +13,46 @@ namespace BansheeEngine
 		OpenGL
 	};
 
-	class BS_ED_EXPORT EditorApplication : public Module<EditorApplication>
+	class BS_ED_EXPORT EditorApplication : public Application
 	{
 	public:
 		EditorApplication(RenderSystemPlugin renderSystemPlugin);
-		~EditorApplication();
+		virtual ~EditorApplication();
 
-		void runMainLoop();
+		static void startUp(RenderSystemPlugin renderSystemPlugin);
 
 		bool isProjectLoaded() const;
 		const Path& getActiveProjectPath() const;
 	private:
-		static const Path WIDGET_LAYOUT_PATH;
-		RenderSystemPlugin mActiveRSPlugin;
-
 		static const String& getLibraryNameForRenderSystem(RenderSystemPlugin plugin);
 
-		void update();
+		virtual void onStartUp();
+		virtual void update();
 
 		EditorWidgetLayoutPtr loadWidgetLayout();
 		void saveWidgetLayout(const EditorWidgetLayoutPtr& layout);
 
 		static void closeModalWindow(RenderWindowPtr window, HSceneObject sceneObject);
+
+	private:
+		static const Path WIDGET_LAYOUT_PATH;
+		RenderSystemPlugin mActiveRSPlugin;
+
+		// DEBUG ONLY
+
+		HGpuProgram mFragProgRef;
+		HGpuProgram mVertProgRef;
+
+		ShaderPtr mTestShader;
+		TechniquePtr mNewTechniqueGL;
+		PassPtr mNewPassGL;
+		TechniquePtr mNewTechniqueDX;
+		PassPtr mNewPassDX;
+		TechniquePtr mNewTechniqueDX11;
+		PassPtr mNewPassDX11;
+
+		HMaterial mTestMaterial;
+		HTexture mTestTexRef;
+		HMesh mDbgMeshRef;
 	};
 }

+ 1 - 1
BansheeEditor/Source/BsDockManager.cpp

@@ -8,7 +8,7 @@
 #include "CmMaterial.h"
 #include "CmVector2.h"
 #include "CmRenderQueue.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmRendererManager.h"
 #include "CmRenderer.h"
 #include "CmSceneObject.h"

+ 148 - 154
BansheeEditor/Source/BsEditorApplication.cpp

@@ -2,8 +2,6 @@
 #include "BsEditorWindowManager.h"
 #include "BsEditorWidgetManager.h"
 #include "BsMainEditorWindow.h"
-#include "BsApplication.h"
-#include "CmApplication.h"
 #include "CmRenderWindow.h"
 #include "BsEditorGUI.h"
 #include "BsUndoRedo.h"
@@ -41,8 +39,7 @@ namespace BansheeEngine
 {
 	const Path EditorApplication::WIDGET_LAYOUT_PATH = L"Internal\\Layout.asset";
 
-	EditorApplication::EditorApplication(RenderSystemPlugin renderSystemPlugin)
-		:mActiveRSPlugin(renderSystemPlugin)
+	RENDER_WINDOW_DESC createRenderWindowDesc()
 	{
 		RENDER_WINDOW_DESC renderWindowDesc;
 		renderWindowDesc.videoMode = VideoMode(1280, 720);
@@ -50,8 +47,13 @@ namespace BansheeEngine
 		renderWindowDesc.fullscreen = false;
 		renderWindowDesc.border = WindowBorder::None;
 
-		const String& renderSystemLibraryName = getLibraryNameForRenderSystem(renderSystemPlugin);
-		gBansheeApp().startUp(renderWindowDesc, renderSystemLibraryName, "BansheeRenderer"); // TODO - Make renderer and resource cache dir customizable
+		return renderWindowDesc;
+	}
+
+	EditorApplication::EditorApplication(RenderSystemPlugin renderSystemPlugin)
+		:Application(createRenderWindowDesc(), getLibraryNameForRenderSystem(renderSystemPlugin), "BansheeRenderer"), 
+		mActiveRSPlugin(renderSystemPlugin)
+	{
 		EditorGUI::startUp();
 
 		{
@@ -70,14 +72,62 @@ namespace BansheeEngine
 
 		UndoRedo::startUp();
 		EditorWindowManager::startUp();
-
-		MainEditorWindow* mainWindow = MainEditorWindow::create(gApplication().getPrimaryWindow());
 		EditorWidgetManager::startUp();
+	}
+
+	EditorApplication::~EditorApplication()
+	{
+		saveWidgetLayout(EditorWidgetManager::instance().getLayout());
+
+		EditorWidgetManager::shutDown();
+		EditorWindowManager::shutDown();
+		UndoRedo::shutDown();
+
+
+		/************************************************************************/
+		/* 								DEBUG CODE                      		*/
+		/************************************************************************/
+
+		gResources().unload(mTestTexRef);
+		gResources().unload(mDbgMeshRef);
+		gResources().unload(mFragProgRef);
+		gResources().unload(mVertProgRef);
+		gResources().unload(mTestMaterial);
 
-		gApplication().loadPlugin("SBansheeEditor"); // Managed part of the editor
+		mTestMaterial = nullptr;
+		mTestTexRef = nullptr;
+		mDbgMeshRef = nullptr;
+		mFragProgRef = nullptr;
+		mVertProgRef = nullptr;
+
+		mNewPassGL = nullptr;
+		mNewTechniqueGL = nullptr;
+
+		mNewPassDX = nullptr;
+		mNewTechniqueDX = nullptr;
+
+		mNewPassDX11 = nullptr;
+		mNewTechniqueDX11 = nullptr;
+
+		mTestShader = nullptr;
+
+		/************************************************************************/
+		/* 							END DEBUG CODE                      		*/
+		/************************************************************************/
+
+		ProjectLibrary::shutDown();
+		EditorGUI::shutDown();
+	}
+
+	void EditorApplication::onStartUp()
+	{
+		Application::onStartUp();
+
+		MainEditorWindow* mainWindow = MainEditorWindow::create(getPrimaryWindow());
+		loadPlugin("SBansheeEditor"); // Managed part of the editor
 
 		EditorWidgetLayoutPtr layout = loadWidgetLayout();
-		if(layout != nullptr)
+		if (layout != nullptr)
 			EditorWidgetManager::instance().setLayout(layout);
 
 		/************************************************************************/
@@ -85,7 +135,6 @@ namespace BansheeEngine
 		/************************************************************************/
 
 		RenderSystem* renderSystem = RenderSystem::instancePtr();
-		RenderWindowPtr renderWindow = gApplication().getPrimaryWindow();
 
 		HSceneObject testModelGO = SceneObject::create("TestMesh");
 		HRenderable testRenderable = testModelGO->addComponent<Renderable>();
@@ -101,45 +150,45 @@ namespace BansheeEngine
 
 		String language;
 
-		switch (renderSystemPlugin)
+		switch (mActiveRSPlugin)
 		{
 		case RenderSystemPlugin::DX11:
-			{
-				psLoc = L"C:\\Projects\\BansheeEngine\\Data\\hlsl11_ps.gpuprog";
-				vsLoc = L"C:\\Projects\\BansheeEngine\\Data\\hlsl11_vs.gpuprog";
-				language = "hlsl";
-				psProfile = GPP_PS_4_0;
-				vsProfile = GPP_VS_4_0;
-				psEntry = "ps_main";
-				vsEntry = "vs_main";
-				break;
-			}
+		{
+										 psLoc = L"C:\\Projects\\BansheeEngine\\Data\\hlsl11_ps.gpuprog";
+										 vsLoc = L"C:\\Projects\\BansheeEngine\\Data\\hlsl11_vs.gpuprog";
+										 language = "hlsl";
+										 psProfile = GPP_PS_4_0;
+										 vsProfile = GPP_VS_4_0;
+										 psEntry = "ps_main";
+										 vsEntry = "vs_main";
+										 break;
+		}
 		case RenderSystemPlugin::DX9:
-			{
-				psLoc = L"C:\\Projects\\BansheeEngine\\Data\\hlsl9_ps.gpuprog";
-				vsLoc = L"C:\\Projects\\BansheeEngine\\Data\\hlsl9_vs.gpuprog";
-				language = "hlsl";
-				psProfile = GPP_PS_2_0;
-				vsProfile = GPP_VS_2_0;
-				psEntry = "ps_main";
-				vsEntry = "vs_main";
-				break;
-			}
+		{
+										psLoc = L"C:\\Projects\\BansheeEngine\\Data\\hlsl9_ps.gpuprog";
+										vsLoc = L"C:\\Projects\\BansheeEngine\\Data\\hlsl9_vs.gpuprog";
+										language = "hlsl";
+										psProfile = GPP_PS_2_0;
+										vsProfile = GPP_VS_2_0;
+										psEntry = "ps_main";
+										vsEntry = "vs_main";
+										break;
+		}
 		case RenderSystemPlugin::OpenGL:
-			{
-				psLoc = L"C:\\Projects\\BansheeEngine\\Data\\glsl_ps.gpuprog";
-				vsLoc = L"C:\\Projects\\BansheeEngine\\Data\\glsl_vs.gpuprog";
-				language = "glsl";
-				psProfile = GPP_PS_2_0;
-				vsProfile = GPP_VS_2_0;
-				psEntry = "main";
-				vsEntry = "main";
-				break;
-			}
+		{
+										   psLoc = L"C:\\Projects\\BansheeEngine\\Data\\glsl_ps.gpuprog";
+										   vsLoc = L"C:\\Projects\\BansheeEngine\\Data\\glsl_vs.gpuprog";
+										   language = "glsl";
+										   psProfile = GPP_PS_2_0;
+										   vsProfile = GPP_VS_2_0;
+										   psEntry = "main";
+										   vsEntry = "main";
+										   break;
+		}
 		}
 
 		ImportOptionsPtr gpuProgImportOptions = Importer::instance().createImportOptions(psLoc);
-		if(rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
+		if (rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
 		{
 			GpuProgramImportOptions* importOptions = static_cast<GpuProgramImportOptions*>(gpuProgImportOptions.get());
 
@@ -149,10 +198,10 @@ namespace BansheeEngine
 			importOptions->setType(GPT_FRAGMENT_PROGRAM);
 		}
 
-		HGpuProgram fragProgRef = Importer::instance().import(psLoc, gpuProgImportOptions);
+		mFragProgRef = Importer::instance().import(psLoc, gpuProgImportOptions);
 
 		gpuProgImportOptions = Importer::instance().createImportOptions(vsLoc);
-		if(rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
+		if (rtti_is_of_type<GpuProgramImportOptions>(gpuProgImportOptions))
 		{
 			GpuProgramImportOptions* importOptions = static_cast<GpuProgramImportOptions*>(gpuProgImportOptions.get());
 
@@ -162,49 +211,48 @@ namespace BansheeEngine
 			importOptions->setType(GPT_VERTEX_PROGRAM);
 		}
 
-		HGpuProgram vertProgRef = Importer::instance().import(vsLoc, gpuProgImportOptions);
-
-		gResources().save(vertProgRef, L"C:\\vertProgCg.vprog", true);
-		gResources().unload(vertProgRef);
-		vertProgRef = gResources().load(L"C:\\vertProgCg.vprog");
+		mVertProgRef = Importer::instance().import(vsLoc, gpuProgImportOptions);
 
-		gResources().save(fragProgRef, L"C:\\fragProgCg.vprog", true);
-		gResources().unload(fragProgRef);
-		fragProgRef = gResources().load(L"C:\\fragProgCg.vprog");
+		gResources().save(mVertProgRef, L"C:\\vertProgCg.vprog", true);
+		gResources().unload(mVertProgRef);
+		mVertProgRef = gResources().load(L"C:\\vertProgCg.vprog");
 
-		ShaderPtr testShader = Shader::create("TestShader");
+		gResources().save(mFragProgRef, L"C:\\fragProgCg.vprog", true);
+		gResources().unload(mFragProgRef);
+		mFragProgRef = gResources().load(L"C:\\fragProgCg.vprog");
 
-		testShader->addParameter("matViewProjection", "matViewProjection", GPDT_MATRIX_4X4);
+		mTestShader = Shader::create("TestShader");
+		mTestShader->addParameter("matViewProjection", "matViewProjection", GPDT_MATRIX_4X4);
 
-		if(renderSystemPlugin == RenderSystemPlugin::DX11)
-				testShader->addParameter("input", "input", GPDT_STRUCT, 2, 8);
+		if (mActiveRSPlugin == RenderSystemPlugin::DX11)
+			mTestShader->addParameter("input", "input", GPDT_STRUCT, 2, 8);
 
-		testShader->addParameter("samp", "samp", GPOT_SAMPLER2D);
-		testShader->addParameter("tex", "tex", GPOT_TEXTURE2D);
-		TechniquePtr newTechniqueGL = testShader->addTechnique("GLRenderSystem", "BansheeRenderer");
-		PassPtr newPassGL = newTechniqueGL->addPass();
-		newPassGL->setVertexProgram(vertProgRef);
-		newPassGL->setFragmentProgram(fragProgRef);
+		mTestShader->addParameter("samp", "samp", GPOT_SAMPLER2D);
+		mTestShader->addParameter("tex", "tex", GPOT_TEXTURE2D);
+		mNewTechniqueGL = mTestShader->addTechnique("GLRenderSystem", "BansheeRenderer");
+		mNewPassGL = mNewTechniqueGL->addPass();
+		mNewPassGL->setVertexProgram(mVertProgRef);
+		mNewPassGL->setFragmentProgram(mFragProgRef);
 
 		// TODO - I need to create different techniques for different render systems (and renderers, if there were any),
 		// which is redundant as some techniques can be reused. I should add a functionality that supports multiple
 		// render systems/renderers per technique
-		TechniquePtr newTechniqueDX = testShader->addTechnique("D3D9RenderSystem", "BansheeRenderer");
-		PassPtr newPassDX = newTechniqueDX->addPass();
-		newPassDX->setVertexProgram(vertProgRef);
-		newPassDX->setFragmentProgram(fragProgRef);
+		mNewTechniqueDX = mTestShader->addTechnique("D3D9RenderSystem", "BansheeRenderer");
+		mNewPassDX = mNewTechniqueDX->addPass();
+		mNewPassDX->setVertexProgram(mVertProgRef);
+		mNewPassDX->setFragmentProgram(mFragProgRef);
 
-		TechniquePtr newTechniqueDX11 = testShader->addTechnique("D3D11RenderSystem", "BansheeRenderer");
-		PassPtr newPassDX11 = newTechniqueDX11->addPass();
-		newPassDX11->setVertexProgram(vertProgRef);
-		newPassDX11->setFragmentProgram(fragProgRef);
+		mNewTechniqueDX11 = mTestShader->addTechnique("D3D11RenderSystem", "BansheeRenderer");
+		mNewPassDX11 = mNewTechniqueDX11->addPass();
+		mNewPassDX11->setVertexProgram(mVertProgRef);
+		mNewPassDX11->setFragmentProgram(mFragProgRef);
 
-		HMaterial testMaterial = Material::create();
-		testMaterial->setShader(testShader);
+		mTestMaterial = Material::create();
+		mTestMaterial->setShader(mTestShader);
 
-		testMaterial->setMat4("matViewProjection", Matrix4::IDENTITY);
+		mTestMaterial->setMat4("matViewProjection", Matrix4::IDENTITY);
 
-		if(renderSystemPlugin == RenderSystemPlugin::DX11)
+		if (mActiveRSPlugin == RenderSystemPlugin::DX11)
 		{
 			float dbgMultipliers1[2];
 			dbgMultipliers1[0] = 0.0f;
@@ -214,41 +262,41 @@ namespace BansheeEngine
 			dbgMultipliers2[0] = 1.0f;
 			dbgMultipliers2[1] = 1.0f;
 
-			testMaterial->setStructData("input", dbgMultipliers1, sizeof(dbgMultipliers1), 0);
-			testMaterial->setStructData("input", dbgMultipliers2, sizeof(dbgMultipliers2), 1);
+			mTestMaterial->setStructData("input", dbgMultipliers1, sizeof(dbgMultipliers1), 0);
+			mTestMaterial->setStructData("input", dbgMultipliers2, sizeof(dbgMultipliers2), 1);
 		}
 
-		HTexture testTexRef = static_resource_cast<Texture>(Importer::instance().import(L"C:\\ArenaTowerDFS.psd"));
-		HMesh dbgMeshRef = static_resource_cast<Mesh>(Importer::instance().import(L"C:\\X_Arena_Tower.FBX"));
+		mTestTexRef = static_resource_cast<Texture>(Importer::instance().import(L"C:\\ArenaTowerDFS.psd"));
+		mDbgMeshRef = static_resource_cast<Mesh>(Importer::instance().import(L"C:\\X_Arena_Tower.FBX"));
 
-		gResources().save(testTexRef, L"C:\\ExportTest.tex", true);
-		gResources().save(dbgMeshRef, L"C:\\ExportMesh.mesh", true);
+		gResources().save(mTestTexRef, L"C:\\ExportTest.tex", true);
+		gResources().save(mDbgMeshRef, L"C:\\ExportMesh.mesh", true);
 
-		gResources().unload(testTexRef);
-		gResources().unload(dbgMeshRef);
+		gResources().unload(mTestTexRef);
+		gResources().unload(mDbgMeshRef);
 
-		testTexRef = static_resource_cast<Texture>(gResources().loadAsync(L"C:\\ExportTest.tex"));
-		dbgMeshRef = static_resource_cast<Mesh>(gResources().loadAsync(L"C:\\ExportMesh.mesh"));
+		mTestTexRef = static_resource_cast<Texture>(gResources().loadAsync(L"C:\\ExportTest.tex"));
+		mDbgMeshRef = static_resource_cast<Mesh>(gResources().loadAsync(L"C:\\ExportMesh.mesh"));
 
-		dbgMeshRef.synchronize();
-		testTexRef.synchronize();
+		mDbgMeshRef.synchronize();
+		mTestTexRef.synchronize();
 
-		testMaterial->setTexture("tex", testTexRef);
-		gResources().save(testMaterial, L"C:\\ExportMaterial.mat", true);
+		mTestMaterial->setTexture("tex", mTestTexRef);
+		gResources().save(mTestMaterial, L"C:\\ExportMaterial.mat", true);
 
-		gResources().unload(testMaterial);
+		gResources().unload(mTestMaterial);
 
-		testMaterial = gResources().load(L"C:\\ExportMaterial.mat");
+		mTestMaterial = gResources().load(L"C:\\ExportMaterial.mat");
 
-		testRenderable->setMesh(dbgMeshRef);
-		testRenderable->setMaterial(0, testMaterial);
+		testRenderable->setMesh(mDbgMeshRef);
+		testRenderable->setMaterial(0, mTestMaterial);
 
 		GameObjectHandle<DbgTestGameObjectRef> dbgTestGameObjectRef = testModelGO->addComponent<DbgTestGameObjectRef>();
 		dbgTestGameObjectRef->mRenderable = testRenderable;
 
 		HSceneObject clone = testModelGO->clone();
 		GameObjectHandle<DbgTestGameObjectRef> clonedDbgTestGameObjectRef = clone->getComponent<DbgTestGameObjectRef>();
-		
+
 		testModelGO->destroy();
 
 		//Win32FolderMonitor* folderMonitor = cm_new<Win32FolderMonitor>();
@@ -303,57 +351,13 @@ namespace BansheeEngine
 		/* 							END DEBUG CODE                      		*/
 		/************************************************************************/
 
-		gApplication().mainLoopCallback.connect(std::bind(&EditorApplication::update, this));
-
 		DbgEditorWidget1::open(); // DEBUG ONLY
 		DbgEditorWidget2::open(); // DEBUG ONLY
+	}
 
-		gBansheeApp().runMainLoop();
-
-		saveWidgetLayout(EditorWidgetManager::instance().getLayout());
-
-		EditorWidgetManager::shutDown();
-		EditorWindowManager::shutDown();
-		UndoRedo::shutDown();
-
-
-		/************************************************************************/
-		/* 								DEBUG CODE                      		*/
-		/************************************************************************/
-
-		gResources().unload(testTexRef);
-		gResources().unload(dbgMeshRef);
-		gResources().unload(fragProgRef);
-		gResources().unload(vertProgRef);
-		gResources().unload(testMaterial);
-
-		testMaterial = nullptr;
-		testTexRef = nullptr;
-		dbgMeshRef = nullptr;
-		fragProgRef = nullptr;
-		vertProgRef = nullptr;
-
-		newPassGL = nullptr;
-		newTechniqueGL = nullptr;
-
-		newPassDX = nullptr;
-		newTechniqueDX = nullptr;
-
-		newPassDX11 = nullptr;
-		newTechniqueDX11 = nullptr;
-
-		testShader = nullptr;
-
-		renderWindow = nullptr;
-
-		/************************************************************************/
-		/* 							END DEBUG CODE                      		*/
-		/************************************************************************/
-
-		ProjectLibrary::shutDown();
-		EditorGUI::shutDown();
-		gBansheeApp().shutDown();
-
+	void EditorApplication::startUp(RenderSystemPlugin renderSystemPlugin)
+	{
+		CoreApplication::startUp<EditorApplication>(renderSystemPlugin);
 	}
 
 	void EditorApplication::closeModalWindow(RenderWindowPtr window, HSceneObject sceneObject)
@@ -362,20 +366,10 @@ namespace BansheeEngine
 		window->destroy();
 	}
 
-	EditorApplication::~EditorApplication()
-	{
-		// TODO - Move shutdown code from constructor to here. Right now I don't care because cleanup 
-		// isn't working as intended and if I move stuff I will probably break it even more
-	}
-
-	void EditorApplication::runMainLoop()
-	{
-		// TODO - Move "runMainLoop" code from constructor to here. Right now I don't care because cleanup 
-		// isn't working as intended and if I move stuff I will probably break it even more
-	}
-
 	void EditorApplication::update()
 	{
+		Application::update();
+
 		ProjectLibrary::instance().update();
 		EditorWindowManager::instance().update();	
 	}

+ 2 - 2
BansheeEditor/Source/BsEditorWindowBase.cpp

@@ -1,5 +1,5 @@
 #include "BsEditorWindowBase.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmCoreThread.h"
 #include "CmSceneObject.h"
 #include "CmRenderWindow.h"
@@ -21,7 +21,7 @@ namespace BansheeEngine
 		renderWindowDesc.border = WindowBorder::None;
 		renderWindowDesc.toolWindow = true;
 
-		mRenderWindow = RenderWindow::create(renderWindowDesc, gApplication().getPrimaryWindow());
+		mRenderWindow = RenderWindow::create(renderWindowDesc, gCoreApplication().getPrimaryWindow());
 
 		construct(mRenderWindow);
 	}

+ 1 - 1
BansheeEditor/Source/BsGUIWindowDropArea.cpp

@@ -1,5 +1,5 @@
 #include "BsGUIWindowDropArea.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmTexture.h"
 #include "BsGUIWidget.h"
 #include "BsGUISkin.h"

+ 1 - 1
BansheeEditor/Source/BsGUIWindowFrame.cpp

@@ -5,7 +5,7 @@
 #include "BsSpriteTexture.h"
 #include "BsGUILayoutOptions.h"
 #include "BsGUIMouseEvent.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmPlatform.h"
 #include "CmTexture.h"
 #include "CmRenderWindow.h"

+ 3 - 3
BansheeEditor/Source/DbgEditorWidget2.cpp

@@ -21,7 +21,7 @@
 #include "CmHString.h"
 
 #include "CmCoreThread.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 
 namespace BansheeEngine
 {
@@ -31,12 +31,12 @@ namespace BansheeEngine
 	{
 		if (cm_dbg_fullscreen)
 		{
-			gCoreAccessor().setWindowed(gApplication().getPrimaryWindow());
+			gCoreAccessor().setWindowed(gCoreApplication().getPrimaryWindow());
 		}
 		else
 		{
 			//gCoreAccessor().setFullscreen(window, *videoMode);
-			gCoreAccessor().setFullscreen(gApplication().getPrimaryWindow(), 1920, 1200, 60, 0);
+			gCoreAccessor().setFullscreen(gCoreApplication().getPrimaryWindow(), 1920, 1200, 60, 0);
 		}
 
 		cm_dbg_fullscreen = !cm_dbg_fullscreen;

+ 10 - 21
BansheeEngine/Include/BsApplication.h

@@ -1,40 +1,29 @@
 #pragma once
 
 #include "BsPrerequisites.h"
+#include "BsCoreApplication.h"
 #include "BsEvent.h"
 
 namespace BansheeEngine
 {
-	class BS_EXPORT BsApplication
+	class BS_EXPORT Application : public CoreApplication
 	{
 	public:
-			BsApplication();
+		Application(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer);
+		virtual ~Application();
 
-			/**
-			 * @brief	Starts the application using the specified options. 
-			 * 			This is how you start the engine.
-			 */
-			void startUp(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer);
+		static void startUp(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer);
 
-			/**
-			 * @brief	Executes the main loop. This will cause actually rendering to be performed
-			 * 			and simulation to be run. Usually called immediately after startUp().
-			 */
-			void runMainLoop();
+		const ViewportPtr& getPrimaryViewport() const;
+	protected:
+		virtual void onStartUp();
 
-			/**
-			 * @brief	Frees up all resources allocated during startUp, and while the application was running.
-			 */
-			void shutDown();
+		virtual void update();
 
-			const ViewportPtr& getPrimaryViewport() const;
 	private:
-		HEvent updateCallbackConn;
 		DynLib* mMonoPlugin;
 		DynLib* mSBansheeEnginePlugin;
-
-		void update();
 	};
 
-	BS_EXPORT BsApplication& gBansheeApp();
+	BS_EXPORT Application& gApplication();
 }

+ 1 - 1
BansheeEngine/Include/BsCursor.h

@@ -114,7 +114,7 @@ namespace BansheeEngine
 		UnorderedMap<String, UINT32> mCustomIconNameToId;
 		UnorderedMap<UINT32, CustomIcon> mCustomIcons;
 		UINT32 mNextUniqueId;
-		UINT32 mActiveCursorId;
+		INT32 mActiveCursorId;
 
 		void restoreCursorIcon(CursorType type);
 		void updateCursorImage();

+ 32 - 35
BansheeEngine/Source/BsApplication.cpp

@@ -10,24 +10,17 @@
 #include "BsGLBuiltinMaterialFactory.h"
 #include "BsBuiltinResources.h"
 #include "BsScriptManager.h"
-#include "CmApplication.h"
 #include "CmProfiler.h"
 #include "BsVirtualInput.h"
 #include "BsCursor.h"
 
 namespace BansheeEngine
 {
-	BsApplication::BsApplication()
-		:mMonoPlugin(nullptr), mSBansheeEnginePlugin(nullptr)
-	{
-
-	}
-
-	void BsApplication::startUp(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer)
+	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.renderer = renderer;
 		desc.primaryWindowDesc = primaryWindowDesc;
 
 		desc.input = "BansheeOISInput";
@@ -35,9 +28,13 @@ namespace BansheeEngine
 		desc.importers.push_back("BansheeFreeImgImporter");
 		desc.importers.push_back("BansheeFBXImporter");
 		desc.importers.push_back("BansheeFontImporter");
-		
-		gApplication().startUp(desc);
 
+		return desc;
+	}
+
+	Application::Application(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer)
+		:CoreApplication(createStartUpDesc(primaryWindowDesc, renderSystem, renderer)), mMonoPlugin(nullptr), mSBansheeEnginePlugin(nullptr)
+	{
 		VirtualInput::startUp();
 		ScriptManager::startUp();
 		GUIManager::startUp();
@@ -48,7 +45,7 @@ namespace BansheeEngine
 		BuiltinMaterialManager::instance().addFactory(cm_new<D3D9BuiltinMaterialFactory>());
 		BuiltinMaterialManager::instance().addFactory(cm_new<D3D11BuiltinMaterialFactory>());
 		BuiltinMaterialManager::instance().addFactory(cm_new<GLBuiltinMaterialFactory>());
-		BuiltinMaterialManager::instance().setActive(desc.renderSystem);
+		BuiltinMaterialManager::instance().setActive(renderSystem);
 
 		DrawHelper2D::startUp();
 		DrawHelper3D::startUp();
@@ -56,26 +53,15 @@ namespace BansheeEngine
 		BuiltinResources::startUp();
 		Cursor::startUp();
 
-		gApplication().loadPlugin("BansheeMono", &mMonoPlugin);
-		gApplication().loadPlugin("SBansheeEngine", &mSBansheeEnginePlugin); // Scripting interface
-		
-		updateCallbackConn = gApplication().mainLoopCallback.connect(std::bind(&BsApplication::update, this));
-
-		Cursor::instance().setCursor(CursorType::Arrow);
-	}
-
-	void BsApplication::runMainLoop()
-	{
-		gApplication().runMainLoop();
+		loadPlugin("BansheeMono", &mMonoPlugin);
+		loadPlugin("SBansheeEngine", &mSBansheeEnginePlugin); // Scripting interface
 	}
 
-	void BsApplication::shutDown()
+	Application::~Application()
 	{
-		updateCallbackConn.disconnect();
-
 		ScriptManager::instance().destroy();
-		gApplication().unloadPlugin(mSBansheeEnginePlugin);
-		gApplication().unloadPlugin(mMonoPlugin);
+		unloadPlugin(mSBansheeEnginePlugin);
+		unloadPlugin(mMonoPlugin);
 
 		Cursor::shutDown();
 		BuiltinResources::shutDown();
@@ -92,25 +78,36 @@ namespace BansheeEngine
 		GUIMaterialManager::shutDown();
 		ScriptManager::shutDown();
 		VirtualInput::shutDown();
-		
-		gApplication().shutDown();
 	}
 
-	void BsApplication::update()
+	void Application::onStartUp()
 	{
+		CoreApplication::onStartUp();
+
+		Cursor::instance().setCursor(CursorType::Arrow);
+	}
+
+	void Application::startUp(RENDER_WINDOW_DESC& primaryWindowDesc, const String& renderSystem, const String& renderer)
+	{
+		CoreApplication::startUp<Application>(primaryWindowDesc, renderSystem, renderer);
+	}
+
+	void Application::update()
+	{
+		CoreApplication::update();
+
 		VirtualInput::instance().update();
 		PROFILE_CALL(GUIManager::instance().update(), "GUI");
 	}
 
-	const ViewportPtr& BsApplication::getPrimaryViewport() const
+	const ViewportPtr& Application::getPrimaryViewport() const
 	{
 		// TODO - Need a way to determine primary viewport!
 		return nullptr;
 	}
 
-	BsApplication& gBansheeApp()
+	Application& gApplication()
 	{
-		static BsApplication application;
-		return application;
+		return static_cast<Application&>(Application::instance());
 	}
 }

+ 1 - 1
BansheeEngine/Source/BsBuiltinResources.cpp

@@ -13,7 +13,7 @@
 #include "CmImporter.h"
 #include "CmRTTIType.h"
 #include "CmFileSystem.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmCoreThread.h"
 
 namespace BansheeEngine

+ 4 - 4
BansheeEngine/Source/BsCursor.cpp

@@ -6,13 +6,10 @@
 namespace BansheeEngine
 {
 	Cursor::Cursor()
-		:mActiveCursorId(0), mNextUniqueId((UINT32)CursorType::Count)
+		:mActiveCursorId(-1), mNextUniqueId((UINT32)CursorType::Count)
 	{
 		for(UINT32 i = 0; i < (UINT32)CursorType::Count; i++)
 			restoreCursorIcon((CursorType)i);
-
-		setCursor(CursorType::Arrow);
-		updateCursorImage();
 	}
 
 	void Cursor::setScreenPosition(const Vector2I& screenPos)
@@ -169,6 +166,9 @@ namespace BansheeEngine
 
 	void Cursor::updateCursorImage()
 	{
+		if (mActiveCursorId < 0)
+			return;
+
 		CustomIcon& customIcon = mCustomIcons[mActiveCursorId];
 		Platform::setCursor(customIcon.pixelData, customIcon.hotSpot);
 	}

+ 2 - 2
BansheeEngine/Source/BsDragAndDropManager.cpp

@@ -1,6 +1,6 @@
 #include "BsDragAndDropManager.h"
 #include "CmPlatform.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 
 using namespace std::placeholders;
 
@@ -29,7 +29,7 @@ namespace BansheeEngine
 		mCaptureActive.store(false);
 		mCaptureChanged.store(false);
 
-		Platform::captureMouse(*gApplication().getPrimaryWindow());
+		Platform::captureMouse(*gCoreApplication().getPrimaryWindow());
 	}
 
 	void DragAndDropManager::update()

+ 1 - 1
BansheeEngine/Source/BsDrawHelper2D.cpp

@@ -5,7 +5,7 @@
 #include "CmVector2.h"
 #include "CmMaterial.h"
 #include "CmPass.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmRenderQueue.h"
 #include "BsCamera.h"
 #include "CmCoreThreadAccessor.h"

+ 1 - 1
BansheeEngine/Source/BsDrawHelper3D.cpp

@@ -5,7 +5,7 @@
 #include "CmVector2.h"
 #include "CmMaterial.h"
 #include "CmPass.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmRenderQueue.h"
 #include "CmException.h"
 #include "BsCamera.h"

+ 1 - 1
BansheeEngine/Source/BsDrawHelperTemplate.cpp

@@ -5,7 +5,7 @@
 #include "CmVector2.h"
 #include "CmMaterial.h"
 #include "CmPass.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmRenderQueue.h"
 #include "BsCamera.h"
 #include "BsBuiltinMaterialManager.h"

+ 1 - 1
BansheeEngine/Source/BsGUIManager.cpp

@@ -13,7 +13,7 @@
 #include "CmRenderWindowManager.h"
 #include "CmPlatform.h"
 #include "CmRectI.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmException.h"
 #include "CmInput.h"
 #include "CmPass.h"

+ 1 - 1
BansheeEngine/Source/BsGUIWidget.cpp

@@ -4,7 +4,7 @@
 #include "BsGUILabel.h"
 #include "BsGUIMouseEvent.h"
 #include "BsGUIArea.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmCoreThreadAccessor.h"
 #include "CmMaterial.h"
 #include "CmPass.h"

+ 1 - 1
BansheeFBXImporter/Source/CmFBXImporter.cpp

@@ -1,6 +1,6 @@
 #include "CmFBXImporter.h"
 #include "CmResource.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmDebug.h"
 #include "CmDataStream.h"
 #include "CmPath.h"

+ 1 - 1
BansheeFontImporter/Source/CmFontImporter.cpp

@@ -6,7 +6,7 @@
 #include "CmDebug.h"
 #include "CmPath.h"
 #include "CmTexAtlasGenerator.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmCoreThread.h"
 #include "CmCoreThreadAccessor.h"
 

+ 1 - 1
BansheeFreeImgImporter/Source/CmFreeImgImporter.cpp

@@ -7,7 +7,7 @@
 #include "CmTextureManager.h"
 #include "CmTexture.h"
 #include "CmFileSystem.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmCoreThread.h"
 #include "CmCoreThreadAccessor.h"
 

+ 2 - 3
BansheeOISInput/Source/CmOISPlugin.cpp

@@ -1,7 +1,6 @@
 #include "CmOISPrerequisites.h"
 #include "CmInputHandlerOIS.h"
 #include "CmRenderWindow.h"
-#include "CmApplication.h"
 #include "CmInput.h"
 
 namespace BansheeEngine
@@ -18,9 +17,9 @@ namespace BansheeEngine
 	/**
 	 * @brief	Entry point to the plugin. Called by the engine when the plugin is loaded.
 	 */
-	extern "C" BS_OIS_EXPORT void* loadPlugin()
+	extern "C" BS_OIS_EXPORT void* loadPlugin(void* primaryWindowPtr)
 	{
-		RenderWindowPtr primaryWindow = gApplication().getPrimaryWindow();
+		RenderWindow* primaryWindow = (RenderWindow*)primaryWindowPtr;
 
 		if (primaryWindow == nullptr)
 			assert(false && "Unable to get window handle. No active window exists!");

+ 1 - 1
BansheeRenderer/Source/BsBansheeRenderer.cpp

@@ -8,7 +8,7 @@
 #include "CmBlendState.h"
 #include "CmRasterizerState.h"
 #include "CmDepthStencilState.h"
-#include "CmApplication.h"
+#include "BsCoreApplication.h"
 #include "CmViewport.h"
 #include "CmRenderTarget.h"
 #include "CmRenderOperation.h"

+ 1 - 0
BansheeUtility/Source/CmTime.cpp

@@ -10,6 +10,7 @@ namespace BansheeEngine
 	{
 		mTimer = cm_new<Timer>();
 		mAppStartTime = (UINT64)mTimer->getStartMs();
+		mLastFrameTime = mTimer->getMicroseconds();
 	}
 
 	Time::~Time()

+ 4 - 4
ExampleProject/Main/Main.cpp

@@ -122,7 +122,7 @@ namespace BansheeEngine
 		// Set up scene camera
 		HSceneObject sceneCameraGO = SceneObject::create("SceneCamera");
 
-		RenderWindowPtr window = gApplication().getPrimaryWindow(); // TODO - Up until now I'm using gBansheeApp and now I'm using gApplication. It's confusing. BansheeApp should derive from application
+		RenderWindowPtr window = gApplication().getPrimaryWindow();
 		sceneCamera = sceneCameraGO->addComponent<Camera>(window, 0.0f, 0.0f, 1.0f, 1.0f);
 
 		sceneCamera->setPriority(1);
@@ -193,11 +193,11 @@ int CALLBACK WinMain(
 	renderWindowDesc.title = "Banshee Example App";
 	renderWindowDesc.fullscreen = false;
 
-	gBansheeApp().startUp(renderWindowDesc, "BansheeD3D11RenderSystem", "BansheeRenderer"); // TODO - Use enums instead of names. BansheeApp is a high level system that doesn't need to be as customizable.
+	Application::startUp(renderWindowDesc, "BansheeD3D11RenderSystem", "BansheeRenderer"); // TODO - Use enums instead of names. BansheeApp is a high level system that doesn't need to be as customizable.
 	setUpExample();
 	
-	gBansheeApp().runMainLoop();
-	gBansheeApp().shutDown();
+	Application::instance().runMainLoop();
+	Application::shutDown();
 
 	return 0;
 }

+ 5 - 1
Polish.txt

@@ -33,4 +33,8 @@ DISREGARD MONITOR INDEX ON DX9
  - If I merge CmApp and BsApp consider refactoring CmApplication::mainLoopCallback
 
 Consider renaming Profiler to CPUProfiler and CPUProfiler to something else. Since now I have GPUProfiler it's confusing to have one named just Profiler.
-Profiler can only be called from sim/core thread which is also a bit weird.
+Profiler can only be called from sim/core thread which is also a bit weird.
+
+Find and rename any other CM_ defines
+
+Rename CamelotOIS external library