Use double precision for vectors serialization in Lua

psi29a-master-patch-54550
Petr Mikheev 3 years ago
parent 98d1588477
commit 97d56e198f

@ -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<osg::Vec2f>());
EXPECT_EQ(value.as<osg::Vec2f>(), 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<osg::Vec3f>());
EXPECT_EQ(value.as<osg::Vec3f>(), 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);

@ -99,17 +99,17 @@ namespace LuaUtil
{
appendType(out, SerializedType::VEC2);
osg::Vec2f v = data.as<osg::Vec2f>();
appendValue<float>(out, v.x());
appendValue<float>(out, v.y());
appendValue<double>(out, v.x());
appendValue<double>(out, v.y());
return;
}
if (data.is<osg::Vec3f>())
{
appendType(out, SerializedType::VEC3);
osg::Vec3f v = data.as<osg::Vec3f>();
appendValue<float>(out, v.x());
appendValue<float>(out, v.y());
appendValue<float>(out, v.z());
appendValue<double>(out, v.x());
appendValue<double>(out, v.y());
appendValue<double>(out, v.z());
return;
}
if (data.is<TransformM>())
@ -241,16 +241,16 @@ namespace LuaUtil
throw std::runtime_error("Unexpected end of table during deserialization.");
case SerializedType::VEC2:
{
float x = getValue<float>(binaryData);
float y = getValue<float>(binaryData);
float x = getValue<double>(binaryData);
float y = getValue<double>(binaryData);
sol::stack::push<osg::Vec2f>(lua, osg::Vec2f(x, y));
return;
}
case SerializedType::VEC3:
{
float x = getValue<float>(binaryData);
float y = getValue<float>(binaryData);
float z = getValue<float>(binaryData);
float x = getValue<double>(binaryData);
float y = getValue<double>(binaryData);
float z = getValue<double>(binaryData);
sol::stack::push<osg::Vec3f>(lua, osg::Vec3f(x, y, z));
return;
}

Loading…
Cancel
Save