[Scummvm-cvs-logs] SF.net SVN: scummvm: [20879] scummvm/trunk/engines/scumm

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Feb 25 09:37:08 CET 2006


Revision: 20879
Author:   fingolfin
Date:     2006-02-25 09:36:32 -0800 (Sat, 25 Feb 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm?rev=20879&view=rev

Log Message:
-----------
Split SCUMM's generateSubstResFileName into two functions: findSubstResFileName and applySubstResFileName

Modified Paths:
--------------
    scummvm/trunk/engines/scumm/cursor.cpp
    scummvm/trunk/engines/scumm/he/intern_he.h
    scummvm/trunk/engines/scumm/he/resource_he.cpp
    scummvm/trunk/engines/scumm/he/sound_he.cpp
    scummvm/trunk/engines/scumm/intern.h
    scummvm/trunk/engines/scumm/resource.cpp
    scummvm/trunk/engines/scumm/scumm.cpp
    scummvm/trunk/engines/scumm/scumm.h
    scummvm/trunk/engines/scumm/sound.cpp
Modified: scummvm/trunk/engines/scumm/cursor.cpp
===================================================================
--- scummvm/trunk/engines/scumm/cursor.cpp	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/cursor.cpp	2006-02-25 17:36:32 UTC (rev 20879)
@@ -93,8 +93,8 @@
 	0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, 0x00,0x0F,0x00, 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
 };
 
-ScummEngine_v5::ScummEngine_v5(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
- : ScummEngine(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v5::ScummEngine_v5(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+ : ScummEngine(detector, syst, gs, md5sum, subst) {
 
 	for (int i = 0; i < 4; i++) {
 		memcpy(_cursorImages[i], default_cursor_images[i], 32);

Modified: scummvm/trunk/engines/scumm/he/intern_he.h
===================================================================
--- scummvm/trunk/engines/scumm/he/intern_he.h	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/he/intern_he.h	2006-02-25 17:36:32 UTC (rev 20879)
@@ -51,7 +51,7 @@
 	Common::File _hFileTable[17];
 
 public:
-	ScummEngine_v60he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex) : ScummEngine_v6(detector, syst, gs, md5sum, substResFileNameIndex) {}
+	ScummEngine_v60he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst) : ScummEngine_v6(detector, syst, gs, md5sum, subst) {}
 
 	virtual void scummInit();
 
@@ -113,7 +113,7 @@
 	bool _skipProcessActors;
 
 public:
-	ScummEngine_v70he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v70he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 	~ScummEngine_v70he();
 
 	Wiz *_wiz;
@@ -178,7 +178,7 @@
 
 class ScummEngine_v71he : public ScummEngine_v70he {
 public:
-	ScummEngine_v71he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v71he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 protected:
 	virtual void saveOrLoad(Serializer *s);
@@ -233,7 +233,7 @@
 	WizParameters _wizParams;
 
 public:
-	ScummEngine_v72he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v72he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 	virtual void scummInit();
 
@@ -345,7 +345,7 @@
 	int32 _heSndResId, _curSndId, _sndPtrOffs, _sndTmrOffs;
 
 public:
-	ScummEngine_v80he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v80he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 protected:
 	virtual void setupOpcodes();
@@ -418,7 +418,7 @@
 	int32 _curSpriteGroupId;
 
 public:
-	ScummEngine_v90he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v90he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 	~ScummEngine_v90he();
 
 	virtual void scummInit();
@@ -518,7 +518,7 @@
 
 class ScummEngine_v99he : public ScummEngine_v90he {
 public:
-	ScummEngine_v99he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex) : ScummEngine_v90he(detector, syst, gs, md5sum, substResFileNameIndex) {}
+	ScummEngine_v99he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst) : ScummEngine_v90he(detector, syst, gs, md5sum, subst) {}
 
 	virtual void scummInit();
 
@@ -549,7 +549,7 @@
 	const OpcodeEntryV100he *_opcodesV100he;
 
 public:
-	ScummEngine_v100he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex) : ScummEngine_v99he(detector, syst, gs, md5sum, substResFileNameIndex) {}
+	ScummEngine_v100he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst) : ScummEngine_v99he(detector, syst, gs, md5sum, subst) {}
 
 protected:
 	virtual void setupOpcodes();

Modified: scummvm/trunk/engines/scumm/he/resource_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/resource_he.cpp	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/he/resource_he.cpp	2006-02-25 17:36:32 UTC (rev 20879)
@@ -161,7 +161,7 @@
 	if (!_fileName[0]) { // We are running for the first time
 		snprintf(_fileName, 256, "%s.he3", _vm->getBaseName());
 
-		if (_vm->_substResFileNameIndex > 0) {
+		if (_vm->_substResFileName.winName != 0) {
 			char buf1[128];
 
 			_vm->generateSubstResFileName(_fileName, buf1, sizeof(buf1));
@@ -1290,7 +1290,7 @@
 	int size;
 
 	if (!_fileName[0]) // We are running for the first time
-		if (_vm->_substResFileNameIndex > 0) {
+		if (_vm->_substResFileName.winName != 0) {
 			char buf1[128];
 
 			snprintf(buf1, 128, "%s.he3", _vm->getBaseName());

Modified: scummvm/trunk/engines/scumm/he/sound_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/sound_he.cpp	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/he/sound_he.cpp	2006-02-25 17:36:32 UTC (rev 20879)
@@ -160,7 +160,7 @@
 
 	sprintf(buf, "%s.he4", _vm->getBaseName());
 
-	if (_vm->_substResFileNameIndex > 0) {
+	if (_vm->_substResFileName.winName != 0) {
 		_vm->generateSubstResFileName(buf, buf1, sizeof(buf1));
 		strcpy(buf, buf1);
 	}
@@ -352,7 +352,7 @@
 
 		sprintf(buf, "%s.he4", _vm->getBaseName());
 
-		if (_vm->_substResFileNameIndex > 0) {
+		if (_vm->_substResFileName.winName != 0) {
 			_vm->generateSubstResFileName(buf, buf1, sizeof(buf1));
 			strcpy(buf, buf1);
 		}

Modified: scummvm/trunk/engines/scumm/intern.h
===================================================================
--- scummvm/trunk/engines/scumm/intern.h	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/intern.h	2006-02-25 17:36:32 UTC (rev 20879)
@@ -50,7 +50,7 @@
 	byte _cursorHotspots[2 * 4];
 
 public:
-	ScummEngine_v5(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v5(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 protected:
 	virtual void setupOpcodes();
@@ -193,7 +193,7 @@
  */
 class ScummEngine_v4 : public ScummEngine_v5 {
 public:
-	ScummEngine_v4(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v4(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 protected:
 	virtual void readIndexFile();
@@ -210,7 +210,7 @@
  */
 class ScummEngine_v3 : public ScummEngine_v4 {
 public:
-	ScummEngine_v3(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v3(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 protected:
 	virtual void readRoomsOffsets();
@@ -222,7 +222,7 @@
  */
 class ScummEngine_v3old : public ScummEngine_v3 {
 public:
-	ScummEngine_v3old(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v3old(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 protected:
 	virtual void readResTypeList(int id, const char *name);
@@ -255,7 +255,7 @@
 	int8 _mouseOverBoxV2;
 
 public:
-	ScummEngine_v2(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v2(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 	virtual void scummInit();
 
@@ -395,7 +395,7 @@
 	int _currentAction;
 	int _currentMode;
 public:
-	ScummEngine_c64(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_c64(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 	virtual void scummInit();
 
@@ -535,7 +535,7 @@
 
 
 public:
-	ScummEngine_v6(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v6(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 
 	virtual void scummInit();
 
@@ -764,7 +764,7 @@
 #ifndef DISABLE_SCUMM_7_8
 class ScummEngine_v7 : public ScummEngine_v6 {
 public:
-	ScummEngine_v7(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v7(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 	~ScummEngine_v7();
 
 	struct LangIndexNode {
@@ -844,7 +844,7 @@
 	ObjectNameId *_objectIDMap;
 
 public:
-	ScummEngine_v8(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine_v8(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 	~ScummEngine_v8();
 
 protected:

Modified: scummvm/trunk/engines/scumm/resource.cpp
===================================================================
--- scummvm/trunk/engines/scumm/resource.cpp	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/resource.cpp	2006-02-25 17:36:32 UTC (rev 20879)
@@ -154,7 +154,7 @@
 		}
 
 		// If we have substitute
-		if (_substResFileNameIndex > 0 && !(_game.platform == Common::kPlatformNES || _game.platform == Common::kPlatformC64)) {
+		if (_substResFileName.winName != 0 && !(_game.platform == Common::kPlatformNES || _game.platform == Common::kPlatformC64)) {
 			char tmpBuf[128];
 			generateSubstResFileName(buf, tmpBuf, sizeof(tmpBuf));
 			strcpy(buf, tmpBuf);
@@ -255,27 +255,24 @@
 		// from target name. dottdemo.000 vs tentacle.000. So we should
 		// substitute those names too
 		if (resourceFile == true) {
-			if (_substResFileNameIndexBundle == 0) {
+			if (_substResFileNameBundle.winName == 0) {
 				int substLastIndex = 0;
 
 				while (substLastIndex != -1) {
 					if (file.openSubFile(name))
 						break;
 
-					substLastIndex = generateSubstResFileName(filename, name, sizeof(name), substLastIndex + 1);
+					substLastIndex = findSubstResFileName(_substResFileNameBundle, filename, substLastIndex + 1);
+					applySubstResFileName(_substResFileNameBundle, filename, name, sizeof(name));
 				}
 
-				if (substLastIndex == 0)
-					substLastIndex = -1;
-
-				_substResFileNameIndexBundle = substLastIndex;
-
-				if (substLastIndex != -1)
-					debug(5, "Generated substitute in Mac bundle: [%s -> %s]", filename, name);
+				if (_substResFileNameBundle.winName != 0) {
+					debug(5, "Generated substitute in Mac bundle: [%s -> %s]", filename, _substResFileNameBundle.winName);
+				}
 			}
 
-			if (_substResFileNameIndexBundle != -1)
-				generateSubstResFileName(filename, name, sizeof(name), _substResFileNameIndexBundle);
+			if (_substResFileNameBundle.winName != 0)
+				applySubstResFileName(_substResFileNameBundle, filename, name, sizeof(name));
 		}
 
 		result = file.openSubFile(name);

Modified: scummvm/trunk/engines/scumm/scumm.cpp
===================================================================
--- scummvm/trunk/engines/scumm/scumm.cpp	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/scumm.cpp	2006-02-25 17:36:32 UTC (rev 20879)
@@ -81,8 +81,6 @@
 }
 #endif
 
-static int generateSubstResFileName_(const char *filename, char *buf, int bufsize, int index);
-
 using Common::File;
 
 namespace Scumm {
@@ -895,19 +893,6 @@
 	{NULL, NULL, 0, 0, MDT_NONE, 0, 0, Common::kPlatformUnknown}
 };
 
-enum genMethods {
-	kGenMac,
-	kGenMacNoParens,
-	kGenPC,
-	kGenAsIs
-};
-
-struct SubstResFileNames {
-	const char *winName;
-	const char *macName;
-	int genMethod;
-};
-
 static SubstResFileNames substResFileNameTable[] = {
 	{ "Intentionally/left/blank", "", kGenMacNoParens },
 	{ "00.LFL", "Maniac Mansion (E).prg", kGenAsIs },
@@ -1119,20 +1104,104 @@
 	{ "thinkerk", "ThinkerK", kGenMac },
 	{ "water", "Water Worries", kGenMac },
 #endif
-	{ NULL, NULL, 0 }
+	{ NULL, NULL, kGenAsIs }
 };
 
+static bool applySubstResFileName(const SubstResFileNames &subst, char *buf, int bufsize, const char *ext, int num) {
+	switch (subst.genMethod) {
+	case kGenMac:
+	case kGenMacNoParens:
+		if (num == '3') { // special case for cursors
+			// For mac they're stored in game binary
+			strncpy(buf, subst.macName, bufsize);
+		} else {
+			if (subst.genMethod == kGenMac)
+				snprintf(buf, bufsize, "%s (%c)", subst.macName, num);
+			else
+				snprintf(buf, bufsize, "%s %c", subst.macName, num);
+		}
+		break;
+
+	case kGenPC:
+		if (ext)
+			snprintf(buf, bufsize, "%s%s", subst.macName, ext);
+		else
+			strncpy(buf, subst.macName, bufsize);
+		break;
+
+	case kGenAsIs:
+		strncpy(buf, subst.macName, bufsize);
+		break;
+
+	default:
+		*buf = 0;
+		break;
+	}
+}
+
+bool applySubstResFileName(const SubstResFileNames &subst, const char *filename, char *buf, int bufsize) {
+	if (subst.winName == 0)
+		return false;
+
+	size_t len = strlen(filename);
+	assert(len > 0);
+
+	char num = filename[len - 1];
+
+	// In some cases we have .(a) and .(b) extensions
+	if (num == ')')
+		num = filename[len - 2];
+
+	const char *ext = strrchr(filename, '.');
+	if (ext)
+		len = ext - filename;
+
+	if (!scumm_strnicmp(filename, subst.winName, len)) {
+		applySubstResFileName(subst, buf, bufsize, ext, num);
+		return true;
+	}
+
+	return false;
+}
+
+int findSubstResFileName(SubstResFileNames &subst, const char *filename, int index) {
+	if (index <= 0)
+		return -1;
+
+	size_t len = strlen(filename);
+	assert(len > 0);
+
+	char num = filename[len - 1];
+
+	// In some cases we have .(a) and .(b) extensions
+	if (num == ')')
+		num = filename[len - 2];
+
+	const char *ext = strrchr(filename, '.');
+	if (ext)
+		len = ext - filename;
+
+	int i;
+	for (i = index; substResFileNameTable[i].winName; i++) {
+		if (!scumm_strnicmp(filename, substResFileNameTable[i].winName, len)) {
+			subst = substResFileNameTable[i];
+			return i;
+		}
+	}
+	subst = substResFileNameTable[i];
+	return -1;
+}
+
 static int compareMD5Table(const void *a, const void *b) {
 	const char *key = (const char *)a;
 	const MD5Table *elem = (const MD5Table *)b;
 	return strcmp(key, elem->md5);
 }
 
-ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
+ScummEngine::ScummEngine(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
 	: Engine(syst),
 	  _game(gs),
-	  _substResFileNameIndex(substResFileNameIndex),
-	  _substResFileNameIndexBundle(0),
+	  _substResFileName(subst),
 	  _debugger(0),
 	  _currentScript(0xFF), // Let debug() work on init stage
 	  gdi(this),
@@ -1142,6 +1211,9 @@
 
 	// Copy MD5 checksum
 	memcpy(_gameMD5, md5sum, 16);
+	
+	// Clean _substResFileNameBundle
+	memset(&_substResFileNameBundle, 0, sizeof(_substResFileNameBundle));
 
 	// Check for unknown MD5
 	char md5str[32+1];
@@ -1232,12 +1304,12 @@
 
 	// We read data directly from NES ROM instead of extracting it with
 	// external tool
-	if ((_game.platform == Common::kPlatformNES) && _substResFileNameIndex) {
+	if ((_game.platform == Common::kPlatformNES) && _substResFileName.winName) {
 		char tmpBuf[128];
 		generateSubstResFileName("00.LFL", tmpBuf, sizeof(tmpBuf));
 		_fileHandle = new ScummNESFile();
 		_containerFile = tmpBuf;
-	} else if ((_game.platform == Common::kPlatformC64) && _substResFileNameIndex) {
+	} else if ((_game.platform == Common::kPlatformC64) && _substResFileName.winName) {
 		char tmpBuf1[128], tmpBuf2[128];
 		generateSubstResFileName("00.LFL", tmpBuf1, sizeof(tmpBuf1));
 		generateSubstResFileName("01.LFL", tmpBuf2, sizeof(tmpBuf2));
@@ -1256,12 +1328,12 @@
 	// (we do that here); the rest is handled by the  ScummFile class and 
 	// code in openResourceFile() (and in the Sound class, for MONSTER.SOU
 	// handling).
-	if (_game.version >= 5 && _game.heversion == 0 && _substResFileNameIndex &&
+	if (_game.version >= 5 && _game.heversion == 0 && _substResFileName.winName &&
 		_game.platform == Common::kPlatformMacintosh && 
-		substResFileNameTable[_substResFileNameIndex].genMethod == kGenAsIs) {
-		if (_fileHandle->open(substResFileNameTable[_substResFileNameIndex].macName)) {
-			_containerFile = substResFileNameTable[_substResFileNameIndex].macName;
-			_substResFileNameIndex = 0;
+		_substResFileName.genMethod == kGenAsIs) {
+		if (_fileHandle->open(_substResFileName.macName)) {
+			_containerFile = _substResFileName.macName;
+			_substResFileName.winName = 0;
 		}
 	}
 
@@ -1740,33 +1812,33 @@
 	delete _debugger;
 }
 
-ScummEngine_v4::ScummEngine_v4(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v5(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v4::ScummEngine_v4(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v5(detector, syst, gs, md5sum, subst) {
 	_resourceHeaderSize = 6;
 }
 
-ScummEngine_v3::ScummEngine_v3(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v4(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v3::ScummEngine_v3(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v4(detector, syst, gs, md5sum, subst) {
 }
 
-ScummEngine_v3old::ScummEngine_v3old(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v3(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v3old::ScummEngine_v3old(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v3(detector, syst, gs, md5sum, subst) {
 	_resourceHeaderSize = 4;
 }
 
-ScummEngine_v2::ScummEngine_v2(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v3old(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v2::ScummEngine_v2(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v3old(detector, syst, gs, md5sum, subst) {
 }
 
-ScummEngine_c64::ScummEngine_c64(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v2(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_c64::ScummEngine_c64(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v2(detector, syst, gs, md5sum, subst) {
 
 	_currentAction = 0;
 	_currentMode = 0;
 }
 
-ScummEngine_v6::ScummEngine_v6(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v6::ScummEngine_v6(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine(detector, syst, gs, md5sum, subst) {
 	_blastObjectQueuePos = 0;
 	memset(_blastObjectQueue, 0, sizeof(_blastObjectQueue));
 	_blastTextQueuePos = 0;
@@ -1787,8 +1859,8 @@
 }
 
 #ifndef DISABLE_HE
-ScummEngine_v70he::ScummEngine_v70he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v60he(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v70he::ScummEngine_v70he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v60he(detector, syst, gs, md5sum, subst) {
 	if (_game.platform == Common::kPlatformMacintosh && (_game.heversion >= 72 && _game.heversion <= 73))
 		_resExtractor = new MacResExtractor(this);
 	else
@@ -1819,16 +1891,16 @@
 	free(_storedFlObjects);
 }
 
-ScummEngine_v71he::ScummEngine_v71he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v70he(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v71he::ScummEngine_v71he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v70he(detector, syst, gs, md5sum, subst) {
 	_auxBlocksNum = 0;
 	memset(_auxBlocks, 0, sizeof(_auxBlocks));
 	_auxEntriesNum = 0;
 	memset(_auxEntries, 0, sizeof(_auxEntries));
 }
 
-ScummEngine_v72he::ScummEngine_v72he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v71he(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v72he::ScummEngine_v72he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v71he(detector, syst, gs, md5sum, subst) {
 	VAR_NUM_ROOMS = 0xFF;
 	VAR_NUM_SCRIPTS = 0xFF;
 	VAR_NUM_SOUNDS = 0xFF;
@@ -1838,8 +1910,8 @@
 	VAR_POLYGONS_ONLY = 0xFF;
 }
 
-ScummEngine_v80he::ScummEngine_v80he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v72he(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v80he::ScummEngine_v80he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v72he(detector, syst, gs, md5sum, subst) {
 	_heSndResId = 0;
 	_curSndId = 0;
 	_sndPtrOffs = 0;
@@ -1851,8 +1923,8 @@
 	VAR_COLOR_DEPTH = 0xFF;
 }
 
-ScummEngine_v90he::ScummEngine_v90he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v80he(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v90he::ScummEngine_v90he(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v80he(detector, syst, gs, md5sum, subst) {
 	_sprite = new Sprite(this);
 
 	VAR_NUM_SPRITE_GROUPS = 0xFF;
@@ -1876,8 +1948,8 @@
 #endif
 
 #ifndef DISABLE_SCUMM_7_8
-ScummEngine_v7::ScummEngine_v7(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v6(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v7::ScummEngine_v7(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v6(detector, syst, gs, md5sum, subst) {
 	_existLanguageFile = false;
 	_languageBuffer = NULL;
 	_languageIndex = NULL;
@@ -1889,8 +1961,8 @@
 	free(_languageIndex);
 }
 
-ScummEngine_v8::ScummEngine_v8(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex)
-	: ScummEngine_v7(detector, syst, gs, md5sum, substResFileNameIndex) {
+ScummEngine_v8::ScummEngine_v8(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst)
+	: ScummEngine_v7(detector, syst, gs, md5sum, subst) {
 	_objectIDMap = 0;
 }
 
@@ -3052,11 +3124,8 @@
 	}
 }
 
-int ScummEngine::generateSubstResFileName(const char *filename, char *buf, int bufsize, int index) {
-	if (index == -3)
-		index = _substResFileNameIndex;
-
-	return generateSubstResFileName_(filename, buf, bufsize, index);
+void ScummEngine::generateSubstResFileName(const char *filename, char *buf, int bufsize) {
+	applySubstResFileName(_substResFileName, filename, buf, bufsize);
 }
 
 
@@ -3163,7 +3232,7 @@
 	const ScummGameSettings *g;
 	char detectName[128];
 	char tempName[128];
-	int substLastIndex = 0;
+	SubstResFileNames subst = { 0, 0, kGenAsIs };
 
 	typedef Common::Map<Common::String, bool> StringSet;
 	StringSet fileSet;
@@ -3180,7 +3249,7 @@
 
 			strcpy(tempName, detectName);
 
-			substLastIndex = 0;
+			int substLastIndex = 0;
 
 			while (substLastIndex != -1) {
 				// Iterate over all files in the given directory
@@ -3219,7 +3288,7 @@
 										break;
 									// Candidates: maniac enhanced, zak enhanced, indy3ega, loom
 								/*
-								TODO: MIght be possible to distinguish those by the script count.
+								TODO: Might be possible to distinguish those by the script count.
 								Specifically, my versions of these games have this in their headers:
 
 								Loom (en; de; en demo; en MAC):
@@ -3326,8 +3395,8 @@
 
 							// Match found, add to list of candidates, then abort inner loop.
 							if (substLastIndex > 0 && // HE Mac versions.
-								(substResFileNameTable[substLastIndex].genMethod == kGenMac ||
-								 substResFileNameTable[substLastIndex].genMethod == kGenMacNoParens)) {
+								(subst.genMethod == kGenMac ||
+								 subst.genMethod == kGenMacNoParens)) {
 								detectedGames.push_back(DetectedGame(toGameSettings(*g),
 																	 Common::UNK_LANG,
 																	 Common::kPlatformMacintosh));
@@ -3352,7 +3421,8 @@
 					}
 				}
 
-				substLastIndex = generateSubstResFileName_(tempName, detectName, sizeof(detectName), substLastIndex+1);
+				substLastIndex = findSubstResFileName(subst, tempName, substLastIndex + 1);
+				applySubstResFileName(subst, tempName, detectName, sizeof(detectName));
 			}
 		}
 	}
@@ -3397,61 +3467,6 @@
 	return detectedGames;
 }
 
-static int generateSubstResFileName_(const char *filename, char *buf, int bufsize, int index) {
-	if (index <= 0)
-		return -1;
-
-	size_t len = strlen(filename);
-	assert(len > 0);
-
-	char num = filename[len - 1];
-
-	// In some cases we have .(a) and .(b) extensions
-	if (num == ')')
-		num = filename[len - 2];
-
-	const char *ext = strrchr(filename, '.');
-	if (ext)
-		len = ext - filename;
-
-	for (int i = index; substResFileNameTable[i].winName; i++) {
-		if (!scumm_strnicmp(filename, substResFileNameTable[i].winName, len)) {
-			switch (substResFileNameTable[i].genMethod) {
-			case kGenMac:
-			case kGenMacNoParens:
-				if (num == '3') { // special case for cursors
-					// For mac they're stored in game binary
-					strncpy(buf, substResFileNameTable[i].macName, bufsize);
-				} else {
-					if (substResFileNameTable[i].genMethod == kGenMac)
-						snprintf(buf, bufsize, "%s (%c)", substResFileNameTable[i].macName, num);
-					else
-						snprintf(buf, bufsize, "%s %c", substResFileNameTable[i].macName, num);
-				}
-				break;
-
-			case kGenPC:
-				if (ext)
-					snprintf(buf, bufsize, "%s%s", substResFileNameTable[i].macName, ext);
-				else
-					strncpy(buf, substResFileNameTable[i].macName, bufsize);
-				break;
-
-			case kGenAsIs:
-				strncpy(buf, substResFileNameTable[i].macName, bufsize);
-				break;
-
-			default:
-				*buf = 0;
-				break;
-			}
-
-			return i;
-		}
-	}
-	return -1;
-}
-
 /**
  * Create a ScummEngine instance, based on the given detector data.
  *
@@ -3497,7 +3512,7 @@
 	const char *gameid = g->gameid;
 	char detectName[256], tempName[256], gameMD5[32+1];
 	uint8 md5sum[16];
-	int substLastIndex = 0;
+	SubstResFileNames subst = { 0, 0, kGenAsIs };
 	bool found = false;
 
 	ScummGameSettings game = *g;
@@ -3511,7 +3526,7 @@
 
 		strcpy(tempName, detectName);
 
-		substLastIndex = 0;
+		int substLastIndex = 0;
 		while (substLastIndex != -1) {
 			// FIXME: Repeatedly calling File::exists like this is a bad idea.
 			// Instead, use the fs.h code to get a list of all files in that 
@@ -3522,7 +3537,8 @@
 				break;
 			}
 
-			substLastIndex = generateSubstResFileName_(tempName, detectName, sizeof(detectName), substLastIndex + 1);
+			substLastIndex = findSubstResFileName(subst, tempName, substLastIndex + 1);
+			applySubstResFileName(subst, tempName, detectName, sizeof(detectName));
 		}
 		if (found) {
 			if (substLastIndex != 0)
@@ -3537,9 +3553,9 @@
 	}
 
 	// Force game to have Mac platform if needed
-	if (substLastIndex > 0) {
-		if (substResFileNameTable[substLastIndex].genMethod == kGenMac ||
-			substResFileNameTable[substLastIndex].genMethod == kGenMacNoParens)
+	if (subst.winName) {
+		if (subst.genMethod == kGenMac ||
+			subst.genMethod == kGenMacNoParens)
 			game.platform = Common::kPlatformMacintosh;
 	}
 
@@ -3603,65 +3619,65 @@
 	case 1:
 	case 2:
 		if (game.id == GID_MANIAC && game.platform == Common::kPlatformC64)
-			engine = new ScummEngine_c64(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_c64(detector, syst, game, md5sum, subst);
 		else
-			engine = new ScummEngine_v2(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v2(detector, syst, game, md5sum, subst);
 		break;
 	case 3:
 		if (game.features & GF_OLD_BUNDLE)
-			engine = new ScummEngine_v3old(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v3old(detector, syst, game, md5sum, subst);
 		else
-			engine = new ScummEngine_v3(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v3(detector, syst, game, md5sum, subst);
 		break;
 	case 4:
-		engine = new ScummEngine_v4(detector, syst, game, md5sum, substLastIndex);
+		engine = new ScummEngine_v4(detector, syst, game, md5sum, subst);
 		break;
 	case 5:
-		engine = new ScummEngine_v5(detector, syst, game, md5sum, substLastIndex);
+		engine = new ScummEngine_v5(detector, syst, game, md5sum, subst);
 		break;
 	case 6:
 		switch (game.heversion) {
 #ifndef DISABLE_HE
 		case 100:
-			engine = new ScummEngine_v100he(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v100he(detector, syst, game, md5sum, subst);
 			break;
 		case 99:
-			engine = new ScummEngine_v99he(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v99he(detector, syst, game, md5sum, subst);
 			break;
 		case 98:
 		case 95:
 		case 90:
-			engine = new ScummEngine_v90he(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v90he(detector, syst, game, md5sum, subst);
 			break;
 		case 80:
-			engine = new ScummEngine_v80he(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v80he(detector, syst, game, md5sum, subst);
 			break;
 		case 73:
 		case 72:
-			engine = new ScummEngine_v72he(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v72he(detector, syst, game, md5sum, subst);
 			break;
 		case 71:
-			engine = new ScummEngine_v71he(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v71he(detector, syst, game, md5sum, subst);
 			break;
 		case 70:
-			engine = new ScummEngine_v70he(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v70he(detector, syst, game, md5sum, subst);
 			break;
 #endif
 #ifndef PALMOS_68K
 		case 61:
-			engine = new ScummEngine_v60he(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v60he(detector, syst, game, md5sum, subst);
 			break;
 #endif
 		default:
-			engine = new ScummEngine_v6(detector, syst, game, md5sum, substLastIndex);
+			engine = new ScummEngine_v6(detector, syst, game, md5sum, subst);
 		}
 		break;
 #ifndef DISABLE_SCUMM_7_8
 	case 7:
-		engine = new ScummEngine_v7(detector, syst, game, md5sum, substLastIndex);
+		engine = new ScummEngine_v7(detector, syst, game, md5sum, subst);
 		break;
 	case 8:
-		engine = new ScummEngine_v8(detector, syst, game, md5sum, substLastIndex);
+		engine = new ScummEngine_v8(detector, syst, game, md5sum, subst);
 		break;
 #endif
 	default:

Modified: scummvm/trunk/engines/scumm/scumm.h
===================================================================
--- scummvm/trunk/engines/scumm/scumm.h	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/scumm.h	2006-02-25 17:36:32 UTC (rev 20879)
@@ -334,6 +334,27 @@
 
 };
 
+
+enum GenMethods {
+	kGenMac,
+	kGenMacNoParens,
+	kGenPC,
+	kGenAsIs
+};
+
+struct SubstResFileNames {
+	const char *winName;
+	const char *macName;
+	GenMethods genMethod;
+};
+
+
+extern bool applySubstResFileName(const SubstResFileNames &subst, const char *filename, char *buf, int bufsize);
+extern int findSubstResFileName(SubstResFileNames &subst, const char *filename, int index);
+
+
+
+
 /**
  * The 'resource manager' class. Currently doesn't really deserve to be called
  * a 'class', at least until somebody gets around to OOfying this more.
@@ -432,7 +453,7 @@
 
 public:
 	// Constructor / Destructor
-	ScummEngine(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], int substResFileNameIndex);
+	ScummEngine(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs, uint8 md5sum[16], SubstResFileNames subst);
 	virtual ~ScummEngine();
 
 	/** Startup function, main loop. */
@@ -575,9 +596,9 @@
 	int _roomResource;  // FIXME - should be protected but Sound::pauseSounds uses it
 	bool _egoPositioned;	// Used by Actor::putActor, hence public
 
-	int generateSubstResFileName(const char *filename, char *buf, int bufsize, int index = -3);
-	int _substResFileNameIndex;
-	int _substResFileNameIndexBundle; // Used with Mac bundles
+	void generateSubstResFileName(const char *filename, char *buf, int bufsize);
+	SubstResFileNames _substResFileName;
+	SubstResFileNames _substResFileNameBundle; // Used with Mac bundles
 
 protected:
 	int _keyPressed;

Modified: scummvm/trunk/engines/scumm/sound.cpp
===================================================================
--- scummvm/trunk/engines/scumm/sound.cpp	2006-02-25 14:45:31 UTC (rev 20878)
+++ scummvm/trunk/engines/scumm/sound.cpp	2006-02-25 17:36:32 UTC (rev 20879)
@@ -1007,7 +1007,7 @@
 	basename[0] = _vm->getBaseName();
 	basename[1] = "monster";
 	
-	if (_vm->_substResFileNameIndex > 0) {
+	if (_vm->_substResFileName.winName != 0) {
 
 		strcpy(buf, basename[0]);
 		_vm->generateSubstResFileName(buf, buf1, sizeof(buf1));
@@ -1032,7 +1032,7 @@
 			sprintf(buf, "%s.tlk", _vm->getBaseName());
 		}
 
-		if (_vm->_substResFileNameIndex > 0) {
+		if (_vm->_substResFileName.winName != 0) {
 			_vm->generateSubstResFileName(buf, buf1, sizeof(buf1));
 			strcpy(buf, buf1);
 		}







More information about the Scummvm-git-logs mailing list