[Scummvm-cvs-logs] CVS: scummvm/scumm gfx.cpp,1.3,1.4 resource.cpp,1.2,1.3 saveload.cpp,1.5,1.6 script_v1.cpp,1.3,1.4 script_v2.cpp,1.3,1.4 scumm.h,1.6,1.7 scummvm.cpp,1.5,1.6

Max Horn fingolfin at users.sourceforge.net
Thu Aug 29 13:02:05 CEST 2002


Update of /cvsroot/scummvm/scummvm/scumm
In directory usw-pr-cvs1:/tmp/cvs-serv11767/scumm

Modified Files:
	gfx.cpp resource.cpp saveload.cpp script_v1.cpp script_v2.cpp 
	scumm.h scummvm.cpp 
Log Message:
some cleanup/refactoring

Index: gfx.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/gfx.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- gfx.cpp	25 Aug 2002 18:40:23 -0000	1.3
+++ gfx.cpp	29 Aug 2002 20:01:25 -0000	1.4
@@ -2370,6 +2370,88 @@
 	}
 }
 
+void Scumm::palManipulateInit(int start, int end, int d, int time, int e)
+{
+	// TODO - correctly implement this function (see also bug #558245)
+	//
+	// There are two known places (both in FOA) where this function is being
+	// called. The fist is during the FOA extro, to change the color to match
+	// the sinking sun. The following three calls (with some pauses between them)
+	// are issued:
+	//
+	// palManipulateInit(16, 190, 32, 180, 1)
+	// palManipulateInit(16, 190, 32, 1, 1)
+	// palManipulateInit(16, 190, 32, 800, 1)
+	//
+	// The second place is in the Inner Sanctum after you used the stone discs,
+	// here it is used to give the scene a "lava glow".
+	//
+	// palManipulateInit(32, 65, 46, 20, 1): not implemented!
+	//
+	// The first two parameters seem to specify a palette range (as the colors
+	// from 16 to 190 are the ones that make up water & sky).
+	//
+	// Maybe the change has to be done over a period of time, possibly specified
+	// by the second last parameter - between call 1 and 2, about 17-18 seconds
+	// seem to pass (well using get_msecs, I measured 17155 ms, 17613 ms, 17815 ms).
+	//
+	// No clue about the third and fifth parameter right now, they just always
+	// are 32 and 1 - possibly finding another example of this function being
+	// used would help a lot. Also, I can't currently compare it with the original,
+	// doing that (and possibly, taking screenshots of it for analysis!) would 
+	// help a lot.
+	
+	warning("palManipulateInit(%d, %d, %d, %d, %d): not implemented", start, end, d, time, e);
+
+	// FIXME - is this right?
+	// It seems we already have had this "palManipulate" and "moveMemInPalRes"
+	// functions, only they were never used (somebody disassembled them and
+	// didn't disassmble the functions using them?).
+	//
+	// I 
+	_palManipStart = start;
+	_palManipEnd = end;
+	//_palManipCounter = ?
+	
+	{
+		int redScale = 0xFF;
+		int greenScale = 0xFF - d;
+		int blueScale = 0xFF - d;
+		byte *cptr;
+		byte *cur;
+		int num;
+		int color;
+	
+		cptr = _currentPalette + start * 3;
+		cur = _currentPalette + start * 3;
+		num = end - start + 1;
+
+		do {
+			color = *cptr++;
+			if (redScale != 0xFF)
+				color = color * redScale / 0xFF;
+			if (color > 255)
+				color = 255;
+			*cur++ = color;
+
+			color = *cptr++;
+			if (greenScale != 0xFF)
+				color = color * greenScale / 0xFF;
+			if (color > 255)
+				color = 255;
+			*cur++ = color;
+
+			color = *cptr++;
+			if (blueScale != 0xFF)
+				color = color * blueScale / 0xFF;
+			if (color > 255)
+				color = 255;
+			*cur++ = color;
+		} while (--num);
+		setDirtyColors(start, end);
+	}
+}
+
 void Scumm::palManipulate()
 {
 	byte *srcptr, *destptr;
@@ -2378,8 +2460,12 @@
 
 	if (!_palManipCounter)
 		return;
+	
 	srcptr = getResourceAddress(rtTemp, 4) + _palManipStart * 6;
 	destptr = getResourceAddress(rtTemp, 5) + _palManipStart * 6;
+	if (!srcptr || !destptr)
+		return;
+	
 	pal = _currentPalette + _palManipStart * 3;
 
 	i = _palManipStart;
@@ -2402,9 +2488,69 @@
 		i++;
 	}
 	setDirtyColors(_palManipStart, _palManipEnd);
-	if (!--_palManipCounter) {
+	_palManipCounter--;
+	if (!_palManipCounter) {
 		nukeResource(rtTemp, 4);
 		nukeResource(rtTemp, 5);
+	}
+}
+
+void Scumm::unkRoomFunc3(int unk1, int unk2, int rfact, int gfact, int bfact)
+{
+	byte *pal = _currentPalette;
+	byte *table = _shadowPalette;
+	int i;
+
+	warning("unkRoomFunc3(%d,%d,%d,%d,%d): not fully implemented", unk1, unk2, rfact, gfact, bfact);
+
+	// TODO - correctly implement this function (see also patch #588501)
+	//
+	// Some "typical" examples of how this function is being invoked in real life:
+	//
+	// 1)
+	// unkRoomFunc3(16, 255, 200, 200, 200)
+	//
+	// FOA: Sets up the colors for the boat and submarine shadows in the
+	// diving scene. Are the shadows too light? Maybe unk1 is used to
+	// darken the colors?
+	//
+	// 2)
+	// unkRoomFunc3(0, 255, 700, 700, 700)
+	//
+	// FOA: Sets up the colors for the subway car headlight when it first
+	// goes on. This seems to work ok.
+	//
+	// 3)
+	// unkRoomFunc3(160, 191, 300, 300, 300)
+	// unkRoomFunc3(160, 191, 289, 289, 289)
+	//     ...
+	// unkRoomFunc3(160, 191, 14, 14, 14)
+	// unkRoomFunc3(160, 191, 3, 3, 3)
+	//
+	// 4)
+	// FOA: Sets up the colors for the subway car headlight for the later
+	// half of the trip, where it fades out. This currently doesn't work
+	// at all. The colors are too dark to be brightened. At first I thought
+	// unk1 and unk2 were used to tell which color interval to manipulate,
+	// but as far as I can tell the colors 160-191 aren't used at all to
+	// draw the light, that can't be it. Apparently unk1 and/or unk2 are
+	// used to brighten the colors.
+	//
+	// 5)
+	// unkRoomFunc3(16,255,500,500,500)
+	//
+	// FOA: Used in the Inner Sanctum after you activated the machine using the
+	// stone discs (briefly before the Nazis arrive). No idea at all if it is
+	// right here; also note that palManipulateInit() is called at the same time.
+	//
+	//
+	
+	for (i = 0; i <= 255; i++) {
+		int r = (int) (*pal++ * rfact) >> 8;
+		int g = (int) (*pal++ * gfact) >> 8;
+		int b = (int) (*pal++ * bfact) >> 8;
+
+		*table++ = remapPaletteColor(r, g, b, (uint) -1);
 	}
 }
 

Index: resource.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- resource.cpp	29 Aug 2002 16:57:43 -0000	1.2
+++ resource.cpp	29 Aug 2002 20:01:25 -0000	1.3
@@ -470,8 +470,8 @@
 	assert(no < (int)sizeof(_charsetData) / 16);
 	checkRange(_maxCharsets - 1, 1, no, "Loading illegal charset %d");
 
-//  ensureResourceLoaded(6, no);
-	ptr = getResourceAddress(6, no);
+//  ensureResourceLoaded(rtCharset, no);
+	ptr = getResourceAddress(rtCharset, no);
 
 	for (i = 0; i < 15; i++) {
 		_charsetData[no][i + 1] = ptr[i + 14];
@@ -537,54 +537,52 @@
 			return 0;
 	}
 
-	do {
-		for (i = 0; i < 5; i++) {
-			openRoom(roomNr);
-
-			fileSeek(_fileHandle, fileOffs + _fileOffset, SEEK_SET);
+	for (i = 0; i < 5; i++) {
+		openRoom(roomNr);
 
-			if (_features & GF_OLD_BUNDLE) {
-				size = fileReadWordLE();
-			} else if (_features & GF_SMALL_HEADER) {
-				if (!(_features & GF_SMALL_NAMES))
-					fileSeek(_fileHandle, 8, SEEK_CUR);
-				size = fileReadDwordLE();
-				tag = fileReadWordLE();
-				fileSeek(_fileHandle, -6, SEEK_CUR);
-			} else {
-				if (type == rtSound) {
-					fileReadDwordLE();
-					fileReadDwordLE();
-					return readSoundResource(type, idx);
-				}
+		fileSeek(_fileHandle, fileOffs + _fileOffset, SEEK_SET);
 
-				tag = fileReadDword();
+		if (_features & GF_OLD_BUNDLE) {
+			size = fileReadWordLE();
+		} else if (_features & GF_SMALL_HEADER) {
+			if (!(_features & GF_SMALL_NAMES))
+				fileSeek(_fileHandle, 8, SEEK_CUR);
+			size = fileReadDwordLE();
+			tag = fileReadWordLE();
+			fileSeek(_fileHandle, -6, SEEK_CUR);
+		} else {
+			if (type == rtSound) {
+				fileReadDwordLE();
+				fileReadDwordLE();
+				return readSoundResource(type, idx);
+			}
 
-				if (tag != res.tags[type]) {
-					error("%s %d not in room %d at %d+%d", res.name[type], type, roomNr, _fileOffset, fileOffs);
-				}
+			tag = fileReadDword();
 
-				size = fileReadDwordBE();
-				fileSeek(_fileHandle, -8, SEEK_CUR);
+			if (tag != res.tags[type]) {
+				error("%s %d not in room %d at %d+%d", res.name[type], type, roomNr, _fileOffset, fileOffs);
 			}
-			fileRead(_fileHandle, createResource(type, idx, size), size);
 
-			/* dump the resource */
+			size = fileReadDwordBE();
+			fileSeek(_fileHandle, -8, SEEK_CUR);
+		}
+		fileRead(_fileHandle, createResource(type, idx, size), size);
+
+		/* dump the resource */
 #ifdef DUMP_SCRIPTS
-			if (type == rtScript) {
-				dumpResource("script-", idx, getResourceAddress(rtScript, idx));
-			}
+		if (type == rtScript) {
+			dumpResource("script-", idx, getResourceAddress(rtScript, idx));
+		}
 #endif
 
-			if (!fileReadFailed(_fileHandle)) {
-				return 1;
-			}
-
-			nukeResource(type, idx);
+		if (!fileReadFailed(_fileHandle)) {
+			return 1;
 		}
 
-		error("Cannot read resource");
-	} while (1);
+		nukeResource(type, idx);
+	}
+
+	error("Cannot read resource");
 }
 
 int Scumm::readSoundResource(int type, int idx)
@@ -763,10 +761,9 @@
 {
 	byte *ptr;
 
-
 	CHECK_HEAP validateResource("getResourceAddress", type, idx);
 	if (!res.address[type]) {
-		debug(9, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
+		debug(1, "getResourceAddress(%s,%d), res.address[type] == NULL", resTypeFromId(type), idx);
 		return NULL;
 	}
 
@@ -774,9 +771,8 @@
 		ensureResourceLoaded(type, idx);
 	}
 
-
 	if (!(ptr = (byte *)res.address[type][idx])) {
-		debug(9, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
+		debug(1, "getResourceAddress(%s,%d) == NULL", resTypeFromId(type), idx);
 		return NULL;
 	}
 
@@ -857,9 +853,8 @@
 {
 	byte *ptr;
 
-
 	CHECK_HEAP if (!res.address[type])
-		  return;
+		return;
 
 	assert(idx >= 0 && idx < res.num[type]);
 
@@ -874,17 +869,14 @@
 
 byte *Scumm::findResourceData(uint32 tag, byte *ptr)
 {
-	if (_features & GF_SMALL_HEADER) {
+	if (_features & GF_SMALL_HEADER)
 		ptr = findResourceSmall(tag, ptr, 0);
-		if (ptr == NULL)
-			return NULL;
-		return ptr + 6;
-	}
+	else
+		ptr = findResource(tag, ptr, 0);
 
-	ptr = findResource(tag, ptr, 0);
 	if (ptr == NULL)
 		return NULL;
-	return ptr + 8;
+	return ptr + _resourceHeaderSize;
 }
 
 int Scumm::getResourceDataSize(byte *ptr)

Index: saveload.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/saveload.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- saveload.cpp	26 Aug 2002 16:47:14 -0000	1.5
+++ saveload.cpp	29 Aug 2002 20:01:26 -0000	1.6
@@ -337,6 +337,7 @@
 		MKLINE(Scumm, _EXCD_offs, sleUint32),
 		MKLINE(Scumm, _IM00_offs, sleUint32),
 		MKLINE(Scumm, _CLUT_offs, sleUint32),
+		/* XXX Remove _EPAL_offs next time format changes */
 		MKLINE(Scumm, _EPAL_offs, sleUint32),
 		MKLINE(Scumm, _PALS_offs, sleUint32),
 		MKLINE(Scumm, _curPalIndex, sleByte),
@@ -441,6 +442,7 @@
 		MKLINE(Scumm, _EXCD_offs, sleUint32),
 		MKLINE(Scumm, _IM00_offs, sleUint32),
 		MKLINE(Scumm, _CLUT_offs, sleUint32),
+		/* XXX Remove _EPAL_offs next time format changes */
 		MKLINE(Scumm, _EPAL_offs, sleUint32),
 		MKLINE(Scumm, _PALS_offs, sleUint32),
 		MKLINE(Scumm, _curPalIndex, sleByte),

Index: script_v1.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v1.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- script_v1.cpp	24 Aug 2002 21:32:16 -0000	1.3
+++ script_v1.cpp	29 Aug 2002 20:01:26 -0000	1.4
@@ -1899,6 +1899,7 @@
 			}
 			checkRange(256, 0, a, "o5_roomOps: 2: Illegal room color slot (%d)");
 			_currentPalette[a] = b;
+printf("palette change, %d -> %d\n", a, b);
 			_fullRedraw = 1;
 		} else {
 			error("room-color is no longer a valid command");
@@ -1919,6 +1920,7 @@
 				b = getVarOrDirectWord(0x40);
 			}
 			checkRange(256, 0, a, "o5_roomOps: 2: Illegal room color slot (%d)");
+printf("shadow palette change, %d -> %d\n", a, b);
 			_shadowPalette[b] = a;
 			setDirtyColors(b, b);
 		} else {
@@ -2049,7 +2051,7 @@
 		c = getVarOrDirectByte(0x40);
 		_opcode = fetchScriptByte();
 		d = getVarOrDirectByte(0x80);
-		palManipulate(b, c, a, d, 1);
+		palManipulateInit(b, c, a, d, 1);
 		break;
 
 	case 16:

Index: script_v2.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v2.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- script_v2.cpp	25 Aug 2002 11:35:13 -0000	1.3
+++ script_v2.cpp	29 Aug 2002 20:01:26 -0000	1.4
@@ -1878,7 +1878,7 @@
 		c = pop();
 		b = pop();
 		a = pop();
-		palManipulate(a, b, c, d, 1);
+		palManipulateInit(a, b, c, d, 1);
 		break;
 
 	case 187:										/* color cycle delay */

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- scumm.h	29 Aug 2002 16:57:43 -0000	1.6
+++ scumm.h	29 Aug 2002 20:01:26 -0000	1.7
@@ -461,8 +461,6 @@
 	byte _numObjectsInRoom;
 	int8 _userPut;
 	int _resourceHeaderSize;
-	void unkRoomFunc3(int a, int b, int c, int d, int e);
-	void palManipulate(int a, int b, int c, int d, int e);
 	void setScaleItem(int slot, int a, int b, int c, int d);
 	void clearClickedStatus();
 	void startManiac();
@@ -796,7 +794,9 @@
 	void swapPalColors(int a, int b);
 	void cyclePalette();
 	void stopCycle(int i);
+	void palManipulateInit(int a, int b, int c, int d, int e);
 	void palManipulate();
+	void unkRoomFunc3(int a, int b, int c, int d, int e);
 	int remapPaletteColor(int r, int g, int b, uint threshold);
 	void moveMemInPalRes(int start, int end, byte direction);
 	void setupShadowPalette(int slot, int rfact, int gfact, int bfact, int from, int to);

Index: scummvm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scummvm.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- scummvm.cpp	29 Aug 2002 16:57:43 -0000	1.5
+++ scummvm.cpp	29 Aug 2002 20:01:27 -0000	1.6
@@ -780,14 +780,13 @@
 		}
 	}
 
-	if (_features & GF_SMALL_HEADER)
-		ptr = findResourceSmall(MKID('EPAL'), roomptr);
-	else
-		ptr = findResource(MKID('EPAL'), roomptr);
-
-	if (ptr)
-		_EPAL_offs = ptr - roomptr;
-
+	// FIXME - we could simply always call findResourceData here, it will
+	// do the right thing even if GF_SMALL_HEADER is set. But then, we have
+	// to change setPaletteFromPtr() (easy). The problematic bit is save game
+	// compatibility - _CLUT_offs is stored in the save game after all.
+	// Of course we could just decide to not use _CLUT_offs anymore, and change
+	// setPaletteFromRes() to invoke findResourceData() each time
+	// (and also getPalettePtr()).
 	if (_features & GF_SMALL_HEADER)
 		ptr = findResourceSmall(MKID('CLUT'), roomptr);
 	else
@@ -806,13 +805,10 @@
 		}
 	}
 
-	if (_features & GF_SMALL_HEADER)
-		ptr = findResourceData(MKID('CYCL'), roomptr);
-	else
-		ptr = findResourceData(MKID('CYCL'), roomptr);
+	ptr = findResourceData(MKID('CYCL'), roomptr);
 
 	if (ptr)
-		initCycl(findResourceData(MKID('CYCL'), roomptr));
+		initCycl(ptr);
 
 	ptr = findResourceData(MKID('TRNS'), roomptr);
 	if (ptr)
@@ -895,125 +891,6 @@
 	int a = _keyPressed;
 	_keyPressed = 0;
 	return a;
-}
-
-void Scumm::unkRoomFunc3(int unk1, int unk2, int rfact, int gfact, int bfact)
-{
-	byte *pal = _currentPalette;
-	byte *table = _shadowPalette;
-	int i;
-
-	warning("unkRoomFunc3(%d,%d,%d,%d,%d): not fully implemented", unk1, unk2, rfact, gfact, bfact);
-
-	// TODO - correctly implement this function (see also patch #588501)
-	//
-	// Some "typical" examples of how this function is being invoked in real life:
-	//
-	// unkRoomFunc3(16, 255, 200, 200, 200)
-	//
-	// FOA: Sets up the colors for the boat and submarine shadows in the
-	// diving scene. Are the shadows too light? Maybe unk1 is used to
-	// darken the colors?
-	//
-	// unkRoomFunc3(0, 255, 700, 700, 700)
-	//
-	// FOA: Sets up the colors for the subway car headlight when it first
-	// goes on. This seems to work ok.
-	//
-	// unkRoomFunc3(160, 191, 300, 300, 300)
-	// unkRoomFunc3(160, 191, 289, 289, 289)
-	//     ...
-	// unkRoomFunc3(160, 191, 14, 14, 14)
-	// unkRoomFunc3(160, 191, 3, 3, 3)
-	//
-	// FOA: Sets up the colors for the subway car headlight for the later
-	// half of the trip, where it fades out. This currently doesn't work
-	// at all. The colors are too dark to be brightened. At first I thought
-	// unk1 and unk2 were used to tell which color interval to manipulate,
-	// but as far as I can tell the colors 160-191 aren't used at all to
-	// draw the light, that can't be it. Apparently unk1 and/or unk2 are
-	// used to brighten the colors.
-	
-	for (i = 0; i <= 255; i++) {
-		int r = (int) (*pal++ * rfact) >> 8;
-		int g = (int) (*pal++ * gfact) >> 8;
-		int b = (int) (*pal++ * bfact) >> 8;
-
-		*table++ = remapPaletteColor(r, g, b, (uint) -1);
-	}
-}
-
-
-void Scumm::palManipulate(int start, int end, int d, int time, int e)
-{
-	// TODO - correctly implement this function (see also bug #558245)
-	//
-	// The only place I know of where this function is being called is in the 
-	// FOA extro, to change the color to match the sinking sun. The following
-	// three calls (with some pauses between them) are issued:
-	//
-	// palManipulate(16, 190, 32, 180, 1)
-	// palManipulate(16, 190, 32, 1, 1)
-	// palManipulate(16, 190, 32, 800, 1)
-	//
-	// The first two parameters seem to specify a palette range (as the colors
-	// from 16 to 190 are the ones that make up water & sky).
-	//
-	// Maybe the change has to be done over a period of time, possibly specified
-	// by the second last parameter - between call 1 and 2, about 17-18 seconds
-	// seem to pass (well using get_msecs, I measured 17155 ms, 17613 ms, 17815 ms).
-	//
-	// No clue about the third and fifth parameter right now, they just always
-	// are 32 and 1 - possibly finding another example of this function being
-	// used would help a lot. Also, I can't currently compare it with the original,
-	// doing that (and possibly, taking screenshots of it for analysis!) would 
-	// help a lot.
-	
-	static int sys_time = 0;
-	int new_sys_time = _system->get_msecs();
-	
-	warning("palManipulate(%d, %d, %d, %d, %d): not implemented", start, end, d, time, e);
-	if (sys_time != 0)
-		printf("Time since last call: %d\n", new_sys_time-sys_time);
-	sys_time = new_sys_time;
-	
-	{
-		int redScale = 0xFF;
-		int greenScale = 0xFF - d;
-		int blueScale = 0xFF - d;
-		byte *cptr;
-		byte *cur;
-		int num;
-		int color;
-	
-		cptr = _currentPalette + start * 3;
-		cur = _currentPalette + start * 3;
-		num = end - start + 1;
-
-		do {
-			color = *cptr++;
-			if (redScale != 0xFF)
-				color = color * redScale / 0xFF;
-			if (color > 255)
-				color = 255;
-			*cur++ = color;
-
-			color = *cptr++;
-			if (greenScale != 0xFF)
-				color = color * greenScale / 0xFF;
-			if (color > 255)
-				color = 255;
-			*cur++ = color;
-
-			color = *cptr++;
-			if (blueScale != 0xFF)
-				color = color * blueScale / 0xFF;
-			if (color > 255)
-				color = 255;
-			*cur++ = color;
-		} while (--num);
-		setDirtyColors(start, end);
-	}
 }
 
 void Scumm::pauseGame(bool user)





More information about the Scummvm-git-logs mailing list