Browse Source

Added a way to retrieve resource dependencies from managed code

BearishSun 10 years ago
parent
commit
4d598f3d9e

+ 7 - 1
BansheeCore/Include/BsResources.h

@@ -124,6 +124,12 @@ namespace BansheeEngine
 		 */
 		void save(HResource resource);
 
+		/**
+		 * @brief	Updates an existing resource handle with a new resource. Caller must ensure that
+		 * 			new resource type matches the original resource type.
+		 */
+		void update(HResource& handle, const ResourcePtr& resource);
+
 		/**
 		 * @brief	Checks is the resource with the specified UUID loaded.
 		 *
@@ -207,7 +213,7 @@ namespace BansheeEngine
 		 *
 		 * @note	It is undefined from which thread this will get called from.
 		 */
-		Event<void(const HResource&)> onResourceModified; // TODO - Not used, implement when I add hot-swapping
+		Event<void(const HResource&)> onResourceModified;
 	private:
 		/**
 		 * @brief	Starts resource loading or returns an already loaded resource. Both UUID and filePath must match the

+ 1 - 1
BansheeCore/Include/BsUtility.h

@@ -30,7 +30,7 @@ namespace BansheeEngine
 		 *
 		 * @param	object		Object to search for resource dependencies.
 		 * @param	recursive	Determines whether or not child objects will also be
-		 *						searched (if object has any children).
+		 *						searched (if the object has any children).
 		 *
 		 * @returns	A list of unique, non-null resources.
 		 */

+ 1 - 1
BansheeCore/Source/BsImporter.cpp

@@ -103,7 +103,7 @@ namespace BansheeEngine
 		}
 
 		ResourcePtr importedResource = importer->import(inputFilePath, importOptions);
-		existingResource._setHandleData(importedResource, existingResource.getUUID());
+		gResources().update(existingResource, importedResource);
 	}
 
 	ImportOptionsPtr Importer::createImportOptions(const Path& inputFilePath)

+ 7 - 0
BansheeCore/Source/BsResources.cpp

@@ -396,6 +396,13 @@ namespace BansheeEngine
 			save(resource, path, true);
 	}
 
+	void Resources::update(HResource& handle, const ResourcePtr& resource)
+	{
+		handle._setHandleData(resource, handle.getUUID());
+
+		onResourceModified(handle);
+	}
+
 	void Resources::registerResourceManifest(const ResourceManifestPtr& manifest)
 	{
 		if(manifest->getName() == "Default")

+ 1 - 1
BansheeEngine/Source/BsSplashScreen.cpp

@@ -15,7 +15,7 @@ namespace BansheeEngine
 
 	// Note: Never freed, but that's fine
 	SplashScreen::Pimpl* SplashScreen::m = bs_new<Pimpl>();
-	const UINT32 SplashScreen::SPLASH_SCREEN_DURATION_MS = 2000;
+	const UINT32 SplashScreen::SPLASH_SCREEN_DURATION_MS = 1000;
 
 	void SplashScreen::show()
 	{

+ 15 - 0
MBansheeEditor/EditorUtility.cs

@@ -60,10 +60,25 @@ namespace BansheeEditor
             return flattenedHierarchy.ToArray();
         }
 
+        /// <summary>
+        /// Find all resources that the provided resource depends on.
+        /// </summary>
+        /// <param name="resource">Resource whose dependencies to find.</param>
+        /// <param name="recursive">Determines whether or not child objects will also be searched (if object has any 
+        ///                         children).</param>
+        /// <returns>All resources the provided resource is dependant on (does not include itself).</returns>
+        public static Resource[] FindDependencies(Resource resource, bool recursive = true)
+        {
+            return Internal_FindDependencies(resource, recursive);
+        }
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_CalculateBounds(SceneObject so, out AABox bounds);
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_CalculateBoundsArray(SceneObject[] objects, out AABox bounds);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Resource[] Internal_FindDependencies(Resource resource, bool recursive);
     }
 }

+ 1 - 0
SBansheeEditor/Include/BsScriptEditorUtility.h

@@ -21,5 +21,6 @@ namespace BansheeEngine
 		/************************************************************************/
 		static void internal_CalculateBounds(MonoObject* so, AABox* bounds);
 		static void internal_CalculateBoundsArray(MonoArray* objects, AABox* bounds);
+		static MonoArray* internal_FindDependencies(MonoObject* resource, bool recursive);
 	};
 }

+ 28 - 3
SBansheeEditor/Source/BsScriptEditorUtility.cpp

@@ -6,6 +6,9 @@
 #include "BsMonoUtil.h"
 #include "BsEditorUtility.h"
 #include "BsScriptSceneObject.h"
+#include "BsScriptResource.h"
+#include "BsScriptResourceManager.h"
+#include "BsUtility.h"
 
 namespace BansheeEngine
 {
@@ -17,11 +20,9 @@ namespace BansheeEngine
 	{
 		metaData.scriptClass->addInternalCall("Internal_CalculateBounds", &ScriptEditorUtility::internal_CalculateBounds);
 		metaData.scriptClass->addInternalCall("Internal_CalculateBoundsArray", &ScriptEditorUtility::internal_CalculateBoundsArray);
+		metaData.scriptClass->addInternalCall("Internal_FindDependencies", &ScriptEditorUtility::internal_FindDependencies);
 	}
 
-	static void internal_CalculateBounds(MonoObject* so, AABox* bounds);
-	static void internal_CalculateBounds(MonoArray* objects, AABox* bounds);
-
 	void ScriptEditorUtility::internal_CalculateBounds(MonoObject* so, AABox* bounds)
 	{
 		ScriptSceneObject* scriptSO = ScriptSceneObject::toNative(so);
@@ -49,4 +50,28 @@ namespace BansheeEngine
 
 		*bounds = EditorUtility::calculateBounds(sceneObjects);
 	}
+
+	MonoArray* ScriptEditorUtility::internal_FindDependencies(MonoObject* resource, bool recursive)
+	{
+		ScriptResource* srcResource = ScriptResource::toNative(resource);
+		if (srcResource == nullptr)
+		{
+			ScriptArray emptyArray = ScriptArray::create<ScriptResource>(0);
+			return emptyArray.getInternal();
+		}
+
+		Vector<ResourceDependency> dependencies = Utility::findResourceDependencies(srcResource->getGenericHandle(), recursive);
+
+		UINT32 numEntries = (UINT32)dependencies.size();
+		ScriptArray output = ScriptArray::create<ScriptResource>(numEntries);
+		for (int i = 0; i < numEntries; i++)
+		{
+			ScriptResource* dependency;
+			ScriptResourceManager::instance().getScriptResource(dependencies[i].resource, &dependency, true);
+
+			output.set(i, dependency->getManagedInstance());
+		}
+
+		return output.getInternal();
+	}
 }

+ 8 - 18
TODO.txt

@@ -1,12 +1,5 @@
 --------- ALL LONG TERM TASKS / FIXES BELONG TO GOOGLE DOCS: ImplementationTODO OR PossibleImprovements ----------
 
-----------------------------------------------------------------------
-C# Material/Shader:
-
-TODO - Implement param block and sampler support
-TODO - When creating a Material without a shader, a default one should be used, at least in editor
-TODO - Setting Material array parameters isn't possible from C#
-
 ----------------------------------------------------------------------
 Polish
 
@@ -122,13 +115,6 @@ Game window
    - When frame-step is hit:
      - Time and component updates are unpaused for a single frame and then paused again
 
-----------------------------------------------------------------------
-Other
-
-There is a memory corruption happening. Haven't determined where exactly but it's possible it has something
-to do with the opening of ColorPicker window. One time I got a heap read after delete error caused by GUIManager
-attempting to allocate a new transient mesh, and another time I got a hang when inserting a script object into a std::set.
-
 /*********************************************************************/
 /************************ LESS IMPORTANT *****************************/
 /*********************************************************************/
@@ -196,7 +182,11 @@ Include files:
 ----------------------------------------------------------------------
 Scene View
 
-Test:
- - Custom handles from C#
- - Handle snapping
- - Multi-select Move/Rotate/scale
+Test custom handles from C#
+
+----------------------------------------------------------------------
+C# Material/Shader
+
+TODO - Implement param block and sampler support
+TODO - When creating a Material without a shader, a default one should be used, at least in editor
+TODO - Setting Material array parameters isn't possible from C#