瀏覽代碼

Async loading tested

Marko Pintera 13 年之前
父節點
當前提交
dee589d88e

+ 9 - 9
CamelotClient/TestingGround.cpp

@@ -10,16 +10,16 @@ using namespace CamelotEngine;
 
 void test()
 {
-	FileSerializer fs;
+	//FileSerializer fs;
 
-	TexturePtr dbgTexture = TextureManager::instance().create(TEX_TYPE_2D, 128, 128, 1, PF_A8B8G8R8);
-	dbgTexture->setFSAA(0, "test");
-	fs.encode(dbgTexture.get(), "C:\\DbgTexture.tex");
+	//TexturePtr dbgTexture = TextureManager::instance().create(TEX_TYPE_2D, 128, 128, 1, PF_A8B8G8R8);
+	//dbgTexture->setFSAA(0, "test");
+	//fs.encode(dbgTexture.get(), "C:\\DbgTexture.tex");
 
-	TexturePtr emptyTexture = std::static_pointer_cast<Texture>(fs.decode("C:\\DbgTexture.tex"));
-	
-	TextureDataPtr data = emptyTexture->mTextureData[0];
-	UINT32 size2 = data->getSize();
+	//TexturePtr emptyTexture = std::static_pointer_cast<Texture>(fs.decode("C:\\DbgTexture.tex"));
+	//
+	//TextureDataPtr data = emptyTexture->mTextureData[0];
+	//UINT32 size2 = data->getSize();
 
-	int a = 5;
+	//int a = 5;
 }

+ 1 - 1
CamelotRenderer/Include/CmResourceRef.h

@@ -53,7 +53,7 @@ namespace CamelotEngine
 		template <typename T1>
 		void init(const ResourceRef<T1>& ptr)
 		{
-			init(std::static_pointer_cast<Resource>(ptr.mData->mPtr));
+			mData = ptr.mData;
 		}
 	private:
 		friend class Resources;

+ 5 - 0
CamelotRenderer/Include/CmResources.h

@@ -45,6 +45,11 @@ namespace CamelotEngine
 		Resources(const String& metaDataFolder);
 		~Resources();
 
+		/**
+		 * @brief	Called every frame by the main loop.
+		 */
+		void update();
+
 		/**
 		 * @brief	Loads the resource from a given path. Returns null if resource can't be loaded.
 		 *

+ 8 - 4
CamelotRenderer/Source/CmApplication.cpp

@@ -173,10 +173,8 @@ namespace CamelotEngine
 		gResources().create(testTex, "C:\\ExportTest.tex", true);
 		gResources().create(mDbgMesh, "C:\\ExportMesh.mesh", true);
 
-		mDbgTexture = static_resource_cast<Texture>(gResources().load("C:\\ExportTest.tex"));
-		mDbgMesh = static_resource_cast<Mesh>(gResources().load("C:\\ExportMesh.mesh"));
-
-		mDbgTexture = testTex;
+		mDbgTexture = static_resource_cast<Texture>(gResources().loadAsync("C:\\ExportTest.tex"));
+		mDbgMesh = static_resource_cast<Mesh>(gResources().loadAsync("C:\\ExportMesh.mesh"));
 
 		loadPlugin("CamelotOISInput"); // TODO - Load this automatically somehow
 	}
@@ -191,6 +189,7 @@ namespace CamelotEngine
 
 			gTime().update();
 			gInput().update();
+			gResources().update();
 		}
 	}
 
@@ -252,6 +251,11 @@ namespace CamelotEngine
 
 	void Application::DBG_renderSimpleFrame()
 	{
+		if(!mDbgTexture.isResolved() || !mDbgMesh.isResolved())
+		{
+			return;
+		}
+
 		RenderSystem* renderSystem = RenderSystemManager::getActive();
 		renderSystem->_setViewport(mCamera->getViewport());
 

+ 7 - 5
CamelotRenderer/Source/CmResources.cpp

@@ -40,11 +40,8 @@ namespace CamelotEngine
 			ResourceLoadResponsePtr resResponse = boost::any_cast<ResourceLoadResponsePtr>(res->getData());
 			ResourceLoadRequestPtr resRequest = boost::any_cast<ResourceLoadRequestPtr>(res->getRequest()->getData());
 
-			if(resRequest->resource != nullptr)
-			{
-				resResponse->rawResource->init();
-				resRequest->resource.resolve(resResponse->rawResource);
-			}
+			resResponse->rawResource->init();
+			resRequest->resource.resolve(resResponse->rawResource);
 		}
 		else
 		{
@@ -99,6 +96,11 @@ namespace CamelotEngine
 			delete mResponseHandler;
 	}
 
+	void Resources::update()
+	{
+		mWorkQueue->processResponses();
+	}
+
 	BaseResourceRef Resources::load(const String& filePath)
 	{
 		// TODO - Make sure this uses the same code as loadAsync. Only forceSyncronous

+ 0 - 1
CamelotRenderer/Source/CmTextureManager.cpp

@@ -61,7 +61,6 @@ namespace CamelotEngine {
         ret->setUsage(usage);
 		ret->setHardwareGammaEnabled(hwGamma);
 		ret->setFSAA(fsaa, fsaaHint);
-		ret->createInternalResources();
 		return ret;
     }
     //-----------------------------------------------------------------------

+ 2 - 5
CamelotUtility/Include/CmWorkQueue.h

@@ -393,17 +393,14 @@ namespace CamelotEngine
 		/** Returns whether the queue is trying to shut down. */
 		bool isShuttingDown() const { return mShuttingDown; }
 
-	protected:
 		/** Process the responses in the queue.
 		@remarks
 			This method is public, and must be called from the main render
-			thread to 'pump' responses through the system. The method will usually
-			try to clear all responses before returning = 0; however, you can specify
-			a time limit on the response processing to limit the impact of
-			spikes in demand by calling setResponseProcessingTimeLimit.
+			thread to 'pump' responses through the system.
 		*/
 		void processResponses(); 
 
+	protected:
 		void processRequestResponse(Request* r, bool synchronous);
 		Response* processRequest(Request* r);
 		void processResponse(Response* r);

+ 2 - 0
CamelotUtility/Source/CmWorkQueue.cpp

@@ -371,6 +371,8 @@ namespace CamelotEngine {
 	//---------------------------------------------------------------------
 	void WorkQueue::processResponses() 
 	{
+		// TODO Low priority - Processing a lot of responses can cause a frame rate spike. Maybe limit the processing to Xms?
+
 		// keep going until we run out of responses
 		while(true)
 		{