Commits

Adam Labranche  committed f6be0ff

Patch reviews.

  • Participants
  • Parent commits 9685664

Comments (0)

Files changed (3)

File ALAnimationDefinitionSerialization

-# HG changeset patch
-# Parent c265a2f83ec0fd838429a40008db159cd389bec3
-Wrote the serialization functions to serialize and deserialize an AnimationDefinition.
-
-diff -r c265a2f83ec0 RedBox/RedBox/Display/AnimationDefinition.cpp
---- a/RedBox/RedBox/Display/AnimationDefinition.cpp	Thu Jan 26 09:04:12 2012 -0500
-+++ b/RedBox/RedBox/Display/AnimationDefinition.cpp	Thu Jan 26 09:12:23 2012 -0500
-@@ -1,6 +1,79 @@
- #include "AnimationDefinition.h"
- 
-+#include "DefaultSerializer.h"
-+#include "Serializer.h"
-+
- namespace RedBox {
-+
-+	void AnimationDefinition::serialize(const AnimationDefinition &input,
-+	                                    Value &node) {
-+		node["nbLoops"].setInt(input.nbLoops);
-+		node["timePerFrame"].setDouble(input.timePerFrame);
-+		Value &tmpValue = node["frames"];
-+		tmpValue.setArray(Array(input.frames.size()));
-+
-+		for (std::vector<unsigned int>::size_type i = 0; i < input.frames.size(); ++i) {
-+			tmpValue[i].setInt(static_cast<int>(input.frames[i]));
-+		}
-+	}
-+
-+	bool AnimationDefinition::deserialize(const Value &node,
-+	                                      AnimationDefinition &output) {
-+		bool result = true;
-+		const Object &tmpObject = node.getObject();
-+		Object::const_iterator itNbLoops = tmpObject.find("nbLoops");
-+		Object::const_iterator itTimePerFrame = tmpObject.find("timePerFrame");
-+		Object::const_iterator itFrames = tmpObject.find("frames");
-+
-+		if (itNbLoops != tmpObject.end() &&
-+		    itTimePerFrame != tmpObject.end() &&
-+		    itFrames != tmpObject.end()) {
-+
-+			// We make sure the frames value is an Array.
-+			if (itFrames->second.isArray()) {
-+				// We make sure the array contains only numbers.
-+				const Array &tmpArray = itFrames->second.getArray();
-+				Array::const_iterator i = tmpArray.begin();
-+
-+				while (result && i != tmpArray.end()) {
-+					if (i->isNumeric()) {
-+						++i;
-+
-+					} else {
-+						result = false;
-+					}
-+				}
-+
-+				if (result) {
-+					// We make sure the nbLoops ans timePerFrame attributes are
-+					// of correct type.
-+					if (itNbLoops->second.isNumeric() && itTimePerFrame->second.isNumeric()) {
-+
-+						output.nbLoops = itNbLoops->second.getInt();
-+						output.timePerFrame = itTimePerFrame->second.getDouble();
-+
-+						output.frames.resize(tmpArray.size());
-+
-+						for (Array::size_type i2 = 0; i2 < tmpArray.size(); ++i2) {
-+							output.frames[i2] = static_cast<unsigned int>(tmpArray[i2].getInt());
-+						}
-+
-+					} else {
-+						result = false;
-+					}
-+				}
-+
-+			} else {
-+				result = false;
-+			}
-+
-+		} else {
-+			result = false;
-+		}
-+
-+		return result;
-+	}
-+
- 	AnimationDefinition::AnimationDefinition(): frames(), timePerFrame(0.0),
- 		nbLoops(-1) {
- 	}
-@@ -27,18 +100,9 @@
- 
- 	std::ostream &operator<<(std::ostream &output,
- 	                         const AnimationDefinition &a) {
--		output << "{timePerFrame: ";
--		output << a.timePerFrame << ", nbLoops: " << a.nbLoops << ", frames: [";
--
--		for (std::vector<unsigned int>::const_iterator i = a.frames.begin(); i != a.frames.end(); ++i) {
--			if (i != a.frames.begin()) {
--				output << ", ";
--			}
--
--			output << *i;
--		}
--
--		output << "]}";
-+		Value tmpValue;
-+		DefaultSerializer::serialize(a, tmpValue);
-+		DefaultSerializer::getDefaultSerializer().writeToStream(output, tmpValue);
- 		return output;
- 	}
- }
-diff -r c265a2f83ec0 RedBox/RedBox/Display/AnimationDefinition.h
---- a/RedBox/RedBox/Display/AnimationDefinition.h	Thu Jan 26 09:04:12 2012 -0500
-+++ b/RedBox/RedBox/Display/AnimationDefinition.h	Thu Jan 26 09:12:23 2012 -0500
-@@ -10,6 +10,8 @@
- #include <string>
- #include <iostream>
- 
-+#include "Value.h"
-+
- namespace RedBox {
- 	/**
- 	 * Represents the details of an animation in a RenderStep.
-@@ -17,6 +19,23 @@
- 	 */
- 	struct AnimationDefinition {
- 		/**
-+		 * Serializes the animation definition to a Value.
-+		 * @param input Animation definition to serialize.
-+		 * @param node Value to serialize the animation definition to.
-+		 */
-+		static void serialize(const AnimationDefinition &input, Value &node);
-+
-+		/**
-+		 * Deserializes the animation definition from a Value.
-+		 * @param node Node to read the animation definition from.
-+		 * @param output Animation definition instance to write the Value to.
-+		 * @return True if the deserialization was successful, false if not. If
-+		 * the deserialization failed, the output animation definition is not
-+		 * modified.
-+		 */
-+		static bool deserialize(const Value &node, AnimationDefinition &output);
-+
-+		/**
- 		 * Default constructor. By default, an animation will loop indefinetely.
- 		 */
- 		AnimationDefinition();
-diff -r c265a2f83ec0 RedBox/RedBox/Helper/Serialization/Value.cpp
---- a/RedBox/RedBox/Helper/Serialization/Value.cpp	Thu Jan 26 09:04:12 2012 -0500
-+++ b/RedBox/RedBox/Helper/Serialization/Value.cpp	Thu Jan 26 09:12:23 2012 -0500
-@@ -1,6 +1,6 @@
- #include "Value.h"
- 
--#include <strstream>
-+#include <sstream>
- 
- #include "Serializer.h"
- 

File ALVector2SerializationFix

-# HG changeset patch
-# Parent 8dc41a3dab3c91767fe302618a7c517e0253ed8f
-Cleaned the Vector2 serialization functions a bit.
-
-diff -r 8dc41a3dab3c RedBox/RedBox/Vector2.h
---- a/RedBox/RedBox/Vector2.h	Thu Jan 26 09:12:23 2012 -0500
-+++ b/RedBox/RedBox/Vector2.h	Thu Jan 26 09:16:54 2012 -0500
-@@ -59,38 +59,11 @@
- 
- 			// We make sure the value contains the "x" and "y" values.
- 			if (itX != node.getObject().end() &&
--			    itY != node.getObject().end()) {
--				// We make sure the x and y values are numerics.
--				if (itX->second.isDouble()) {
-+			    itY != node.getObject().end() &&
-+			    itX->second.isNumeric() && itY->second.isNumeric()) {
- 
--					if (itY->second.isDouble()) {
--						output.setX(static_cast<ValueType>(itX->second.getDouble()));
--						output.setY(static_cast<ValueType>(itY->second.getDouble()));
--
--					} else if (itY->second.isInteger()) {
--						output.setX(static_cast<ValueType>(itX->second.getDouble()));
--						output.setY(static_cast<ValueType>(itY->second.getInt()));
--
--					} else {
--						result = false;
--					}
--
--				} else if (itX->second.isInteger()) {
--					if (itY->second.isDouble()) {
--						output.setX(static_cast<ValueType>(itX->second.getInt()));
--						output.setY(static_cast<ValueType>(itY->second.getDouble()));
--
--					} else if (itY->second.isInteger()) {
--						output.setX(static_cast<ValueType>(itX->second.getInt()));
--						output.setY(static_cast<ValueType>(itY->second.getInt()));
--
--					} else {
--						result = false;
--					}
--
--				} else {
--					result = false;
--				}
-+				output.setXY(static_cast<ValueType>(itX->second.getDouble()),
-+				             static_cast<ValueType>(itY->second.getDouble()));
- 
- 			} else {
- 				result = false;
-ALAnimationDefinitionSerialization
-ALVector2SerializationFix
 #ALTileSet
 #ALBatchMod
 #ALTileMap