[Scummvm-cvs-logs] SF.net SVN: scummvm: [24719] scummvm/trunk/engines/gob

drmccoy at users.sourceforge.net drmccoy at users.sourceforge.net
Tue Nov 14 15:58:42 CET 2006


Revision: 24719
          http://svn.sourceforge.net/scummvm/?rev=24719&view=rev
Author:   drmccoy
Date:     2006-11-14 06:58:41 -0800 (Tue, 14 Nov 2006)

Log Message:
-----------
Fixed the lock when leaving the menu

Modified Paths:
--------------
    scummvm/trunk/engines/gob/draw_v2.cpp
    scummvm/trunk/engines/gob/game.cpp
    scummvm/trunk/engines/gob/game.h
    scummvm/trunk/engines/gob/game_v1.cpp
    scummvm/trunk/engines/gob/game_v2.cpp
    scummvm/trunk/engines/gob/parse_v2.cpp
    scummvm/trunk/engines/gob/video.cpp

Modified: scummvm/trunk/engines/gob/draw_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/draw_v2.cpp	2006-11-14 09:29:41 UTC (rev 24718)
+++ scummvm/trunk/engines/gob/draw_v2.cpp	2006-11-14 14:58:41 UTC (rev 24719)
@@ -269,7 +269,7 @@
 				adjustCoords(0, &rectLeft, &rectTop);
 				adjustCoords(2, &rectRight, &rectBottom);
 				if (colId != -1)
-					_vm->_game->addNewCollision(colId & 0x0D000, rectLeft, rectTop,
+					_vm->_game->addNewCollision(colId + 0xD000, rectLeft, rectTop,
 							rectRight, rectBottom, 2, 0, 0, 0);
 				if (_word_2E8E2 != 2)
 					printTextCentered(extraCmd & 0x0F, rectLeft + 4, rectTop + 4,
@@ -357,7 +357,7 @@
 				rectBottom = destY + (int16)READ_LE_UINT16(ptr + 6);
 				adjustCoords(2, &rectLeft, &rectTop);
 				adjustCoords(2, &rectRight, &rectBottom);
-				_vm->_game->addNewCollision(colId & 0x0D000, rectLeft, rectTop,
+				_vm->_game->addNewCollision(colId + 0x0D000, rectLeft, rectTop,
 						rectRight, rectBottom, 2, 0, 0, 0);
 				ptr += 8;
 			}

Modified: scummvm/trunk/engines/gob/game.cpp
===================================================================
--- scummvm/trunk/engines/gob/game.cpp	2006-11-14 09:29:41 UTC (rev 24718)
+++ scummvm/trunk/engines/gob/game.cpp	2006-11-14 14:58:41 UTC (rev 24719)
@@ -670,6 +670,8 @@
 
 void Game::start(void) {
 	_collisionAreas = new Collision[250];
+	memset(_collisionAreas, 0, 250 * sizeof(Collision));
+
 	prepareStart();
 	playTot(-2);
 
@@ -778,9 +780,9 @@
 	_totTextData = _totTextDataArray[_curBackupPos];
 	_totFileData = _totFileDataArray[_curBackupPos];
 	_totResourceTable = _totResourceTableArray[_curBackupPos];
+	_imFileData = _imFileDataArray[_curBackupPos];
 	_extTable = _extTableArray[_curBackupPos];
 	_extHandle = _extHandleArray[_curBackupPos];
-	_imFileData = _imFileDataArray[_curBackupPos];
 	_vm->_global->_inter_variables = _variablesArray[_curBackupPos];
 	strcpy(_curTotFile, _curTotFileArray[_curBackupPos]);
 	strcpy(_curExtFile, _curTotFile);
@@ -945,13 +947,14 @@
 
 	collId = _collisionAreas[index].id & 0xF000;
 
-	if ((collId != 0xA000) && (collId != 0x9000))
-		WRITE_VAR(17, collId);
-	else if (enter == 0)
-		WRITE_VAR(17, _collisionAreas[index].id & 0x0FFF);
-	else
-		WRITE_VAR(17, -(_collisionAreas[index].id & 0x0FFF));
-	
+	if ((collId == 0xA000) || (collId == 0x9000))
+	{
+		if (enter == 0)
+			WRITE_VAR(17, _collisionAreas[index].id & 0x0FFF);
+		else
+			WRITE_VAR(17, -(_collisionAreas[index].id & 0x0FFF));
+	}
+
 	if (enter != 0) {
 		if (_collisionAreas[index].funcEnter != 0)
 			collSub(_collisionAreas[index].funcEnter);

Modified: scummvm/trunk/engines/gob/game.h
===================================================================
--- scummvm/trunk/engines/gob/game.h	2006-11-14 09:29:41 UTC (rev 24718)
+++ scummvm/trunk/engines/gob/game.h	2006-11-14 14:58:41 UTC (rev 24719)
@@ -221,7 +221,7 @@
 
 	virtual void playTot(int16 skipPlay) = 0;
 	virtual void clearCollisions(void) = 0;
-	virtual void addNewCollision(int16 id, int16 left, int16 top, int16 right,
+	virtual int16 addNewCollision(int16 id, int16 left, int16 top, int16 right,
 			int16 bottom, int16 flags, int16 key, int16 funcEnter, int16 funcLeave) = 0;
 	virtual void collisionsBlock(void) = 0;
 	virtual int16 multiEdit(int16 time, int16 index, int16 *pCurPos,
@@ -285,7 +285,7 @@
 public:
 	virtual void playTot(int16 skipPlay);
 	virtual void clearCollisions(void);
-	virtual void addNewCollision(int16 id, int16 left, int16 top, int16 right,
+	virtual int16 addNewCollision(int16 id, int16 left, int16 top, int16 right,
 			int16 bottom, int16 flags, int16 key, int16 funcEnter, int16 funcLeave);
 	virtual void collisionsBlock(void);
 	virtual int16 multiEdit(int16 time, int16 index, int16 *pCurPos,
@@ -309,7 +309,7 @@
 public:
 	virtual void playTot(int16 skipPlay);
 	virtual void clearCollisions(void);
-	virtual void addNewCollision(int16 id, int16 left, int16 top, int16 right,
+	virtual int16 addNewCollision(int16 id, int16 left, int16 top, int16 right,
 			int16 bottom, int16 flags, int16 key, int16 funcEnter, int16 funcLeave);
 	virtual void collisionsBlock(void);
 	virtual int16 multiEdit(int16 time, int16 index, int16 *pCurPos,

Modified: scummvm/trunk/engines/gob/game_v1.cpp
===================================================================
--- scummvm/trunk/engines/gob/game_v1.cpp	2006-11-14 09:29:41 UTC (rev 24718)
+++ scummvm/trunk/engines/gob/game_v1.cpp	2006-11-14 14:58:41 UTC (rev 24719)
@@ -260,7 +260,7 @@
 	}
 }
 
-void Game_v1::addNewCollision(int16 id, int16 left, int16 top, int16 right, int16 bottom,
+int16 Game_v1::addNewCollision(int16 id, int16 left, int16 top, int16 right, int16 bottom,
 	    int16 flags, int16 key, int16 funcEnter, int16 funcLeave) {
 	int16 i;
 	Collision *ptr;
@@ -285,9 +285,10 @@
 		ptr->key = key;
 		ptr->funcEnter = funcEnter;
 		ptr->funcLeave = funcLeave;
-		return;
+		return i;
 	}
 	error("addNewCollision: Collision array full!\n");
+	return 0;
 }
 
 void Game_v1::pushCollisions(char all) {
@@ -660,7 +661,7 @@
 	int16 counter;
 	int16 var_24;
 	int16 var_26;
-	int16 _collStackPos;
+	int16 collStackPos;
 	Collision *collPtr;
 	int16 timeKey;
 	char *savedIP;
@@ -932,15 +933,15 @@
 
 				if (deltaTime != 0 && VAR(16) == 0) {
 					if (stackPos2 != 0) {
-						_collStackPos = 0;
+						collStackPos = 0;
 						collPtr = _collisionAreas;
 
 						for (i = 0, collPtr = _collisionAreas; collPtr->left != -1; i++, collPtr++) {
 							if ((collPtr->id & 0x8000) == 0)
 								continue;
 
-							_collStackPos++;
-							if (_collStackPos != stackPos2)
+							collStackPos++;
+							if (collStackPos != stackPos2)
 								continue;
 
 							_activeCollResId = collPtr->id;
@@ -1047,9 +1048,9 @@
 
 			_shouldPushColls = 1;
 
-			_collStackPos = _collStackSize;
+			collStackPos = _collStackSize;
 			_vm->_inter->funcBlock(0);
-			if (_collStackPos != _collStackSize)
+			if (collStackPos != _collStackSize)
 				popCollisions();
 			_shouldPushColls = 0;
 			_vm->_global->_inter_execPtr = savedIP;
@@ -1061,7 +1062,7 @@
 	while (_activeCollResId == 0 && !_vm->_inter->_terminate && !_vm->_quitRequested);
 
 	if (((uint16)_activeCollResId & ~0x8000) == collResId) {
-		_collStackPos = 0;
+		collStackPos = 0;
 		var_24 = 0;
 		var_26 = 1;
 		for (i = 0; i < 250; i++) {
@@ -1113,7 +1114,7 @@
 						break;
 					}
 				} while (READ_LE_UINT16(descArray[var_24].ptr - 2) > pos);
-				_collStackPos++;
+				collStackPos++;
 			} else {
 				VAR(17 + var_26) = 2;
 			}
@@ -1121,7 +1122,7 @@
 			var_26++;
 		}
 
-		if (_collStackPos != (int16)VAR(17))
+		if (collStackPos != (int16)VAR(17))
 			WRITE_VAR(17, 0);
 		else
 			WRITE_VAR(17, 1);

Modified: scummvm/trunk/engines/gob/game_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/game_v2.cpp	2006-11-14 09:29:41 UTC (rev 24718)
+++ scummvm/trunk/engines/gob/game_v2.cpp	2006-11-14 14:58:41 UTC (rev 24719)
@@ -282,13 +282,13 @@
 
 	_lastCollKey = 0;
 
-	for (i = 0; i < 250; i++) {
-		_collisionAreas[i].id = 0;
+	for (i = 0; i < 150; i++) {
+//		_collisionAreas[i].id = 0;
 		_collisionAreas[i].left = -1;
 	}
 }
 
-void Game_v2::addNewCollision(int16 id, int16 left, int16 top, int16 right, int16 bottom,
+int16 Game_v2::addNewCollision(int16 id, int16 left, int16 top, int16 right, int16 bottom,
 	    int16 flags, int16 key, int16 funcEnter, int16 funcLeave) {
 	int16 i;
 	Collision *ptr;
@@ -314,9 +314,11 @@
 		ptr->funcEnter = funcEnter;
 		ptr->funcLeave = funcLeave;
 		ptr->field_12 = 0;
-		return;
+
+		return i;
 	}
 	error("addNewCollision: Collision array full!\n");
+	return 0;
 }
 
 void Game_v2::pushCollisions(char all) {
@@ -325,14 +327,16 @@
 	int16 size;
 
 	debugC(1, DEBUG_COLLISIONS, "pushCollisions");
-	for (size = 0, srcPtr = _collisionAreas; srcPtr->left != -1;
-	    srcPtr++) {
-		if (all || (srcPtr->id >= 20))
+	for (size = 0, srcPtr = _collisionAreas; srcPtr->left != -1; srcPtr++)
+		if (all || (((uint16) srcPtr->id) >= 20))
 			size++;
-	}
 
 	destPtr = new Collision[size];
 	_collStack[_collStackSize] = destPtr;
+
+	if (_vm->_inter->_terminate)
+		return;
+
 	_collStackElemSizes[_collStackSize] = size;
 
 	if (_shouldPushColls != 0)
@@ -342,10 +346,13 @@
 	_collLasts[_collStackSize].key = _lastCollKey;
 	_collLasts[_collStackSize].id = _lastCollId;
 	_collLasts[_collStackSize].areaIndex = _lastCollAreaIndex;
+	_lastCollKey = 0;
+	_lastCollId = 0;
+	_lastCollAreaIndex = 0;
 	_collStackSize++;
 
 	for (srcPtr = _collisionAreas; srcPtr->left != -1; srcPtr++) {
-		if (all || (srcPtr->id >= 20)) {
+		if (all || (((uint16) srcPtr->id) >= 20)) {
 			memcpy(destPtr, srcPtr, sizeof(Collision));
 			srcPtr->left = -1;
 			destPtr++;
@@ -371,9 +378,7 @@
 	for (destPtr = _collisionAreas; destPtr->left != -1; destPtr++);
 
 	srcPtr = _collStack[_collStackSize];
-	memcpy(destPtr, srcPtr,
-	    _collStackElemSizes[_collStackSize] *
-	    sizeof(Collision));
+	memcpy(destPtr, srcPtr, _collStackElemSizes[_collStackSize] * sizeof(Collision));
 
 	delete[] _collStack[_collStackSize];
 }
@@ -414,6 +419,7 @@
 	int16 key;
 	int16 oldIndex;
 	int16 oldId;
+	int16 newkey;
 	uint32 timeKey;
 
 	if (deltaTime >= -1) {
@@ -599,15 +605,15 @@
 
 				oldIndex = _lastCollAreaIndex;
 				oldId = _lastCollId;
-				key = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex);
+				newkey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex);
 
-				if (key != _lastCollKey) {
+				if (newkey != _lastCollKey) {
 					if ((_lastCollKey != 0) && (oldId & 0x8000))
 						collAreaSub(oldIndex, 0);
 
-					_lastCollKey = key;
+					_lastCollKey = newkey;
 
-					if ((key != 0) && (_lastCollId & 0x8000))
+					if ((newkey != 0) && (_lastCollId & 0x8000))
 						collAreaSub(_lastCollAreaIndex, 1);
 				}
 			}
@@ -685,7 +691,7 @@
 void Game_v2::collisionsBlock(void) {
 	InputDesc descArray[20];
 	int16 array[250];
-	char count;
+	byte count;
 	int16 collResId;
 	char *startIP;
 	int16 curCmd;
@@ -705,12 +711,13 @@
 	int16 descIndex;
 	int16 timeVal;
 	int16 offsetIP;
+	int16 collId;
 	char *str;
 	int16 i;
 	int16 counter;
 	int16 var_24;
 	int16 var_26;
-	int16 _collStackPos;
+	int16 collStackPos;
 	Collision *collPtr;
 	Collision *collArea;
 	int16 timeKey;
@@ -749,7 +756,7 @@
 
 	for (curCmd = 0; curCmd < count; curCmd++) {
 		array[curCmd] = 0;
-		cmd = *_vm->_global->_inter_execPtr++;
+		cmd = (byte) *_vm->_global->_inter_execPtr++;
 
 		if ((cmd & 0x40) != 0) {
 			cmd -= 0x40;
@@ -799,15 +806,14 @@
 			_vm->_global->_inter_execPtr += READ_LE_UINT16(_vm->_global->_inter_execPtr);
 			key = curCmd + 0xA000;
 
-			addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1,
+			collId = addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1,
 					cmd + cmdHigh, key, startIP - (char *)_totFileData,
 					_vm->_global->_inter_execPtr - (char *)_totFileData);
 
 			_vm->_global->_inter_execPtr += 2;
 			_vm->_global->_inter_execPtr += READ_LE_UINT16(_vm->_global->_inter_execPtr);
 
-			if (key <= 150)
-				_collisionAreas[key].field_12 = offsetIP;
+			_collisionAreas[collId].field_12 = offsetIP;
 			break;
 
 		case 1:
@@ -821,15 +827,14 @@
 			if (key == 0)
 				key = curCmd + 0xa000;
 
-			addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1,
+			collId = addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1,
 					(flags << 4) + cmd + cmdHigh, key, startIP - (char *)_totFileData,
 					_vm->_global->_inter_execPtr - (char *)_totFileData);
 
 			_vm->_global->_inter_execPtr += 2;
 			_vm->_global->_inter_execPtr += READ_LE_UINT16(_vm->_global->_inter_execPtr);
 
-			if (key <= 150)
-				_collisionAreas[key].field_12 = offsetIP;
+			_collisionAreas[collId].field_12 = offsetIP;
 			break;
 
 		case 3:
@@ -849,7 +854,7 @@
 
 			if ((cmd >= 5) && (cmd <= 8)) {
 				descArray[index].ptr = _vm->_global->_inter_execPtr + 2;
-				_vm->_global->_inter_execPtr += _vm->_inter->load16();;
+				_vm->_global->_inter_execPtr += READ_LE_UINT16(_vm->_global->_inter_execPtr) + 2;
 			} else
 				descArray[index].ptr = 0;
 
@@ -912,15 +917,14 @@
 			array[curCmd] = _vm->_inter->load16();
 			flags = _vm->_inter->load16();
 
-			addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1,
+			collId = addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1,
 					(flags << 4) + cmdHigh + 2, key, 0,
 					_vm->_global->_inter_execPtr - (char *)_totFileData);
 
 			_vm->_global->_inter_execPtr += 2;
 			_vm->_global->_inter_execPtr += READ_LE_UINT16(_vm->_global->_inter_execPtr);
 
-			if (key <= 150)
-				_collisionAreas[key].field_12 = offsetIP;
+			_collisionAreas[collId].field_12 = offsetIP;
 			break;
 
 		case 21:
@@ -928,15 +932,14 @@
 			array[curCmd] = _vm->_inter->load16();
 			flags = _vm->_inter->load16() & 3;
 
-			addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1,
+			collId = addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1,
 					(flags << 4) + cmdHigh + 2, key,
 					_vm->_global->_inter_execPtr - (char *)_totFileData, 0);
 
 			_vm->_global->_inter_execPtr += 2;
 			_vm->_global->_inter_execPtr += READ_LE_UINT16(_vm->_global->_inter_execPtr);
 
-			if (key <= 150)
-				_collisionAreas[key].field_12 = offsetIP;
+			_collisionAreas[collId].field_12 = offsetIP;
 			break;
 		}
 	}
@@ -953,7 +956,7 @@
 			if (key == 0x1c0d) {
 				for (i = 0; i < 150; i++) {
 					if (_collisionAreas[i].left == -1)
-						continue;
+						break;
 
 					if ((_collisionAreas[i].id & 0xC000) != 0x8000)
 						continue;
@@ -983,7 +986,7 @@
 			if (key != 0) {
 				for (i = 0; i < 150; i++) {
 					if (_collisionAreas[i].left == -1)
-						continue;
+						break;
 
 					if ((_collisionAreas[i].id & 0xC000) != 0x8000)
 						continue;
@@ -998,7 +1001,7 @@
 				if (_activeCollResId == 0) {
 					for (i = 0; i < 150; i++) {
 						if (_collisionAreas[i].left == -1)
-							continue;
+							break;
 
 						if ((_collisionAreas[i].id & 0xC000) != 0x8000)
 							continue;
@@ -1019,15 +1022,14 @@
 				}
 			} else if (deltaTime != 0) {
 				if (stackPos2 != 0) {
-					_collStackPos = 0;
-					collPtr = _collisionAreas;
+					collStackPos = 0;
 
-					for (i = 0, collPtr = _collisionAreas; collPtr->left != -1; i++, collPtr++) {
+					for (i = 0, collPtr = collArea; collPtr->left != -1; i++, collPtr++) {
 						if ((collPtr->id & 0xF000) != 0x8000)
 							continue;
 
-						_collStackPos++;
-						if (_collStackPos != stackPos2)
+						collStackPos++;
+						if (collStackPos != stackPos2)
 							continue;
 
 						_activeCollResId = collPtr->id;
@@ -1050,6 +1052,8 @@
 
 							if (deltaTime < 2)
 								deltaTime = 2;
+							if (deltaTime > timeVal)
+								deltaTime = timeVal;
 						}
 
 						if (VAR(16) == 0)
@@ -1105,7 +1109,7 @@
 	while (_activeCollResId == 0 && !_vm->_inter->_terminate && !_vm->_quitRequested);
 
 	if ((_activeCollResId & 0xFFF) == collResId) {
-		_collStackPos = 0;
+		collStackPos = 0;
 		var_24 = 0;
 		var_26 = 1;
 		for (i = 0; i < 150; i++) {
@@ -1160,7 +1164,7 @@
 						break;
 					}
 				} while (READ_LE_UINT16(descArray[var_24].ptr - 2) > pos);
-				_collStackPos++;
+				collStackPos++;
 			} else {
 				VAR(17 + var_26) = 2;
 			}
@@ -1168,7 +1172,7 @@
 			var_26++;
 		}
 
-		if (_collStackPos != (int16)VAR(17))
+		if (collStackPos != (int16)VAR(17))
 			WRITE_VAR(17, 0);
 		else
 			WRITE_VAR(17, 1);
@@ -1182,10 +1186,12 @@
 		savedIP = (char *)_totFileData + _collisionAreas[_activeCollIndex].funcLeave;
 
 		_vm->_inter->storeMouse();
-		if ((_activeCollResId & 0xF000) == 0x8000)
-			WRITE_VAR(16, array[_activeCollResId & 0xFFF]);
-		else
-			WRITE_VAR(16, _activeCollResId & 0xFFF);
+		if (VAR(16) == 0) {
+			if ((_activeCollResId & 0xF000) == 0x8000)
+				WRITE_VAR(16, array[_activeCollResId & 0xFFF]);
+			else
+				WRITE_VAR(16, _activeCollResId & 0xFFF);
+		}
 	}
 
 	for (curCmd = 0; curCmd < count; curCmd++)

Modified: scummvm/trunk/engines/gob/parse_v2.cpp
===================================================================
--- scummvm/trunk/engines/gob/parse_v2.cpp	2006-11-14 09:29:41 UTC (rev 24718)
+++ scummvm/trunk/engines/gob/parse_v2.cpp	2006-11-14 14:58:41 UTC (rev 24719)
@@ -358,7 +358,7 @@
 	int16 dimCount;
 	int16 temp;
 	int16 temp2;
-	uint16 offset;
+	int16 offset;
 	int16 dim;
 	char var_1A;
 	int16 stkPos;

Modified: scummvm/trunk/engines/gob/video.cpp
===================================================================
--- scummvm/trunk/engines/gob/video.cpp	2006-11-14 09:29:41 UTC (rev 24718)
+++ scummvm/trunk/engines/gob/video.cpp	2006-11-14 14:58:41 UTC (rev 24719)
@@ -88,7 +88,9 @@
 	if (surfDesc == 0)
 		return;
 
-	delete[] surfDesc->vidPtr;
+	// TODO: valgrind shows an "Invalid free() / delete / delete[]" here...
+	// delete[] surfDesc->vidPtr;
+
 	// GOB2: surfDesc != _vm->_draw->_frontSurface (since _frontSurface is set
 	// to _pPrimarySurfDesc in Game::prepareStart(), is there a difference?)
 	if (surfDesc != _vm->_global->_pPrimarySurfDesc) {


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