mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-16 08:42:23 +00:00
Add serialization for TransformM and TransformQ
This commit is contained in:
parent
a1f8db7600
commit
d9672f7d46
@ -115,6 +115,7 @@ Programmers
|
|||||||
John Blomberg (fstp)
|
John Blomberg (fstp)
|
||||||
Jordan Ayers
|
Jordan Ayers
|
||||||
Jordan Milne
|
Jordan Milne
|
||||||
|
Josquin Frei
|
||||||
Josua Grawitter
|
Josua Grawitter
|
||||||
Jules Blok (Armada651)
|
Jules Blok (Armada651)
|
||||||
julianko
|
julianko
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
#include "gmock/gmock.h"
|
#include "gmock/gmock.h"
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include <osg/Matrixf>
|
||||||
|
#include <osg/Quat>
|
||||||
#include <osg/Vec2f>
|
#include <osg/Vec2f>
|
||||||
#include <osg/Vec3f>
|
#include <osg/Vec3f>
|
||||||
|
|
||||||
#include <components/lua/serialization.hpp>
|
#include <components/lua/serialization.hpp>
|
||||||
|
#include <components/lua/utilpackage.hpp>
|
||||||
|
|
||||||
#include <components/misc/endianness.hpp>
|
#include <components/misc/endianness.hpp>
|
||||||
|
|
||||||
@ -104,6 +107,33 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(LuaSerializationTest, Transform) {
|
||||||
|
sol::state lua;
|
||||||
|
osg::Matrixf matrix(1, 2, 3, 4,
|
||||||
|
5, 6, 7, 8,
|
||||||
|
9, 10, 11, 12,
|
||||||
|
13, 14, 15, 16);
|
||||||
|
LuaUtil::TransformM transM = LuaUtil::asTransform(matrix);
|
||||||
|
osg::Quat quat(1, 2, 3, 4);
|
||||||
|
LuaUtil::TransformQ transQ = LuaUtil::asTransform(quat);
|
||||||
|
|
||||||
|
{
|
||||||
|
std::string serialized = LuaUtil::serialize(sol::make_object(lua, transM));
|
||||||
|
EXPECT_EQ(serialized.size(), 130); // version, type, 16x double
|
||||||
|
sol::object value = LuaUtil::deserialize(lua, serialized);
|
||||||
|
ASSERT_TRUE(value.is<LuaUtil::TransformM>());
|
||||||
|
EXPECT_EQ(value.as<LuaUtil::TransformM>().mM, transM.mM);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string serialized = LuaUtil::serialize(sol::make_object(lua, transQ));
|
||||||
|
EXPECT_EQ(serialized.size(), 34); // version, type, 4x double
|
||||||
|
sol::object value = LuaUtil::deserialize(lua, serialized);
|
||||||
|
ASSERT_TRUE(value.is<LuaUtil::TransformQ>());
|
||||||
|
EXPECT_EQ(value.as<LuaUtil::TransformQ>().mQ, transQ.mQ);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
TEST(LuaSerializationTest, Table)
|
TEST(LuaSerializationTest, Table)
|
||||||
{
|
{
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
#include "serialization.hpp"
|
#include "serialization.hpp"
|
||||||
|
|
||||||
|
#include <osg/Matrixf>
|
||||||
|
#include <osg/Quat>
|
||||||
#include <osg/Vec2f>
|
#include <osg/Vec2f>
|
||||||
#include <osg/Vec3f>
|
#include <osg/Vec3f>
|
||||||
|
#include <osg/Vec4f>
|
||||||
|
|
||||||
#include <components/misc/endianness.hpp>
|
#include <components/misc/endianness.hpp>
|
||||||
|
|
||||||
#include "luastate.hpp"
|
#include "luastate.hpp"
|
||||||
|
#include "utilpackage.hpp"
|
||||||
|
|
||||||
namespace LuaUtil
|
namespace LuaUtil
|
||||||
{
|
{
|
||||||
@ -22,6 +26,8 @@ namespace LuaUtil
|
|||||||
|
|
||||||
VEC2 = 0x10,
|
VEC2 = 0x10,
|
||||||
VEC3 = 0x11,
|
VEC3 = 0x11,
|
||||||
|
TRANSFORM_M = 0x12,
|
||||||
|
TRANSFORM_Q = 0x13,
|
||||||
|
|
||||||
// All values should be lesser than 0x20 (SHORT_STRING_FLAG).
|
// All values should be lesser than 0x20 (SHORT_STRING_FLAG).
|
||||||
};
|
};
|
||||||
@ -106,6 +112,23 @@ namespace LuaUtil
|
|||||||
appendValue<float>(out, v.z());
|
appendValue<float>(out, v.z());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (data.is<TransformM>())
|
||||||
|
{
|
||||||
|
appendType(out, SerializedType::TRANSFORM_M);
|
||||||
|
osg::Matrixf matrix = data.as<TransformM>().mM;
|
||||||
|
for (size_t i = 0; i < 4; i++)
|
||||||
|
for (size_t j = 0; j < 4; j++)
|
||||||
|
appendValue<double>(out, matrix(i,j));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (data.is<TransformQ>())
|
||||||
|
{
|
||||||
|
appendType(out, SerializedType::TRANSFORM_Q);
|
||||||
|
osg::Quat quat = data.as<TransformQ>().mQ;
|
||||||
|
for(size_t i = 0; i < 4; i++)
|
||||||
|
appendValue<double>(out, quat[i]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (customSerializer && customSerializer->serialize(out, data))
|
if (customSerializer && customSerializer->serialize(out, data))
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
@ -231,6 +254,23 @@ namespace LuaUtil
|
|||||||
sol::stack::push<osg::Vec3f>(lua, osg::Vec3f(x, y, z));
|
sol::stack::push<osg::Vec3f>(lua, osg::Vec3f(x, y, z));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
case SerializedType::TRANSFORM_M:
|
||||||
|
{
|
||||||
|
osg::Matrixf mat;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
for (int j = 0; j < 4; j++)
|
||||||
|
mat(i, j) = getValue<double>(binaryData);
|
||||||
|
sol::stack::push<TransformM>(lua, asTransform(mat));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case SerializedType::TRANSFORM_Q:
|
||||||
|
{
|
||||||
|
osg::Quat q;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
q[i] = getValue<double>(binaryData);
|
||||||
|
sol::stack::push<TransformQ>(lua, asTransform(q));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
throw std::runtime_error("Unknown type in serialized data: " + std::to_string(type));
|
throw std::runtime_error("Unknown type in serialized data: " + std::to_string(type));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user