Browse Source

Fixed drop targets so they are properly destroyed before new ones are added
Fixed an issue where resource refs weren't being properly loaded
Moved some common warning messages to a separate channel

BearishSun 10 years ago
parent
commit
15f45489c8

+ 7 - 7
BansheeCore/Include/Win32/BsWin32DropTarget.h

@@ -96,7 +96,7 @@ namespace BansheeEngine
 		 * @brief	COM requirement. Returns instance of an interface of
 		 * 			provided type.
 		 */
-		HRESULT __stdcall QueryInterface(REFIID iid, void** ppvObject)
+		HRESULT __stdcall QueryInterface(REFIID iid, void** ppvObject) override
 		{
 			if(iid == IID_IDropTarget || iid == IID_IUnknown)
 			{
@@ -115,7 +115,7 @@ namespace BansheeEngine
 		 * @brief	COM requirement. Increments objects
 		 * 			reference count.
 		 */
-		ULONG __stdcall AddRef()
+		ULONG __stdcall AddRef() override
 		{
 			return InterlockedIncrement(&mRefCount);
 		} 
@@ -125,7 +125,7 @@ namespace BansheeEngine
 		 * 			reference count and deletes the object
 		 * 			if its zero.
 		 */
-		ULONG __stdcall Release()
+		ULONG __stdcall Release() override
 		{
 			LONG count = InterlockedDecrement(&mRefCount);
 
@@ -145,7 +145,7 @@ namespace BansheeEngine
 		 * 			
 		 * @note	Called on core thread.
 		 */
-		HRESULT __stdcall DragEnter(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
+		HRESULT __stdcall DragEnter(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) override
 		{
 			*pdwEffect = DROPEFFECT_LINK;
 
@@ -174,7 +174,7 @@ namespace BansheeEngine
 		 * 			
 		 * @note	Called on core thread.
 		 */
-		HRESULT __stdcall DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
+		HRESULT __stdcall DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) override
 		{
 			*pdwEffect = DROPEFFECT_LINK;
 
@@ -200,7 +200,7 @@ namespace BansheeEngine
 		 * 			
 		 * @note	Called on core thread.
 		 */
-		HRESULT __stdcall DragLeave()
+		HRESULT __stdcall DragLeave() override
 		{
 			{
 				BS_LOCK_MUTEX(mSync);
@@ -221,7 +221,7 @@ namespace BansheeEngine
 		 * 			
 		 * @note	Called on core thread.
 		 */
-		HRESULT __stdcall Drop(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
+		HRESULT __stdcall Drop(IDataObject* pDataObj, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect) override
 		{
 			*pdwEffect = DROPEFFECT_LINK;
 			mAcceptDrag = false;

+ 20 - 8
BansheeCore/Source/BsMaterial.cpp

@@ -365,6 +365,15 @@ namespace BansheeEngine
 		return output;
 	}
 
+	template<class T>
+	bool isShaderValid(const T& shader) { return false; }
+
+	template<>
+	bool isShaderValid(const HShader& shader) { return shader.isLoaded(); }
+
+	template<>
+	bool isShaderValid(const SPtr<ShaderCore>& shader) { return shader != nullptr; }
+
 	Vector<GpuParamDescPtr> MaterialBase::getAllParamDescs(const SPtr<Technique>& technique)
 	{
 		Vector<GpuParamDescPtr> allParamDescs;
@@ -483,7 +492,7 @@ namespace BansheeEngine
 		auto iterFind = mValidParams.find(name);
 		if (iterFind == mValidParams.end())
 		{
-			LOGWRN("Material doesn't have a parameter named " + name);
+			LOGWRN_VERBOSE("Material doesn't have a parameter named " + name);
 			return TMaterialParamStruct<Core>();
 		}
 
@@ -519,7 +528,7 @@ namespace BansheeEngine
 		auto iterFind = mValidParams.find(name);
 		if (iterFind == mValidParams.end())
 		{
-			LOGWRN("Material doesn't have a parameter named " + name);
+			LOGWRN_VERBOSE("Material doesn't have a parameter named " + name);
 			return TMaterialParamTexture<Core>();
 		}
 
@@ -555,7 +564,7 @@ namespace BansheeEngine
 		auto iterFind = mValidParams.find(name);
 		if (iterFind == mValidParams.end())
 		{
-			LOGWRN("Material doesn't have a parameter named " + name);
+			LOGWRN_VERBOSE("Material doesn't have a parameter named " + name);
 			return TMaterialParamLoadStoreTexture<Core>();
 		}
 
@@ -591,7 +600,7 @@ namespace BansheeEngine
 		auto iterFind = mValidParams.find(name);
 		if (iterFind == mValidParams.end())
 		{
-			LOGWRN("Material doesn't have a parameter named " + name);
+			LOGWRN_VERBOSE("Material doesn't have a parameter named " + name);
 			return TMaterialParamSampState<Core>();
 		}
 
@@ -624,7 +633,7 @@ namespace BansheeEngine
 		auto iterFind = mValidShareableParamBlocks.find(name);
 		if (iterFind == mValidShareableParamBlocks.end())
 		{
-			LOGWRN("Material doesn't have a parameter block named " + name);
+			LOGWRN_VERBOSE("Material doesn't have a parameter block named " + name);
 			return;
 		}
 
@@ -650,7 +659,7 @@ namespace BansheeEngine
 		mBestTechnique = nullptr;
 		mParametersPerPass.clear();
 
-		if (mShader)
+		if (isShaderValid(mShader))
 		{
 			mBestTechnique = mShader->getBestTechnique();
 
@@ -900,7 +909,7 @@ namespace BansheeEngine
 		auto iterFind = mValidParams.find(name);
 		if (iterFind == mValidParams.end())
 		{
-			LOGWRN("Material doesn't have a parameter named " + name);
+			LOGWRN_VERBOSE("Material doesn't have a parameter named " + name);
 			return;
 		}
 
@@ -1076,6 +1085,9 @@ namespace BansheeEngine
 
 	void Material::setShader(const HShader& shader)
 	{
+		//if (mShader == shader)
+		//	return;
+
 		mShader = shader;
 		mBestTechnique = nullptr;
 		mLoadFlags = Load_None;
@@ -1109,7 +1121,7 @@ namespace BansheeEngine
 		MaterialCore* material = nullptr;
 
 		SPtr<ShaderCore> shader;
-		if (mShader != nullptr)
+		if (mShader.isLoaded())
 		{
 			shader = mShader->getCore();
 

+ 2 - 2
BansheeCore/Source/BsResources.cpp

@@ -133,7 +133,7 @@ namespace BansheeEngine
 		{
 			if (!alreadyLoading)
 			{
-				gDebug().logWarning("Cannot load resource. Resource with UUID '" + UUID + "' doesn't exist.");
+				LOGWRN_VERBOSE("Cannot load resource. Resource with UUID '" + UUID + "' doesn't exist.");
 
 				// Complete the load as that the depedency counter is properly reduced, in case this 
 				// is a dependency of some other resource.
@@ -143,7 +143,7 @@ namespace BansheeEngine
 		}
 		else if (!FileSystem::isFile(filePath))
 		{
-			LOGWRN("Cannot load resource. Specified file: " + filePath.toString() + " doesn't exist.");
+			LOGWRN_VERBOSE("Cannot load resource. Specified file: " + filePath.toString() + " doesn't exist.");
 
 			// Complete the load as that the depedency counter is properly reduced, in case this 
 			// is a dependency of some other resource.

+ 7 - 7
BansheeCore/Source/Win32/BsWin32Platform.cpp

@@ -319,23 +319,23 @@ namespace BansheeEngine
 
 		{
 			BS_LOCK_MUTEX(mData->mSync);
-			for (auto& dropTargetToInit : mData->mDropTargets.dropTargetsToInitialize)
+			for (auto& dropTargetToDestroy : mData->mDropTargets.dropTargetsToDestroy)
 			{
-				dropTargetToInit->registerWithOS();
+				dropTargetToDestroy->unregisterWithOS();
+				dropTargetToDestroy->Release();
 			}
 
-			mData->mDropTargets.dropTargetsToInitialize.clear();
+			mData->mDropTargets.dropTargetsToDestroy.clear();
 		}
 
 		{
 			BS_LOCK_MUTEX(mData->mSync);
-			for (auto& dropTargetToDestroy : mData->mDropTargets.dropTargetsToDestroy)
+			for (auto& dropTargetToInit : mData->mDropTargets.dropTargetsToInitialize)
 			{
-				dropTargetToDestroy->unregisterWithOS();
-				dropTargetToDestroy->Release();
+				dropTargetToInit->registerWithOS();
 			}
 
-			mData->mDropTargets.dropTargetsToDestroy.clear();
+			mData->mDropTargets.dropTargetsToInitialize.clear();
 		}
 
 		_messagePump();

+ 3 - 0
BansheeUtility/Include/BsDebug.h

@@ -80,4 +80,7 @@ namespace BansheeEngine
 #define LOGDBG(x) BansheeEngine::gDebug().logDebug((x));
 #define LOGWRN(x) BansheeEngine::gDebug().logWarning((x));
 #define LOGERR(x) BansheeEngine::gDebug().logError((x));
+
+#define LOGDBG_VERBOSE(x)
+#define LOGWRN_VERBOSE(x)
 }

+ 2 - 0
MBansheeEditor/Library/LibraryWindow.cs

@@ -213,6 +213,8 @@ namespace BansheeEditor
         {
             Selection.OnSelectionChanged -= OnSelectionChanged;
             Selection.OnResourcePing -= OnPing;
+
+            dropTarget.Destroy();
         }
 
         private void OnEditorUpdate()

+ 2 - 7
SBansheeEngine/Include/BsScriptResourceRef.h

@@ -25,11 +25,7 @@ namespace BansheeEngine
 		template<class T>
 		static MonoObject* create(const WeakResourceHandle<T>& handle)
 		{
-			MonoClass* resourceClass = ScriptResource::getClassFromTypeId(T::getRTTIStatic()->getRTTIId());
-			if (resourceClass == nullptr)
-				return nullptr;
-
-			return create(resourceClass->_getInternalClass(), handle);
+			return createInternal(handle);
 		}
 
 		/**
@@ -52,10 +48,9 @@ namespace BansheeEngine
 		/**
 		 * @brief	Creates a new managed ResourceRef for the provided resource type.
 		 *
-		 * @param	resourceClass	Managed class of the resource to reference.
 		 * @param	handle			Handle to the resource to wrap.
 		 */
-		static MonoObject* create(::MonoClass* resourceClass, const WeakResourceHandle<Resource>& handle);
+		static MonoObject* createInternal(const WeakResourceHandle<Resource>& handle);
 
 		WeakResourceHandle<Resource> mResource;
 

+ 4 - 4
SBansheeEngine/Source/BsScriptResourceRef.cpp

@@ -24,7 +24,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_GetUUID", &ScriptResourceRef::internal_GetUUID);
 	}
 
-	MonoObject* ScriptResourceRef::create(::MonoClass* resourceClass, const WeakResourceHandle<Resource>& handle)
+	MonoObject* ScriptResourceRef::createInternal(const WeakResourceHandle<Resource>& handle)
 	{
 		MonoObject* obj = metaData.scriptClass->createInstance();
 		ScriptResourceRef* scriptResourceRef = new (bs_alloc<ScriptResourceRef>()) ScriptResourceRef(obj, handle);
@@ -37,11 +37,11 @@ namespace BansheeEngine
 		switch (type)
 		{
 		case TEX_TYPE_2D:
-			return create(ScriptTexture2D::getMetaData()->scriptClass->_getInternalClass(), handle);
+			return createInternal(handle);
 		case TEX_TYPE_3D:
-			return create(ScriptTexture3D::getMetaData()->scriptClass->_getInternalClass(), handle);
+			return createInternal(handle);
 		case TEX_TYPE_CUBE_MAP:
-			return create(ScriptTextureCube::getMetaData()->scriptClass->_getInternalClass(), handle);
+			return createInternal(handle);
 		}
 
 		return nullptr;

+ 4 - 0
TODO.txt

@@ -55,6 +55,10 @@ Optional:
    - When a GUI element containing a long piece of text is created, and it has flexible size, the initial optimal size
      calculation will try to fit all the text in one row, even if during the actual size calculation that turns out to be impossible.
      What happens then is that the text is rendered into multiple rows but its visible area only shows the first row.
+ - If a field gets optimized out from a material's GPU program it won't get persisted by the inspector (or serialized)
+  - (i.e. the field exists in shader desc but not as a GPU variable)
+  - I should probably store a copy of all shader fields in Material itself (and serialize that)
+   - When I modify this make sure to copy parameter copying method that is called when shader changes (that persist parameters)
 
 Seriously optional:
  - Drag to select in scene view