Просмотр исходного кода

Create Banshee App and made sure everything runs so far
Continuing porting to Banshee

Marko Pintera 13 лет назад
Родитель
Сommit
630371789b

+ 2 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -146,6 +146,7 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClInclude Include="Include\BsApplication.h" />
     <ClInclude Include="Include\BsPrerequisites.h" />
     <ClInclude Include="Include\BsGUIElement.h" />
     <ClInclude Include="Include\BsGUIElementStyle.h" />
@@ -162,6 +163,7 @@
     <ClInclude Include="Include\BsTextSprite.h" />
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="Source\BsApplication.cpp" />
     <ClCompile Include="Source\BsGUIElement.cpp" />
     <ClCompile Include="Source\BsGUILabel.cpp" />
     <ClCompile Include="Source\BsGUIManager.cpp" />

+ 6 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -69,6 +69,9 @@
     <ClInclude Include="Include\BsTextSprite.h">
       <Filter>Header Files\2D</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsApplication.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -101,5 +104,8 @@
     <ClCompile Include="Source\BsTextSprite.cpp">
       <Filter>Source Files\2D</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsApplication.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 31 - 0
BansheeEngine/Include/BsApplication.h

@@ -0,0 +1,31 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+
+namespace BansheeEngine
+{
+	class BS_EXPORT Application
+	{
+	public:
+			Application();
+
+			/**
+			 * @brief	Starts the application using the specified options. 
+			 * 			This is how you start the engine.
+			 */
+			void startUp(const CM::String& renderSystem, const CM::String& renderer, const CM::String& resourceCacheDir);
+
+			/**
+			 * @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();
+
+			/**
+			 * @brief	Frees up all resources allocated during startUp, and while the application was running.
+			 */
+			void shutDown();
+	};
+
+	BS_EXPORT Application& gBansheeApp();
+}

+ 2 - 0
BansheeEngine/Include/BsGUIMaterialManager.h

@@ -37,6 +37,8 @@ namespace BansheeEngine
 		 * 			and their textures when they are no longer being used.
 		 */
 		void releaseMaterial(const CM::HMaterial& material) const;
+
+		void forceReleaseAllMaterials();
 	private:
 		struct GUIMaterial
 		{

+ 1 - 1
BansheeEngine/Include/BsGUIWidget.h

@@ -17,7 +17,7 @@ namespace BansheeEngine
 
 		virtual void render(const CM::Camera* camera, CM::DeferredRenderContextPtr& renderContext) const;
 	protected:
-		friend class SceneObject;
+		friend class CM::SceneObject;
 		friend class GUIElement;
 
 		GUIWidget(const CM::HSceneObject& parent);

+ 53 - 0
BansheeEngine/Source/BsApplication.cpp

@@ -0,0 +1,53 @@
+#include "BsApplication.h"
+#include "BsGUIMaterialManager.h"
+#include "BsGUIManager.h"
+#include "CmApplication.h"
+
+using namespace CamelotEngine;
+
+namespace BansheeEngine
+{
+	Application::Application()
+	{
+
+	}
+
+	void Application::startUp(const String& renderSystem, const String& renderer, const String& resourceCacheDir)
+	{
+		CM::START_UP_DESC desc;
+		desc.renderSystem = renderSystem;
+		desc.renderer= renderer;
+		desc.resourceCacheDirectory = resourceCacheDir;
+
+		desc.input = "CamelotOISInput";
+		desc.importers.push_back("CamelotFreeImgImporter");
+		desc.importers.push_back("CamelotFBXImporter");
+		desc.importers.push_back("CamelotFontImporter");
+
+		CM::gApplication().startUp(desc);
+
+		GUIManager::startUp(CM_NEW(GUIManager, GenAlloc) GUIManager());
+		GUIMaterialManager::startUp(CM_NEW(GUIMaterialManager, GenAlloc) GUIMaterialManager());
+	}
+
+	void Application::runMainLoop()
+	{
+		CM::gApplication().runMainLoop();
+	}
+
+	void Application::shutDown()
+	{
+		GUIMaterialManager::instance().forceReleaseAllMaterials();
+
+		CM::gApplication().shutDown();
+
+		GUIMaterialManager::shutDown();
+		GUIManager::shutDown();
+	}
+
+	Application& gBansheeApp()
+	{
+		static Application application;
+		return application;
+	}
+}

+ 5 - 4
BansheeEngine/Source/BsGUIMaterialManager.cpp

@@ -86,10 +86,11 @@ namespace BansheeEngine
 
 			i++;
 		}
+	}
 
-		if(!released)
-		{
-			LOGWRN("Trying to release a material that doesn't exist in the GUI Manager. Material ID: " + toString(material->getInternalID()));
-		}
+	void GUIMaterialManager::forceReleaseAllMaterials()
+	{
+		mTextMaterials.clear();
+		mImageMaterials.clear();
 	}
 }

+ 10 - 8
CamelotClient/CamelotClient.cpp

@@ -1,6 +1,7 @@
 #include "stdafx.h"
 #include <windows.h>
 
+#include "BsApplication.h"
 #include "CmApplication.h"
 #include "CmDynLibManager.h"
 
@@ -33,6 +34,7 @@
 
 using namespace CamelotEngine;
 using namespace CamelotEditor;
+using namespace BansheeEngine;
 
 int CALLBACK WinMain(
 	_In_  HINSTANCE hInstance,
@@ -42,11 +44,11 @@ int CALLBACK WinMain(
 	)
 {
 #ifdef DX11
-	gApplication().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer");
+	gBansheeApp().startUp("CamelotD3D11RenderSystem", "CamelotForwardRenderer", "D:\\CamelotResourceMetas");
 #elif defined DX9
-	gApplication().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer");
+	gBansheeApp().startUp("CamelotD3D9RenderSystem", "CamelotForwardRenderer", "D:\\CamelotResourceMetas");
 #else
-	gApplication().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer");
+	gBansheeApp().startUp("CamelotGLRenderSystem", "CamelotForwardRenderer", "D:\\CamelotResourceMetas");
 #endif
 
 	//CommandQueue::addBreakpoint(1, 11);
@@ -68,8 +70,8 @@ int CALLBACK WinMain(
 	HSceneObject testModelGO = SceneObject::create("TestMesh");
 	HRenderable testRenderable = testModelGO->addComponent<Renderable>();
 
-	//HSceneObject testTextGO = SceneObject::create("TestText");
-	//GameObjectHandle<TestTextSprite> textSprite = testTextGO->addComponent<TestTextSprite>();
+	HSceneObject testTextGO = SceneObject::create("TestText");
+	GameObjectHandle<TestTextSprite> textSprite = testTextGO->addComponent<TestTextSprite>();
 
 	HFont font;
 	
@@ -87,7 +89,7 @@ int CALLBACK WinMain(
 		font = Importer::instance().import("C:\\arial.ttf", fontImportOptions);
 	}
 
-	//textSprite->setText(camera, "Testing in a new row, does this work?", font, 12);
+	textSprite->setText(camera, "Testing in a new row, does this work?", font, 12);
 
 #if defined DX9
 	///////////////// HLSL 9 SHADERS //////////////////////////
@@ -279,7 +281,7 @@ int CALLBACK WinMain(
 	
 	EditorWindow* newWindow = new EditorWindow("Test window", font, 12);
 
-	gApplication().runMainLoop();
+	gBansheeApp().runMainLoop();
 
 	// Release everything before shutdown
 	
@@ -319,7 +321,7 @@ int CALLBACK WinMain(
 	
 	renderWindow = nullptr;
 	
-	gApplication().shutDown();
+	gBansheeApp().shutDown();
 
 	return 0;
 }

+ 2 - 4
CamelotClient/CmTestTextSprite.cpp

@@ -21,10 +21,8 @@ namespace CamelotEngine
 
 	TestTextSprite::~TestTextSprite()
 	{
-
-		// TODO - temporarily not deleting this
-		//if(mSkin != nullptr)
-		//	CM_DELETE(mSkin, GUISkin, PoolAlloc);
+		if(mSkin != nullptr)
+			CM_DELETE(mSkin, GUISkin, PoolAlloc);
 	}
 
 	void TestTextSprite::setText(const HCamera& camera, const String& text, HFont font, UINT32 fontSize)

+ 1 - 1
CamelotClient/CmTestTextSprite.h

@@ -6,7 +6,7 @@ namespace CamelotEngine
 	class TestTextSprite : public BansheeEngine::GUIWidget
 	{
 	protected:
-		friend class SceneObject;
+		friend class CM::SceneObject;
 
 		TestTextSprite(const HSceneObject& parent);
 

+ 1 - 2
CamelotCore/CamelotCore.vcxproj

@@ -120,7 +120,7 @@
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;CM_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>./Include;../CamelotUtility/Include;../Dependencies/Include;../BansheeEngine/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>./Include;../CamelotUtility/Include;../Dependencies/Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
@@ -295,7 +295,6 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Include\CmMaterialManager.cpp" />
-    <ClCompile Include="Source\CamelotRenderer.cpp" />
     <ClCompile Include="Source\CmBuiltinMaterialManager.cpp" />
     <ClCompile Include="Source\CmGameObjectHandle.cpp" />
     <ClCompile Include="Source\CmGameObject.cpp" />

+ 0 - 3
CamelotCore/CamelotCore.vcxproj.filters

@@ -443,9 +443,6 @@
     </ClInclude>
   </ItemGroup>
   <ItemGroup>
-    <ClCompile Include="Source\CamelotRenderer.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
     <ClCompile Include="Source\CmApplication.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>

+ 13 - 1
CamelotCore/Include/CmApplication.h

@@ -13,6 +13,18 @@ namespace CamelotEngine
 
 namespace CamelotEngine
 {
+	struct START_UP_DESC
+	{
+		String renderSystem;
+		String renderer;
+
+		String input;
+
+		std::vector<String> importers;
+
+		String resourceCacheDirectory;
+	};
+
 	class CM_EXPORT Application
 	{
 		public:
@@ -22,7 +34,7 @@ namespace CamelotEngine
 			 * @brief	Starts the application using the specified options. 
 			 * 			This is how you start the engine.
 			 */
-			void startUp(const String& renderSystemDll, const String& rendererDll);
+			void startUp(const START_UP_DESC& desc);
 
 			/**
 			 * @brief	Executes the main loop. This will cause actually rendering to be performed

+ 1 - 1
CamelotCore/Include/CmOverlay.h

@@ -20,7 +20,7 @@ namespace CamelotEngine
 		virtual void update() {}
 
 	protected:
-		friend class SceneObject;
+		friend class CamelotEngine::SceneObject;
 
 		Overlay(const HSceneObject& parent);
 	};

+ 0 - 38
CamelotCore/Source/CamelotRenderer.cpp

@@ -1,38 +0,0 @@
-// CamelotRenderer.cpp : Defines the entry point for the console application.
-//
-
-#include "stdafx.h"
-
-#include <string>
-
-#include "CmColor.h"
-#include "CmMath.h"
-#include "CmMatrix3.h"
-#include "CmMatrix4.h"
-#include "CmPlane.h"
-#include "CmPrerequisites.h"
-#include "CmQuaternion.h"
-#include "CmString.h"
-#include "CmVector2.h"
-#include "CmVector3.h"
-#include "CmVector4.h"
-#include "CmHardwareBuffer.h"
-#include "CmRenderSystem.h"
-
-#include "CmApplication.h"
-
-using namespace CamelotEngine;
-
-int _tmain(int argc, _TCHAR* argv[])
-{
-	//const String& name = CamelotEngine::gApplication().getRenderSystem()->getName();
-
-	gApplication().startUp("RenderSystemD3D9.dll", "");
-
-	int a = 5;
-
-	gApplication().shutDown();
-
-	return 0;
-}
-

+ 9 - 9
CamelotCore/Source/CmApplication.cpp

@@ -42,22 +42,22 @@ namespace CamelotEngine
 		:mPrimaryRenderWindow(nullptr), mIsFrameRenderingFinished(true), mRunMainLoop(false)
 	{ }
 
-	void Application::startUp(const String& renderSystemName, const String& rendererName)
+	void Application::startUp(const START_UP_DESC& desc)
 	{
 		Time::startUp(CM_NEW(Time, GenAlloc) Time());
 		Input::startUp(CM_NEW(Input, GenAlloc) Input());
 		DynLibManager::startUp(CM_NEW(DynLibManager, GenAlloc) DynLibManager());
 		CoreGpuObjectManager::startUp(CM_NEW(CoreGpuObjectManager, GenAlloc) CoreGpuObjectManager());
-		Resources::startUp(CM_NEW(Resources, GenAlloc) Resources("D:\\CamelotResourceMetas"));
+		Resources::startUp(CM_NEW(Resources, GenAlloc) Resources(desc.resourceCacheDirectory));
 		HighLevelGpuProgramManager::startUp(CM_NEW(HighLevelGpuProgramManager, GenAlloc) HighLevelGpuProgramManager());
 
 		RenderSystemManager::startUp(CM_NEW(RenderSystemManager, GenAlloc) RenderSystemManager());
-		RenderSystemManager::instance().setActive(renderSystemName);
+		RenderSystemManager::instance().setActive(desc.renderSystem);
 
 		RendererManager::startUp(CM_NEW(RendererManager, GenAlloc) RendererManager());
 
-		loadPlugin(rendererName);
-		RendererManager::instance().setActive("ForwardRenderer");
+		loadPlugin(desc.renderer);
+		RendererManager::instance().setActive(desc.renderer);
 
 		RenderSystem* renderSystem = RenderSystem::instancePtr();
 
@@ -85,11 +85,11 @@ namespace CamelotEngine
 
 
 		Importer::startUp(CM_NEW(Importer, GenAlloc) Importer());
-		loadPlugin("CamelotFreeImgImporter"); // TODO - Load this automatically somehow
-		loadPlugin("CamelotFBXImporter"); // TODO - Load this automatically somehow
-		loadPlugin("CamelotFontImporter"); // TODO - Load this automatically somehow
 
-		loadPlugin("CamelotOISInput"); // TODO - Load this automatically somehow
+		for(auto& importerName : desc.importers)
+			loadPlugin(importerName);
+
+		loadPlugin(desc.input);
 	}
 
 	void Application::runMainLoop()

+ 0 - 8
CamelotEngine.sln

@@ -90,15 +90,7 @@ EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BansheeEngine", "BansheeEngine\BansheeEngine.vcxproj", "{07B0C186-5173-46F2-BE26-7E4148BD0CCA}"
 	ProjectSection(ProjectDependencies) = postProject
 		{9B21D41C-516B-43BF-9B10-E99B599C7589} = {9B21D41C-516B-43BF-9B10-E99B599C7589}
-		{122B7A22-0C62-4B35-B661-EBF3F394EA79} = {122B7A22-0C62-4B35-B661-EBF3F394EA79}
 		{CC7F9445-71C9-4559-9976-FF0A64DCB582} = {CC7F9445-71C9-4559-9976-FF0A64DCB582}
-		{1437BB4E-DDB3-4307-AA41-8C035DA3014B} = {1437BB4E-DDB3-4307-AA41-8C035DA3014B}
-		{F58FF869-2EA6-4FFF-AB84-328C531BA9D9} = {F58FF869-2EA6-4FFF-AB84-328C531BA9D9}
-		{08975177-4A13-4EE7-BB21-3BB92FB3F3CC} = {08975177-4A13-4EE7-BB21-3BB92FB3F3CC}
-		{AB6C9284-D1CB-4AAD-BA4B-8A9E81AD1A73} = {AB6C9284-D1CB-4AAD-BA4B-8A9E81AD1A73}
-		{7F449698-73DF-4203-9F31-0877DBF01695} = {7F449698-73DF-4203-9F31-0877DBF01695}
-		{BFEBBAF8-8A84-4899-8899-D0D7196AF9A1} = {BFEBBAF8-8A84-4899-8899-D0D7196AF9A1}
-		{796B6DFF-BA04-42B7-A43A-2B14D707A33A} = {796B6DFF-BA04-42B7-A43A-2B14D707A33A}
 	EndProjectSection
 EndProject
 Global

+ 1 - 1
CamelotForwardRenderer/Include/CmForwardRendererFactory.h

@@ -5,7 +5,7 @@
 
 namespace CamelotEngine
 {
-	const std::string SystemName = "ForwardRenderer";
+	const std::string SystemName = "CamelotForwardRenderer";
 
 	class CM_FWDRND_EXPORT ForwardRendererFactory : public RendererFactory
 	{

+ 12 - 0
TODO.txt

@@ -1,6 +1,18 @@
 ----------------------- CAMELOT 2D / GUI -----------------------------------------------------------
 
 ----------------------------------------------------------------------------------------------
+
+BansheeEngine refactor:
+ - Move built-in materials and their managers to BansheeEngine
+ - Move Camera class
+ - Move Overlay & OverlayManager
+ - Move Renderable
+ - Extend SceneManager so it works without knowing about Camera/Renderable
+ - Remove all mentioned classes from CmPrerequisites (including Ptrs, and handles from GameObject.h)
+ - Rename CamelotEngine -> CamelotFramework
+ - Rename main folder to BansheeEngine
+ - I'm temporarily not deleting GUISkin in TestTextSprite because of an issue with CM_DELETE and namespaces. Figure that out
+
 Immediate TODO:
  - Issue with rendering same object from multiple cameras:
    - Material parameters should be copied after being submitted to the render context