Răsfoiți Sursa

Half assed commit before I break even more shit

Marko Pintera 13 ani în urmă
părinte
comite
f55ac7be6e

+ 1 - 1
CamelotRenderer/Include/CmApplication.h

@@ -43,7 +43,7 @@ namespace CamelotEngine
 			GameObjectPtr mCameraGO;
 			GameObjectPtr mCameraGO;
 
 
 			ShaderPtr mTestShader;
 			ShaderPtr mTestShader;
-			MaterialPtr mTestMaterial;
+			MaterialRef mTestMaterial;
 	};
 	};
 
 
 	CM_EXPORT Application& gApplication();
 	CM_EXPORT Application& gApplication();

+ 9 - 5
CamelotRenderer/Include/CmMaterialRTTI.h

@@ -42,7 +42,7 @@ namespace CamelotEngine
 		class FloatParamKVPRTTI;
 		class FloatParamKVPRTTI;
 		typedef KeyValuePair<String, FloatParam, FloatParamKVPRTTI> FloatParamKVP;
 		typedef KeyValuePair<String, FloatParam, FloatParamKVPRTTI> FloatParamKVP;
 
 
-		class FloatParamKVPRTTI : public KeyValuePairRTTI<String, FloatParam>
+		class FloatParamKVPRTTI : public KeyValuePairRTTI<String, FloatParam, FloatParamKVP>
 		{
 		{
 		public:
 		public:
 			virtual const String& getRTTIName()
 			virtual const String& getRTTIName()
@@ -65,7 +65,7 @@ namespace CamelotEngine
 		class TexParamKVPRTTI;
 		class TexParamKVPRTTI;
 		typedef KeyValuePair<String, TextureRef, TexParamKVPRTTI> TexParamKVP;
 		typedef KeyValuePair<String, TextureRef, TexParamKVPRTTI> TexParamKVP;
 
 
-		class TexParamKVPRTTI : public KeyValuePairRTTI<String, TextureRef>
+		class TexParamKVPRTTI : public KeyValuePairRTTI<String, TextureRef, TexParamKVP>
 		{
 		{
 		public:
 		public:
 			virtual const String& getRTTIName()
 			virtual const String& getRTTIName()
@@ -134,7 +134,7 @@ namespace CamelotEngine
 
 
 			UINT32 getNumFloatParams(MaterialParams* obj)
 			UINT32 getNumFloatParams(MaterialParams* obj)
 			{
 			{
-				obj->mFloatParams.size();
+				return obj->mFloatParams.size();
 			}
 			}
 
 
 			std::shared_ptr<TexParamKVP> getTexParam(MaterialParams* obj, UINT32 idx)
 			std::shared_ptr<TexParamKVP> getTexParam(MaterialParams* obj, UINT32 idx)
@@ -165,7 +165,7 @@ namespace CamelotEngine
 
 
 			UINT32 getNumTexParams(MaterialParams* obj)
 			UINT32 getNumTexParams(MaterialParams* obj)
 			{
 			{
-				obj->mTextureParams.size();
+				return obj->mTextureParams.size();
 			}
 			}
 
 
 			ManagedDataBlock getFloatBuffer(MaterialParams* obj)
 			ManagedDataBlock getFloatBuffer(MaterialParams* obj)
@@ -193,7 +193,11 @@ namespace CamelotEngine
 		public:
 		public:
 			MaterialParamsRTTI()
 			MaterialParamsRTTI()
 			{
 			{
-				
+				addReflectablePtrArrayField("mFloatParams", 0, &MaterialParamsRTTI::getFloatParam, &MaterialParamsRTTI::getNumFloatParams, 
+					&MaterialParamsRTTI::setFloatParam, &MaterialParamsRTTI::setNumFloatParams);
+				addReflectablePtrArrayField("mTexParams", 1, &MaterialParamsRTTI::getTexParam, &MaterialParamsRTTI::getNumTexParams, 
+					&MaterialParamsRTTI::setTexParam, &MaterialParamsRTTI::setNumTexParams);
+				addDataBlockField("mFloatBuffer", 2, &MaterialParamsRTTI::getFloatBuffer, &MaterialParamsRTTI::setFloatBuffer);
 			}
 			}
 
 
 			virtual const String& getRTTIName()
 			virtual const String& getRTTIName()

+ 1 - 0
CamelotRenderer/Include/CmPrerequisites.h

@@ -185,6 +185,7 @@ namespace CamelotEngine
 	typedef ResourceRef<Mesh> MeshRef;
 	typedef ResourceRef<Mesh> MeshRef;
 	typedef ResourceRef<GpuProgram> GpuProgramRef;
 	typedef ResourceRef<GpuProgram> GpuProgramRef;
 	typedef ResourceRef<HighLevelGpuProgram> HighLevelGpuProgramRef;
 	typedef ResourceRef<HighLevelGpuProgram> HighLevelGpuProgramRef;
+	typedef ResourceRef<Material> MaterialRef;
 }
 }
 
 
 #endif // __OgrePrerequisites_H__
 #endif // __OgrePrerequisites_H__

+ 6 - 0
CamelotRenderer/Include/CmResourceRef.h

@@ -61,6 +61,12 @@ namespace CamelotEngine
 		 */
 		 */
 		void resolve(std::shared_ptr<Resource> ptr);
 		void resolve(std::shared_ptr<Resource> ptr);
 
 
+		/**
+		 * @brief	Sets an uuid of the ResourceRef. Should only be called by
+		 * 			Resources class.
+		 */
+		void ResourceRefBase::setUUID(const String& uuid);
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								RTTI		                     		*/
 		/* 								RTTI		                     		*/
 		/************************************************************************/
 		/************************************************************************/

+ 1 - 0
CamelotRenderer/Include/CmResources.h

@@ -135,6 +135,7 @@ namespace CamelotEngine
 	private:
 	private:
 		typedef std::shared_ptr<ResourceMetaData> ResourceMetaDataPtr;
 		typedef std::shared_ptr<ResourceMetaData> ResourceMetaDataPtr;
 		map<String, ResourceMetaDataPtr>::type mResourceMetaData;
 		map<String, ResourceMetaDataPtr>::type mResourceMetaData;
+		map<String, ResourceMetaDataPtr>::type mResourceMetaData_FilePath;
 
 
 		ResourceRequestHandler* mRequestHandler;
 		ResourceRequestHandler* mRequestHandler;
 		ResourceResponseHandler* mResponseHandler;
 		ResourceResponseHandler* mResponseHandler;

+ 5 - 1
CamelotRenderer/Source/CmApplication.cpp

@@ -176,6 +176,11 @@ namespace CamelotEngine
 		mDbgTexture = static_resource_cast<Texture>(gResources().loadAsync("C:\\ExportTest.tex"));
 		mDbgTexture = static_resource_cast<Texture>(gResources().loadAsync("C:\\ExportTest.tex"));
 		mDbgMesh = static_resource_cast<Mesh>(gResources().loadAsync("C:\\ExportMesh.mesh"));
 		mDbgMesh = static_resource_cast<Mesh>(gResources().loadAsync("C:\\ExportMesh.mesh"));
 
 
+		mTestMaterial->setTexture("tex", mDbgTexture);
+		gResources().create(mTestMaterial, "C:\\ExportMaterial.mat", true);
+
+		mTestMaterial = gResources().load("C:\\ExportMaterial.mat");
+
 		loadPlugin("CamelotOISInput"); // TODO - Load this automatically somehow
 		loadPlugin("CamelotOISInput"); // TODO - Load this automatically somehow
 	}
 	}
 
 
@@ -276,7 +281,6 @@ namespace CamelotEngine
 		renderSystem->_beginFrame();
 		renderSystem->_beginFrame();
 
 
 		mTestMaterial->setMat4("matViewProjection", viewProjMatrix);
 		mTestMaterial->setMat4("matViewProjection", viewProjMatrix);
-		mTestMaterial->setTexture("tex", mDbgTexture);
 
 
 		mTestMaterial->applyPass(0);
 		mTestMaterial->applyPass(0);
 		
 		

+ 5 - 0
CamelotRenderer/Source/CmResourceRef.cpp

@@ -26,6 +26,11 @@ namespace CamelotEngine
 		init(ptr);
 		init(ptr);
 	}
 	}
 
 
+	void ResourceRefBase::setUUID(const String& uuid) 
+	{ 
+		mData->mUUID = uuid;
+	}
+
 	void ResourceRefBase::init(Resource* ptr)
 	void ResourceRefBase::init(Resource* ptr)
 	{
 	{
 		init(std::shared_ptr<Resource>(ptr));
 		init(std::shared_ptr<Resource>(ptr));

+ 30 - 17
CamelotRenderer/Source/CmResources.cpp

@@ -178,7 +178,19 @@ namespace CamelotEngine
 			return nullptr;
 			return nullptr;
 		}
 		}
 
 
+		// TODO Low priority - Right now I don't allow loading of resources that don't have meta-data, because I need to know resources UUID
+		// at this point. And I can't do that without having meta-data. Other option is to partially load the resource to read the UUID but due to the
+		// nature of the serializer it could complicate things. (But possible if this approach proves troublesome)
+		// The reason I need the UUID is that when resource is loaded Async, the returned ResourceRef needs to have a valid UUID, in case I assign that
+		// ResourceRef to something and then save that something. If I didn't assign it, the saved ResourceRef would have a blank (i.e. invalid) UUID.
+		if(!metaExists_Path(filePath))
+		{
+			CM_EXCEPT(InternalErrorException, "Cannot load resource that isn't registered in the meta database. Call Resources::create first.");
+		}
+
+		String uuid = getUUIDFromPath(filePath);
 		BaseResourceRef newResource;
 		BaseResourceRef newResource;
+		newResource.setUUID(uuid); // UUID needs to be set immediately if the resource gets loaded async
 
 
 		ResourceLoadRequestPtr resRequest = ResourceLoadRequestPtr(new Resources::ResourceLoadRequest());
 		ResourceLoadRequestPtr resRequest = ResourceLoadRequestPtr(new Resources::ResourceLoadRequest());
 		resRequest->filePath = filePath;
 		resRequest->filePath = filePath;
@@ -263,6 +275,7 @@ namespace CamelotEngine
 
 
 				ResourceMetaDataPtr metaData = std::static_pointer_cast<ResourceMetaData>(loadedData);
 				ResourceMetaDataPtr metaData = std::static_pointer_cast<ResourceMetaData>(loadedData);
 				mResourceMetaData[metaData->mUUID] = metaData;
 				mResourceMetaData[metaData->mUUID] = metaData;
+				mResourceMetaData_FilePath[metaData->mPath] = metaData;
 			}
 			}
 		}
 		}
 	}
 	}
@@ -280,7 +293,15 @@ namespace CamelotEngine
 		String fullPath = Path::combine(mMetaDataFolderPath, uuid + ".resmeta");
 		String fullPath = Path::combine(mMetaDataFolderPath, uuid + ".resmeta");
 		FileSystem::remove(fullPath);
 		FileSystem::remove(fullPath);
 
 
-		mResourceMetaData.erase(uuid);
+		auto iter = mResourceMetaData.find(uuid);
+
+		if(iter != mResourceMetaData.end())
+		{
+			mResourceMetaData.erase(iter);
+			mResourceMetaData_FilePath.erase(iter->second->mPath);
+		}
+		else
+			gDebug().logWarning("Trying to remove meta data that doesn't exist.");
 	}
 	}
 
 
 	void Resources::addMetaData(const String& uuid, const String& filePath)
 	void Resources::addMetaData(const String& uuid, const String& filePath)
@@ -296,6 +317,7 @@ namespace CamelotEngine
 		dbEntry->mUUID = uuid;
 		dbEntry->mUUID = uuid;
 
 
 		mResourceMetaData[uuid] = dbEntry;
 		mResourceMetaData[uuid] = dbEntry;
+		mResourceMetaData_FilePath[filePath] = dbEntry;
 
 
 		saveMetaData(dbEntry);
 		saveMetaData(dbEntry);
 	}
 	}
@@ -325,15 +347,12 @@ namespace CamelotEngine
 
 
 	const String& Resources::getUUIDFromPath(const String& path) const
 	const String& Resources::getUUIDFromPath(const String& path) const
 	{
 	{
-		for(auto iter = mResourceMetaData.begin(); iter != mResourceMetaData.end(); ++iter)
-		{
-			if(iter->second->mPath == path)
-			{
-				return iter->second->mUUID;
-			}
-		}
+		auto findIter = mResourceMetaData_FilePath.find(path);
 
 
-		return StringUtil::BLANK;
+		if(findIter != mResourceMetaData_FilePath.end())
+			return findIter->second->mUUID;
+		else
+			return StringUtil::BLANK;
 	}
 	}
 
 
 	bool Resources::metaExists_UUID(const String& uuid) const
 	bool Resources::metaExists_UUID(const String& uuid) const
@@ -345,15 +364,9 @@ namespace CamelotEngine
 
 
 	bool Resources::metaExists_Path(const String& path) const
 	bool Resources::metaExists_Path(const String& path) const
 	{
 	{
-		for(auto iter = mResourceMetaData.begin(); iter != mResourceMetaData.end(); ++iter)
-		{
-			if(iter->second->mPath == path)
-			{
-				return true;
-			}
-		}
+		auto findIter = mResourceMetaData_FilePath.find(path);
 
 
-		return false;
+		return findIter != mResourceMetaData_FilePath.end();
 	}
 	}
 
 
 	CM_EXPORT Resources& gResources()
 	CM_EXPORT Resources& gResources()

+ 6 - 6
CamelotUtility/Include/CmKeyValuepair.h

@@ -6,7 +6,7 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
-	template <typename Key, typename Value>
+	template <typename Key, typename Value, typename RTTIType>
 	class KeyValuePairRTTI;
 	class KeyValuePairRTTI;
 
 
 	template <typename Key, typename Value>
 	template <typename Key, typename Value>
@@ -28,17 +28,17 @@ namespace CamelotEngine
 	public:
 	public:
 		static RTTITypeBase* getRTTIStatic()
 		static RTTITypeBase* getRTTIStatic()
 		{
 		{
-			return KeyValuePairRTTI<Key, Value>::instance();
+			return nullptr;
 		}
 		}
 
 
 		RTTITypeBase* getRTTI() const
 		RTTITypeBase* getRTTI() const
 		{
 		{
-			return KeyValuePairBase<Key, Value>::getRTTIStatic();
+			return nullptr;
 		}
 		}
 	};
 	};
 
 
-	template <typename Key, typename Value>
-	class KeyValuePairRTTI : public RTTIType<KeyValuePairBase<Key, Value>, IReflectable, KeyValuePairRTTI<Key, Value>>
+	template <typename Key, typename Value, typename MyType>
+	class KeyValuePairRTTI : public RTTIType<MyType, IReflectable, KeyValuePairRTTI<Key, Value, MyType>>
 	{
 	{
 	private:
 	private:
 		Key& getKey(KeyValuePairBase<Key, Value>* obj) { return obj->mKey; }
 		Key& getKey(KeyValuePairBase<Key, Value>* obj) { return obj->mKey; }
@@ -91,7 +91,7 @@ namespace CamelotEngine
 			return RTTIClass::instance();
 			return RTTIClass::instance();
 		}
 		}
 
 
-		RTTITypeBase* getRTTI() const
+		virtual RTTITypeBase* getRTTI() const
 		{
 		{
 			return KeyValuePair<Key, Value, RTTIClass>::getRTTIStatic();
 			return KeyValuePair<Key, Value, RTTIClass>::getRTTIStatic();
 		}
 		}

+ 21 - 6
CamelotUtility/Source/CmBinarySerializer.cpp

@@ -192,6 +192,27 @@ namespace CamelotEngine
 				curPtr.field->setValue(curPtr.object.get(), resolvedObject);
 				curPtr.field->setValue(curPtr.object.get(), resolvedObject);
 		}
 		}
 
 
+		// Finish serialization for all objects
+		// TODO Low priority - If we're decoding a very large class hierarchy, finishing serialization
+		// only at the end of the entire decode process could cause issues. It would be better if I can do it 
+		// every time I know a certain object has been fully decoded. (This would probably involve resolving 
+		// pointers at an earlier stage as well)
+		for(auto iter = mDecodedObjects.rbegin(); iter != mDecodedObjects.rend(); ++iter)
+		{
+			std::shared_ptr<IReflectable> resolvedObject = iter->second;
+
+			if(resolvedObject != nullptr)
+			{
+				RTTITypeBase* si = object->getRTTI();
+
+				while(si != nullptr)
+				{
+					si->onDeserializationEnded(object.get());
+					si = si->getBaseClass();
+				}
+			}
+		}
+
 		return rootObject;
 		return rootObject;
 	}
 	}
 
 
@@ -471,9 +492,6 @@ namespace CamelotEngine
 
 
 			if(isObjectMetaData(metaData)) // We've reached a new object
 			if(isObjectMetaData(metaData)) // We've reached a new object
 			{
 			{
-				if(si != nullptr)
-					si->onDeserializationEnded(object.get());
-
 				if((bytesRead + sizeof(ObjectMetaData)) > dataLength)
 				if((bytesRead + sizeof(ObjectMetaData)) > dataLength)
 				{
 				{
 					CM_EXCEPT(InternalErrorException, 
 					CM_EXCEPT(InternalErrorException, 
@@ -754,9 +772,6 @@ namespace CamelotEngine
 			}
 			}
 		}
 		}
 
 
-		if(si != nullptr)
-			si->onDeserializationEnded(object.get());
-
 		return false;
 		return false;
 	}
 	}