diff --git a/include/Nazara/Core/Color.hpp b/include/Nazara/Core/Color.hpp index a7df6b9a2..91a8cc43d 100644 --- a/include/Nazara/Core/Color.hpp +++ b/include/Nazara/Core/Color.hpp @@ -13,6 +13,8 @@ namespace Nz { + struct SerializationContext; + class Color { public: @@ -62,6 +64,9 @@ namespace Nz private: static float Hue2RGB(float v1, float v2, float vH); }; + + inline bool Serialize(SerializationContext& context, const Color& color); + inline bool Unserialize(SerializationContext& context, Color* color); } std::ostream& operator<<(std::ostream& out, const Nz::Color& color); diff --git a/include/Nazara/Core/Color.inl b/include/Nazara/Core/Color.inl index c3359cd0f..4ac3a2246 100644 --- a/include/Nazara/Core/Color.inl +++ b/include/Nazara/Core/Color.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -610,6 +611,54 @@ namespace Nz return v1; } + + /*! + * \brief Serializes a Color + * \return true if successfully serialized + * + * \param context Serialization context + * \param color Input color + */ + inline bool Serialize(SerializationContext& context, const Color& color) + { + if (!Serialize(context, color.r)) + return false; + + if (!Serialize(context, color.g)) + return false; + + if (!Serialize(context, color.b)) + return false; + + if (!Serialize(context, color.a)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Color + * \return true if successfully unserialized + * + * \param context Serialization context + * \param color Output color + */ + inline bool Unserialize(SerializationContext& context, Color* color) + { + if (!Unserialize(context, &color->r)) + return false; + + if (!Unserialize(context, &color->g)) + return false; + + if (!Unserialize(context, &color->b)) + return false; + + if (!Unserialize(context, &color->a)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/BoundingVolume.hpp b/include/Nazara/Math/BoundingVolume.hpp index e0ca2f556..60a16c260 100644 --- a/include/Nazara/Math/BoundingVolume.hpp +++ b/include/Nazara/Math/BoundingVolume.hpp @@ -14,6 +14,8 @@ namespace Nz { + struct SerializationContext; + template class BoundingVolume { @@ -66,6 +68,9 @@ namespace Nz typedef BoundingVolume BoundingVolumed; typedef BoundingVolume BoundingVolumef; + + template bool Serialize(SerializationContext& context, const BoundingVolume& boundingVolume); + template bool Unserialize(SerializationContext& context, BoundingVolume* boundingVolume); } template diff --git a/include/Nazara/Math/BoundingVolume.inl b/include/Nazara/Math/BoundingVolume.inl index 4047769dc..03e6476bc 100644 --- a/include/Nazara/Math/BoundingVolume.inl +++ b/include/Nazara/Math/BoundingVolume.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -545,6 +546,60 @@ namespace Nz return volume; } + + /*! + * \brief Serializes a BoundingVolume + * \return true if successfully serialized + * + * \param context Serialization context + * \param boundingVolume Input bounding volume + * + * \remark Does not save OBB corners + */ + template + bool Serialize(SerializationContext& context, const BoundingVolume& boundingVolume) + { + if (!Serialize(context, static_cast(boundingVolume.extend))) + return false; + + if (!Serialize(context, boundingVolume.aabb)) + return false; + + if (!Serialize(context, boundingVolume.obb)) + return false; + + return true; + } + + /*! + * \brief Unserializes a BoundingVolume + * \return true if successfully unserialized + * + * \param context Serialization context + * \param boundingVolume Output bounding volume + * + * \remark The resulting oriented box corners will *not* be updated, a call to Update is required + */ + template + bool Unserialize(SerializationContext& context, BoundingVolume* boundingVolume) + { + UInt8 extend; + if (!Unserialize(context, &extend)) + return false; + + if (extend > Extend_Max) + return false; + + boundingVolume->extend = extend; + + if (!Unserialize(context, &boundingVolume->aabb)) + return false; + + if (!Unserialize(context, &boundingVolume->obb)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Box.hpp b/include/Nazara/Math/Box.hpp index d8de5bdab..a2a6f25d1 100644 --- a/include/Nazara/Math/Box.hpp +++ b/include/Nazara/Math/Box.hpp @@ -16,6 +16,8 @@ namespace Nz { + struct SerializationContext; + template class Box { @@ -96,6 +98,9 @@ namespace Nz typedef Box Boxui; typedef Box Boxi32; typedef Box Boxui32; + + template bool Serialize(SerializationContext& context, const Box& box); + template bool Unserialize(SerializationContext& context, Box* box); } template diff --git a/include/Nazara/Math/Box.inl b/include/Nazara/Math/Box.inl index 8c8d655ef..a6200cbe4 100644 --- a/include/Nazara/Math/Box.inl +++ b/include/Nazara/Math/Box.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -920,6 +921,68 @@ namespace Nz return box; } + + /*! + * \brief Serializes a Box + * \return true if successfully serialized + * + * \param context Serialization context + * \param box Input Box + */ + template + bool Serialize(SerializationContext& context, const Box& box) + { + if (!Serialize(context, box.x)) + return false; + + if (!Serialize(context, box.y)) + return false; + + if (!Serialize(context, box.z)) + return false; + + if (!Serialize(context, box.width)) + return false; + + if (!Serialize(context, box.height)) + return false; + + if (!Serialize(context, box.depth)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Box + * \return true if successfully unserialized + * + * \param context Serialization context + * \param box Output Box + */ + template + bool Unserialize(SerializationContext& context, Box* box) + { + if (!Unserialize(context, &box->x)) + return false; + + if (!Unserialize(context, &box->y)) + return false; + + if (!Unserialize(context, &box->z)) + return false; + + if (!Unserialize(context, &box->width)) + return false; + + if (!Unserialize(context, &box->height)) + return false; + + if (!Unserialize(context, &box->depth)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/EulerAngles.hpp b/include/Nazara/Math/EulerAngles.hpp index 3c9a6b684..6ada39982 100644 --- a/include/Nazara/Math/EulerAngles.hpp +++ b/include/Nazara/Math/EulerAngles.hpp @@ -13,6 +13,8 @@ namespace Nz { + struct SerializationContext; + template class EulerAngles { @@ -61,6 +63,9 @@ namespace Nz typedef EulerAngles EulerAnglesd; typedef EulerAngles EulerAnglesf; + + template bool Serialize(SerializationContext& context, const EulerAngles& eulerAngles); + template bool Unserialize(SerializationContext& context, EulerAngles* eulerAngles); } template std::ostream& operator<<(std::ostream& out, const Nz::EulerAngles& angles); diff --git a/include/Nazara/Math/EulerAngles.inl b/include/Nazara/Math/EulerAngles.inl index 5c442f6c9..24bfd4630 100644 --- a/include/Nazara/Math/EulerAngles.inl +++ b/include/Nazara/Math/EulerAngles.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -330,6 +331,50 @@ namespace Nz return angles; } + + /*! + * \brief Serializes a EulerAngles + * \return true if successfully serialized + * + * \param context Serialization context + * \param angles Input euler angles + */ + template + bool Serialize(SerializationContext& context, const EulerAngles& angles) + { + if (!Serialize(context, angles.pitch)) + return false; + + if (!Serialize(context, angles.yaw)) + return false; + + if (!Serialize(context, angles.roll)) + return false; + + return true; + } + + /*! + * \brief Unserializes a EulerAngles + * \return true if successfully unserialized + * + * \param context Serialization context + * \param angles Output euler angles + */ + template + bool Unserialize(SerializationContext& context, EulerAngles* angles) + { + if (!Unserialize(context, &angles->pitch)) + return false; + + if (!Unserialize(context, &angles->yaw)) + return false; + + if (!Unserialize(context, &angles->roll)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Frustum.hpp b/include/Nazara/Math/Frustum.hpp index 44c3bc0e7..e170c2e55 100644 --- a/include/Nazara/Math/Frustum.hpp +++ b/include/Nazara/Math/Frustum.hpp @@ -18,6 +18,8 @@ namespace Nz { + struct SerializationContext; + template class Frustum { @@ -60,6 +62,9 @@ namespace Nz typedef Frustum Frustumd; typedef Frustum Frustumf; + + template bool Serialize(SerializationContext& context, const Frustum& frustum); + template bool Unserialize(SerializationContext& context, Frustum* frustum); } template diff --git a/include/Nazara/Math/Frustum.inl b/include/Nazara/Math/Frustum.inl index 4ff2b8f1b..2e78682d1 100644 --- a/include/Nazara/Math/Frustum.inl +++ b/include/Nazara/Math/Frustum.inl @@ -6,6 +6,7 @@ // http://www.crownandcutlass.com/features/technicaldetails/frustum.html // http://www.lighthouse3d.com/tutorials/view-frustum-culling/ +#include #include #include #include @@ -674,6 +675,56 @@ namespace Nz << " Right: " << m_planes[FrustumPlane_Right].ToString() << "\n" << " Top: " << m_planes[FrustumPlane_Top].ToString() << ")\n"; } + + /*! + * \brief Serializes a Frustum + * \return true if successfully serialized + * + * \param context Serialization context + * \param matrix Input frustum + */ + template + bool Serialize(SerializationContext& context, const Frustum& frustum) + { + for (unsigned int i = 0; i <= BoxCorner_Max; ++i) + { + if (!Serialize(context, m_corners[i])) + return false; + } + + for (unsigned int i = 0; i <= FrustumPlane_Max; ++i) + { + if (!Serialize(context, m_planes[i])) + return false; + } + + return true; + } + + /*! + * \brief Unserializes a Matrix4 + * \return true if successfully unserialized + * + * \param context Serialization context + * \param matrix Output matrix + */ + template + bool Unserialize(SerializationContext& context, Frustum* frustum) + { + for (unsigned int i = 0; i <= BoxCorner_Max; ++i) + { + if (!Unserialize(context, &m_corners[i])) + return false; + } + + for (unsigned int i = 0; i <= FrustumPlane_Max; ++i) + { + if (!Unserialize(context, &m_planes[i])) + return false; + } + + return true; + } } /*! diff --git a/include/Nazara/Math/Matrix4.hpp b/include/Nazara/Math/Matrix4.hpp index 211e8eedb..91927d68a 100644 --- a/include/Nazara/Math/Matrix4.hpp +++ b/include/Nazara/Math/Matrix4.hpp @@ -14,6 +14,8 @@ namespace Nz { + struct SerializationContext; + template class EulerAngles; template class Quaternion; template class Vector2; @@ -138,6 +140,9 @@ namespace Nz typedef Matrix4 Matrix4d; typedef Matrix4 Matrix4f; + + template bool Serialize(SerializationContext& context, const Matrix4& matrix); + template bool Unserialize(SerializationContext& context, Matrix4* matrix); } template std::ostream& operator<<(std::ostream& out, const Nz::Matrix4& matrix); diff --git a/include/Nazara/Math/Matrix4.inl b/include/Nazara/Math/Matrix4.inl index 6d84c241e..afa8143e3 100644 --- a/include/Nazara/Math/Matrix4.inl +++ b/include/Nazara/Math/Matrix4.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -1761,6 +1762,44 @@ namespace Nz return matrix; } + + /*! + * \brief Serializes a Matrix4 + * \return true if successfully serialized + * + * \param context Serialization context + * \param matrix Input matrix + */ + template + bool Serialize(SerializationContext& context, const Matrix4& matrix) + { + for (unsigned int i = 0; i < 16; ++i) + { + if (!Serialize(context, matrix[i])) + return false; + } + + return true; + } + + /*! + * \brief Unserializes a Matrix4 + * \return true if successfully unserialized + * + * \param context Serialization context + * \param matrix Output matrix + */ + template + bool Unserialize(SerializationContext& context, Matrix4* matrix) + { + for (unsigned int i = 0; i < 16; ++i) + { + if (!Unserialize(context, &matrix[i])) + return false; + } + + return true; + } } /*! diff --git a/include/Nazara/Math/OrientedBox.hpp b/include/Nazara/Math/OrientedBox.hpp index 627f4cbe9..43d4b1aaf 100644 --- a/include/Nazara/Math/OrientedBox.hpp +++ b/include/Nazara/Math/OrientedBox.hpp @@ -14,6 +14,8 @@ namespace Nz { + struct SerializationContext; + template class OrientedBox { @@ -67,6 +69,9 @@ namespace Nz typedef OrientedBox OrientedBoxd; typedef OrientedBox OrientedBoxf; + + template bool Serialize(SerializationContext& context, const OrientedBox& obb); + template bool Unserialize(SerializationContext& context, OrientedBox* obb); } template diff --git a/include/Nazara/Math/OrientedBox.inl b/include/Nazara/Math/OrientedBox.inl index 188b6d8fc..9bcd94e1d 100644 --- a/include/Nazara/Math/OrientedBox.inl +++ b/include/Nazara/Math/OrientedBox.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -430,6 +431,42 @@ namespace Nz return orientedBox; } + + /*! + * \brief Serializes a OrientedBox + * \return true if successfully serialized + * + * \param context Serialization context + * \param obb Input oriented box + * + * \remark Does not save OBB corners + */ + template + bool Serialize(SerializationContext& context, const OrientedBox& obb) + { + if (!Serialize(context, obb.localBox)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Matrix4 + * \return true if successfully unserialized + * + * \param context Serialization context + * \param obb Output oriented box + * + * \remark The resulting oriented box corners will *not* be updated, a call to Update is required + */ + template + bool Unserialize(SerializationContext& context, OrientedBox* obb) + { + if (!Unserialize(context, &obb->localBox)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Plane.hpp b/include/Nazara/Math/Plane.hpp index 70bc06051..f37fc90c7 100644 --- a/include/Nazara/Math/Plane.hpp +++ b/include/Nazara/Math/Plane.hpp @@ -12,6 +12,8 @@ namespace Nz { + struct SerializationContext; + template class Plane { @@ -57,6 +59,9 @@ namespace Nz typedef Plane Planed; typedef Plane Planef; + + template bool Serialize(SerializationContext& context, const Plane& plane); + template bool Unserialize(SerializationContext& context, Plane* plane); } template diff --git a/include/Nazara/Math/Plane.inl b/include/Nazara/Math/Plane.inl index 29bd829b2..625abe3e4 100644 --- a/include/Nazara/Math/Plane.inl +++ b/include/Nazara/Math/Plane.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -424,6 +425,44 @@ namespace Nz return plane; } + + /*! + * \brief Serializes a Vector2 + * \return true if successfully serialized + * + * \param context Serialization context + * \param plane Input Vector2 + */ + template + bool Serialize(SerializationContext& context, const Plane& plane) + { + if (!Serialize(context, plane.normal)) + return false; + + if (!Serialize(context, plane.distance)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Plane + * \return true if successfully unserialized + * + * \param context Serialization context + * \param plane Output Plane + */ + template + bool Unserialize(SerializationContext& context, Plane* plane) + { + if (!Unserialize(context, &plane->normal)) + return false; + + if (!Unserialize(context, &plane->distance)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Quaternion.hpp b/include/Nazara/Math/Quaternion.hpp index f33dec0b6..bbb313bd5 100644 --- a/include/Nazara/Math/Quaternion.hpp +++ b/include/Nazara/Math/Quaternion.hpp @@ -11,6 +11,8 @@ namespace Nz { + struct SerializationContext; + template class EulerAngles; template class Vector3; @@ -88,6 +90,9 @@ namespace Nz typedef Quaternion Quaterniond; typedef Quaternion Quaternionf; + + template bool Serialize(SerializationContext& context, const Quaternion& quat); + template bool Unserialize(SerializationContext& context, Quaternion* quat); } template std::ostream& operator<<(std::ostream& out, const Nz::Quaternion& quat); diff --git a/include/Nazara/Math/Quaternion.inl b/include/Nazara/Math/Quaternion.inl index 75e3966d3..bc672cd81 100644 --- a/include/Nazara/Math/Quaternion.inl +++ b/include/Nazara/Math/Quaternion.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -831,6 +832,57 @@ namespace Nz return quaternion; } + + + /*! + * \brief Serializes a Quaternion + * \return true if successfully serialized + * + * \param context Serialization context + * \param quat Input Quaternion + */ + template + bool Serialize(SerializationContext& context, const Quaternion& quat) + { + if (!Serialize(context, quat.x)) + return false; + + if (!Serialize(context, quat.y)) + return false; + + if (!Serialize(context, quat.z)) + return false; + + if (!Serialize(context, quat.w)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Quaternion + * \return true if successfully unserialized + * + * \param context Serialization context + * \param quat Output Quaternion + */ + template + bool Unserialize(SerializationContext& context, Quaternion* quat) + { + if (!Unserialize(context, &quat->x)) + return false; + + if (!Unserialize(context, &quat->y)) + return false; + + if (!Unserialize(context, &quat->z)) + return false; + + if (!Unserialize(context, &quat->w)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Ray.hpp b/include/Nazara/Math/Ray.hpp index c4c53664d..b391ad866 100644 --- a/include/Nazara/Math/Ray.hpp +++ b/include/Nazara/Math/Ray.hpp @@ -18,6 +18,8 @@ namespace Nz { + struct SerializationContext; + template class Ray { @@ -73,6 +75,9 @@ namespace Nz typedef Ray Rayd; typedef Ray Rayf; + + template bool Serialize(SerializationContext& context, const Ray& ray); + template bool Unserialize(SerializationContext& context, Ray* ray); } template std::ostream& operator<<(std::ostream& out, const Nz::Ray& vec); diff --git a/include/Nazara/Math/Ray.inl b/include/Nazara/Math/Ray.inl index e83c39488..6045615ed 100644 --- a/include/Nazara/Math/Ray.inl +++ b/include/Nazara/Math/Ray.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -762,6 +763,44 @@ namespace Nz { return Ray(Nz::Vector3::Lerp(from.origin, to.origin, interpolation), Nz::Vector3::Lerp(from.direction, to.direction, interpolation)); } + + /*! + * \brief Serializes a Ray + * \return true if successfully serialized + * + * \param context Serialization context + * \param ray Input Ray + */ + template + bool Serialize(SerializationContext& context, const Ray& ray) + { + if (!Serialize(context, ray.origin)) + return false; + + if (!Serialize(context, ray.direction)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Ray + * \return true if successfully unserialized + * + * \param context Serialization context + * \param ray Output Ray + */ + template + bool Unserialize(SerializationContext& context, Ray* ray) + { + if (!Unserialize(context, &ray->origin)) + return false; + + if (!Unserialize(context, &ray->direction)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Rect.hpp b/include/Nazara/Math/Rect.hpp index ec203848f..393d8d116 100644 --- a/include/Nazara/Math/Rect.hpp +++ b/include/Nazara/Math/Rect.hpp @@ -13,6 +13,8 @@ namespace Nz { + struct SerializationContext; + template class Rect { @@ -90,6 +92,9 @@ namespace Nz typedef Rect Rectui; typedef Rect Recti32; typedef Rect Rectui32; + + template bool Serialize(SerializationContext& context, const Rect& rect); + template bool Unserialize(SerializationContext& context, Rect* rect); } template diff --git a/include/Nazara/Math/Rect.inl b/include/Nazara/Math/Rect.inl index 9a2737a02..f53dd0c0f 100644 --- a/include/Nazara/Math/Rect.inl +++ b/include/Nazara/Math/Rect.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -816,6 +817,56 @@ namespace Nz return rect; } + + /*! + * \brief Serializes a Rect + * \return true if successfully serialized + * + * \param context Serialization context + * \param rect Input Rect + */ + template + bool Serialize(SerializationContext& context, const Rect& rect) + { + if (!Serialize(context, rect.x)) + return false; + + if (!Serialize(context, rect.y)) + return false; + + if (!Serialize(context, rect.width)) + return false; + + if (!Serialize(context, rect.height)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Rect + * \return true if successfully unserialized + * + * \param context Serialization context + * \param rect Output Rect + */ + template + bool Unserialize(SerializationContext& context, Rect* rect) + { + if (!Unserialize(context, &rect->x)) + return false; + + if (!Unserialize(context, &rect->y)) + return false; + + if (!Unserialize(context, &rect->width)) + return false; + + if (!Unserialize(context, &rect->height)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Sphere.hpp b/include/Nazara/Math/Sphere.hpp index 65203c4b0..929c1ec71 100644 --- a/include/Nazara/Math/Sphere.hpp +++ b/include/Nazara/Math/Sphere.hpp @@ -12,6 +12,8 @@ namespace Nz { + struct SerializationContext; + template class Box; template @@ -80,6 +82,9 @@ namespace Nz typedef Sphere Sphered; typedef Sphere Spheref; + + template bool Serialize(SerializationContext& context, const Sphere& sphere); + template bool Unserialize(SerializationContext& context, Sphere* sphere); } template diff --git a/include/Nazara/Math/Sphere.inl b/include/Nazara/Math/Sphere.inl index eac46d76c..4d30c7ca3 100644 --- a/include/Nazara/Math/Sphere.inl +++ b/include/Nazara/Math/Sphere.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -674,6 +675,56 @@ namespace Nz return sphere; } + + /*! + * \brief Serializes a Sphere + * \return true if successfully serialized + * + * \param context Serialization context + * \param sphere Input Sphere + */ + template + bool Serialize(SerializationContext& context, const Sphere& sphere) + { + if (!Serialize(context, sphere.x)) + return false; + + if (!Serialize(context, sphere.y)) + return false; + + if (!Serialize(context, sphere.z)) + return false; + + if (!Serialize(context, sphere.radius)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Sphere + * \return true if successfully unserialized + * + * \param context Serialization context + * \param sphere Output Sphere + */ + template + bool Unserialize(SerializationContext& context, Sphere* sphere) + { + if (!Unserialize(context, &sphere->x)) + return false; + + if (!Unserialize(context, &sphere->y)) + return false; + + if (!Unserialize(context, &sphere->z)) + return false; + + if (!Unserialize(context, &sphere->radius)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Vector2.hpp b/include/Nazara/Math/Vector2.hpp index 3712f0d09..b275d0544 100644 --- a/include/Nazara/Math/Vector2.hpp +++ b/include/Nazara/Math/Vector2.hpp @@ -11,6 +11,8 @@ namespace Nz { + struct SerializationContext; + template class Vector3; template class Vector4; @@ -106,6 +108,9 @@ namespace Nz typedef Vector2 Vector2ui; typedef Vector2 Vector2i32; typedef Vector2 Vector2ui32; + + template bool Serialize(SerializationContext& context, const Vector2& vector); + template bool Unserialize(SerializationContext& context, Vector2* vector); } template std::ostream& operator<<(std::ostream& out, const Nz::Vector2& vec); diff --git a/include/Nazara/Math/Vector2.inl b/include/Nazara/Math/Vector2.inl index 6fd58cf38..80e588ba4 100644 --- a/include/Nazara/Math/Vector2.inl +++ b/include/Nazara/Math/Vector2.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -940,7 +941,6 @@ namespace Nz * * \see MakeUnitY */ - template Vector2 Vector2::UnitY() { @@ -956,7 +956,6 @@ namespace Nz * * \see MakeZero */ - template Vector2 Vector2::Zero() { @@ -965,6 +964,44 @@ namespace Nz return vector; } + + /*! + * \brief Serializes a Vector2 + * \return true if successfully serialized + * + * \param context Serialization context + * \param vector Input Vector2 + */ + template + bool Serialize(SerializationContext& context, const Vector2& vector) + { + if (!Serialize(context, vector.x)) + return false; + + if (!Serialize(context, vector.y)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Vector2 + * \return true if successfully unserialized + * + * \param context Serialization context + * \param vector Output Vector2 + */ + template + bool Unserialize(SerializationContext& context, Vector2* vector) + { + if (!Unserialize(context, &vector->x)) + return false; + + if (!Unserialize(context, &vector->y)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Vector3.hpp b/include/Nazara/Math/Vector3.hpp index 0ab620406..b9d16011c 100644 --- a/include/Nazara/Math/Vector3.hpp +++ b/include/Nazara/Math/Vector3.hpp @@ -11,6 +11,8 @@ namespace Nz { + struct SerializationContext; + template class Vector2; template class Vector4; @@ -125,6 +127,9 @@ namespace Nz typedef Vector3 Vector3ui; typedef Vector3 Vector3i32; typedef Vector3 Vector3ui32; + + template bool Serialize(SerializationContext& context, const Vector3& vector); + template bool Unserialize(SerializationContext& context, Vector3* vector); } template std::ostream& operator<<(std::ostream& out, const Nz::Vector3& vec); diff --git a/include/Nazara/Math/Vector3.inl b/include/Nazara/Math/Vector3.inl index c386f146d..fa48b7bef 100644 --- a/include/Nazara/Math/Vector3.inl +++ b/include/Nazara/Math/Vector3.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -28,7 +29,6 @@ namespace Nz * \param Y Y component * \param Z Z component */ - template Vector3::Vector3(T X, T Y, T Z) { @@ -41,7 +41,6 @@ namespace Nz * \param X X component * \param vec vec.X = Y component and vec.y = Z component */ - template Vector3::Vector3(T X, const Vector2& vec) { @@ -53,7 +52,6 @@ namespace Nz * * \param scale X component = Y component = Z component */ - template Vector3::Vector3(T scale) { @@ -65,7 +63,6 @@ namespace Nz * * \param vec[3] vec[0] is X component, vec[1] is Y component and vec[2] is Z component */ - template Vector3::Vector3(const T vec[3]) { @@ -78,7 +75,6 @@ namespace Nz * \param vec vec.X = X component and vec.y = Y component * \param Z Z component */ - template Vector3::Vector3(const Vector2& vec, T Z) { @@ -90,7 +86,6 @@ namespace Nz * * \param vec Vector of type U to convert to type T */ - template template Vector3::Vector3(const Vector3& vec) @@ -103,7 +98,6 @@ namespace Nz * * \param vec Vector4 where only the first three components are taken */ - template Vector3::Vector3(const Vector4& vec) { @@ -118,7 +112,6 @@ namespace Nz * * \see DotProduct */ - template T Vector3::AbsDotProduct(const Vector3& vec) const { @@ -137,7 +130,6 @@ namespace Nz * * \see NormalizeAngle */ - template T Vector3::AngleBetween(const Vector3& vec) const { @@ -166,7 +158,6 @@ namespace Nz * * \see CrossProduct */ - template Vector3 Vector3::CrossProduct(const Vector3& vec) const { @@ -181,7 +172,6 @@ namespace Nz * * \see SquaredDistance */ - template T Vector3::Distance(const Vector3& vec) const { @@ -194,7 +184,6 @@ namespace Nz * * \param vec The other vector to measure the distance with */ - template float Vector3::Distancef(const Vector3& vec) const { @@ -209,7 +198,6 @@ namespace Nz * * \see AbsDotProduct, DotProduct */ - template T Vector3::DotProduct(const Vector3& vec) const { @@ -222,7 +210,6 @@ namespace Nz * * \see GetSquaredLength */ - template T Vector3::GetLength() const { @@ -233,7 +220,6 @@ namespace Nz * \brief Calculates the length (magnitude) of the vector * \return The length in float of the vector */ - template float Vector3::GetLengthf() const { @@ -250,7 +236,6 @@ namespace Nz * * \see Normalize */ - template Vector3 Vector3::GetNormal(T* length) const { @@ -266,7 +251,6 @@ namespace Nz * * \see GetLength */ - template T Vector3::GetSquaredLength() const { @@ -279,7 +263,6 @@ namespace Nz * * \see Backward */ - template Vector3& Vector3::MakeBackward() { @@ -292,7 +275,6 @@ namespace Nz * * \see Down */ - template Vector3& Vector3::MakeDown() { @@ -305,7 +287,6 @@ namespace Nz * * \see Forward */ - template Vector3& Vector3::MakeForward() { @@ -318,7 +299,6 @@ namespace Nz * * \see Left */ - template Vector3& Vector3::MakeLeft() { @@ -331,7 +311,6 @@ namespace Nz * * \see Right */ - template Vector3& Vector3::MakeRight() { @@ -344,7 +323,6 @@ namespace Nz * * \see Unit */ - template Vector3& Vector3::MakeUnit() { @@ -357,7 +335,6 @@ namespace Nz * * \see UnitX */ - template Vector3& Vector3::MakeUnitX() { @@ -370,7 +347,6 @@ namespace Nz * * \see UnitY */ - template Vector3& Vector3::MakeUnitY() { @@ -383,7 +359,6 @@ namespace Nz * * \see UnitZ */ - template Vector3& Vector3::MakeUnitZ() { @@ -396,7 +371,6 @@ namespace Nz * * \see Up */ - template Vector3& Vector3::MakeUp() { @@ -409,7 +383,6 @@ namespace Nz * * \see Zero */ - template Vector3& Vector3::MakeZero() { @@ -424,7 +397,6 @@ namespace Nz * * \see Minimize */ - template Vector3& Vector3::Maximize(const Vector3& vec) { @@ -448,7 +420,6 @@ namespace Nz * * \see Maximize */ - template Vector3& Vector3::Minimize(const Vector3& vec) { @@ -474,7 +445,6 @@ namespace Nz * * \see GetNormal */ - template Vector3& Vector3::Normalize(T* length) { @@ -501,7 +471,6 @@ namespace Nz * \param Y Y component * \param Z Z component */ - template Vector3& Vector3::Set(T X, T Y, T Z) { @@ -518,7 +487,6 @@ namespace Nz * \param X X component * \param vec vec.X = Y component and vec.y = Z component */ - template Vector3& Vector3::Set(T X, const Vector2& vec) { @@ -535,7 +503,6 @@ namespace Nz * * \param scale X component = Y component = Z component */ - template Vector3& Vector3::Set(T scale) { @@ -552,7 +519,6 @@ namespace Nz * * \param vec[3] vec[0] is X component, vec[1] is Y component and vec[2] is Z component */ - template Vector3& Vector3::Set(const T vec[3]) { @@ -567,7 +533,6 @@ namespace Nz * \param vec vec.X = X component and vec.y = Y component * \param Z Z component */ - template Vector3& Vector3::Set(const Vector2& vec, T Z) { @@ -584,7 +549,6 @@ namespace Nz * * \param vec The other vector */ - template Vector3& Vector3::Set(const Vector3& vec) { @@ -599,7 +563,6 @@ namespace Nz * * \param vec Vector of type U to convert its components */ - template template Vector3& Vector3::Set(const Vector3& vec) @@ -617,7 +580,6 @@ namespace Nz * * \param vec Vector4 where only the first three components are taken */ - template Vector3& Vector3::Set(const Vector4& vec) { @@ -636,7 +598,6 @@ namespace Nz * * \see Distance */ - template T Vector3::SquaredDistance(const Vector3& vec) const { @@ -647,7 +608,6 @@ namespace Nz * \brief Gives a string representation * \return A string representation of the object: "Vector3(x, y, z)" */ - template String Vector3::ToString() const { @@ -662,7 +622,6 @@ namespace Nz * * \remark Access to index greather than 2 is undefined behavior */ - template Vector3::operator T* () { @@ -675,7 +634,6 @@ namespace Nz * * \remark Access to index greather than 2 is undefined behavior */ - template Vector3::operator const T* () const { @@ -686,7 +644,6 @@ namespace Nz * \brief Helps to represent the sign of the vector * \return A constant reference to this vector */ - template const Vector3& Vector3::operator+() const { @@ -697,7 +654,6 @@ namespace Nz * \brief Negates the components of the vector * \return A constant reference to this vector with negate components */ - template Vector3 Vector3::operator-() const { @@ -710,7 +666,6 @@ namespace Nz * * \param vec The other vector to add components with */ - template Vector3 Vector3::operator+(const Vector3& vec) const { @@ -723,7 +678,6 @@ namespace Nz * * \param vec The other vector to substract components with */ - template Vector3 Vector3::operator-(const Vector3& vec) const { @@ -736,7 +690,6 @@ namespace Nz * * \param vec The other vector to multiply components with */ - template Vector3 Vector3::operator*(const Vector3& vec) const { @@ -749,7 +702,6 @@ namespace Nz * * \param scale The scalar to multiply components with */ - template Vector3 Vector3::operator*(T scale) const { @@ -765,7 +717,6 @@ namespace Nz * \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined * \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null */ - template Vector3 Vector3::operator/(const Vector3& vec) const { @@ -791,7 +742,6 @@ namespace Nz * \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined * \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ - template Vector3 Vector3::operator/(T scale) const { @@ -814,7 +764,6 @@ namespace Nz * * \param vec The other vector to add components with */ - template Vector3& Vector3::operator+=(const Vector3& vec) { @@ -831,7 +780,6 @@ namespace Nz * * \param vec The other vector to substract components with */ - template Vector3& Vector3::operator-=(const Vector3& vec) { @@ -848,7 +796,6 @@ namespace Nz * * \param vec The other vector to multiply components with */ - template Vector3& Vector3::operator*=(const Vector3& vec) { @@ -865,7 +812,6 @@ namespace Nz * * \param vec The other vector to multiply components with */ - template Vector3& Vector3::operator*=(T scale) { @@ -885,7 +831,6 @@ namespace Nz * \remark Produce a NazaraError if one of the vec components is null with NAZARA_MATH_SAFE defined * \throw std::domain_error if NAZARA_MATH_SAFE is defined and one of the vec components is null */ - template Vector3& Vector3::operator/=(const Vector3& vec) { @@ -913,7 +858,6 @@ namespace Nz * \remark Produce a NazaraError if scale is null with NAZARA_MATH_SAFE defined * \throw std::domain_error if NAZARA_MATH_SAFE is defined and scale is null */ - template Vector3& Vector3::operator/=(T scale) { @@ -938,7 +882,6 @@ namespace Nz * * \param vec Other vector to compare with */ - template bool Vector3::operator==(const Vector3& vec) const { @@ -953,7 +896,6 @@ namespace Nz * * \param vec Other vector to compare with */ - template bool Vector3::operator!=(const Vector3& vec) const { @@ -966,7 +908,6 @@ namespace Nz * * \param vec Other vector to compare with */ - template bool Vector3::operator<(const Vector3& vec) const { @@ -987,7 +928,6 @@ namespace Nz * * \param vec Other vector to compare with */ - template bool Vector3::operator<=(const Vector3& vec) const { @@ -1008,7 +948,6 @@ namespace Nz * * \param vec Other vector to compare with */ - template bool Vector3::operator>(const Vector3& vec) const { @@ -1021,7 +960,6 @@ namespace Nz * * \param vec Other vector to compare with */ - template bool Vector3::operator>=(const Vector3& vec) const { @@ -1037,7 +975,6 @@ namespace Nz * * \see CrossProduct */ - template Vector3 Vector3::CrossProduct(const Vector3& vec1, const Vector3& vec2) { @@ -1053,7 +990,6 @@ namespace Nz * * \see AbsDotProduct, DotProduct */ - template T Vector3::DotProduct(const Vector3& vec1, const Vector3& vec2) { @@ -1066,7 +1002,6 @@ namespace Nz * * \see MakeBackward */ - template Vector3 Vector3::Backward() { @@ -1082,7 +1017,6 @@ namespace Nz * * \see MakeDown */ - template Vector3 Vector3::Down() { @@ -1098,7 +1032,6 @@ namespace Nz * * \see Forward */ - template Vector3 Vector3::Forward() { @@ -1114,7 +1047,6 @@ namespace Nz * * \see MakeLeft */ - template Vector3 Vector3::Left() { @@ -1136,7 +1068,6 @@ namespace Nz * * \see Lerp */ - template Vector3 Vector3::Lerp(const Vector3& from, const Vector3& to, T interpolation) { @@ -1158,7 +1089,6 @@ namespace Nz * * \see GetNormal */ - template Vector3 Vector3::Normalize(const Vector3& vec) { @@ -1171,7 +1101,6 @@ namespace Nz * * \see MakeRight */ - template Vector3 Vector3::Right() { @@ -1187,7 +1116,6 @@ namespace Nz * * \see MakeUnit */ - template Vector3 Vector3::Unit() { @@ -1203,7 +1131,6 @@ namespace Nz * * \see MakeUnitX */ - template Vector3 Vector3::UnitX() { @@ -1219,7 +1146,6 @@ namespace Nz * * \see MakeUnitY */ - template Vector3 Vector3::UnitY() { @@ -1235,7 +1161,6 @@ namespace Nz * * \see MakeUnitZ */ - template Vector3 Vector3::UnitZ() { @@ -1251,7 +1176,6 @@ namespace Nz * * \see MakeUp */ - template Vector3 Vector3::Up() { @@ -1267,7 +1191,6 @@ namespace Nz * * \see MakeZero */ - template Vector3 Vector3::Zero() { @@ -1276,6 +1199,50 @@ namespace Nz return vector; } + + /*! + * \brief Serializes a Vector3 + * \return true if successfully serialized + * + * \param context Serialization context + * \param vector Input Vector3 + */ + template + bool Serialize(SerializationContext& context, const Vector3& vector) + { + if (!Serialize(context, vector.x)) + return false; + + if (!Serialize(context, vector.y)) + return false; + + if (!Serialize(context, vector.z)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Vector3 + * \return true if successfully unserialized + * + * \param context Serialization context + * \param vector Output Vector3 + */ + template + bool Unserialize(SerializationContext& context, Vector3* vector) + { + if (!Unserialize(context, &vector->x)) + return false; + + if (!Unserialize(context, &vector->y)) + return false; + + if (!Unserialize(context, &vector->z)) + return false; + + return true; + } } /*! diff --git a/include/Nazara/Math/Vector4.hpp b/include/Nazara/Math/Vector4.hpp index 319f18e3b..d1e51433a 100644 --- a/include/Nazara/Math/Vector4.hpp +++ b/include/Nazara/Math/Vector4.hpp @@ -11,6 +11,8 @@ namespace Nz { + struct SerializationContext; + template class Vector2; template class Vector3; @@ -104,6 +106,9 @@ namespace Nz typedef Vector4 Vector4ui; typedef Vector4 Vector4i32; typedef Vector4 Vector4ui32; + + template bool Serialize(SerializationContext& context, const Vector4& vector); + template bool Unserialize(SerializationContext& context, Vector4* vector); } template std::ostream& operator<<(std::ostream& out, const Nz::Vector4& vec); diff --git a/include/Nazara/Math/Vector4.inl b/include/Nazara/Math/Vector4.inl index 01c771f8f..73a9a0802 100644 --- a/include/Nazara/Math/Vector4.inl +++ b/include/Nazara/Math/Vector4.inl @@ -2,6 +2,7 @@ // This file is part of the "Nazara Engine - Mathematics module" // For conditions of distribution and use, see copyright notice in Config.hpp +#include #include #include #include @@ -1013,6 +1014,56 @@ namespace Nz return vector; } + + /*! + * \brief Serializes a Vector4 + * \return true if successfully serialized + * + * \param context Serialization context + * \param vector Input Vector3 + */ + template + bool Serialize(SerializationContext& context, const Vector4& vector) + { + if (!Serialize(context, vector.x)) + return false; + + if (!Serialize(context, vector.y)) + return false; + + if (!Serialize(context, vector.z)) + return false; + + if (!Serialize(context, vector.w)) + return false; + + return true; + } + + /*! + * \brief Unserializes a Vector4 + * \return true if successfully unserialized + * + * \param context Serialization context + * \param vector Output Vector3 + */ + template + bool Unserialize(SerializationContext& context, Vector4* vector) + { + if (!Unserialize(context, &vector->x)) + return false; + + if (!Unserialize(context, &vector->y)) + return false; + + if (!Unserialize(context, &vector->z)) + return false; + + if (!Unserialize(context, &vector->w)) + return false; + + return true; + } } /*!