[Scummvm-cvs-logs] CVS: scummvm/queen cutaway.cpp,1.130,1.131 cutaway.h,1.36,1.37 queen.cpp,1.89,1.90 resource.cpp,1.49,1.50 sound.cpp,1.43,1.44 talk.cpp,1.103,1.104 talk.h,1.33,1.34

Gregory Montoir cyx at users.sourceforge.net
Tue Aug 24 09:33:00 CEST 2004


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

Modified Files:
	cutaway.cpp cutaway.h queen.cpp resource.cpp sound.cpp 
	talk.cpp talk.h 
Log Message:
Rewrote the way strings are extracting from the datafiles, now it should be 'alignment safe'. Maybe it will fix bugs #923570 and #1013886, too.

Index: cutaway.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/cutaway.cpp,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -d -r1.130 -r1.131
--- cutaway.cpp	14 Aug 2004 22:32:59 -0000	1.130
+++ cutaway.cpp	24 Aug 2004 16:31:45 -0000	1.131
@@ -106,19 +106,18 @@
 		 Pointers to other places in the cutaway data
 	 */
 
-	_gameStatePtr       = _fileData + READ_BE_UINT16(ptr);
+	_gameStatePtr = _fileData + READ_BE_UINT16(ptr);
 	ptr += 2;
 
-	_nextSentence       = _fileData + READ_BE_UINT16(ptr);
+	_nextSentenceOff = READ_BE_UINT16(ptr);
 	ptr += 2;
 
-	byte *bankNamesPtr  = _fileData + READ_BE_UINT16(ptr);
+	uint16 bankNamesOff = READ_BE_UINT16(ptr);
 	ptr += 2;
-	debug(6, "Bank name file offset = %08x", 20 + bankNamesPtr - _fileData);
 
 	_objectData = ptr;
 
-	loadStrings(bankNamesPtr);
+	loadStrings(bankNamesOff);
 
 	if (_bankNames[0][0]) {
 		debug(6, "Loading bank '%s'", _bankNames[0]);
@@ -126,7 +125,7 @@
 	}
 
 	char entryString[MAX_STRING_SIZE];
-	_nextSentence = Talk::getString(_nextSentence, entryString, MAX_STRING_LENGTH);
+	Talk::getString(_fileData, _nextSentenceOff, entryString, MAX_STRING_LENGTH);
 	debug(6, "Entry string = '%s'", entryString);
 
 	_vm->logic()->joeCutFacing(_vm->logic()->joeFacing());
@@ -153,11 +152,11 @@
 
 }
 
-void Cutaway::loadStrings(byte *ptr) {
+void Cutaway::loadStrings(uint16 offset) {
 	int i,j;
 
-	int bankNameCount = READ_BE_UINT16(ptr);
-	ptr += 2;
+	int bankNameCount = READ_BE_UINT16(_fileData + offset);
+	offset += 2;
 
 	debug(6, "Bank name count = %i", bankNameCount);
 
@@ -167,8 +166,7 @@
 	 */
 
 	for (i = 0, j = 0; i < bankNameCount; i++) {
-		ptr = Talk::getString(ptr, _bankNames[j], MAX_FILENAME_LENGTH);
-
+		Talk::getString(_fileData, offset, _bankNames[j], MAX_FILENAME_LENGTH);
 		if (_bankNames[j][0]) {
 			debug(6, "Bank name %i = '%s'", j, _bankNames[j]);
 			j++;
@@ -176,17 +174,16 @@
 	}
 
 	debug(6, "Getting talk file");
-	ptr = Talk::getString(ptr, _talkFile, MAX_FILENAME_LENGTH);
+	Talk::getString(_fileData, offset, _talkFile, MAX_FILENAME_LENGTH);
 	debug(6, "Talk file = '%s'", _talkFile);
 
-	_talkTo = (int16)READ_BE_INT16(ptr);
-	ptr += 2;
+	_talkTo = (int16)READ_BE_INT16(_fileData + offset);
 	debug(6, "_talkTo = %i", _talkTo);
 }
 
-byte *Cutaway::getCutawayObject(byte *ptr, CutawayObject &object)
+const byte *Cutaway::getCutawayObject(const byte *ptr, CutawayObject &object)
 {
-	byte *oldPtr = ptr;
+	const byte *oldPtr = ptr;
 
 	object.objectNumber = (int16)READ_BE_INT16(ptr); ptr += 2;
 	object.moveToX      = (int16)READ_BE_INT16(ptr); ptr += 2;
@@ -261,7 +258,7 @@
 }
 
 
-byte *Cutaway::turnOnPeople(byte *ptr, CutawayObject &object) {
+const byte *Cutaway::turnOnPeople(const byte *ptr, CutawayObject &object) {
 	// Lines 1248-1259 in cutaway.c
 	object.personCount = (int16)READ_BE_INT16(ptr);
 	ptr += 2;
@@ -471,7 +468,7 @@
 	return objectType;
 }
 
-byte *Cutaway::getCutawayAnim(byte *ptr, int header, CutawayAnim &anim) {
+const byte *Cutaway::getCutawayAnim(const byte *ptr, int header, CutawayAnim &anim) {
 	// lines 1531-1607 in cutaway.c
 
 	//debug(6, "[Cutaway::getCutawayAnim] header=%i", header);
@@ -564,7 +561,7 @@
 	if (anim.song) debug(6, "song = %i", anim.song);
 }
 
-byte *Cutaway::handleAnimation(byte *ptr, CutawayObject &object) {
+const byte *Cutaway::handleAnimation(const byte *ptr, CutawayObject &object) {
 	// lines 1517-1770 in cutaway.c
 	int frameCount = 0;
 	int header = 0;
@@ -828,7 +825,7 @@
 	memset(_personFace, 0, sizeof(_personFace));
 	_personFaceCount = 0;
 
-	byte *ptr = _objectData;
+	const byte *ptr = _objectData;
 
 	for (i = 0; i < _cutawayObjectCount; i++) {
 		CutawayObject object;
@@ -857,7 +854,7 @@
 		limitBob(object);
 
 		char sentence[MAX_STRING_SIZE];
-		_nextSentence = Talk::getString(_nextSentence, sentence, MAX_STRING_LENGTH);
+		Talk::getString(_fileData, _nextSentenceOff, sentence, MAX_STRING_LENGTH);
 
 		if (OBJECT_ROOMFADE == object.objectNumber) {
 			_roomFade = true;
@@ -1268,8 +1265,6 @@
 		const char *sentence) {
 	// lines 1776-1863 in cutaway.c
 
-	//debug(6, "----- Write '%s' ----", sentence);
-
 	int spaces = countSpaces(type, sentence);
 
 	int x;

Index: cutaway.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/cutaway.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- cutaway.h	6 Apr 2004 20:15:19 -0000	1.36
+++ cutaway.h	24 Aug 2004 16:31:45 -0000	1.37
@@ -142,7 +142,7 @@
 		byte *_objectData;
 
 		//! Pointer to next sentence string in _fileData
-		byte *_nextSentence;
+		uint16 _nextSentenceOff;
 
 		//! ???
 		bool _roomFade;
@@ -205,10 +205,10 @@
 		void load(const char *filename);
 
 		//! Used by load to read string data
-		void loadStrings(byte *ptr);
+		void loadStrings(uint16 offset);
 
 		//! Get persons
-		byte *turnOnPeople(byte *ptr, CutawayObject &object);
+		const byte *turnOnPeople(const byte *ptr, CutawayObject &object);
 
 		//! Limit the BOB
 		void limitBob(CutawayObject &object);
@@ -220,7 +220,7 @@
 		ObjectType getObjectType(CutawayObject &object);
 
 		//! Perform actions for an animation
-		byte *handleAnimation(byte *ptr, CutawayObject &object);
+		const byte *handleAnimation(const byte *ptr, CutawayObject &object);
 
 		//! Perform actions for a person record
 		void handlePersonRecord(
@@ -248,13 +248,13 @@
 		void talk(char *nextFilename);
 
 		//! Get CutawayAnim data from ptr and return new ptr
-		byte *getCutawayAnim(byte *ptr, int header, CutawayAnim &anim);
+		const byte *getCutawayAnim(const byte *ptr, int header, CutawayAnim &anim);
 
 		//! Special animation
 		int makeComplexAnimation(int16 currentImage, CutawayAnim *objAnim, int frameCount);
 
 		//! Read a CutawayObject from ptr and return new ptr
-		static byte *getCutawayObject(byte *ptr, CutawayObject &object);
+		static const byte *getCutawayObject(const byte *ptr, CutawayObject &object);
 
 		//! Dump a CutawayObject with debug()
 		void dumpCutawayObject(int index, CutawayObject &object);

Index: queen.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/queen.cpp,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -d -r1.89 -r1.90
--- queen.cpp	6 Aug 2004 17:01:58 -0000	1.89
+++ queen.cpp	24 Aug 2004 16:31:45 -0000	1.90
@@ -216,7 +216,7 @@
 		// write header
 		GameStateHeader header;
 		memset(&header, 0, sizeof(header));
-		file->writeUint32BE(MKID_BE('SCVM'));
+		file->writeUint32BE('SCVM');
 		header.version = TO_BE_32(SAVESTATE_CUR_VER);
 		header.flags = TO_BE_32(0);
 		header.dataSize = TO_BE_32(dataSize);
@@ -260,7 +260,7 @@
 	char name[20];
 	makeGameStateName(slot, name);
 	SaveFile *file = _saveFileMan->open_savefile(name, getSavePath(), false);
-	if (file && file->readUint32BE() == MKID_BE('SCVM')) {
+	if (file && file->readUint32BE() == 'SCVM') {
 		gsh->version = file->readUint32BE();
 		gsh->flags = file->readUint32BE();
 		gsh->dataSize = file->readUint32BE();

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- resource.cpp	6 Aug 2004 17:01:58 -0000	1.49
+++ resource.cpp	24 Aug 2004 16:31:45 -0000	1.50
@@ -196,7 +196,7 @@
 bool Resource::readTableFile(const GameVersion *gameVersion) {
 	File tableFile;
 	tableFile.open(_tableFilename);
-	if (tableFile.isOpen() && tableFile.readUint32BE() == MKID_BE('QTBL')) {
+	if (tableFile.isOpen() && tableFile.readUint32BE() == 'QTBL') {
 		if (tableFile.readUint32BE() != CURRENT_TBL_VERSION)
 			warning("Incorrect version of queen.tbl, please update it");
 		tableFile.seek(gameVersion->tableOffset);
@@ -207,7 +207,7 @@
 }
 
 void Resource::readTableCompResource() {
-	if (_resourceFile->readUint32BE() != MKID_BE('QTBL'))
+	if (_resourceFile->readUint32BE() != 'QTBL')
 		error("Invalid table header");
 
 	_resourceFile->read(_versionString, 6);

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/sound.cpp,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- sound.cpp	6 Aug 2004 17:01:58 -0000	1.43
+++ sound.cpp	24 Aug 2004 16:31:45 -0000	1.44
@@ -50,7 +50,6 @@
 					return new SilentSound(mixer, vm);
 				#else
 					return new MP3Sound(mixer, vm);
-
 				#endif
 				break;
 		case COMPRESSION_OGG:

Index: talk.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.cpp,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -d -r1.103 -r1.104
--- talk.cpp	17 Aug 2004 19:22:30 -0000	1.103
+++ talk.cpp	24 Aug 2004 16:31:45 -0000	1.104
@@ -146,7 +146,7 @@
 		if (hasTalkedTo() && head == 1)
 			strcpy(_talkString[0], _person2String);
 		else
-			findDialogueString(_person1Ptr, head, _pMax, _talkString[0]);
+			findDialogueString(_person1PtrOff, head, _pMax, _talkString[0]);
 
 		if (hasTalkedTo() && head == 1)
 			sprintf(otherVoiceFilePrefix, "%2dXXXXP", _talkKey);
@@ -154,14 +154,14 @@
 			sprintf(otherVoiceFilePrefix, "%2d%4xP", _talkKey, head);
 
 		if (_talkString[0][0] == '\0' && retval > 1) {
-			findDialogueString(_person1Ptr, retval, _pMax, _talkString[0]);
+			findDialogueString(_person1PtrOff, retval, _pMax, _talkString[0]);
 			sprintf(otherVoiceFilePrefix,"%2d%4xP", _talkKey, retval);
 		}
 
 		// Joe dialogue
 
 		for (i = 1; i <= 4; i++) {
-			findDialogueString(_joePtr, _dialogueTree[level][i].head, _jMax, _talkString[i]);
+			findDialogueString(_joePtrOff, _dialogueTree[level][i].head, _jMax, _talkString[i]);
 
 			int16 index = _dialogueTree[level][i].gameStateIndex;
 
@@ -267,7 +267,7 @@
 
 		// check to see if person has something final to say
 		if (-1 == retval) {
-			findDialogueString(_person1Ptr, head, _pMax, _talkString[0]);
+			findDialogueString(_person1PtrOff, head, _pMax, _talkString[0]);
 			if (_talkString[0][0] != '\0') {
 				sprintf(otherVoiceFilePrefix, "%2d%4xP", _talkKey, head);
 				if (speak(_talkString[0], &person, otherVoiceFilePrefix))
@@ -291,13 +291,13 @@
 	
 	_vm->grid()->setupPanel();
 
-	uint8 *ptr = _cutawayPtr;
+	uint16 offset = _cutawayPtrOff;
 
-	int16 cutawayGameState = (int16)READ_BE_INT16(ptr); ptr += 2;
-	int16 cutawayTestValue = (int16)READ_BE_INT16(ptr); ptr += 2;
+	int16 cutawayGameState = (int16)READ_BE_INT16(_fileData + offset); offset += 2;
+	int16 cutawayTestValue = (int16)READ_BE_INT16(_fileData + offset); offset += 2;
 
 	if (_vm->logic()->gameState(cutawayGameState) == cutawayTestValue) {
-		getString(ptr, cutawayFilename, 20);
+		getString(_fileData, offset, cutawayFilename, 20);
 		if (cutawayFilename[0]) {
 			//CR 2 - 7/3/95, If we're executing a cutaway scene, then make sure
 			// Joe can talk, so set TALKQUIT to 0 just in case we exit on the
@@ -348,19 +348,18 @@
 	_dialogueTree[oldLevel][selectedSentence].dialogueNodeValue1 = -1;
 }
 
-void Talk::findDialogueString(byte *ptr, int16 id, int16 max, char *str) {
+void Talk::findDialogueString(uint16 offset, int16 id, int16 max, char *str) {
 	str[0] = '\0';
-
 	for (int i = 1; i <= max; i++) {
-		ptr += 2;
-		int16 currentId = (int16)READ_BE_INT16(ptr); ptr += 2;
+		offset += 2;
+		int16 currentId = (int16)READ_BE_INT16(_fileData + offset);
+		offset += 2;
 		if (id == currentId) {
-			ptr = getString(ptr, str, MAX_STRING_LENGTH, 4);
-			//debug(6, "Found string with ID %i: '%s'", id, str);
+			getString(_fileData, offset, str, MAX_STRING_LENGTH, 4);
 			break;
+		} else {
+			getString(_fileData, offset, NULL, MAX_STRING_LENGTH, 4);
 		}
-		else
-			ptr = getString(ptr, NULL, MAX_STRING_LENGTH, 4);
 	}
 }
 
@@ -403,9 +402,9 @@
 	if (_levelMax < 0) {
 		_levelMax = -_levelMax;
 		canQuit = false;
-	}
-	else
+	} else {
 		canQuit = true;
+	}
 
 	_uniqueKey      = (int16)READ_BE_INT16(ptr); ptr += 2;
 	_talkKey        = (int16)READ_BE_INT16(ptr); ptr += 2;
@@ -418,19 +417,13 @@
 		_itemNumber[i] = (int16)READ_BE_INT16(ptr); ptr += 2;
 	}
 
-	_person1Ptr = _fileData + READ_BE_UINT16(ptr); ptr += 2;
-	_cutawayPtr = _fileData + READ_BE_UINT16(ptr); ptr += 2;
-	_person2Ptr = _fileData + READ_BE_UINT16(ptr); ptr += 2;
-
-	if (ptr != (_fileData + 28))
-		error("ptr != (_fileData + 28))");
-	
-	byte *dataPtr    = _fileData + 32;
-	_joePtr          = dataPtr + _levelMax * 96;
+	_person1PtrOff = READ_BE_UINT16(ptr); ptr += 2;
+	_cutawayPtrOff = READ_BE_UINT16(ptr); ptr += 2;
+	_person2PtrOff = READ_BE_UINT16(ptr); ptr += 2;	
+	_joePtrOff     = 32 + _levelMax * 96;
 	
 	// Load dialogue tree
-	ptr = dataPtr;
-
+	ptr = _fileData + 32;
 	memset(&_dialogueTree[0], 0, sizeof(_dialogueTree[0]));
 	for (i = 1; i <= _levelMax; i++)
 		for (int j = 0; j <= 5; j++) {
@@ -448,22 +441,20 @@
 void Talk::initialTalk() {
 	// Lines 848-903 in talk.c 
 
-	byte *ptr = _joePtr + 2;
-	
-	uint16 hasNotString = READ_BE_UINT16(ptr); ptr += 2;
+	uint16 offset = _joePtrOff + 2;
+	uint16 hasNotString = READ_BE_UINT16(_fileData + offset); offset += 2;
 
 	char joeString[MAX_STRING_SIZE];
 	if (!hasNotString) {
-		ptr = getString(ptr, joeString, MAX_STRING_LENGTH);
+		getString(_fileData, offset, joeString, MAX_STRING_LENGTH);
 	} else {
 		joeString[0] = '\0';
 	}
 
-	ptr = _person2Ptr;
-	ptr = getString(ptr, _person2String, MAX_STRING_LENGTH);
-
+	offset = _person2PtrOff;
 	char joe2String[MAX_STRING_SIZE];
-	ptr = getString(ptr, joe2String, MAX_STRING_LENGTH);
+	getString(_fileData, offset, _person2String, MAX_STRING_LENGTH);
+	getString(_fileData, offset, joe2String, MAX_STRING_LENGTH);
 
 	if (!hasTalkedTo()) {		
 		// Not yet talked to this person		
@@ -487,33 +478,33 @@
 	int commandCode = SPEAK_DEFAULT;
 	uint16 id = (sentence[index] << 8) | sentence[index + 1];
 	switch (id) {
-	case MKID_BE('AO'):
+	case 'AO':
 		commandCode = SPEAK_AMAL_ON;
 		break;			
-	case MKID_BE('FL'):
+	case 'FL':
 		commandCode = SPEAK_FACE_LEFT;
 		break;
-	case MKID_BE('FF'):
+	case 'FF':
 		commandCode = SPEAK_FACE_FRONT;
 		break;
-	case MKID_BE('FB'):
+	case 'FB':
 		commandCode = SPEAK_FACE_BACK;
 		break;
-	case MKID_BE('FR'):
+	case 'FR':
 		commandCode = SPEAK_FACE_RIGHT;
 		break;
-	case MKID_BE('GD'):
+	case 'GD':
 		_vm->logic()->joeGrab(STATE_GRAB_DOWN);
 		commandCode = SPEAK_NONE;
 		break;
-	case MKID_BE('GM'):
+	case 'GM':
 		_vm->logic()->joeGrab(STATE_GRAB_MID);
 		commandCode = SPEAK_NONE;
 		break; 
-	case MKID_BE('WT'):
+	case 'WT':
 		commandCode = SPEAK_PAUSE;
 		break;			
-	case MKID_BE('XY'):
+	case 'XY':
 		// For example *XY00(237,112)
 		{
 			commandCode = atoi(sentence + index + 2);
@@ -1081,27 +1072,20 @@
 	return iterator;
 }
 
-byte *Talk::getString(byte *ptr, char *str, int maxLength, int align) {
-	int length = *ptr;
-	ptr++;
+void Talk::getString(const byte *ptr, uint16 &offset, char *str, int maxLength, int align) {
+	assert((align & 1) == 0);
+	int length = *(ptr + offset);
+	++offset;
 
 	if (length > maxLength) {
-		error("String too long. Length = %i, maxLength = %i, str = '%*s'",
-				length, maxLength, length, (const char*)ptr);
-	}
-	else if (length) {
-		if (str)
-			memcpy(str, (const char*)ptr, length);
-		ptr += length;
-
-		while ((int)ptr % align)
-			ptr++;
+		error("String too long. Length = %i, maxLength = %i", length, maxLength, length);
+	} else if (length) {
+		if (str) {
+			memcpy(str, ptr + offset, length);
+			str[length] = '\0';
+		}
+		offset = (offset + length + (align - 1)) & ~(align - 1);
 	}
-
-	if (str)
-		str[length] = '\0';
-
-	return ptr;
 }
 
 TalkSelected *Talk::talkSelected() {

Index: talk.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/talk.h,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- talk.h	3 Apr 2004 17:58:58 -0000	1.33
+++ talk.h	24 Aug 2004 16:31:46 -0000	1.34
@@ -46,8 +46,8 @@
 		const char *voiceFilePrefix,
 		QueenEngine *vm);
 
-	//! Read a string from ptr and return new ptr
-	static byte *getString(byte *ptr, char *str, int maxLength, int align = 2);
+	//! Read a string from ptr and update offset
+	static void getString(const byte *ptr, uint16 &offset, char *str, int maxLength, int align = 2);
 
 private:
 	//!  Collection of constants used by Talk
@@ -131,16 +131,16 @@
 	int16 _itemNumber[2];
 
 	//! String data
-	byte *_person1Ptr;
+	uint16 _person1PtrOff;
 
 	//! Cutaway data
-	byte *_cutawayPtr;
+	uint16 _cutawayPtrOff;
 
 	//! Data used if we have talked to the person before
-	byte *_person2Ptr;
+	uint16 _person2PtrOff;
 
 	//! Data used if we haven't talked to the person before
-	byte *_joePtr;
+	uint16 _joePtrOff;
 
 	//! Is a talking head
 	bool _talkHead;
@@ -176,7 +176,7 @@
 	void initialTalk();
 
 	//! Find a string in the dialogue tree
-	void findDialogueString(byte *ptr, int16 id, int16 max, char *str);
+	void findDialogueString(uint16 offset, int16 id, int16 max, char *str);
 
 	//! Get TalkSelected struct for this talk
 	TalkSelected *talkSelected();





More information about the Scummvm-git-logs mailing list