Browse Source

Re-enabled save/load for resources

Marko Pintera 13 years ago
parent
commit
b51882b16c

+ 1 - 0
CamelotRenderer/CamelotRenderer.vcxproj

@@ -139,6 +139,7 @@
     <ClInclude Include="Include\CmRenderWindow.h" />
     <ClInclude Include="Include\CmRenderWindow.h" />
     <ClInclude Include="Include\CmResource.h" />
     <ClInclude Include="Include\CmResource.h" />
     <ClInclude Include="Include\CmResourceRef.h" />
     <ClInclude Include="Include\CmResourceRef.h" />
+    <ClInclude Include="Include\CmResourceRefRTTI.h" />
     <ClInclude Include="Include\CmResources.h" />
     <ClInclude Include="Include\CmResources.h" />
     <ClInclude Include="Include\CmSceneManager.h" />
     <ClInclude Include="Include\CmSceneManager.h" />
     <ClInclude Include="Include\CmSpecificImporter.h" />
     <ClInclude Include="Include\CmSpecificImporter.h" />

+ 3 - 0
CamelotRenderer/CamelotRenderer.vcxproj.filters

@@ -271,6 +271,9 @@
     <ClInclude Include="Include\CmResourceRef.h">
     <ClInclude Include="Include\CmResourceRef.h">
       <Filter>Header Files\Resources</Filter>
       <Filter>Header Files\Resources</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="Include\CmResourceRefRTTI.h">
+      <Filter>Header Files\RTTI</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\CamelotRenderer.cpp">
     <ClCompile Include="Source\CamelotRenderer.cpp">

+ 2 - 1
CamelotRenderer/Include/CmPrerequisites.h

@@ -153,7 +153,8 @@ namespace CamelotEngine
 		TID_VertexData = 1005,
 		TID_VertexData = 1005,
 		TID_Component = 1006,
 		TID_Component = 1006,
 		TID_Camera = 1007,
 		TID_Camera = 1007,
-		TID_Renderable = 1008
+		TID_Renderable = 1008,
+		TID_ResourceRef = 1009
 	};
 	};
 }
 }
 
 

+ 13 - 3
CamelotRenderer/Include/CmResourceRef.h

@@ -1,11 +1,13 @@
 #pragma once
 #pragma once
 
 
+#include "CmIReflectable.h"
+
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
 	template <typename T>
 	template <typename T>
 	class ResourceRef;
 	class ResourceRef;
 
 
-	class CM_EXPORT ResourceRefBase
+	class CM_EXPORT ResourceRefBase : public IReflectable
 	{
 	{
 	protected:
 	protected:
 		ResourceRefBase()
 		ResourceRefBase()
@@ -24,6 +26,14 @@ namespace CamelotEngine
 		{
 		{
 			init(std::static_pointer_cast<Resource>(ptr.mPtr));
 			init(std::static_pointer_cast<Resource>(ptr.mPtr));
 		}
 		}
+
+		/************************************************************************/
+		/* 								RTTI		                     		*/
+		/************************************************************************/
+	public:
+		friend class ResourceRefRTTI;
+		static RTTITypeBase* getRTTIStatic();
+		virtual RTTITypeBase* getRTTI() const;
 	};
 	};
 
 
 	template <typename T>
 	template <typename T>
@@ -53,9 +63,9 @@ namespace CamelotEngine
 			init(ptr);
 			init(ptr);
 		}
 		}
 
 
-		operator ResourceRef<Resource>&() 
+		operator ResourceRef<Resource>() 
 		{
 		{
-			return *this; 
+			return ResourceRef<Resource>(this->mPtr); 
 		}
 		}
 
 
 		const T* get() const { return static_cast<T*>(mPtr.get()); }
 		const T* get() const { return static_cast<T*>(mPtr.get()); }

+ 35 - 0
CamelotRenderer/Include/CmResourceRefRTTI.h

@@ -0,0 +1,35 @@
+#pragma once
+
+#include "CmPrerequisites.h"
+#include "CmRTTIType.h"
+#include "CmResourceRef.h"
+
+namespace CamelotEngine
+{
+	class CM_EXPORT ResourceRefRTTI : public RTTIType<ResourceRefBase, IReflectable, ResourceRefRTTI>
+	{
+	private:
+
+	public:
+		ResourceRefRTTI()
+		{
+
+		}
+
+		virtual const String& getRTTIName()
+		{
+			static String name = "ResourceRef";
+			return name;
+		}
+
+		virtual UINT32 getRTTIId()
+		{
+			return TID_ResourceRef;
+		}
+
+		virtual std::shared_ptr<IReflectable> newRTTIObject()
+		{
+			return std::shared_ptr<ResourceRefBase>(new ResourceRefBase());
+		}
+	};
+}

+ 3 - 3
CamelotRenderer/Include/CmResources.h

@@ -31,7 +31,7 @@ namespace CamelotEngine
 		 *
 		 *
 		 * @return	Loaded resource, or null if it cannot be found.
 		 * @return	Loaded resource, or null if it cannot be found.
 		 */
 		 */
-		ResourcePtr load(const String& filePath);
+		BaseResourceRef load(const String& filePath);
 
 
 		/**
 		/**
 		 * @brief	Loads the resource with the given uuid.
 		 * @brief	Loads the resource with the given uuid.
@@ -40,7 +40,7 @@ namespace CamelotEngine
 		 *
 		 *
 		 * @return	Loaded resource, or null if it cannot be found.
 		 * @return	Loaded resource, or null if it cannot be found.
 		 */
 		 */
-		ResourcePtr load(const UUID& uuid);
+		BaseResourceRef load(const UUID& uuid);
 
 
 		/**
 		/**
 		 * @brief	Saves the resource at the specified location.
 		 * @brief	Saves the resource at the specified location.
@@ -48,7 +48,7 @@ namespace CamelotEngine
 		 * @param	resource	The resource.
 		 * @param	resource	The resource.
 		 * @param	filePath	Full pathname of the file.
 		 * @param	filePath	Full pathname of the file.
 		 */
 		 */
-		void save(ResourcePtr resource, const String& filePath);
+		void save(BaseResourceRef resource, const String& filePath);
 	};
 	};
 
 
 	CM_EXPORT Resources& gResources();
 	CM_EXPORT Resources& gResources();

+ 4 - 4
CamelotRenderer/Source/CmApplication.cpp

@@ -162,11 +162,11 @@ namespace CamelotEngine
 
 
 		Resources::startUp(new Resources());
 		Resources::startUp(new Resources());
 
 
-		//gResources().save(testTex, "C:\\ExportTest.tex");
-		//gResources().save(mDbgMesh, "C:\\ExportMesh.mesh");
+		gResources().save(testTex, "C:\\ExportTest.tex");
+		gResources().save(mDbgMesh, "C:\\ExportMesh.mesh");
 
 
-		//mDbgTexture = std::static_pointer_cast<Texture>(gResources().load("C:\\ExportTest.tex"));
-		//mDbgMesh = std::static_pointer_cast<Mesh>(gResources().load("C:\\ExportMesh.mesh"));
+		mDbgTexture = static_resource_cast<Texture>(gResources().load("C:\\ExportTest.tex"));
+		mDbgMesh = static_resource_cast<Mesh>(gResources().load("C:\\ExportMesh.mesh"));
 
 
 		mDbgTexture = testTex;
 		mDbgTexture = testTex;
 
 

+ 11 - 0
CamelotRenderer/Source/CmResourceRef.cpp

@@ -1,6 +1,7 @@
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 #include "CmResourceRef.h"
 #include "CmResourceRef.h"
 #include "CmResource.h"
 #include "CmResource.h"
+#include "CmResourceRefRTTI.h"
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
@@ -19,4 +20,14 @@ namespace CamelotEngine
 			mUUIDSet = true;
 			mUUIDSet = true;
 		}
 		}
 	}
 	}
+
+	RTTITypeBase* ResourceRefBase::getRTTIStatic()
+	{
+		return ResourceRefRTTI::instance();
+	}
+
+	RTTITypeBase* ResourceRefBase::getRTTI() const
+	{
+		return ResourceRefBase::getRTTIStatic();
+	}
 }
 }

+ 5 - 5
CamelotRenderer/Source/CmResources.cpp

@@ -15,7 +15,7 @@ namespace CamelotEngine
 
 
 	}
 	}
 
 
-	ResourcePtr Resources::load(const String& filePath)
+	BaseResourceRef Resources::load(const String& filePath)
 	{
 	{
 		FileSerializer fs;
 		FileSerializer fs;
 		std::shared_ptr<IReflectable> loadedData = fs.decode(filePath);
 		std::shared_ptr<IReflectable> loadedData = fs.decode(filePath);
@@ -31,17 +31,17 @@ namespace CamelotEngine
 		ResourcePtr resource = std::static_pointer_cast<Resource>(loadedData);
 		ResourcePtr resource = std::static_pointer_cast<Resource>(loadedData);
 		resource->load();
 		resource->load();
 
 
-		return resource;
+		return BaseResourceRef(resource);
 	}
 	}
 
 
-	ResourcePtr Resources::load(const UUID& uuid)
+	BaseResourceRef Resources::load(const UUID& uuid)
 	{
 	{
 		CM_EXCEPT(NotImplementedException, "Not implemented");
 		CM_EXCEPT(NotImplementedException, "Not implemented");
 	}
 	}
 
 
-	void Resources::save(ResourcePtr resource, const String& filePath)
+	void Resources::save(BaseResourceRef resource, const String& filePath)
 	{
 	{
-		assert(resource != nullptr);
+		assert(resource.get() != nullptr);
 
 
 		// TODO - Low priority. Check is file path valid?
 		// TODO - Low priority. Check is file path valid?