Parcourir la source

Before changing some RTTI stuff to references

Marko Pintera il y a 13 ans
Parent
commit
e5ff8b42a4

+ 4 - 0
CamelotClient/CamelotClient.cpp

@@ -5,10 +5,14 @@
 
 
 #include "CmApplication.h"
 #include "CmApplication.h"
 
 
+#include "TestingGround.h"
+
 using namespace CamelotEngine;
 using namespace CamelotEngine;
 
 
 int _tmain(int argc, _TCHAR* argv[])
 int _tmain(int argc, _TCHAR* argv[])
 {
 {
+	test();
+
 	gApplication().startUp("CamelotGLRenderer.dll");
 	gApplication().startUp("CamelotGLRenderer.dll");
 	//gApplication().startUp("CamelotD3D9Renderer.dll");
 	//gApplication().startUp("CamelotD3D9Renderer.dll");
 
 

+ 6 - 4
CamelotClient/CamelotClient.vcxproj

@@ -54,12 +54,12 @@
       <WarningLevel>Level3</WarningLevel>
       <WarningLevel>Level3</WarningLevel>
       <Optimization>Disabled</Optimization>
       <Optimization>Disabled</Optimization>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>..\CamelotRenderer\Include;..\CamelotD3D9Renderer\Include;..\CamelotUtility\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\CamelotRenderer\Include;..\CamelotD3D9Renderer\Include;..\CamelotUtility\Include;..\Dependencies\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     </ClCompile>
     <Link>
     <Link>
       <SubSystem>Console</SubSystem>
       <SubSystem>Console</SubSystem>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <GenerateDebugInformation>true</GenerateDebugInformation>
-      <AdditionalDependencies>CamelotRenderer.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>CamelotRenderer.lib;CamelotUtility.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalLibraryDirectories>..\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <AdditionalLibraryDirectories>..\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
     </Link>
     </Link>
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
@@ -72,7 +72,7 @@
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <FunctionLevelLinking>true</FunctionLevelLinking>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <IntrinsicFunctions>true</IntrinsicFunctions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalIncludeDirectories>..\CamelotRenderer\Include;..\CamelotD3D9Renderer\Include;..\CamelotUtility\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\CamelotRenderer\Include;..\CamelotD3D9Renderer\Include;..\CamelotUtility\Include;..\Dependencies\Include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </ClCompile>
     </ClCompile>
     <Link>
     <Link>
       <SubSystem>Console</SubSystem>
       <SubSystem>Console</SubSystem>
@@ -80,7 +80,7 @@
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
       <OptimizeReferences>true</OptimizeReferences>
       <AdditionalLibraryDirectories>..\lib\$(Configuration)</AdditionalLibraryDirectories>
       <AdditionalLibraryDirectories>..\lib\$(Configuration)</AdditionalLibraryDirectories>
-      <AdditionalDependencies>CamelotRenderer.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>CamelotRenderer.lib;CamelotUtility.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     </Link>
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>
   <ItemGroup>
   <ItemGroup>
@@ -89,10 +89,12 @@
   <ItemGroup>
   <ItemGroup>
     <ClInclude Include="stdafx.h" />
     <ClInclude Include="stdafx.h" />
     <ClInclude Include="targetver.h" />
     <ClInclude Include="targetver.h" />
+    <ClInclude Include="TestingGround.h" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="CamelotClient.cpp" />
     <ClCompile Include="CamelotClient.cpp" />
     <ClCompile Include="stdafx.cpp" />
     <ClCompile Include="stdafx.cpp" />
+    <ClCompile Include="TestingGround.cpp" />
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   <ImportGroup Label="ExtensionTargets">

+ 6 - 0
CamelotClient/CamelotClient.vcxproj.filters

@@ -24,6 +24,9 @@
     <ClInclude Include="targetver.h">
     <ClInclude Include="targetver.h">
       <Filter>Header Files</Filter>
       <Filter>Header Files</Filter>
     </ClInclude>
     </ClInclude>
+    <ClInclude Include="TestingGround.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <ClCompile Include="stdafx.cpp">
     <ClCompile Include="stdafx.cpp">
@@ -32,5 +35,8 @@
     <ClCompile Include="CamelotClient.cpp">
     <ClCompile Include="CamelotClient.cpp">
       <Filter>Source Files</Filter>
       <Filter>Source Files</Filter>
     </ClCompile>
     </ClCompile>
+    <ClCompile Include="TestingGround.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   </ItemGroup>
 </Project>
 </Project>

+ 19 - 0
CamelotClient/TestingGround.cpp

@@ -0,0 +1,19 @@
+#include "TestingGround.h"
+
+#include "CmFileSerializer.h"
+#include "CmResource.h"
+
+using namespace CamelotEngine;
+
+void test()
+{
+	Resource* dbgResource = new Resource();
+	UINT32 size = 5;
+	dbgResource->getSerializable()->setPlainValue(dbgResource, "Size", size);
+
+	FileSerializer fs;
+	fs.encode(dbgResource, "C:\\ResourceTest.res");
+
+	Resource* loadedResource = new Resource();
+	fs.decode(loadedResource, "C:\\ResourceTest.res");
+}

+ 3 - 0
CamelotClient/TestingGround.h

@@ -0,0 +1,3 @@
+#pragma once
+
+void test();

+ 4 - 3
CamelotRenderer/Include/CmResource.h

@@ -12,6 +12,9 @@ namespace CamelotEngine
 	class CM_EXPORT Resource : public ISerializable
 	class CM_EXPORT Resource : public ISerializable
 	{
 	{
 	public:
 	public:
+		Resource(/*const UUID& sourceUUID*/) // TODO - Temporarily don't initialize UUID, because I want texture to inherit from resource and UUIDs arent set up yet
+			:mSize(0) /*mSourceUUID(sourceUUID),*/
+		{}
 		virtual ~Resource() {};
 		virtual ~Resource() {};
 
 
 		//public 
 		//public 
@@ -19,9 +22,7 @@ namespace CamelotEngine
 	protected:
 	protected:
 		friend class Resources;
 		friend class Resources;
 
 
-		Resource(/*const UUID& sourceUUID*/) // TODO - Temporarily don't initialize UUID, because I want texture to inherit from resource and UUIDs arent set up yet
-			:mSize(0) /*mSourceUUID(sourceUUID),*/
-		{}
+
 
 
 		//virtual void load() = 0;
 		//virtual void load() = 0;
 		//virtual void unload() = 0;
 		//virtual void unload() = 0;

+ 6 - 0
CamelotRenderer/Include/CmResourceST.h

@@ -7,15 +7,21 @@
 
 
 namespace CamelotEngine
 namespace CamelotEngine
 {
 {
+	CM_SERIALIZABLE_SIMPLE_TYPE(UUID, 11);
+	CM_SERIALIZABLE_SIMPLE_TYPE(UINT32&, 12);
 	class CM_EXPORT ResourceST : public SerializableType
 	class CM_EXPORT ResourceST : public SerializableType
 	{
 	{
 	private:
 	private:
 		UINT32 getSize(Resource* obj) { return obj->mSize; }
 		UINT32 getSize(Resource* obj) { return obj->mSize; }
 		void setSize(Resource* obj, UINT32 size) { obj->mSize = size; } 
 		void setSize(Resource* obj, UINT32 size) { obj->mSize = size; } 
+		UUID getUUID(Resource* obj) { return obj->mSourceUUID; }
+		void setUUID(Resource* obj, UUID uuid) { obj->mSourceUUID = uuid; }
+
 	public:
 	public:
 		ResourceST()
 		ResourceST()
 		{
 		{
 			addPlainField("Size", 0, &ResourceST::getSize, &ResourceST::setSize);
 			addPlainField("Size", 0, &ResourceST::getSize, &ResourceST::setSize);
+			addPlainField("UUID", 1, &ResourceST::getUUID, &ResourceST::setUUID);
 		}
 		}
 	};
 	};
 }
 }

+ 20 - 18
CamelotUtility/Include/CmRTTIField.h

@@ -4,6 +4,7 @@
 
 
 #include <boost/function.hpp>
 #include <boost/function.hpp>
 #include <boost/any.hpp>
 #include <boost/any.hpp>
+#include <boost/static_assert.hpp>
 
 
 #include "CmPrerequisitesUtil.h"
 #include "CmPrerequisitesUtil.h"
 #include "CmIReflectable.h"
 #include "CmIReflectable.h"
@@ -15,24 +16,25 @@ namespace CamelotEngine
 	struct RTTIField;
 	struct RTTIField;
 
 
 	template<class T>
 	template<class T>
-	struct SerializableSimpleType { enum { id = T::TYPE_ID }; enum { isNativeType = 0 }; };
-	
-#define SERIALIZABLE_SIMPLE_TYPE(type, type_id) \
-	template<> struct SerializableSimpleType<##type##> { enum { id=##type_id }; enum { isNativeType = 1 }; }; 
-
-	SERIALIZABLE_SIMPLE_TYPE(UINT8, 0);
-	SERIALIZABLE_SIMPLE_TYPE(UINT16, 1);
-	SERIALIZABLE_SIMPLE_TYPE(UINT32, 2);
-	SERIALIZABLE_SIMPLE_TYPE(UINT64, 3);
-	SERIALIZABLE_SIMPLE_TYPE(INT8, 4);
-	SERIALIZABLE_SIMPLE_TYPE(INT16, 5);
-	SERIALIZABLE_SIMPLE_TYPE(INT32, 6);
-	SERIALIZABLE_SIMPLE_TYPE(INT64, 7);
-	SERIALIZABLE_SIMPLE_TYPE(float, 8);
-	SERIALIZABLE_SIMPLE_TYPE(double, 9);
-	SERIALIZABLE_SIMPLE_TYPE(bool, 10);
-
-#undef SERIALIZABLE_SIMPLE_TYPE
+	struct SerializableSimpleType 
+	{ 
+		BOOST_STATIC_ASSERT_MSG(sizeof(T) == 0, // We need this hacky check, otherwise if we only use "false" compiler will evaluate the template and trigger this message 
+			"Provided serializable data type doesn't define have a type ID. Use CM_SERIALIZABLE_SIMPLE_TYPE(type, id) macro to define a unique ID for the type.");
+
+		enum { id = T::TYPE_ID }; enum { isNativeType = 0 }; 
+	};
+
+	CM_SERIALIZABLE_SIMPLE_TYPE(UINT8, 0);
+	CM_SERIALIZABLE_SIMPLE_TYPE(UINT16, 1);
+	CM_SERIALIZABLE_SIMPLE_TYPE(UINT32, 2);
+	CM_SERIALIZABLE_SIMPLE_TYPE(UINT64, 3);
+	CM_SERIALIZABLE_SIMPLE_TYPE(INT8, 4);
+	CM_SERIALIZABLE_SIMPLE_TYPE(INT16, 5);
+	CM_SERIALIZABLE_SIMPLE_TYPE(INT32, 6);
+	CM_SERIALIZABLE_SIMPLE_TYPE(INT64, 7);
+	CM_SERIALIZABLE_SIMPLE_TYPE(float, 8);
+	CM_SERIALIZABLE_SIMPLE_TYPE(double, 9);
+	CM_SERIALIZABLE_SIMPLE_TYPE(bool, 10);
 
 
 	/**
 	/**
 	 * @brief	Types of fields we can serialize:
 	 * @brief	Types of fields we can serialize:

+ 3 - 0
CamelotUtility/Include/CmTypes.h

@@ -19,4 +19,7 @@ namespace CamelotEngine
 	typedef unsigned long long UINT64;
 	typedef unsigned long long UINT64;
 	typedef long long INT64;
 	typedef long long INT64;
 #endif
 #endif
+
+#define CM_SERIALIZABLE_SIMPLE_TYPE(type, type_id) \
+	template<> struct SerializableSimpleType<##type##> { enum { id=##type_id }; enum { isNativeType = 1 }; }; 
 }
 }