소스 검색

Added a check & warning for plain types larger than 255 bytes

Marko Pintera 13 년 전
부모
커밋
7af4988bd3
3개의 변경된 파일8개의 추가작업 그리고 10개의 파일을 삭제
  1. 0 2
      CamelotRenderer/TODO.txt
  2. 8 6
      CamelotUtility/Include/CmRTTIPlainField.h
  3. 0 2
      CamelotUtility/Include/CmRTTIType.h

+ 0 - 2
CamelotRenderer/TODO.txt

@@ -45,9 +45,7 @@ TODO:
  - OpenGL too
 
 TOMORROW:
- - Check for duplicate type IDs in InitRTTIOnStart
  - Depth test is disabled by default (OpenGL renderer at least)
- - Non-dynamic-size types cannot have size over 255 bytes but that isn't marked or checked anywhere!
  - Serializable callbacks can't be null otherwise compiler complains
  - Ogre performed special DDS loading. I removed that. I'm not sure if I'll need to re-add it?
  - How do I serialize derived classes, without rewriting all the base class serialization?

+ 8 - 6
CamelotUtility/Include/CmRTTIPlainField.h

@@ -149,14 +149,15 @@ namespace CamelotEngine
 		 * @param	getter  	The getter method for the field. Cannot be null. Must be a specific signature: DataType(ObjectType*).
 		 * @param	setter  	The setter method for the field. Can be null. Must be a specific signature: void(ObjectType*, DataType)
 		 * 						
-		 * @note	IMPORTANT - Type returned/set by getter/setter must provide "public static int TYPE_ID" field, which can be used for identifying the
-		 * 			type. You can set the ID to anything you wish, as it is not used internally. However its possible that other engine modules do require
-		 * 			you to set this field to a unique value. Native types do not need (or can) set this field. 
 		 */
 		void initSingle(const std::string& name, UINT16 uniqueId, boost::any getter, boost::any setter)
 		{
 			int typeId = SerializableSimpleType<DataType>::id; // Just making sure provided type has a type ID
 
+			BOOST_STATIC_ASSERT_MSG((SerializableSimpleType<DataType>::hasDynamicSize != 0 || (sizeof(DataType) <= 255)), 
+				"Trying to create a plain RTTI field with size larger than 255. In order to use larger sizes for plain types please specialize " \
+				" SerializableSimpleType, set hasDynamicSize to true.");
+
 			initAll(getter, setter, nullptr, nullptr, name, uniqueId, false, SerializableFT_Plain);
 		}
 
@@ -174,15 +175,16 @@ namespace CamelotEngine
 		 * @param	setter  	The setter method for the field. Can be null. Must be a specific signature: void(ObjectType*, UINT32, DataType)
 		 * @param	setSize 	Setter method that allows you to resize an array. Can be null. Must be a specific signature: void(ObjectType*, UINT32)
 		 * 						
-		 * @note	IMPORTANT - Type returned/set by getter/setter must provide "public static UINT32 TYPE_ID" field, which can be used for identifying the
-		 * 			type. You can set the ID to anything you wish, as it is not used internally. However its possible that other engine modules do require
-		 * 			you to set this field to a unique value. Native types do not need (or can) set this field.
 		 */
 		void initArray(const std::string& name, UINT16 uniqueId, boost::any getter, 
 			boost::any getSize, boost::any setter, boost::any setSize)
 		{
 			int typeId = SerializableSimpleType<DataType>::id; // Just making sure provided type has a type ID
 
+			BOOST_STATIC_ASSERT_MSG((SerializableSimpleType<DataType>::hasDynamicSize != 0 || (sizeof(DataType) <= 255)), 
+				"Trying to create a plain RTTI field with size larger than 255. In order to use larger sizes for plain types please specialize " \
+				" SerializableSimpleType, set hasDynamicSize to true.");
+
 			initAll(getter, setter, getSize, setSize, name, uniqueId, true, SerializableFT_Plain);
 		}
 

+ 0 - 2
CamelotUtility/Include/CmRTTIType.h

@@ -259,7 +259,6 @@ namespace CamelotEngine
 	public:
 		InitRTTIOnStart()
 		{
-			// TODO - Check if type ID is unique
 			BaseType::getRTTIStatic()->registerDerivedClass(Type::getRTTIStatic());
 		}
 
@@ -275,7 +274,6 @@ namespace CamelotEngine
 	public:
 		InitRTTIOnStart()
 		{
-			// TODO - Check if type ID is unique
 			IReflectable::registerDerivedClass(Type::getRTTIStatic());
 		}