Răsfoiți Sursa

Added option to load a resource without its dependencies

Marko Pintera 10 ani în urmă
părinte
comite
4f682ae5ce
3 a modificat fișierele cu 30 adăugiri și 20 ștergeri
  1. 6 6
      BansheeCore/Include/BsResources.h
  2. 24 13
      BansheeCore/Source/BsResources.cpp
  3. 0 1
      TODO.txt

+ 6 - 6
BansheeCore/Include/BsResources.h

@@ -36,13 +36,13 @@ namespace BansheeEngine
 		 * @brief	Loads the resource from a given path. Returns an empty handle if resource can't be loaded.
 		 * @brief	Loads the resource from a given path. Returns an empty handle if resource can't be loaded.
 		 *			Resource is loaded synchronously.
 		 *			Resource is loaded synchronously.
 		 */
 		 */
-		HResource load(const Path& filePath);
+		HResource load(const Path& filePath, bool loadDependencies = true);
 
 
 		/**
 		/**
 		 * @copydoc	load
 		 * @copydoc	load
 		 */
 		 */
 		template <class T>
 		template <class T>
-		ResourceHandle<T> load(const Path& filePath)
+		ResourceHandle<T> load(const Path& filePath, bool loadDependencies = true)
 		{
 		{
 			return static_resource_cast<T>(load(filePath));
 			return static_resource_cast<T>(load(filePath));
 		}
 		}
@@ -56,13 +56,13 @@ namespace BansheeEngine
 		 * @note	You can use returned invalid handle in engine systems as the engine will check for handle 
 		 * @note	You can use returned invalid handle in engine systems as the engine will check for handle 
 		 *			validity before using it.
 		 *			validity before using it.
 		 */
 		 */
-		HResource loadAsync(const Path& filePath);
+		HResource loadAsync(const Path& filePath, bool loadDependencies = true);
 
 
 		/**
 		/**
 		 * @copydoc	loadAsync
 		 * @copydoc	loadAsync
 		 */
 		 */
 		template <class T>
 		template <class T>
-		ResourceHandle<T> loadAsync(const Path& filePath)
+		ResourceHandle<T> loadAsync(const Path& filePath, bool loadDependencies = true)
 		{
 		{
 			return static_resource_cast<T>(loadAsync(filePath));
 			return static_resource_cast<T>(loadAsync(filePath));
 		}
 		}
@@ -74,7 +74,7 @@ namespace BansheeEngine
 		 * @param	async	If true resource will be loaded asynchronously. Handle to non-loaded
 		 * @param	async	If true resource will be loaded asynchronously. Handle to non-loaded
 		 *					resource will be returned immediately while loading will continue in the background.
 		 *					resource will be returned immediately while loading will continue in the background.
 		 */
 		 */
-		HResource loadFromUUID(const String& uuid, bool async = false);
+		HResource loadFromUUID(const String& uuid, bool async = false, bool loadDependencies = true);
 
 
 		/**
 		/**
 		 * @brief	Unloads the resource that is referenced by the handle. Resource is unloaded regardless if it is 
 		 * @brief	Unloads the resource that is referenced by the handle. Resource is unloaded regardless if it is 
@@ -183,7 +183,7 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @brief	Starts resource loading or returns an already loaded resource.
 		 * @brief	Starts resource loading or returns an already loaded resource.
 		 */
 		 */
-		HResource loadInternal(const Path& filePath, bool synchronous);
+		HResource loadInternal(const Path& filePath, bool synchronous, bool loadDependencies);
 
 
 		/**
 		/**
 		 * @brief	Performs actually reading and deserializing of the resource file. 
 		 * @brief	Performs actually reading and deserializing of the resource file. 

+ 24 - 13
BansheeCore/Source/BsResources.cpp

@@ -33,17 +33,17 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	HResource Resources::load(const Path& filePath)
+	HResource Resources::load(const Path& filePath, bool loadDependencies)
 	{
 	{
-		return loadInternal(filePath, true);
+		return loadInternal(filePath, true, loadDependencies);
 	}
 	}
 
 
-	HResource Resources::loadAsync(const Path& filePath)
+	HResource Resources::loadAsync(const Path& filePath, bool loadDependencies)
 	{
 	{
-		return loadInternal(filePath, false);
+		return loadInternal(filePath, false, loadDependencies);
 	}
 	}
 
 
-	HResource Resources::loadFromUUID(const String& uuid, bool async)
+	HResource Resources::loadFromUUID(const String& uuid, bool async, bool loadDependencies)
 	{
 	{
 		Path filePath;
 		Path filePath;
 		bool foundPath = false;
 		bool foundPath = false;
@@ -69,10 +69,10 @@ namespace BansheeEngine
 			return outputResource;
 			return outputResource;
 		}
 		}
 
 
-		return loadInternal(filePath, !async);
+		return loadInternal(filePath, !async, loadDependencies);
 	}
 	}
 
 
-	HResource Resources::loadInternal(const Path& filePath, bool synchronous)
+	HResource Resources::loadInternal(const Path& filePath, bool synchronous, bool loadDependencies)
 	{
 	{
 		String uuid;
 		String uuid;
 		bool foundUUID = getUUIDFromFilePath(filePath, uuid);
 		bool foundUUID = getUUIDFromFilePath(filePath, uuid);
@@ -80,6 +80,11 @@ namespace BansheeEngine
 		if(!foundUUID)
 		if(!foundUUID)
 			uuid = UUIDGenerator::generateRandom();
 			uuid = UUIDGenerator::generateRandom();
 
 
+		
+		// TODO - Load dependencies not implemented
+
+
+
 		HResource outputResource;
 		HResource outputResource;
 		bool alreadyLoading = false;
 		bool alreadyLoading = false;
 		{
 		{
@@ -137,21 +142,27 @@ namespace BansheeEngine
 			loadData->remainingDependencies = 1;
 			loadData->remainingDependencies = 1;
 			loadData->notifyImmediately = synchronous; // Make resource listener trigger before exit if loading synchronously
 			loadData->notifyImmediately = synchronous; // Make resource listener trigger before exit if loading synchronously
 
 
-			for (auto& dependency : savedResourceData->getDependencies())
+			if (loadDependencies)
 			{
 			{
-				if (dependency != uuid)
+				for (auto& dependency : savedResourceData->getDependencies())
 				{
 				{
-					mDependantLoads[dependency].push_back(loadData);
-					loadData->remainingDependencies++;
+					if (dependency != uuid)
+					{
+						mDependantLoads[dependency].push_back(loadData);
+						loadData->remainingDependencies++;
+					}
 				}
 				}
 			}
 			}
 		}
 		}
 
 
 		// Load dependencies
 		// Load dependencies
+		if (loadDependencies)
 		{
 		{
-			for (auto& dependency : savedResourceData->getDependencies())
 			{
 			{
-				loadFromUUID(dependency, !synchronous);
+				for (auto& dependency : savedResourceData->getDependencies())
+				{
+					loadFromUUID(dependency, !synchronous);
+				}
 			}
 			}
 		}
 		}
 
 

+ 0 - 1
TODO.txt

@@ -31,7 +31,6 @@ TODO:
  - Hook up prefabs & prefab diffs:
  - Hook up prefabs & prefab diffs:
    - Save a diff whenever a HSceneObject with a HPrefab link is saved (call recordPrefabDiff)
    - Save a diff whenever a HSceneObject with a HPrefab link is saved (call recordPrefabDiff)
    - Update active scene when prefab is modified (destroy them, create original prefab then apply saved diff)
    - Update active scene when prefab is modified (destroy them, create original prefab then apply saved diff)
- - C# prefab
 
 
 TODO - Whenever I load a SceneObject the entire prefab will be loaded as well. It might be better to store the
 TODO - Whenever I load a SceneObject the entire prefab will be loaded as well. It might be better to store the
  prefab link as a UUID and then load it on demand.
  prefab link as a UUID and then load it on demand.