Panagiotis Christopoulos Charitos 15 gadi atpakaļ
vecāks
revīzija
2e92ee956c

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 1
build/debug/Makefile


+ 2 - 1
src/Core/AsyncLoader.cpp

@@ -1,4 +1,3 @@
-#include <fstream>
 #include "AsyncLoader.h"
 #include "Logger.h"
 
@@ -8,6 +7,7 @@
 //======================================================================================================================
 void AsyncLoader::start()
 {
+	INFO("Starting async loader thread...");
 	thread = boost::thread(&AsyncLoader::workingFunc, this);
 }
 
@@ -84,6 +84,7 @@ bool AsyncLoader::getLoaded(std::string& filename, void* buff, bool& ok)
 
 	filename = resp.filename;
 	buff = resp.storage;
+	ok = resp.ok;
 	return true;
 }
 

+ 14 - 7
src/Core/AsyncLoader.h

@@ -3,12 +3,15 @@
 
 #include <list>
 #include <string>
-#include <vector>
 #include <boost/thread/thread.hpp>
 #include <boost/thread/mutex.hpp>
 
 
+/// Asynchronous loader
 ///
+/// It creates a thread that loads files on demand. It accepts requests (in the form of a filename of the file to load,
+/// a pointer to a function for the way to load the file and a generic pointer for the data to load them to). Its not
+/// meant to be destroyed because of a deadlock.
 class AsyncLoader
 {
 	public:
@@ -18,19 +21,23 @@ class AsyncLoader
 		/// Do nothing
 		~AsyncLoader() {}
 
-		/// Tell me what to load, how to load it and where to store it
+		/// Tell me what to load, how to load it and where to store it. This puts a new loading request in the stack
 		/// @param filename The file to load
-		/// @param func How to load the file
-		/// @param storage This points to the storage
+		/// @param func How to load the file. The function should gets a filename (const char*) and the storage. It returns
+		/// false if there was a loading error
+		/// @param storage This points to the storage that the loader will store the data. The storage should not be
+		/// destroyed from other threads
 		void load(const char* filename, bool (*func)(const char*, void*), void* storage);
 
 		/// Query the loader and see if its got something
 		/// @param[out] filename The file that finished loading
 		/// @param[out] storage The data are stored in this buffer
+		/// @param[out] ok Its true if the loading of the resource was ok
 		/// @return Return true if there is something that finished loading
 		bool getLoaded(std::string& filename, void* storage, bool& ok);
 
 	private:
+		/// A loading request
 		struct Request
 		{
 			std::string filename;
@@ -48,12 +55,12 @@ class AsyncLoader
 
 		std::list<Request> requests;
 		std::list<Response> responses;
-		boost::mutex mutexReq;
-		boost::mutex mutexResp;
+		boost::mutex mutexReq; ///< Protect the requests container
+		boost::mutex mutexResp; ///< Protect the responses container
 		boost::thread thread;
 		boost::condition_variable condVar;
 
-		void workingFunc(); ///< The thread function
+		void workingFunc(); ///< The thread function. It waits for something in the requests container
 		void start(); ///< Start thread
 };
 

+ 0 - 7
src/Renderer/Renderer.cpp

@@ -1,14 +1,7 @@
 #include "Renderer.h"
 #include "Camera.h"
 #include "RendererInitializer.h"
-#include "Material.h"
-#include "App.h"
-#include "Scene.h"
 #include "Exception.h"
-#include "ModelNode.h"
-#include "Model.h"
-#include "Mesh.h"
-
 
 
 //======================================================================================================================

+ 21 - 18
src/Resources/Core/ResourceManager.h

@@ -4,6 +4,7 @@
 #include <list>
 #include <string>
 #include "Singleton.h"
+#include "AsyncLoader.h"
 
 
 class Texture;
@@ -20,11 +21,11 @@ class Skin;
 class DummyRsrc;
 
 
-/// Includes information about the resources
+/// Holds information about a resource
 template<typename Type>
 struct RsrcHook
 {
-	std::string uuid;
+	std::string uuid; ///< Unique identifier
 	int referenceCounter;
 	Type* resource;
 };
@@ -58,22 +59,6 @@ class ResourceManager
 		void unload(const typename Types<Type>::Hook& info);
 
 	private:
-		/// Find a resource using the filename
-		template<typename Type>
-		typename Types<Type>::Iterator find(const char* filename, typename Types<Type>::Container& container);
-
-		/// Find a resource using the pointer
-		template<typename Type>
-		typename Types<Type>::Iterator find(const Type* resource, typename Types<Type>::Container& container);
-
-		/// Specialized func
-		template<typename Type>
-		typename Types<Type>::Container& choseContainer();
-
-		/// Unload a resource if no one uses it. This is the real deal
-		template<typename Type>
-		void unloadR(const typename Types<Type>::Hook& info);
-
 		/// @name Containers
 		/// @{
 		Types<Texture>::Container textures;
@@ -89,6 +74,24 @@ class ResourceManager
 		Types<Skin>::Container skins;
 		Types<DummyRsrc>::Container dummies;
 		/// @}
+
+		AsyncLoader al;
+
+		/// Find a resource using the filename
+		template<typename Type>
+		typename Types<Type>::Iterator find(const char* filename, typename Types<Type>::Container& container);
+
+		/// Find a resource using the pointer
+		template<typename Type>
+		typename Types<Type>::Iterator find(const Type* resource, typename Types<Type>::Container& container);
+
+		/// Specialized func
+		template<typename Type>
+		typename Types<Type>::Container& choseContainer();
+
+		/// Unload a resource if no one uses it. This is the real deal
+		template<typename Type>
+		void unloadR(const typename Types<Type>::Hook& info);
 };
 
 

+ 0 - 1
src/Resources/Core/ResourceManager.inl.h

@@ -35,7 +35,6 @@ typename ResourceManager::Types<Type>::Hook& ResourceManager::load(const char* f
 			{
 				delete newInstance;
 			}
-			//throw EXCEPTION("Cannot load resource: " + e.what());
 		}
 
 		c.push_back(typename Types<Type>::Hook());

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels