Pārlūkot izejas kodu

Properly fixing Resources::unloadAllAssets. Handles to the same resource will share the same handle data as intended

Marko Pintera 11 gadi atpakaļ
vecāks
revīzija
5e73fd1b8d

+ 10 - 0
BansheeCore/Include/BsResourceHandle.h

@@ -63,9 +63,19 @@ namespace BansheeEngine
 		 */
 		 */
 		void _setHandleData(std::shared_ptr<Resource> ptr, const String& uuid);
 		void _setHandleData(std::shared_ptr<Resource> ptr, const String& uuid);
 
 
+		/**
+		 * @brief	Sets the internal handle data to another previously created data.
+		 *
+		 * @note	Internal method.
+		 */
+		void _setHandleData(const std::shared_ptr<ResourceHandleData>& data);
+
 	protected:
 	protected:
 		ResourceHandleBase();
 		ResourceHandleBase();
 
 
+		/** @note	All handles to the same source must share this same handle data. Otherwise things
+		 *			like counting number of references or replacing pointed to resource become impossible
+		 *			without additional logic. */
 		std::shared_ptr<ResourceHandleData> mData;
 		std::shared_ptr<ResourceHandleData> mData;
 
 
 	private:
 	private:

+ 1 - 1
BansheeCore/Include/BsResourceHandleRTTI.h

@@ -35,7 +35,7 @@ namespace BansheeEngine
 				HResource loadedResource = gResources().loadFromUUID(resourceHandle->mData->mUUID);
 				HResource loadedResource = gResources().loadFromUUID(resourceHandle->mData->mUUID);
 
 
 				if(loadedResource)
 				if(loadedResource)
-					resourceHandle->_setHandleData(loadedResource.getInternalPtr(), resourceHandle->mData->mUUID);
+					resourceHandle->_setHandleData(loadedResource.getHandleData());
 			}
 			}
 		}
 		}
 
 

+ 5 - 0
BansheeCore/Source/BsResourceHandle.cpp

@@ -61,6 +61,11 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
+	void ResourceHandleBase::_setHandleData(const std::shared_ptr<ResourceHandleData>& data)
+	{
+		mData = data;
+	}
+
 	void ResourceHandleBase::throwIfNotLoaded() const
 	void ResourceHandleBase::throwIfNotLoaded() const
 	{
 	{
 		if(!isLoaded()) 
 		if(!isLoaded()) 

+ 1 - 1
BansheeCore/Source/BsResources.cpp

@@ -207,7 +207,7 @@ namespace BansheeEngine
 			BS_LOCK_MUTEX(mLoadedResourceMutex);
 			BS_LOCK_MUTEX(mLoadedResourceMutex);
 			for(auto iter = mLoadedResources.begin(); iter != mLoadedResources.end(); ++iter)
 			for(auto iter = mLoadedResources.begin(); iter != mLoadedResources.end(); ++iter)
 			{
 			{
-				if (iter->second.mData.unique() && iter->second.mData->mPtr.unique()) // We just have this one reference, meaning nothing is using this resource
+				if (iter->second.mData.unique()) // We just have this one reference, meaning nothing is using this resource
 					resourcesToUnload.push_back(iter->second);
 					resourcesToUnload.push_back(iter->second);
 			}
 			}
 		}
 		}

+ 2 - 16
SceneView.txt

@@ -4,26 +4,12 @@ TODO:
 
 
 Weekend:
 Weekend:
  - Set up grid material and hook it up to renderer (+ actually instantiate it in EditorApplication)
  - Set up grid material and hook it up to renderer (+ actually instantiate it in EditorApplication)
- - Figure out how to load scene grid material in EditorResources
-   - Figure out in general how to deal with built-in resources
-   - e.g. meshes, textures and shaders. I need to import them then at runtime I should just load the engine version directly
-     - When in debug mode probably always reimport as a form of unit testing
-	 - Have two separate folders Resources/EditorRaw and Resources/Editor (similar for Engine)
-	 - Store a BuiltinResources asset which contains last import dates of the files
-	 - When EditorResources get started up check that file and check if EditorRaw version of the resource exists
-	   - If it does and is newer when import it and save it to Editor folder
-	 - Rename BuiltinResources to EngineResources?
-	 - Merge GUI resources in Editor/EngineResources?
-	   - Editor/EngineGUI can then just reference them when creating GUI styles
-   - Fix up all GUI builtin resources to use this approach 
- - Rename EditorGUI to EditorBuildiNResources
+ 
+ - Fix up shader so I can reference two different gpu vars with a single shader var (e.g. DX11 sampler variables will have different names than DX9 or GL sampler variables)
  - You can create a resource handle to invalid resource type. Add a security feature to prevent that, at least in debug mode?
  - You can create a resource handle to invalid resource type. Add a security feature to prevent that, at least in debug mode?
  - When unloading unused resources I should do it recursively so it unloads any new ones that might have been released during the first unload
  - When unloading unused resources I should do it recursively so it unloads any new ones that might have been released during the first unload
  - Ensure that resource handles only have a single mData (and fix Resources::unloadAllUnused)
  - Ensure that resource handles only have a single mData (and fix Resources::unloadAllUnused)
- - Add Scene grid shaders
- - Move dock overlay from engine to editor builtin resources
 
 
- - Grid
  - Think about picking implementation and possibly Handles implementation
  - Think about picking implementation and possibly Handles implementation
 
 
 TODO - Think about:
 TODO - Think about: