From 97d56e198fdef194d68ef597cc0d850f32637ba0 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sat, 15 Jan 2022 11:25:30 +0100 Subject: [PATCH] Use double precision for vectors serialization in Lua --- .../lua/test_serialization.cpp | 6 +++--- components/lua/serialization.cpp | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/openmw_test_suite/lua/test_serialization.cpp b/apps/openmw_test_suite/lua/test_serialization.cpp index 57a1070c83..1d664b06a4 100644 --- a/apps/openmw_test_suite/lua/test_serialization.cpp +++ b/apps/openmw_test_suite/lua/test_serialization.cpp @@ -93,14 +93,14 @@ namespace { std::string serialized = LuaUtil::serialize(sol::make_object(lua, vec2)); - EXPECT_EQ(serialized.size(), 10); // version, type, 2x float + EXPECT_EQ(serialized.size(), 18); // version, type, 2x double sol::object value = LuaUtil::deserialize(lua, serialized); ASSERT_TRUE(value.is()); EXPECT_EQ(value.as(), vec2); } { std::string serialized = LuaUtil::serialize(sol::make_object(lua, vec3)); - EXPECT_EQ(serialized.size(), 14); // version, type, 3x float + EXPECT_EQ(serialized.size(), 26); // version, type, 3x double sol::object value = LuaUtil::deserialize(lua, serialized); ASSERT_TRUE(value.is()); EXPECT_EQ(value.as(), vec3); @@ -149,7 +149,7 @@ namespace table[2] = osg::Vec2f(2, 1); std::string serialized = LuaUtil::serialize(table); - EXPECT_EQ(serialized.size(), 123); + EXPECT_EQ(serialized.size(), 139); sol::table res_table = LuaUtil::deserialize(lua, serialized); sol::table res_readonly_table = LuaUtil::deserialize(lua, serialized, nullptr, true); diff --git a/components/lua/serialization.cpp b/components/lua/serialization.cpp index 8b18294449..e8f66c698c 100644 --- a/components/lua/serialization.cpp +++ b/components/lua/serialization.cpp @@ -99,17 +99,17 @@ namespace LuaUtil { appendType(out, SerializedType::VEC2); osg::Vec2f v = data.as(); - appendValue(out, v.x()); - appendValue(out, v.y()); + appendValue(out, v.x()); + appendValue(out, v.y()); return; } if (data.is()) { appendType(out, SerializedType::VEC3); osg::Vec3f v = data.as(); - appendValue(out, v.x()); - appendValue(out, v.y()); - appendValue(out, v.z()); + appendValue(out, v.x()); + appendValue(out, v.y()); + appendValue(out, v.z()); return; } if (data.is()) @@ -241,16 +241,16 @@ namespace LuaUtil throw std::runtime_error("Unexpected end of table during deserialization."); case SerializedType::VEC2: { - float x = getValue(binaryData); - float y = getValue(binaryData); + float x = getValue(binaryData); + float y = getValue(binaryData); sol::stack::push(lua, osg::Vec2f(x, y)); return; } case SerializedType::VEC3: { - float x = getValue(binaryData); - float y = getValue(binaryData); - float z = getValue(binaryData); + float x = getValue(binaryData); + float y = getValue(binaryData); + float z = getValue(binaryData); sol::stack::push(lua, osg::Vec3f(x, y, z)); return; }