[Scummvm-cvs-logs] CVS: scummvm/sword2/driver _mouse.cpp,1.44,1.45 animation.cpp,1.67,1.68 d_sound.cpp,1.160,1.161 palette.cpp,1.41,1.42 render.cpp,1.79,1.80

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Sat Oct 29 14:26:24 CEST 2005


Update of /cvsroot/scummvm/scummvm/sword2/driver
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23408/driver

Modified Files:
	_mouse.cpp animation.cpp d_sound.cpp palette.cpp render.cpp 
Log Message:
Applied my own patch #1341495, in an attempt to fix alignment issues
reported by Crilith.

To elaborate a bit, the engine no longer accesses resource data through
packed structs. Instead it uses memory streams and the READ/WRITE
functions.

If data is mainly read, not written, I have replaced the old struct with a
new one with a read() function to read the whole thing from memory into the
struct's variables, and a write() function to dump the struct's variables
to memory. In fact, most of these write() functions remain unused.

If data is both read and written, I have replaced the struct with a class
with individual get/set functions to replace the old variables. This
manipulates memory directly.

Since I'm fairly sure that these structs are frequently stored as local
variables for a script, all script variables (both local and global) are
stored as little-endian and accessed through the READ/WRITE functions,
rather than being treated as arrays of 32-bit integers.

On a positive note, the functions for doing endian conversion of resources
and save games have been removed, and some general cleanups have been made
to assist in the rewrite.

Initial reports indicate that this patch indeed fixes alignment issues, and
that I have not - surprisingly - broken the game on big-endian platforms.
At least not in any immediately obvious way. And there's still plenty of
time to fix regressions before 0.9.0, too.


Index: _mouse.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/_mouse.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- _mouse.cpp	18 Oct 2005 01:30:25 -0000	1.44
+++ _mouse.cpp	29 Oct 2005 21:24:54 -0000	1.45
@@ -20,6 +20,7 @@
 
 #include "common/stdafx.h"
 #include "common/system.h"
+#include "common/stream.h"
 
 #include "sword2/sword2.h"
 #include "sword2/defs.h"
@@ -33,12 +34,14 @@
 
 #define MOUSEFLASHFRAME 6
 
-void Mouse::decompressMouse(byte *decomp, byte *comp, int width, int height, int pitch, int xOff, int yOff) {
+void Mouse::decompressMouse(byte *decomp, byte *comp, uint8 frame, int width, int height, int pitch, int xOff, int yOff) {
 	int32 size = width * height;
 	int32 i = 0;
 	int x = 0;
 	int y = 0;
 
+	comp = comp + READ_LE_UINT32(comp + frame * 4) - MOUSE_ANIM_HEADER_SIZE;
+
 	while (i < size) {
 		if (*comp > 183) {
 			decomp[(y + yOff) * pitch + x + xOff] = *comp++;
@@ -61,7 +64,7 @@
 void Mouse::drawMouse() {
 	byte mouseData[MAX_MOUSE_W * MAX_MOUSE_H];
 
-	if (!_mouseAnim && !_luggageAnim)
+	if (!_mouseAnim.data && !_luggageAnim.data)
 		return;
 
 	// When an object is used in the game, the mouse cursor should be a
@@ -77,27 +80,27 @@
 	int deltaX = 0;
 	int deltaY = 0;
 
-	if (_mouseAnim) {
-		hotspot_x = _mouseAnim->xHotSpot;
-		hotspot_y = _mouseAnim->yHotSpot;
-		mouse_width = _mouseAnim->mousew;
-		mouse_height = _mouseAnim->mouseh;
+	if (_mouseAnim.data) {
+		hotspot_x = _mouseAnim.xHotSpot;
+		hotspot_y = _mouseAnim.yHotSpot;
+		mouse_width = _mouseAnim.mousew;
+		mouse_height = _mouseAnim.mouseh;
 	}
 
-	if (_luggageAnim) {
-		if (!_mouseAnim) {
-			hotspot_x = _luggageAnim->xHotSpot;
-			hotspot_y = _luggageAnim->yHotSpot;
+	if (_luggageAnim.data) {
+		if (!_mouseAnim.data) {
+			hotspot_x = _luggageAnim.xHotSpot;
+			hotspot_y = _luggageAnim.yHotSpot;
 		}
-		if (_luggageAnim->mousew > mouse_width)
-			mouse_width = _luggageAnim->mousew;
-		if (_luggageAnim->mouseh > mouse_height)
-			mouse_height = _luggageAnim->mouseh;
+		if (_luggageAnim.mousew > mouse_width)
+			mouse_width = _luggageAnim.mousew;
+		if (_luggageAnim.mouseh > mouse_height)
+			mouse_height = _luggageAnim.mouseh;
 	}
 
-	if (_mouseAnim && _luggageAnim) {
-		deltaX = _mouseAnim->xHotSpot - _luggageAnim->xHotSpot;
-		deltaY = _mouseAnim->yHotSpot - _luggageAnim->yHotSpot;
+	if (_mouseAnim.data && _luggageAnim.data) {
+		deltaX = _mouseAnim.xHotSpot - _luggageAnim.xHotSpot;
+		deltaY = _mouseAnim.yHotSpot - _luggageAnim.yHotSpot;
 	}
 
 	assert(deltaX >= 0);
@@ -114,19 +117,21 @@
 	mouse_width += deltaX;
 	mouse_height += deltaY;
 
-	if ((uint32) (mouse_width * mouse_height) > sizeof(mouseData)) {
+	if ((uint32)(mouse_width * mouse_height) > sizeof(mouseData)) {
 		warning("Mouse cursor too large");
 		return;
 	}
 
 	memset(mouseData, 0, mouse_width * mouse_height);
 
-	if (_luggageAnim)
-		decompressMouse(mouseData, (byte *)_luggageAnim + READ_LE_UINT32(_luggageOffset), _luggageAnim->mousew,
-				_luggageAnim->mouseh, mouse_width, deltaX, deltaY);
+	if (_luggageAnim.data)
+		decompressMouse(mouseData, _luggageAnim.data, 0,
+			_luggageAnim.mousew, _luggageAnim.mouseh,
+			mouse_width, deltaX, deltaY);
 
-	if (_mouseAnim)
-		decompressMouse(mouseData, _mouseSprite, _mouseAnim->mousew, _mouseAnim->mouseh, mouse_width);
+	if (_mouseAnim.data)
+		decompressMouse(mouseData, _mouseAnim.data, _mouseFrame,
+			_mouseAnim.mousew, _mouseAnim.mouseh, mouse_width);
 
 	_vm->_system->setMouseCursor(mouseData, mouse_width, mouse_height, hotspot_x, hotspot_y, 0);
 }
@@ -138,14 +143,12 @@
 int32 Mouse::animateMouse() {
 	uint8 prevMouseFrame = _mouseFrame;
 
-	if (!_mouseAnim)
+	if (!_mouseAnim.data)
 		return RDERR_UNKNOWN;
 
-	if (++_mouseFrame == _mouseAnim->noAnimFrames)
+	if (++_mouseFrame == _mouseAnim.noAnimFrames)
 		_mouseFrame = MOUSEFLASHFRAME;
 
-	_mouseSprite = (byte *)_mouseAnim + READ_LE_UINT32(_mouseOffsets + _mouseFrame);
-
 	if (_mouseFrame != prevMouseFrame)
 		drawMouse();
 
@@ -161,10 +164,8 @@
  */
 
 int32 Mouse::setMouseAnim(byte *ma, int32 size, int32 mouseFlash) {
-	if (_mouseAnim) {
-		free(_mouseAnim);
-		_mouseAnim = NULL;
-	}
+	free(_mouseAnim.data);
+	_mouseAnim.data = NULL;
 
 	if (ma)	{
 		if (mouseFlash == RDMOUSE_FLASH)
@@ -172,19 +173,27 @@
 		else
 			_mouseFrame = MOUSEFLASHFRAME;
 
-		_mouseAnim = (MouseAnim *)malloc(size);
-		if (!_mouseAnim)
+		Common::MemoryReadStream readS(ma, size);
+
+		_mouseAnim.runTimeComp = readS.readByte();
+		_mouseAnim.noAnimFrames = readS.readByte();
+		_mouseAnim.xHotSpot = readS.readSByte();
+		_mouseAnim.yHotSpot = readS.readSByte();
+		_mouseAnim.mousew = readS.readByte();
+		_mouseAnim.mouseh = readS.readByte();
+
+		_mouseAnim.data = (byte *)malloc(size - MOUSE_ANIM_HEADER_SIZE);
+		if (!_mouseAnim.data)
 			return RDERR_OUTOFMEMORY;
 
-		memcpy((byte *)_mouseAnim, ma, size);
-		_mouseOffsets = (int32 *)((byte *)_mouseAnim + sizeof(MouseAnim));
+		readS.read(_mouseAnim.data, size - MOUSE_ANIM_HEADER_SIZE);
 
 		animateMouse();
 		drawMouse();
 
 		_vm->_system->showMouse(true);
 	} else {
-		if (_luggageAnim)
+		if (_luggageAnim.data)
 			drawMouse();
 		else
 			_vm->_system->showMouse(false);
@@ -201,25 +210,31 @@
  */
 
 int32 Mouse::setLuggageAnim(byte *ma, int32 size) {
-	if (_luggageAnim) {
-		free(_luggageAnim);
-		_luggageAnim = NULL;
-	}
+	free(_luggageAnim.data);
+	_luggageAnim.data = NULL;
 
 	if (ma)	{
-		_luggageAnim = (MouseAnim *)malloc(size);
-		if (!_luggageAnim)
+		Common::MemoryReadStream readS(ma, size);
+
+		_luggageAnim.runTimeComp = readS.readByte();
+		_luggageAnim.noAnimFrames = readS.readByte();
+		_luggageAnim.xHotSpot = readS.readSByte();
+		_luggageAnim.yHotSpot = readS.readSByte();
+		_luggageAnim.mousew = readS.readByte();
+		_luggageAnim.mouseh = readS.readByte();
+
+		_luggageAnim.data = (byte *)malloc(size - MOUSE_ANIM_HEADER_SIZE);
+		if (!_luggageAnim.data)
 			return RDERR_OUTOFMEMORY;
 
-		memcpy((byte *)_luggageAnim, ma, size);
-		_luggageOffset = (int32 *)((byte *)_luggageAnim + sizeof(MouseAnim));
+		readS.read(_luggageAnim.data, size - MOUSE_ANIM_HEADER_SIZE);
 
 		animateMouse();
 		drawMouse();
 
 		_vm->_system->showMouse(true);
 	} else {
-		if (_mouseAnim)
+		if (_mouseAnim.data)
 			drawMouse();
 		else
 			_vm->_system->showMouse(false);

Index: animation.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/animation.cpp,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- animation.cpp	18 Oct 2005 01:30:25 -0000	1.67
+++ animation.cpp	29 Oct 2005 21:24:54 -0000	1.68
@@ -176,12 +176,11 @@
 
 	if (leadInRes) {
 		byte *leadIn = _vm->_resman->openResource(leadInRes);
-		uint32 leadInLen = _vm->_resman->fetchLen(leadInRes) - sizeof(StandardHeader);
-		StandardHeader *header = (StandardHeader *)leadIn;
+		uint32 leadInLen = _vm->_resman->fetchLen(leadInRes) - ResHeader::size();
 
-		assert(header->fileType == WAV_FILE);
+		assert(_vm->_resman->fetchType(leadIn) == WAV_FILE);
 
-		leadIn += sizeof(StandardHeader);
+		leadIn += ResHeader::size();
 
 		_vm->_sound->playFx(&leadInHandle, leadIn, leadInLen, Audio::Mixer::kMaxChannelVolume, 0, false, Audio::Mixer::kMusicSoundType);
 	}
@@ -191,15 +190,14 @@
 
 	if (leadOutRes) {
 		leadOut = _vm->_resman->openResource(leadOutRes);
-		leadOutLen = _vm->_resman->fetchLen(leadOutRes) - sizeof(StandardHeader);
-		StandardHeader *header = (StandardHeader *)leadOut;
+		leadOutLen = _vm->_resman->fetchLen(leadOutRes) - ResHeader::size();
 
-		assert(header->fileType == WAV_FILE);
+		assert(_vm->_resman->fetchType(leadOut) == WAV_FILE);
 
-		leadOut += sizeof(StandardHeader);
+		leadOut += ResHeader::size();
 	}
 
-	_leadOutFrame = (uint) -1;
+	_leadOutFrame = (uint)-1;
 
 	int i;
 
@@ -420,16 +418,18 @@
 		data = _vm->_fontRenderer->makeTextSprite(msg, RENDERWIDE, 255, _vm->_speechFontId);
 	}
 
-	FrameHeader *frame = (FrameHeader *)data;
+	FrameHeader frame_head;
 	SpriteInfo msgSprite;
 	byte *msgSurface;
 
-	msgSprite.x = _vm->_screen->getScreenWide() / 2 - frame->width / 2;
-	msgSprite.y = MENUDEEP / 2 - frame->height / 2;
-	msgSprite.w = frame->width;
-	msgSprite.h = frame->height;
+	frame_head.read(data);
+
+	msgSprite.x = _vm->_screen->getScreenWide() / 2 - frame_head.width / 2;
+	msgSprite.y = MENUDEEP / 2 - frame_head.height / 2;
+	msgSprite.w = frame_head.width;
+	msgSprite.h = frame_head.height;
 	msgSprite.type = RDSPR_NOCOMPRESSION;
-	msgSprite.data = data + sizeof(FrameHeader);
+	msgSprite.data = data + FrameHeader::size();
 
 	_vm->_screen->createSurface(&msgSprite, &msgSurface);
 	_vm->_screen->drawSurface(&msgSprite, msgSurface);

Index: d_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/d_sound.cpp,v
retrieving revision 1.160
retrieving revision 1.161
diff -u -d -r1.160 -r1.161
--- d_sound.cpp	23 Oct 2005 10:49:34 -0000	1.160
+++ d_sound.cpp	29 Oct 2005 21:24:54 -0000	1.161
@@ -177,7 +177,7 @@
 int CLUInputStream::readBuffer(int16 *buffer, const int numSamples) {
 	int samples = 0;
 	while (samples < numSamples && !eosIntern()) {
-		const int len = MIN(numSamples - samples, (int) (_bufferEnd - _pos));
+		const int len = MIN(numSamples - samples, (int)(_bufferEnd - _pos));
 		memcpy(buffer, _pos, len * 2);
 		buffer += len;
 		_pos += len;
@@ -195,7 +195,7 @@
 
 	_file->seek(_file_pos, SEEK_SET);
 
-	uint len_left = _file->read(in, MIN((uint32) BUFFER_SIZE, _end_pos - _file->pos()));
+	uint len_left = _file->read(in, MIN((uint32)BUFFER_SIZE, _end_pos - _file->pos()));
 
 	_file_pos = _file->pos();
 
@@ -270,7 +270,7 @@
 
 	int samples = 0;
 	while (samples < numSamples && !eosIntern()) {
-		const int len = MIN(numSamples - samples, (int) (_bufferEnd - _pos));
+		const int len = MIN(numSamples - samples, (int)(_bufferEnd - _pos));
 		memcpy(buffer, _pos, len * 2);
 		buffer += len;
 		_pos += len;
@@ -290,7 +290,7 @@
 
 	len_left = BUFFER_SIZE;
 
-	if (_fading > 0 && (uint32) _fading < len_left)
+	if (_fading > 0 && (uint32)_fading < len_left)
 		len_left = _fading;
 
 	if (_samplesLeft < len_left)

Index: palette.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/palette.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- palette.cpp	18 Oct 2005 01:30:25 -0000	1.41
+++ palette.cpp	29 Oct 2005 21:24:54 -0000	1.42
@@ -60,7 +60,7 @@
 	// is apparently needed for the palette to be restored properly when
 	// you turn the light off. (I didn't even notice the light switch!)
 
-	if (Logic::_scriptVars[LOCATION] == 13) {
+	if (_vm->_logic->readVar(LOCATION) == 13) {
 		// unpausing
 		if (palRes == -1) {
 			// restore whatever palette was last set (screen
@@ -88,10 +88,9 @@
 	if (palRes) {
 		byte *pal = _vm->_resman->openResource(palRes);
 
-		StandardHeader *head = (StandardHeader *)pal;
-		assert(head->fileType == PALETTE_FILE);
+		assert(_vm->_resman->fetchType(pal) == PALETTE_FILE);
 
-		pal += sizeof(StandardHeader);
+		pal += ResHeader::size();
 
 		// always set colour 0 to black because most background screen
 		// palettes have a bright colour 0 although it should come out
@@ -130,7 +129,7 @@
 // linker complained when I tried to use it in sprite.cpp.
 
 uint8 Screen::quickMatch(uint8 r, uint8 g, uint8 b) {
-	return _paletteMatch[((int32) (r >> 2) << 12) + ((int32) (g >> 2) << 6) + (b >> 2)];
+	return _paletteMatch[((int32)(r >> 2) << 12) + ((int32)(g >> 2) << 6) + (b >> 2)];
 }
 
 /**
@@ -174,7 +173,7 @@
 	if (getFadeStatus() != RDFADE_BLACK && getFadeStatus() != RDFADE_NONE)
 		return RDERR_FADEINCOMPLETE;
 
-	_fadeTotalTime = (int32) (time * 1000);
+	_fadeTotalTime = (int32)(time * 1000);
 	_fadeStatus = RDFADE_UP;
 	_fadeStartTime = _vm->_system->getMillis();
 
@@ -190,7 +189,7 @@
 	if (getFadeStatus() != RDFADE_BLACK && getFadeStatus() != RDFADE_NONE)
 		return RDERR_FADEINCOMPLETE;
 
-	_fadeTotalTime = (int32) (time * 1000);
+	_fadeTotalTime = (int32)(time * 1000);
 	_fadeStatus = RDFADE_DOWN;
 	_fadeStartTime = _vm->_system->getMillis();
 
@@ -239,7 +238,7 @@
 			_fadeStatus = RDFADE_NONE;
 			newPalette = _palette;
 		} else {
-			fadeMultiplier = (int16) (((int32) (currentTime - _fadeStartTime) * 256) / _fadeTotalTime);
+			fadeMultiplier = (int16)(((int32)(currentTime - _fadeStartTime) * 256) / _fadeTotalTime);
 			for (i = 0; i < 256; i++) {
 				newPalette[i * 4 + 0] = (_palette[i * 4 + 0] * fadeMultiplier) >> 8;
 				newPalette[i * 4 + 1] = (_palette[i * 4 + 1] * fadeMultiplier) >> 8;
@@ -251,7 +250,7 @@
 			_fadeStatus = RDFADE_BLACK;
 			memset(newPalette, 0, sizeof(fadePalette));
 		} else {
-			fadeMultiplier = (int16) (((int32) (_fadeTotalTime - (currentTime - _fadeStartTime)) * 256) / _fadeTotalTime);
+			fadeMultiplier = (int16)(((int32)(_fadeTotalTime - (currentTime - _fadeStartTime)) * 256) / _fadeTotalTime);
 			for (i = 0; i < 256; i++) {
 				newPalette[i * 4 + 0] = (_palette[i * 4 + 0] * fadeMultiplier) >> 8;
 				newPalette[i * 4 + 1] = (_palette[i * 4 + 1] * fadeMultiplier) >> 8;

Index: render.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sword2/driver/render.cpp,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- render.cpp	18 Oct 2005 01:30:25 -0000	1.79
+++ render.cpp	29 Oct 2005 21:24:54 -0000	1.80
@@ -248,19 +248,22 @@
  * parallax can be either foreground, background or the main screen.
  */
 
-void Screen::renderParallax(Parallax *p, int16 l) {
+void Screen::renderParallax(byte *ptr, int16 l) {
+	Parallax p;
 	int16 x, y;
 	Common::Rect r;
 
+	p.read(ptr);
+
 	if (_locationWide == _screenWide)
 		x = 0;
 	else
-		x = ((int32) ((p->w - _screenWide) * _scrollX) / (int32) (_locationWide - _screenWide));
+		x = ((int32)((p.w - _screenWide) * _scrollX) / (int32)(_locationWide - _screenWide));
 
 	if (_locationDeep == _screenDeep - MENUDEEP * 2)
 		y = 0;
 	else
-		y = ((int32) ((p->h - (_screenDeep - MENUDEEP * 2)) * _scrollY) / (int32) (_locationDeep - (_screenDeep - MENUDEEP * 2)));
+		y = ((int32)((p.h - (_screenDeep - MENUDEEP * 2)) * _scrollY) / (int32)(_locationDeep - (_screenDeep - MENUDEEP * 2)));
 
 	Common::Rect clipRect;
 
@@ -315,8 +318,8 @@
 		_scrollY = _scrollYTarget;
 		_renderTooSlow = true;
 	} else {
-		_scrollX = (int16) (_scrollXOld + ((_scrollXTarget - _scrollXOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
-		_scrollY = (int16) (_scrollYOld + ((_scrollYTarget - _scrollYOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
+		_scrollX = (int16)(_scrollXOld + ((_scrollXTarget - _scrollXOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
+		_scrollY = (int16)(_scrollYOld + ((_scrollYTarget - _scrollYOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
 		_renderTooSlow = false;
 	}
 
@@ -377,8 +380,8 @@
 		_scrollX = _scrollXTarget;
 		_scrollY = _scrollYTarget;
 	} else {
-		_scrollX = (int16) (_scrollXOld + ((_scrollXTarget - _scrollXOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
-		_scrollY = (int16) (_scrollYOld + ((_scrollYTarget - _scrollYOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
+		_scrollX = (int16)(_scrollXOld + ((_scrollXTarget - _scrollXOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
+		_scrollY = (int16)(_scrollYOld + ((_scrollYTarget - _scrollYOld) * (_startTime - _initialTime + _renderAverageTime)) / (_totalTime - _initialTime));
 	}
 
 	if (_scrollX != _scrollXOld || _scrollY != _scrollYOld)
@@ -410,7 +413,8 @@
  * or a NULL pointer in order of background parallax to foreground parallax.
  */
 
-int32 Screen::initialiseBackgroundLayer(Parallax *p) {
+int32 Screen::initialiseBackgroundLayer(byte *parallax) {
+	Parallax p;
 	uint16 i, j, k;
 	byte *data;
 	byte *dst;
@@ -419,13 +423,15 @@
 
 	assert(_layer < MAXLAYERS);
 
-	if (!p) {
+	if (!parallax) {
 		_layer++;
 		return RD_OK;
 	}
 
-	_xBlocks[_layer] = (p->w + BLOCKWIDTH - 1) / BLOCKWIDTH;
-	_yBlocks[_layer] = (p->h + BLOCKHEIGHT - 1) / BLOCKHEIGHT;
+	p.read(parallax);
+
+	_xBlocks[_layer] = (p.w + BLOCKWIDTH - 1) / BLOCKWIDTH;
+	_yBlocks[_layer] = (p.h + BLOCKHEIGHT - 1) / BLOCKHEIGHT;
 
 	_blockSurfaces[_layer] = (BlockSurface **)calloc(_xBlocks[_layer] * _yBlocks[_layer], sizeof(BlockSurface *));
 	if (!_blockSurfaces[_layer])
@@ -437,19 +443,21 @@
 	if (!memchunk)
 		return RDERR_OUTOFMEMORY;
 
-	for (i = 0; i < p->h; i++) {
-		if (!p->offset[i])
+	for (i = 0; i < p.h; i++) {
+		uint32 p_offset = READ_LE_UINT32(parallax + Parallax::size() + 4 * i);
+
+		if (!p_offset)
 			continue;
 
-		byte *pLine = (byte *)p + FROM_LE_32(p->offset[i]);
+		byte *pLine = parallax + p_offset;
 		uint16 packets = READ_LE_UINT16(pLine);
 		uint16 offset = READ_LE_UINT16(pLine + 2);
 
 		data = pLine + 4;
-		dst = memchunk + i * p->w + offset;
+		dst = memchunk + i * p.w + offset;
 
 		if (!packets) {
-			memcpy(dst, data, p->w);
+			memcpy(dst, data, p.w);
 			continue;
 		}
 
@@ -487,12 +495,12 @@
 		int x = BLOCKWIDTH * (i % _xBlocks[_layer]);
 		int y = BLOCKHEIGHT * (i / _xBlocks[_layer]);
 
-		data = memchunk + p->w * y + x;
+		data = memchunk + p.w * y + x;
 
 		for (j = 0; j < BLOCKHEIGHT; j++) {
 			for (k = 0; k < BLOCKWIDTH; k++) {
-				if (x + k < p->w && y + j < p->h) {
-					if (data[j * p->w + k])
+				if (x + k < p.w && y + j < p.h) {
+					if (data[j * p.w + k])
 						block_has_data = true;
 					else
 						block_is_transparent = true;
@@ -509,7 +517,7 @@
 			dst = _blockSurfaces[_layer][i]->data;
 			for (j = 0; j < BLOCKHEIGHT; j++) {
 				memcpy(dst, data, BLOCKWIDTH);
-				data += p->w;
+				data += p.w;
 				dst += BLOCKWIDTH;
 			}
 





More information about the Scummvm-git-logs mailing list