[Scummvm-cvs-logs] SF.net SVN: scummvm:[42612] scummvm/branches/gsoc2009-draci/engines/draci
dkasak13 at users.sourceforge.net
dkasak13 at users.sourceforge.net
Sun Jul 19 15:28:05 CEST 2009
Revision: 42612
http://scummvm.svn.sourceforge.net/scummvm/?rev=42612&view=rev
Author: dkasak13
Date: 2009-07-19 13:28:05 +0000 (Sun, 19 Jul 2009)
Log Message:
-----------
Added capability for reading in Pascal 6-byte floats and made Game::loadRoom() read in pers0 and persStep correctly.
Modified Paths:
--------------
scummvm/branches/gsoc2009-draci/engines/draci/game.cpp
scummvm/branches/gsoc2009-draci/engines/draci/game.h
Modified: scummvm/branches/gsoc2009-draci/engines/draci/game.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/game.cpp 2009-07-19 12:52:19 UTC (rev 42611)
+++ scummvm/branches/gsoc2009-draci/engines/draci/game.cpp 2009-07-19 13:28:05 UTC (rev 42612)
@@ -31,6 +31,8 @@
#include "draci/script.h"
#include "draci/animation.h"
+#include <cmath>
+
namespace Draci {
Game::Game(DraciEngine *vm) : _vm(vm) {
@@ -211,8 +213,22 @@
_currentRoom._imUse = roomReader.readByte();
_currentRoom._mouseOn = roomReader.readByte();
_currentRoom._heroOn = roomReader.readByte();
- roomReader.read(&_currentRoom._pers0, 6);
- roomReader.read(&_currentRoom._persStep, 6);
+
+ // Read in pers0 and persStep (stored as 6-byte Pascal reals)
+ byte real[6];
+
+ for (int i = 5; i >= 0; --i) {
+ real[i] = roomReader.readByte();
+ }
+
+ _currentRoom._pers0 = real_to_double(real);
+
+ for (int i = 5; i >= 0; --i) {
+ real[i] = roomReader.readByte();
+ }
+
+ _currentRoom._persStep = real_to_double(real);
+
_currentRoom._escRoom = roomReader.readByte() - 1;
_currentRoom._numGates = roomReader.readByte();
@@ -503,5 +519,45 @@
return mapByte & (1 << pixelIndex % 8);
}
+static double real_to_double(byte real[6]) {
+ // Extract sign bit
+ int sign = real[0] & (1 << 7);
+
+ // Extract exponent and adjust for bias
+ int exp = real[5] - 129;
+
+ double mantissa;
+ double tmp = 0.0;
+
+ if (real[5] == 0) {
+ mantissa = 0.0;
+ } else {
+
+ // Process the first four least significant bytes
+ for (int i = 4; i >= 1; --i) {
+ tmp += real[i];
+ tmp /= 1 << 8;
+ }
+
+ // Process the most significant byte (remove the sign bit)
+ tmp += real[0] & ((1 << 7) - 1);
+ tmp /= 1 << 8;
+
+ // Calculate mantissa
+ mantissa = 1.0;
+ mantissa += 2.0 * tmp;
+ }
+
+ // Flip sign if necessary
+ if (sign) {
+ mantissa = -mantissa;
+ }
+
+ // Calculate final value
+ return mantissa * pow(2.0, exp);
+}
+
+
+
}
Modified: scummvm/branches/gsoc2009-draci/engines/draci/game.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/game.h 2009-07-19 12:52:19 UTC (rev 42611)
+++ scummvm/branches/gsoc2009-draci/engines/draci/game.h 2009-07-19 13:28:05 UTC (rev 42612)
@@ -43,6 +43,8 @@
personSize = sizeof(uint16) * 2 + sizeof(byte)
};
+static double real_to_double(byte real[6]);
+
class WalkingMap {
public:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list