[Scummvm-cvs-logs] CVS: scummvm/queen journal.cpp,1.10,1.11 logic.cpp,1.141,1.142 resource.cpp,1.33,1.34 resource.h,1.23,1.24

Gregory Montoir cyx at users.sourceforge.net
Sun Dec 28 07:30:01 CET 2003


Update of /cvsroot/scummvm/scummvm/queen
In directory sc8-pr-cvs1:/tmp/cvs-serv9210/queen

Modified Files:
	journal.cpp logic.cpp resource.cpp resource.h 
Log Message:

cleanup Resource class a bit :
- re-use some methods to read the resource table (normal / compressed)
- removed _gameVersion member as we can do without it (and is mostly 
  useless in case of a compressed data file) ; now, we use the 
  'JAS version string' as it is sufficient to detect if the game is 
  a floppy version / demo etc.
- const'ness
- tweaked checkJASVersion() for interview mini game

removed (useless) dirty hack in Logic::changeRoom() to setup initial
scene in demos (pclogo.cut doesn't exist at all !)


Index: journal.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/journal.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- journal.cpp	19 Dec 2003 09:21:02 -0000	1.10
+++ journal.cpp	28 Dec 2003 15:29:04 -0000	1.11
@@ -543,7 +543,7 @@
 		_vm->graphics()->textSetCentered(144, "Fran\x87""ais", false);
 		break;
 	}
-	char versionId[12];
+	char versionId[13];
 	sprintf(versionId, "Version %c.%c%c", ver[2], ver[3], ver[4]);
 	_vm->graphics()->textSetCentered(156, versionId, false);
 }

Index: logic.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/logic.cpp,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- logic.cpp	28 Dec 2003 01:17:29 -0000	1.141
+++ logic.cpp	28 Dec 2003 15:29:04 -0000	1.142
@@ -2458,25 +2458,15 @@
 
 	if (currentRoom() == ROOM_JUNGLE_PINNACLE) {
 		handlePinnacleRoom();
-	}
-	else if (currentRoom() == FOTAQ_LOGO && gameState(VAR_INTRO_PLAYED) == 0) {
-		// FIXME: this should be rewritten in a more elegant way
-		bool pcGamesDemo = _vm->resource()->isDemo() && !_vm->resource()->exists("pclogo.cut");
+	} else if (currentRoom() == FOTAQ_LOGO && gameState(VAR_INTRO_PLAYED) == 0) {
 
-		if (pcGamesDemo) {
+		if (_vm->resource()->isDemo())
 			currentRoom(79);
-		}
 		roomDisplay(currentRoom(), RDM_FADE_NOJOE, 100, 2, true);
 
 		if (_vm->resource()->isDemo()) {
-			if (pcGamesDemo) {
-				playCutaway("clogo.cut");
-			}
-			else {
-				playCutaway("pclogo.cut");
-			}
-		}
-		else {
+			playCutaway("clogo.cut");
+		} else {
 			playCutaway("copy.cut");
 			playCutaway("clogo.cut");
 
@@ -2485,8 +2475,7 @@
 			if (ConfMan.getBool("alt_intro")) {
 				_vm->graphics()->loadPanel();
 				playCutaway("cintr.cut");
-			}
-			else {
+			} else {
 				playCutaway("cdint.cut");
 				_vm->graphics()->loadPanel();
 			}
@@ -2507,8 +2496,7 @@
 
 		inventorySetup();
 		inventoryRefresh();
-	}
-	else {
+	} else {
 		roomDisplay(currentRoom(), RDM_FADE_JOE, 100, 1, false);
 	}
 	_vm->display()->showMouseCursor(true); // _drawMouseFlag = 1;
@@ -2569,7 +2557,7 @@
 	// XXX check master_volume value
 
 	// only CD-ROM version has speech
-	if (_vm->resource()->JASVersion()[0] != 'C' && _vm->sound()->speechOn()) {
+	if (_vm->resource()->isFloppy() && _vm->sound()->speechOn()) {
 		_vm->sound()->speechToggle(false);
 	}
 

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -d -r1.33 -r1.34
--- resource.cpp	26 Dec 2003 15:36:28 -0000	1.33
+++ resource.cpp	28 Dec 2003 15:29:05 -0000	1.34
@@ -28,17 +28,17 @@
 const char *Resource::_tableFilename = "queen.tbl";
 
 const GameVersion Resource::_gameVersions[] = {
-	{ "PEM10", false, 0x00000008,  22677657 },
-	{ "CEM10", false, 0x0000584E, 190787021 },
-	{ "PFM10", false, 0x0002CD93,  22157304 },
-	{ "CFM10", false, 0x00032585, 186689095 },
-	{ "PGM10", false, 0x00059ACA,  22240013 },
-	{ "CGM10", false, 0x0005F2A7, 217648975 },
-	{ "PIM10", false, 0x000866B1,  22461366 },
-	{ "CIM10", false, 0x0008BEE2, 190795582 },
-	{ "CSM10", false, 0x000B343C, 190730602 },
-	{ "PE100", true,  0x000DA981,   3724538 },
-	{ "PE100", true,  0x000DB63A,   3732177 }
+	{ "PEM10", 0x00000008,  22677657 },
+	{ "CEM10", 0x0000584E, 190787021 },
+	{ "PFM10", 0x0002CD93,  22157304 },
+	{ "CFM10", 0x00032585, 186689095 },
+	{ "PGM10", 0x00059ACA,  22240013 },
+	{ "CGM10", 0x0005F2A7, 217648975 },
+	{ "PIM10", 0x000866B1,  22461366 },
+	{ "CIM10", 0x0008BEE2, 190795582 },
+	{ "CSM10", 0x000B343C, 190730602 },
+	{ "PE100", 0x000DA981,   3724538 },
+	{ "PE100", 0x000DB63A,   3732177 }
 };
 
 
@@ -46,46 +46,23 @@
 	: _JAS2Pos(0), _datafilePath(datafilePath), _savePath(savePath), _resourceEntries(0), _resourceTable(NULL), _saveFileManager(mgr) {
 
 	_resourceFile = new File();
-	_resourceFile->open("queen.1", _datafilePath);
-	if (_resourceFile->isOpen() == false)
-		_resourceFile->open("queen.1c", _datafilePath);
-	if (_resourceFile->isOpen() == false)
+	if (!findNormalVersion() && !findCompressedVersion())
 		error("Could not open resource file '%s%s'", _datafilePath.c_str(), "queen.1");
-
-	if (_resourceFile->readUint32BE() == 'QTBL') {
-		readTableCompResource();
-	} else {
-		_compression = COMPRESSION_NONE;
-		_gameVersion = detectGameVersion(_resourceFile->size());
-
-		if (!readTableFile()) {
-			//check if it is the english floppy version, for which we have a hardcoded version of the tables
-			if (!strcmp(_gameVersion->versionString, _gameVersions[VER_ENG_FLOPPY].versionString)) {
-				_gameVersion = &_gameVersions[VER_ENG_FLOPPY];
-				_resourceEntries = 1076;
-				_resourceTable = _resourceTablePEM10;
-			} else {
-				error("Couldn't find tablefile '%s%s'",  _datafilePath.c_str(), _tableFilename);
-			}
-		}
-	}
-	if (strcmp(_gameVersion->versionString, JASVersion()))
-		error("Verifying game version failed! (expected: '%s', found: '%s')", _gameVersion->versionString, JASVersion());
-
-	debug(5, "Detected game version: %s, which has %d resource entries", _gameVersion->versionString, _resourceEntries);
-
+	checkJASVersion();
+	debug(5, "Detected game version: %s, which has %d resource entries", _versionString, _resourceEntries);
 	_JAS2Ptr = (char *)loadFile("QUEEN2.JAS", 0);
 }
 
 Resource::~Resource() {
 	_resourceFile->close();
+	delete _resourceFile;
 	if(_resourceTable != _resourceTablePEM10) 
 		delete[] _resourceTable;
 	delete[] _JAS2Ptr;
 	delete _saveFileManager;
 }
 
-int32 Resource::resourceIndex(const char *filename) {
+int32 Resource::resourceIndex(const char *filename) const {
 
 	char entryName[14];
 	char *ptr = entryName;
@@ -136,14 +113,6 @@
 	return startOfLine;
 }
 
-uint32 Resource::fileSize(const char *filename) {
-	return _resourceTable[resourceIndex(filename)].size;
-}
-
-uint32 Resource::fileOffset(const char *filename) {
-	return _resourceTable[resourceIndex(filename)].offset;
-}
-
 uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) {
 	uint32 size = fileSize(filename) - skipBytes;
 	if (dstBuf == NULL) 
@@ -158,30 +127,60 @@
 	return loadFile(filename, skipBytes, (byte *)malloc(fileSize(filename) - skipBytes));
 }
 
-bool Resource::exists(const char *filename) {
-	return resourceIndex(filename) >= 0;
-}
+bool Resource::findNormalVersion() {
+	_resourceFile->open("queen.1", _datafilePath);
+	if (!_resourceFile->isOpen()) {
+		return false;
+	}
 
-const char *Resource::JASVersion() {
-	static char versionStr[6];
-	if (isDemo())
-		_resourceFile->seek(fileOffset("QUEEN.JAS") + JAS_VERSION_OFFSET_DEMO, SEEK_SET);
-	else
-		_resourceFile->seek(fileOffset("QUEEN.JAS") + JAS_VERSION_OFFSET, SEEK_SET);
-	_resourceFile->read(versionStr, 6);
-	return versionStr;
+	_compression = COMPRESSION_NONE;
+
+	// detect game version based on resource file size ; we try to 
+	// verify that it is indeed the version we think it is later on
+	const GameVersion *gameVersion = detectGameVersion(_resourceFile->size());
+	if (gameVersion == NULL)
+		error("Unknown/unsupported FOTAQ version");
+
+	strcpy(_versionString, gameVersion->versionString);
+	if (!readTableFile(gameVersion)) {
+		// check if it is the english floppy version, for which we have a hardcoded version of the table
+		if (!strcmp(gameVersion->versionString, _gameVersions[VER_ENG_FLOPPY].versionString)) {
+			_resourceEntries = 1076;
+			_resourceTable = _resourceTablePEM10;
+		} else {
+			error("Could not find tablefile '%s%s'",  _datafilePath.c_str(), _tableFilename);
+		}
+	}
+	return true;
 }
 
-bool Resource::isDemo() const {
-	return _gameVersion->isDemo;
+bool Resource::findCompressedVersion() {
+	_resourceFile->open("queen.1c", _datafilePath);
+	if (!_resourceFile->isOpen()) {
+		return false;
+	}
+	readTableCompResource();
+	return true;
 }
 
-bool Resource::isFloppy() const {
-	return _gameVersion->versionString[0] == 'P';
+void Resource::checkJASVersion() {
+	int32 offset = fileOffset("QUEEN.JAS");
+	if (isDemo())
+		offset += JAS_VERSION_OFFSET_DEMO;
+	else if (isInterview())
+		offset += JAS_VERSION_OFFSET_INTV;
+	else 
+		offset += JAS_VERSION_OFFSET;
+	_resourceFile->seek(offset, SEEK_SET);
+
+	char versionStr[6];
+	_resourceFile->read(versionStr, 6);
+	if (strcmp(_versionString, versionStr))
+		error("Verifying game version failed! (expected: '%s', found: '%s')", _versionString, versionStr);
 }
 
 Language Resource::getLanguage() const {
-	switch (_gameVersion->versionString[1]) {
+	switch (_versionString[1]) {
 	case 'E':
 		return ENGLISH;
 	case 'G':
@@ -197,61 +196,52 @@
 	}
 }
 
-const GameVersion *Resource::detectGameVersion(uint32 dataFilesize) {
-	//detect game version based on resource file size.
-	//we try to verify that it is indeed the version we think it is later on
-	const GameVersion *pgv = _gameVersions;
-	int i;
-	for (i = 0; i < VER_COUNT; ++i, ++pgv) {
-		if (pgv->dataFileSize == dataFilesize) {
-			return pgv;
-		}
-	}
-	error("Unknown/unsupported FOTAQ version");
-	return NULL;
-}
-
-bool Resource::readTableFile() {
+bool Resource::readTableFile(const GameVersion *gameVersion) {
 	File tableFile;
 	tableFile.open(_tableFilename, _datafilePath);
 	if (!tableFile.isOpen())	
-		tableFile.open(_tableFilename, ""); //try current directory
+		tableFile.open(_tableFilename, ""); // try current directory
 	if (tableFile.isOpen() && tableFile.readUint32BE() == 'QTBL') {
-		tableFile.seek(_gameVersion->tableOffset);
-		_resourceEntries = tableFile.readUint16BE();
-		_resourceTable = new ResourceEntry[_resourceEntries];
-		ResourceEntry *pre = _resourceTable;
-		for (uint32 i = 0; i < _resourceEntries; ++i, ++pre) {
-			tableFile.read(pre->filename, 12);
-			pre->filename[12] = '\0';
-			pre->inBundle = tableFile.readByte();
-			pre->offset = tableFile.readUint32BE();
-			pre->size = tableFile.readUint32BE();
-		}
+		tableFile.seek(gameVersion->tableOffset);
+		readTableEntries(&tableFile);
 		return true;
 	}
 	return false;
 }
 
 void Resource::readTableCompResource() {
-	GameVersion *gv = new GameVersion;
-	_resourceFile->read(gv->versionString, 6);
-	_resourceFile->readByte();
-	gv->isDemo = _resourceFile->readByte() != 0;
+	if (_resourceFile->readUint32BE() != 'QTBL')
+		error("Invalid table header");
+
+	_resourceFile->read(_versionString, 6);
+	_resourceFile->readByte(); // obsolete
+	_resourceFile->readByte(); // obsolete
 	_compression = _resourceFile->readByte();
-	_resourceEntries = _resourceFile->readUint16BE();
-	_gameVersion = gv;
-	
-	_resourceFile->seek(15, SEEK_SET);
+
+	readTableEntries(_resourceFile);
+}
+
+void Resource::readTableEntries(File *file) {
+	_resourceEntries = file->readUint16BE();
 	_resourceTable = new ResourceEntry[_resourceEntries];
-	ResourceEntry *pre = _resourceTable;
-	for (uint32 i = 0; i < _resourceEntries; ++i, ++pre) {
-		_resourceFile->read(pre->filename, 12);
-		pre->filename[12] = '\0';
-		pre->inBundle = _resourceFile->readByte();
-		pre->offset = _resourceFile->readUint32BE();
-		pre->size = _resourceFile->readUint32BE();
+	for (uint16 i = 0; i < _resourceEntries; ++i) {
+		ResourceEntry *re = &_resourceTable[i];
+		file->read(re->filename, 12);
+		re->filename[12] = '\0';
+		re->bundle = file->readByte();
+		re->offset = file->readUint32BE();
+		re->size = file->readUint32BE();
 	}
+}
+
+const GameVersion *Resource::detectGameVersion(uint32 size) const {
+	const GameVersion *pgv = _gameVersions;
+	for (int i = 0; i < VER_COUNT; ++i, ++pgv) {
+		if (pgv->dataFileSize == size) {
+			return pgv;
+		}
+ 	}
+	return NULL;
 }
 
 File *Resource::giveCompressedSound(const char *filename) {

Index: resource.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/queen/resource.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- resource.h	26 Dec 2003 15:36:28 -0000	1.23
+++ resource.h	28 Dec 2003 15:29:05 -0000	1.24
@@ -37,23 +37,26 @@
 	VER_GER_TALKIE   = 5,
 	VER_ITA_FLOPPY   = 6,
 	VER_ITA_TALKIE   = 7,
+	// VER_ITA_FLOPPY
 	VER_SPA_TALKIE   = 8,
+	// VER_HEB_FLOPPY
+	// VER_HEB_TALKIE
 	VER_DEMO_PCGAMES = 9,
 	VER_DEMO         = 10,
+	// VER_INTERVIEW
 
 	VER_COUNT        = 11
 };
 
 struct ResourceEntry {
 	char filename[13];
-	uint8 inBundle;
+	uint8 bundle;
 	uint32 offset;
 	uint32 size;
 };
 
 struct GameVersion {
 	char versionString[6];
-	bool isDemo;
 	uint32 tableOffset;
 	uint32 dataFileSize;
 };
@@ -64,18 +67,23 @@
 public:
 	Resource(const Common::String &datafilePath, SaveFileManager *mgr, const char *savePath);
 	~Resource(void);
+
 	uint8 *loadFile(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
 	uint8 *loadFileMalloc(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
-	char *getJAS2Line();
-	bool exists(const char *filename);
-	bool isDemo() const;
-	bool isFloppy() const;
-	uint8 compression()	{ return _compression; }
-	uint32 fileSize(const char *filename);
-	uint32 fileOffset(const char *filename);
+	bool exists(const char *filename) const { return resourceIndex(filename) >= 0; }
+	uint32 fileSize(const char *filename) const { return _resourceTable[resourceIndex(filename)].size; }
+	uint32 fileOffset(const char *filename) const { return _resourceTable[resourceIndex(filename)].offset; }
+
 	File *giveCompressedSound(const char *filename);
+
+	bool isDemo() const { return !strcmp(_versionString, "PE100"); }
+	bool isInterview() const { return !strcmp(_versionString, "PEint"); }
+	bool isFloppy() const { return _versionString[0] == 'P'; }
+	uint8 compression()	const { return _compression; }
+	const char *JASVersion() const { return _versionString; }
 	Language getLanguage() const;
-	const char *JASVersion();
+	char *getJAS2Line();
+
 	bool writeSave(uint16 slot, const byte *saveData, uint32 size);
 	bool readSave(uint16 slot, byte *&ptr);
 
@@ -91,21 +99,24 @@
 	uint32 _JAS2Pos;
 	uint8 _compression;
 	const Common::String _datafilePath;
-	const GameVersion *_gameVersion;
+	char _versionString[6];
 	const char *_savePath;
 	uint32 _resourceEntries;
 	ResourceEntry *_resourceTable;
+	SaveFileManager *_saveFileManager;
+
+	bool findNormalVersion();
+	bool findCompressedVersion();
+	void checkJASVersion();
+	int32 resourceIndex(const char *filename) const;
+	bool readTableFile(const GameVersion *gameVersion);
+	void readTableCompResource();
+	void readTableEntries(File *file);
+	const GameVersion *detectGameVersion(uint32 size) const;
 
 	static const char *_tableFilename;
 	static const GameVersion _gameVersions[];
 	static ResourceEntry _resourceTablePEM10[];
-
-	int32 resourceIndex(const char *filename);
-	bool readTableFile();
-	void readTableCompResource();
-	static const GameVersion *detectGameVersion(uint32 dataFilesize);
-
-	SaveFileManager *_saveFileManager;
 };
 
 } // End of namespace Queen





More information about the Scummvm-git-logs mailing list