TSAGE: Fixed problem with saving double values

This commit is contained in:
Paul Gilbert 2011-07-02 13:49:27 +10:00
parent ab7fdccc3b
commit 160a8d96d9
3 changed files with 18 additions and 4 deletions

View File

@ -3105,10 +3105,10 @@ void Scene6100::Object::synchronize(Serializer &s) {
SceneObject::synchronize(s);
// Save the double fields of the FloatSet
s.syncBytes((byte *)&_floats._float1, sizeof(double));
s.syncBytes((byte *)&_floats._float2, sizeof(double));
s.syncBytes((byte *)&_floats._float3, sizeof(double));
s.syncBytes((byte *)&_floats._float4, sizeof(double));
s.syncAsDouble(_floats._float1);
s.syncAsDouble(_floats._float2);
s.syncAsDouble(_floats._float3);
s.syncAsDouble(_floats._float4);
}
/*--------------------------------------------------------------------------*/

View File

@ -103,6 +103,19 @@ void Serializer::validate(int v, Common::Serializer::Version minVersion,
error("Savegame is corrupt");
}
#define DOUBLE_PRECISION 1000000000
void Serializer::syncAsDouble(double &v) {
int32 num = (int32)(v);
uint32 fraction = (uint32)((v - (int32)v) * DOUBLE_PRECISION);
syncAsSint32LE(num);
syncAsUint32LE(fraction);
if (isLoading())
v = num + (double)fraction / DOUBLE_PRECISION;
}
/*--------------------------------------------------------------------------*/
Common::Error Saver::save(int slot, const Common::String &saveName) {

View File

@ -77,6 +77,7 @@ public:
Common::Serializer::Version maxVersion = kLastVersion);
void validate(int v, Common::Serializer::Version minVersion = 0,
Common::Serializer::Version maxVersion = kLastVersion);
void syncAsDouble(double &v);
};
/*--------------------------------------------------------------------------*/