[Scummvm-cvs-logs] CVS: scummvm/kyra kyra.cpp,1.70,1.71 kyra.h,1.35,1.36 screen.cpp,1.23,1.24 script.cpp,1.19,1.20 script.h,1.12,1.13 script_v1.cpp,1.22,1.23 sprites.cpp,1.9,1.10 staticres.cpp,1.16,1.17

Johannes Schickel lordhoto at users.sourceforge.net
Sun Nov 13 11:36:03 CET 2005


Update of /cvsroot/scummvm/scummvm/kyra
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32197

Modified Files:
	kyra.cpp kyra.h screen.cpp script.cpp script.h script_v1.cpp 
	sprites.cpp staticres.cpp 
Log Message:
Fixed a bug with the sprite loader and various things related to
the scene switching code. Now the intro works correctly with a minor graphics glitch.


Index: kyra.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/kyra.cpp,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -d -r1.70 -r1.71
--- kyra.cpp	11 Nov 2005 22:17:06 -0000	1.70
+++ kyra.cpp	13 Nov 2005 19:35:01 -0000	1.71
@@ -1088,6 +1088,7 @@
 	if (_newMusicTheme != _curMusicTheme) {
 		snd_playTheme(_newMusicTheme);
 	}
+	
 	switch (_currentCharacter->sceneId) {
 		case 1:
 			if (sceneId == 0) {
@@ -1145,7 +1146,7 @@
 			break;
 		}
 		
-		moveCharacterToPos(0, 2, xpos, ypos);
+		moveCharacterToPos(0, facing, xpos, ypos);
 	}
 	
 	for (int i = 0; i < 10; ++i) {
@@ -1204,10 +1205,8 @@
 	startSceneScript(brandonAlive);
 	// XXX setupSceneItems
 	initSceneData(facing, unk2, brandonAlive);
-		
-	// XXX setTextFadeTimerCountdown
-	_scriptClick->variables[3] = 1;
 	
+	_loopFlag2 = 0;
 	_screen->showMouse();
 	if (!brandonAlive) {
 		// XXX seq_poisionDeathNow
@@ -1217,30 +1216,34 @@
 void KyraEngine::moveCharacterToPos(int character, int facing, int xpos, int ypos) {
 	debug(9, "moveCharacterToPos(%d, %d, %d, %d)", character, facing, xpos, ypos);
 	Character *ch = &_characterList[character];
+	ch->facing = facing;
 	_screen->hideMouse();
 	xpos &= 0xFFFC;
 	ypos &= 0xFFFE;
+	disableTimer(19);
+	disableTimer(14);
+	disableTimer(18);
 	switch (facing) {
 		case 0:
-			if (ypos < ch->y1) {
+			while (ypos < ch->y1) {
 				setCharacterPositionWithUpdate(character);
 			}
 			break;
 		
 		case 2:	
-			if (ch->x1 < xpos) {
+			while (ch->x1 < xpos) {
 				setCharacterPositionWithUpdate(character);
 			}
 			break;
 		
 		case 4:
-			if (ypos > ch->y1) {
+			while (ypos > ch->y1) {
 				setCharacterPositionWithUpdate(character);
 			}
 			break;
 		
 		case 6:
-			if (ch->x1 > xpos) {
+			while (ch->x1 > xpos) {
 				setCharacterPositionWithUpdate(character);
 			}
 			break;
@@ -1248,13 +1251,17 @@
 		default:
 			break;
 	}
+	enableTimer(19);
+	enableTimer(14);
+	enableTimer(18);
 	_screen->showMouse();
 }
 
 void KyraEngine::setCharacterPositionWithUpdate(int character) {
 	debug(9, "setCharacterPositionWithUpdate(%d)", character);
-	_sprites->updateSceneAnims();
 	setCharacterPosition(character, 0);
+	_sprites->updateSceneAnims();
+	updateGameTimers();
 	updateAllObjectShapes();
 	// XXX processPalette
 	if (_currentCharacter->sceneId == 210) {
@@ -1337,14 +1344,14 @@
 	};
 	
 	if (facing == 0) {
-		if (maxAnimationFrame[36+character] < ch->currentAnimFrame) {
+		if (maxAnimationFrame[36+character] > ch->currentAnimFrame) {
 			ch->currentAnimFrame = maxAnimationFrame[36+character];
 		}
 		if (maxAnimationFrame[30+character] < ch->currentAnimFrame) {
 			ch->currentAnimFrame = maxAnimationFrame[36+character];
 		}
 	} else if (facing == 4) {
-		if (maxAnimationFrame[18+character] < ch->currentAnimFrame) {
+		if (maxAnimationFrame[18+character] > ch->currentAnimFrame) {
 			ch->currentAnimFrame = maxAnimationFrame[18+character];
 		}
 		if (maxAnimationFrame[12+character] < ch->currentAnimFrame) {
@@ -1371,6 +1378,7 @@
 }
 
 int KyraEngine::getOppositeFacingDirection(int dir) {
+	debug(9, "getOppositeFacingDirection(%d)", dir);
 	switch (dir) {
 		case 0:
 			return 2;
@@ -1413,10 +1421,11 @@
 	char fileNameBuffer[32];
 	strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
 	strcat(fileNameBuffer, ".MSC");
+	_screen->fillRect(0, 0, 319, 199, 0, 5);
 	loadBitmap(fileNameBuffer, 3, 5, 0);
 }
 
-// maybe move this two functions to Screen
+// maybe move these two functions to Screen
 void KyraEngine::blockInRegion(int x, int y, int width, int height) {
 	debug(9, "blockInRegion(%d, %d, %d, %d)", x, y, width, height);
 	assert(_screen->_shapePages[0]);
@@ -1452,13 +1461,13 @@
 	strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
 	strcat(fileNameBuffer, ".CPS");
 	loadBitmap(fileNameBuffer, 3, 3, 0);
-
 	_sprites->loadSceneShapes();
+	_exitListPtr = 0;
 
-	_screen->fillRect(4, 4, 312, 136, 0, 0);
-	_screen->updateScreen();
+	_screen->fillRect(7, 7, 312, 136, 0, 0);
 	_screen->setScreenPalette(_screen->_currentPalette);
-	_screen->copyRegion(4, 4, 4, 4, 308, 132, 3, 0);
+	_screen->copyRegion(7, 7, 7, 7, 305, 129, 3, 0);
+	_screen->updateScreen();
 
 	_scaleMode = 1;	
 	for (int i = 0; i < 145; ++i) {
@@ -1483,13 +1492,13 @@
 void KyraEngine::initSceneData(int facing, int unk1, int brandonAlive) {
 	debug(9, "initSceneData(%d, %d, %d)", facing, unk1, brandonAlive);
 	
-	int xpos2 = 0;
+	int16 xpos2 = 0;
 	int setFacing = 1;
 	
-	int xpos = 0, ypos = 0;
+	int16 xpos = 0, ypos = 0;
 	
 	if (_brandonPosX == -1 && _brandonPosY == -1) {
-		switch (facing) {
+		switch (facing+1) {
 			case 0:
 				xpos = ypos = -1;
 			break;
@@ -1518,13 +1527,13 @@
 			break;
 		}
 		
-		if ((_northExitHeight & 0xFF) >= ypos) {
+		if ((uint8)(_northExitHeight & 0xFF) >= ypos) {
 			ypos = (_northExitHeight & 0xFF);
 		}
 		if (xpos >= 308) {
 			xpos = 304;
 		}
-		if ((_northExitHeight >> 8) - 2 <= ypos) {
+		if ((uint8)(_northExitHeight >> 8) - 2 <= ypos) {
 			ypos = (_northExitHeight >> 8) - 4;
 		}
 		if (xpos <= 12) {
@@ -1539,7 +1548,7 @@
 		ypos = _brandonPosY;
 	}
 	
-	int ypos2 = 0;
+	int16 ypos2 = 0;
 	if (_brandonPosX > -1 && _brandonPosY > -1) {
 		switch (_currentCharacter->sceneId) {
 			case 1:
@@ -1550,6 +1559,8 @@
 				facing = 4;
 				xpos2 = 192;
 				ypos2 = 104;
+				setFacing = 0;
+				unk1 = 1;
 				break;
 				
 			case 3:
@@ -1560,6 +1571,8 @@
 				facing = 2;
 				xpos2 = 204;
 				ypos2 = 94;
+				setFacing = 0;
+				unk1 = 1;
 				break;
 				
 			case 26:
@@ -1570,6 +1583,8 @@
 				facing = 4;
 				xpos2 = 192;
 				ypos2 = 128;
+				setFacing = 0;
+				unk1 = 1;
 				break;
 				
 			case 44:
@@ -1580,6 +1595,8 @@
 				facing = 6;
 				xpos2 = 156;
 				ypos2 = 96;
+				setFacing = 0;
+				unk1 = 1;
 				break;
 				
 			case 37:
@@ -1590,19 +1607,19 @@
 				facing = 2;
 				xpos2 = 148;
 				ypos2 = 114;
+				setFacing = 0;
+				unk1 = 1;
 				break;
 				
 			default:
 				break;
 		}
-		
-		setFacing = 0;
-		unk1 = 1;
 	}
 	
 	_brandonPosX = _brandonPosY = -1;
 	
-	if (unk1 != 0 && setFacing != 0) {
+	if (unk1 && setFacing) {
+		ypos2 = ypos;
 		xpos2 = xpos;
 		switch (facing) {
 			case 0:
@@ -1614,11 +1631,11 @@
 				break;
 				
 			case 4:
-				ypos = (_northExitHeight & 0xFF) - 4;
+				ypos = (uint8)(_northExitHeight & 0xFF) - 4;
 				break;
 				
 			case 6:
-				xpos = 335;
+				xpos = 336;
 				break;
 				
 			default:
@@ -1627,7 +1644,7 @@
 	}
 	
 	xpos2 &= 0xFFFC;
-	ypos2 &= 0xFE;
+	ypos2 &= 0xFFFE;
 	xpos &= 0xFFFC;
 	ypos &= 0xFFFE;
 	_currentCharacter->facing = facing;
@@ -1638,7 +1655,7 @@
 	
 	initSceneObjectList(brandonAlive);
 	
-	if (unk1 != 0 && brandonAlive == 0) {
+	if (unk1 && brandonAlive == 0) {
 		moveCharacterToPos(0, facing, xpos2, ypos2);
 	}
 	
@@ -2781,10 +2798,22 @@
 				int xpos = 0, ypos = 0, width = 0, height = 0;
 				xpos = curObject->x1 - (curObject->width2+1);
 				ypos = curObject->y1 - curObject->height2;				
-				width = curObject->width + curObject->width2*2;
+				width = (curObject->width + curObject->width2*2)<<3;
 				height = curObject->height + curObject->height2*2;
 				
-				_screen->copyRegion(xpos, ypos, xpos, ypos, width<<3, height, 2, 0, Screen::CR_CLIPPED);
+				if (xpos < 8) {
+					xpos = 8;
+				} else if (xpos + width > 312) {
+					width = 312 - xpos;
+				}
+				
+				if (ypos < 8) {
+					ypos = 8;
+				} else if (ypos + height > 134) {
+					height = 134 - ypos;
+				}
+				
+				_screen->copyRegion(xpos, ypos, xpos, ypos, width, height, 2, 0, Screen::CR_CLIPPED);
 				curObject->refreshFlag = 0;
 				changed = true;
 			}
@@ -2820,7 +2849,6 @@
 	animObj->drawY = ch->y1;
 	animObj->sceneAnimPtr = _shapes[4+ch->currentAnimFrame];
 	animObj->animFrameNumber = ch->currentAnimFrame;
-	// XXX
 	if (character == 0) {
 		if (_brandonStatusBit & 10) {
 			animObj->animFrameNumber = 88;
@@ -3157,7 +3185,7 @@
 	}
 	
 	if (xdiff >= ydiff) {
-		int temp = xdiff;
+		int temp = ydiff;
 		ydiff = xdiff;
 		xdiff = temp;
 		
@@ -3219,9 +3247,9 @@
 	
 	int ypos = 8;
 	if (_scaleMode) {
-		int scaling = (_scaleTable[y] >> 5) + 1;
-		if (8 >= scaling)
-			ypos = scaling;
+		ypos = (_scaleTable[y] >> 5) + 1;
+		if (8 < ypos)
+			ypos = 8;
 	}
 	
 	x -= (ypos >> 1);
@@ -3230,7 +3258,7 @@
 	
 	int xpos = x;
 	int xtemp = xpos + ypos - 1;
-	if (xpos < 0)
+	if (x < 0)
 		xpos = 0;
 		
 	if (xtemp > 319)
@@ -3333,7 +3361,7 @@
 
 int KyraEngine::handleSceneChange(int xpos, int ypos, int unk1, int frameReset) {
 	debug(9, "handleSceneChange(%d, %d, %d, %d)", xpos, ypos, unk1, frameReset);
-	if (!queryGameFlag(0xEF)) {
+	if (queryGameFlag(0xEF)) {
 		unk1 = 0;
 	}
 	int sceneId = _currentCharacter->sceneId;
@@ -3352,16 +3380,16 @@
 		}
 	}
 	
-	if (ypos < _northExitHeight+2) {
+	if (ypos <= (_northExitHeight&0xFF)+2) {
 		if (_roomTable[sceneId].northExit != 0xFFFF) {
-			xpos = _northExitHeight;
-			ypos = _sceneExits.northXPos;
+			xpos = _sceneExits.northXPos;
+			ypos = _northExitHeight & 0xFF;
 			_pathfinderFlag = 14;
 		}
 	} else if (ypos >= 136) {
 		if (_roomTable[sceneId].southExit != 0xFFFF) {
-			xpos = 136;
-			ypos = _sceneExits.southXPos;
+			xpos = _sceneExits.southXPos;
+			ypos = 136;
 			_pathfinderFlag = 11;
 		}
 	}
@@ -3421,6 +3449,9 @@
 		}
 		
 		returnValue = (changeScene(_currentCharacter->facing) != 0);
+		if (returnValue) {
+			running = false;
+		}
 		
 		if (unk1) {
 			// XXX
@@ -3461,6 +3492,7 @@
 }
 
 int KyraEngine::changeScene(int facing) {
+	debug(9, "changeScene(%d)", facing);
 	if (queryGameFlag(0xEF)) {
 		if (_currentCharacter->sceneId == 5) {
 			return 0;
@@ -3476,22 +3508,22 @@
 	}
 	
 	if (_exitListPtr) {
-		uint16 *ptr = _exitListPtr;
+		int16 *ptr = _exitListPtr;
 		// this loop should be only entered on time, seems to be some hack in the original
 		while (true) {
-			if (*ptr == 0xFFFF)
+			if (*ptr == -1)
 				break;
 			
-			if (*ptr > _currentCharacter->x1 || _currentCharacter->y1 < *(ptr + 1) || _currentCharacter->x1 > *(ptr + 2) || _currentCharacter->y1 > *(ptr + 3)) {
+			if (*ptr > _currentCharacter->x1 || _currentCharacter->y1 < ptr[1] || _currentCharacter->x1 > ptr[2] || _currentCharacter->y1 > ptr[3]) {
 				ptr += 10;
 				break;
 			}
-			_brandonPosX = *(ptr + 6);
-			_brandonPosY = *(ptr + 7);
-			uint16 sceneId = *(ptr + 5);
-			facing = *(ptr + 4);
-			int unk1 = *(ptr + 8);
-			int unk2 = *(ptr + 9);
+			_brandonPosX = ptr[6];
+			_brandonPosY = ptr[7];
+			uint16 sceneId = ptr[5];
+			facing = ptr[4];
+			int unk1 = ptr[8];
+			int unk2 = ptr[9];
 			if (sceneId == 0xFFFF) {
 				switch (facing) {
 					case 0:
@@ -3537,7 +3569,7 @@
 		returnValue = 1;
 	}
 	
-	if (((_northExitHeight >> 8) & 0xFF) - 2 >= ypos || ((_northExitHeight >> 8) & 0xFF) - 2 < _currentCharacter->y1) {
+	if (((_northExitHeight >> 8) & 0xFF) - 2 < ypos || ((_northExitHeight >> 8) & 0xFF) - 2 < _currentCharacter->y1) {
 		facing = 4;
 		returnValue = 1;
 	}
@@ -3550,7 +3582,7 @@
 	if (!returnValue)
 		return 0;
 	
-	int sceneId = 0xFFFF;
+	uint16 sceneId = 0xFFFF;
 	switch (facing) {
 		case 0:
 			sceneId = _roomTable[_currentCharacter->sceneId].northExit;
@@ -3571,7 +3603,7 @@
 	
 	if (sceneId == 0xFFFF)
 		return 0;
-		
+
 	enterNewScene(sceneId, facing, 1, 1, 0);
 	return returnValue;
 }

Index: kyra.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/kyra.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- kyra.h	11 Nov 2005 22:17:06 -0000	1.35
+++ kyra.h	13 Nov 2005 19:35:01 -0000	1.36
@@ -557,8 +557,8 @@
 	
 	Item _itemTable[145];
 	
-	uint16 *_exitListPtr;
-	uint16 _exitList[11];
+	int16 *_exitListPtr;
+	int16 _exitList[11];
 	SceneExits _sceneExits;
 	uint16 _currentRoom;
 	uint8 *_maskBuffer;

Index: screen.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/screen.cpp,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- screen.cpp	10 Nov 2005 14:08:50 -0000	1.23
+++ screen.cpp	13 Nov 2005 19:35:01 -0000	1.24
@@ -1116,7 +1116,7 @@
 				while (len--) {
 					*dst++ = *dstOffs++;
 				}
-			}				
+			}
 		} else if (code != 0x80) {
 			int len = MIN(count, code & 0x3F);
 			while (len--) {

Index: script.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/script.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- script.cpp	29 Oct 2005 18:37:40 -0000	1.19
+++ script.cpp	13 Nov 2005 19:35:01 -0000	1.20
@@ -207,7 +207,7 @@
 		opcode = 0;
 		_parameter = code & 0x7FFF;
 	} else if (code & 0x4000) {
-		_parameter = code & 0xFF;
+		_parameter = (int8)(code);
 	} else if (code & 0x2000) {
 		_parameter = READ_BE_UINT16(_curScript->ip); _curScript->ip += 2;
 	} else {

Index: script.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/script.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- script.h	29 Oct 2005 18:37:40 -0000	1.12
+++ script.h	13 Nov 2005 19:35:01 -0000	1.13
@@ -70,7 +70,7 @@
 	
 	KyraEngine *_vm;
 	ScriptState *_curScript;
-	uint32 _parameter;
+	int16 _parameter;
 	bool _continue;
 
 	typedef void (ScriptHelper::*CommandProc)();

Index: script_v1.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/script_v1.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- script_v1.cpp	11 Nov 2005 22:17:06 -0000	1.22
+++ script_v1.cpp	13 Nov 2005 19:35:01 -0000	1.23
@@ -115,10 +115,10 @@
 }
 
 void ScriptHelper::c1_execOpcode() {
-	assert((int)_parameter < _curScript->dataPtr->opcodeSize);
-	if (_curScript->dataPtr->opcodes[_parameter] == &KyraEngine::cmd_dummy)
-		debug("calling unimplemented opcode(0x%.02X)", _parameter);
-	_curScript->retValue = (_vm->*_curScript->dataPtr->opcodes[_parameter])(_curScript);
+	assert((uint8)_parameter < _curScript->dataPtr->opcodeSize);
+	if (_curScript->dataPtr->opcodes[(uint8)_parameter] == &KyraEngine::cmd_dummy)
+		debug("calling unimplemented opcode(0x%.02X)", (uint8)_parameter);
+	_curScript->retValue = (_vm->*_curScript->dataPtr->opcodes[(uint8)_parameter])(_curScript);
 }
 
 void ScriptHelper::c1_ifNotJmp() {
@@ -296,7 +296,7 @@
 #pragma mark -
 
 #define stackPos(x) script->stack[script->sp+x]
-#define stackPosString(x) (char *)&script->dataPtr->text[READ_BE_UINT16( &((uint16 *)script->dataPtr->text)[stackPos(x)])]
+#define stackPosString(x) (char*)&script->dataPtr->text[READ_BE_UINT16(&((uint16 *)script->dataPtr->text)[stackPos(x)])]
 
 int KyraEngine::cmd_magicInMouseItem(ScriptState *script) {
 	warning("STUB: cmd_magicInMouseItem");

Index: sprites.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/sprites.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- sprites.cpp	11 Nov 2005 22:17:06 -0000	1.9
+++ sprites.cpp	13 Nov 2005 19:35:01 -0000	1.10
@@ -400,7 +400,7 @@
 
 	assert(fileSize > 0x6D);
 
-	_engine->_northExitHeight = READ_BE_UINT16(_dat + 0x15);
+	_engine->_northExitHeight = READ_LE_UINT16(_dat + 0x15);
 	if (_engine->_northExitHeight & 1)
 		_engine->_northExitHeight += 1;
 	// XXX	

Index: staticres.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/staticres.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- staticres.cpp	11 Nov 2005 22:17:06 -0000	1.16
+++ staticres.cpp	13 Nov 2005 19:35:01 -0000	1.17
@@ -312,10 +312,10 @@
 	
 	for (uint32 i = 0; i < count; ++i) {
 		(*loadTo)[i].nameIndex = *src++;
-		(*loadTo)[i].northExit = READ_LE_UINT16(src); src += 2;
-		(*loadTo)[i].eastExit = READ_LE_UINT16(src); src += 2;
-		(*loadTo)[i].southExit = READ_LE_UINT16(src); src += 2;
-		(*loadTo)[i].westExit = READ_LE_UINT16(src); src += 2;
+		(*loadTo)[i].northExit = READ_BE_UINT16(src); src += 2;
+		(*loadTo)[i].eastExit = READ_BE_UINT16(src); src += 2;
+		(*loadTo)[i].southExit = READ_BE_UINT16(src); src += 2;
+		(*loadTo)[i].westExit = READ_BE_UINT16(src); src += 2;
 		memset(&(*loadTo)[i].itemsTable[0], 0xFF, sizeof(byte)*6);
 		memset(&(*loadTo)[i].itemsTable[6], 0, sizeof(byte)*6);
 		memset((*loadTo)[i].itemsXPos, 0, sizeof(uint16)*12);





More information about the Scummvm-git-logs mailing list