[Scummvm-cvs-logs] CVS: scummvm/scumm intern.h,2.44,2.45 resource_v2.cpp,1.10,1.11 resource_v3.cpp,1.7,1.8 script_v6.cpp,1.71,1.72 scumm.h,1.156,1.157 sound.cpp,1.94,1.95

Max Horn fingolfin at users.sourceforge.net
Fri Mar 7 13:39:11 CET 2003


Update of /cvsroot/scummvm/scummvm/scumm
In directory sc8-pr-cvs1:/tmp/cvs-serv29151/scumm

Modified Files:
	intern.h resource_v2.cpp resource_v3.cpp script_v6.cpp scumm.h 
	sound.cpp 
Log Message:
refactored some stuff (and made readMAXS virtual, with V2/V3 code having own implementations); cleaned up V6 array shuffle code; made more Scumm member vars/methods protected

Index: intern.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/intern.h,v
retrieving revision 2.44
retrieving revision 2.45
diff -u -d -r2.44 -r2.45
--- intern.h	6 Mar 2003 21:46:03 -0000	2.44
+++ intern.h	7 Mar 2003 21:38:44 -0000	2.45
@@ -162,7 +162,9 @@
 public:
 	Scumm_v2(GameDetector *detector, OSystem *syst) : Scumm_v5(detector, syst) {}
 
-	virtual void readIndexFile();
+protected:
+	void readIndexFile();
+	void readMAXS();
 };
 
 // FIXME - maybe we should move the opcodes from v5 to v3, and change the inheritance 
@@ -172,14 +174,17 @@
 public:
 	Scumm_v3(GameDetector *detector, OSystem *syst) : Scumm_v5(detector, syst) {}
 
+protected:
 	void readIndexFile();
-	virtual void loadCharset(int no);
+	void loadCharset(int no);
+	void readMAXS();
 };
 
 class Scumm_v4 : public Scumm_v3 {
 public:
 	Scumm_v4(GameDetector *detector, OSystem *syst) : Scumm_v3(detector, syst) {}
 
+protected:
 	void loadCharset(int no);
 };
 
@@ -205,6 +210,8 @@
 	virtual void setupScummVars();
 
 	int popRoomAndObj(int *room);
+	
+	void shuffleArray(int num, int minIdx, int maxIdx);
 
 	virtual void decodeParseString(int a, int b);
 	int getStackList(int *args, uint maxnum);

Index: resource_v2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource_v2.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- resource_v2.cpp	6 Mar 2003 21:46:10 -0000	1.10
+++ resource_v2.cpp	7 Mar 2003 21:38:44 -0000	1.11
@@ -49,30 +49,13 @@
 	_fileHandle.clearIOFailed();
 	_fileHandle.seek(0, SEEK_SET);
 
-	// FIXME - I'm not sure for those values yet, they will have to be rechecked
-
-	_numVariables = 800;				/* 800 */
-	_numBitVariables = 4096;			/* 2048 */
-	_numLocalObjects = 200;				/* 200 */
-	_numArray = 50;
-	_numVerbs = 100;
-	_numNewNames = 0;
-	_objectRoomTable = NULL;
-	_numCharsets = 9;					/* 9 */
-	_numInventory = 80;					/* 80 */
-	_numGlobalScripts = 200;
-
-	_shadowPaletteSize = 256;
-	_shadowPalette = (byte *) calloc(_shadowPaletteSize, 1);	// FIXME - needs to be removed later
+	readMAXS();
 
 	// Jamieson630: palManipulate variable initialization
 	_palManipCounter = 0;
 	_palManipPalette = 0; // Will allocate when needed
 	_palManipIntermediatePal = 0; // Will allocate when needed
 
-	_numFlObject = 50;
-	allocateArrays();
-
 	_fileHandle.readUint16LE(); /* version magic number */
 	_fileHandle.readUint16LE(); /* nb global objects */
 	_fileHandle.seek(_numGlobalObjects, SEEK_CUR); // Skip object flags
@@ -82,4 +65,25 @@
 	readResTypeList(rtSound, MKID('SOUN'), "sound");
 
 	closeRoom();
+}
+
+void Scumm_v2::readMAXS() {
+	// FIXME - I'm not sure for those values yet, they will have to be rechecked
+
+	_numVariables = 800;				// 800
+	_numBitVariables = 4096;			// 2048
+	_numLocalObjects = 200;				// 200
+	_numArray = 50;
+	_numVerbs = 100;
+	_numNewNames = 0;
+	_objectRoomTable = NULL;
+	_numCharsets = 9;					// 9
+	_numInventory = 80;					// 80
+	_numGlobalScripts = 200;
+	_numFlObject = 50;
+
+	_shadowPaletteSize = 256;
+
+	_shadowPalette = (byte *) calloc(_shadowPaletteSize, 1);	// FIXME - needs to be removed later
+	allocateArrays();
 }

Index: resource_v3.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource_v3.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- resource_v3.cpp	6 Mar 2003 21:46:11 -0000	1.7
+++ resource_v3.cpp	7 Mar 2003 21:38:44 -0000	1.8
@@ -69,30 +69,13 @@
 	_fileHandle.clearIOFailed();
 	_fileHandle.seek(0, SEEK_SET);
 
-	/* I'm not sure for those values yet, they will have to be rechecked */
-
-	_numVariables = 800;				/* 800 */
-	_numBitVariables = 4096;			/* 2048 */
-	_numLocalObjects = 200;				/* 200 */
-	_numArray = 50;
-	_numVerbs = 100;
-	_numNewNames = 0;
-	_objectRoomTable = NULL;
-	_numCharsets = 9;					/* 9 */
-	_numInventory = 80;					/* 80 */
-	_numGlobalScripts = 200;
-
-	_shadowPaletteSize = 256;
-	_shadowPalette = (byte *) calloc(_shadowPaletteSize, 1);	// stupid for now. Need to be removed later
+	readMAXS();
 
 	// Jamieson630: palManipulate variable initialization
 	_palManipCounter = 0;
 	_palManipPalette = 0; // Will allocate when needed
 	_palManipIntermediatePal = 0; // Will allocate when needed
 
-	_numFlObject = 50;
-	allocateArrays();
-
 	while (1) {
 		itemsize = _fileHandle.readUint32LE();
 
@@ -163,4 +146,25 @@
 
 	_fileHandle.read(createResource(6, no, size), size);
 	closeRoom();
+}
+
+void Scumm_v3::readMAXS() {
+	// FIXME - I'm not sure for those values yet, they will have to be rechecked
+
+	_numVariables = 800;				// 800
+	_numBitVariables = 4096;			// 2048
+	_numLocalObjects = 200;				// 200
+	_numArray = 50;
+	_numVerbs = 100;
+	_numNewNames = 0;
+	_objectRoomTable = NULL;
+	_numCharsets = 9;					// 9
+	_numInventory = 80;					// 80
+	_numGlobalScripts = 200;
+	_numFlObject = 50;
+
+	_shadowPaletteSize = 256;
+
+	_shadowPalette = (byte *) calloc(_shadowPaletteSize, 1);	// FIXME - needs to be removed later
+	allocateArrays();
 }

Index: script_v6.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v6.cpp,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- script_v6.cpp	6 Mar 2003 21:46:20 -0000	1.71
+++ script_v6.cpp	7 Mar 2003 21:38:45 -0000	1.72
@@ -2808,36 +2808,25 @@
 	push(readVar(0));
 }
 
-static void sub_FEE_78D2(int num, int &arg1, int &arg2) {
-	byte *ptr = g_scumm->getResourceAddress(rtString, num);
-	if (g_scumm->_features & GF_AFTER_V7) {
-		arg1 = READ_LE_UINT32(ptr + 8);
-		arg2 = READ_LE_UINT32(ptr + 4);
-	} else {
-		arg1 = READ_LE_UINT16(ptr + 4);
-		arg2 = READ_LE_UINT16(ptr + 2);
-	}
-}
-
-static void sub_FEE_7822(int num, int arg1, int arg2) {
-	int var_C = arg2 - arg1;
-	int count = var_C * 2;
+void Scumm_v6::shuffleArray(int num, int minIdx, int maxIdx) {
+	int range = maxIdx - minIdx;
+	int count = range * 2;
 
-	if (count-- == 0)
-		return;
-	
-	do {
-		int cx = var_C + 1;
-		int rand1 = (rand() % cx) + arg1;
-		int rand2 = (rand() % cx) + arg1;
-		g_scumm->_vars[g_scumm->VAR_V6_RANDOM_NR] = rand2;
-		g_scumm->writeArray(num, 0, rand1, g_scumm->readArray(num, 0, rand1));
-		g_scumm->writeArray(num, 0, rand2, g_scumm->readArray(num, 0, rand2));
-	} while (--count);
+	while (count--) {
+		int rand1 = _rnd.getRandomNumber(range) + minIdx;
+		int rand2 = _rnd.getRandomNumber(range) + minIdx;
+		_vars[VAR_V6_RANDOM_NR] = rand2;
+		
+		// FIXME - uhm this seems wrong. It replaces item rand1 with itself
+		// It would seem more logical if we first read elements rand1 and rand2,
+		// then swapped them. Assembler analysis, anybody?
+		writeArray(num, 0, rand1, readArray(num, 0, rand1));
+		writeArray(num, 0, rand2, readArray(num, 0, rand2));
+	}
 }
 
 void Scumm_v6::o6_shuffle() {
-	sub_FEE_7822(fetchScriptWord(), pop(), pop());
+	shuffleArray(fetchScriptWord(), pop(), pop());
 }
 
 void Scumm_v6::o6_pickVarRandom() {
@@ -2857,18 +2846,26 @@
 			} while (++counter < num);
 		}
 
-		sub_FEE_7822(value, 1, num);
+		shuffleArray(value, 1, num);
 		writeArray(value, 0, 0, 2);
 		push(readArray(value, 0, 1));
 		return;
 	}
 
 	num = readArray(value, 0, 0);
-	sub_FEE_78D2(readVar(value), var_C, var_A);
+
+	byte *ptr = getResourceAddress(rtString, num);
+	if (_features & GF_AFTER_V7) {
+		var_A = READ_LE_UINT32(ptr + 4);
+		var_C = READ_LE_UINT32(ptr + 8);
+	} else {
+		var_A = READ_LE_UINT16(ptr + 2);
+		var_C = READ_LE_UINT16(ptr + 4);
+	}
 
 	if ((var_A - 1) < num) {
 		int16 var_2 = readArray(value, 0, num - 1);
-		sub_FEE_7822(value, 1, var_A - 1);
+		shuffleArray(value, 1, var_A - 1);
 		if (readArray(value, 0, 1) == var_2) {
 			num = 2;
 		} else {

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.156
retrieving revision 1.157
diff -u -d -r1.156 -r1.157
--- scumm.h	7 Mar 2003 15:37:58 -0000	1.156
+++ scumm.h	7 Mar 2003 21:38:45 -0000	1.157
@@ -564,41 +564,48 @@
 	void askForDisk(const char *filename, int disknum);
 	bool openResourceFile(const char *filename);
 
-public:
+protected:
 	void loadPtrToResource(int type, int i, byte *ptr);
 	void readResTypeList(int id, uint32 tag, const char *name);
 	char *resTypeFromId(int id);
 	void allocResTypeData(int id, uint32 tag, int num, const char *name, int mode);
 	byte *createResource(int type, int index, uint32 size);
+	int loadResource(int type, int i);
 	void nukeResource(int type, int i);	
+
+public:
+	bool isGlobInMemory(int type, int index);
+	bool isResourceLoaded(int type, int index);
 	byte *getResourceAddress(int type, int i);
 	byte *getStringAddress(int i);
 	byte *getStringAddressVar(int i);
 	void ensureResourceLoaded(int type, int i);
-	int loadResource(int type, int i);
 	int getResourceRoomNr(int type, int index);
+
+protected:
 	int readSoundResource(int type, int index);
 	int readSoundResourceSmallHeader(int type, int index);
 	void setResourceCounter(int type, int index, byte flag);
 	bool validateResource(const char *str, int type, int index);
 	void increaseResourceCounter();
 	bool isResourceInUse(int type, int i);
-	bool isResourceLoaded(int type, int index);
 	void initRoomSubBlocks();
 	void clearRoomObjects();
 	void loadRoomObjects();
 	void loadRoomObjectsSmall();
 	void readArrayFromIndexFile();
-	void readMAXS();
-	bool isGlobInMemory(int type, int index);
+	virtual void readMAXS();
 	virtual void readIndexFile();
 	virtual void loadCharset(int i);
 	void nukeCharset(int i);
 
-	int _lastLoadedRoom, _roomResource;
+	int _lastLoadedRoom;
+public:
+	int _roomResource;  // FIXME - should be protected but Sound::pauseSounds accesses it
 	byte *findResourceData(uint32 tag, byte *ptr);
 	int getResourceDataSize(byte *ptr);
 
+protected:
 	int getArrayId();
 	void nukeArray(int a);
 	int defineArray(int a, int b, int c, int d);
@@ -611,7 +618,7 @@
 	void destroy();
 	void dumpResource(char *tag, int index, byte *ptr);
 
-
+public:
 	/* Should be in Object class */
 	byte OF_OWNER_ROOM;
 	int getInventorySlot();

Index: sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/sound.cpp,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -d -r1.94 -r1.95
--- sound.cpp	7 Mar 2003 07:49:10 -0000	1.94
+++ sound.cpp	7 Mar 2003 21:38:46 -0000	1.95
@@ -759,6 +759,8 @@
 		se->pause(pause);
 
 	// Don't pause sounds if the game isn't active
+	// FIXME - this is quite a nasty hack, replace with something cleaner, and w/o
+	// having to access member vars directly!
 	if (!_scumm->_roomResource)
 		return;
 





More information about the Scummvm-git-logs mailing list