[Scummvm-cvs-logs] CVS: scummvm/scumm cursor.cpp,2.9,2.10 intern.h,2.177,2.178 object.cpp,1.176,1.177 resource_v7he.cpp,1.6,1.7 script_v5.cpp,1.258,1.259 script_v6.cpp,1.381,1.382 script_v7he.cpp,2.34,2.35 script_v8.cpp,2.268,2.269 scumm.cpp,1.131,1.132 scumm.h,1.445,1.446

Max Horn fingolfin at users.sourceforge.net
Sun Aug 22 16:39:05 CEST 2004


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

Modified Files:
	cursor.cpp intern.h object.cpp resource_v7he.cpp script_v5.cpp 
	script_v6.cpp script_v7he.cpp script_v8.cpp scumm.cpp scumm.h 
Log Message:
Cursor code cleanup

Index: cursor.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/cursor.cpp,v
retrieving revision 2.9
retrieving revision 2.10
diff -u -d -r2.9 -r2.10
--- cursor.cpp	14 Aug 2004 19:41:59 -0000	2.9
+++ cursor.cpp	22 Aug 2004 23:37:59 -0000	2.10
@@ -21,6 +21,8 @@
 
 #include "stdafx.h"
 #include "scumm/bomp.h"
+#include "scumm/intern.h"
+#include "scumm/object.h"
 #include "scumm/scumm.h"
 
 
@@ -66,16 +68,48 @@
 	8, 7, //zak256
 };
 
-
 void ScummEngine::setupCursor() {
 	_cursor.animate = 1;
-	if (_gameId == GID_TENTACLE && res.roomno[rtRoom][60]) {
-		// HACK: For DOTT we manually set the default cursor. See also bug #786994
-		setCursorImg(697, 60, 1);
-		makeCursorColorTransparent(1);
+}
+
+void ScummEngine::animateCursor() {
+	if (_cursor.animate) {
+		if (!(_cursor.animateIndex & 0x1)) {
+			setBuiltinCursor((_cursor.animateIndex >> 1) & 3);
+		}
+		_cursor.animateIndex++;
 	}
 }
 
+void ScummEngine::setCursor(int cursor) {
+	if (cursor >= 0 && cursor <= 3)
+		_currentCursor = cursor;
+	else
+		warning("setCursor(%d)", cursor);
+}
+
+void ScummEngine::setCursorHotspot(int x, int y) {
+	_cursor.hotspotX = x;
+	_cursor.hotspotY = y;
+}
+
+void ScummEngine::setCursorTransparency(int a) {
+	int i, size;
+
+	size = _cursor.width * _cursor.height;
+
+	for (i = 0; i < size; i++)
+		if (_grabbedCursor[i] == (byte)a)
+			_grabbedCursor[i] = 0xFF;
+
+	updateCursor();
+}
+
+void ScummEngine::updateCursor() {
+	_system->setMouseCursor(_grabbedCursor, _cursor.width, _cursor.height,
+							_cursor.hotspotX, _cursor.hotspotY);
+}
+
 void ScummEngine::grabCursor(int x, int y, int w, int h) {
 	VirtScreen *vs = findVirtScreen(y);
 
@@ -84,11 +118,10 @@
 		return;
 	}
 
-	grabCursor((byte *)vs->pixels + (y - vs->topline) * vs->pitch + x, w, h);
-
+	setCursorFromBuffer((byte *)vs->pixels + (y - vs->topline) * vs->pitch + x, w, h, vs->pitch);
 }
 
-void ScummEngine::grabCursor(byte *ptr, int width, int height) {
+void ScummEngine::setCursorFromBuffer(byte *ptr, int width, int height, int pitch) {
 	uint size;
 	byte *dst;
 
@@ -110,7 +143,54 @@
 	updateCursor();
 }
 
-void ScummEngine::useIm01Cursor(const byte *im, int w, int h) {
+void ScummEngine_v6::setCursorFromImg(uint img, uint room, uint imgindex) {
+	int w, h;
+	const byte *dataptr, *bomp;
+	uint32 size;
+	FindObjectInRoom foir;
+
+	if (room == (uint) - 1)
+		room = getObjectRoom(img);
+
+	findObjectInRoom(&foir, foCodeHeader | foImageHeader | foCheckAlreadyLoaded, img, room);
+
+	if (_version == 8) {
+		setCursorHotspot(READ_LE_UINT32(&foir.imhd->v8.hotspot[0].x),
+		                  READ_LE_UINT32(&foir.imhd->v8.hotspot[0].y));
+		w = READ_LE_UINT32(&foir.imhd->v8.width) / 8;
+		h = READ_LE_UINT32(&foir.imhd->v8.height) / 8;
+	} else if (_version == 7) {
+		setCursorHotspot(READ_LE_UINT16(&foir.imhd->v7.hotspot[0].x),
+		                  READ_LE_UINT16(&foir.imhd->v7.hotspot[0].y));
+		w = READ_LE_UINT16(&foir.imhd->v7.width) / 8;
+		h = READ_LE_UINT16(&foir.imhd->v7.height) / 8;
+	} else {
+		if (!(_features & GF_HUMONGOUS))
+			setCursorHotspot(READ_LE_UINT16(&foir.imhd->old.hotspot[0].x),
+		        	          READ_LE_UINT16(&foir.imhd->old.hotspot[0].y));
+		w = READ_LE_UINT16(&foir.cdhd->v6.w) / 8;
+		h = READ_LE_UINT16(&foir.cdhd->v6.h) / 8;
+	}
+
+	dataptr = getObjectImage(foir.obim, imgindex);
+	assert(dataptr);
+	if (_version == 8) {
+		bomp = dataptr;
+	} else {
+		size = READ_BE_UINT32(dataptr + 4);
+		if (size > sizeof(_grabbedCursor))
+			error("setCursorFromImg: Cursor image too large");
+		
+		bomp = findResource(MKID('BOMP'), dataptr);
+	}
+
+	if (bomp != NULL)
+		useBompCursor(bomp, w, h);
+	else
+		useIm01Cursor(dataptr, w, h);
+}
+
+void ScummEngine_v6::useIm01Cursor(const byte *im, int w, int h) {
 	VirtScreen *vs = &virtscr[0];
 	byte *buf, *dst;
 	const byte *src;
@@ -139,7 +219,7 @@
 	gdi.enableZBuffer();
 
 	// Grab the data we just drew and setup the cursor with it
-	grabCursor(vs->getPixels(0, 0), w, h);
+	setCursorFromBuffer(vs->getPixels(0, 0), w, h, vs->pitch);
 
 	// Restore the screen content
 	src = buf;
@@ -154,33 +234,7 @@
 	free(buf);
 }
 
-void ScummEngine::setCursor(int cursor) {
-	if (cursor >= 0 && cursor <= 3)
-		_currentCursor = cursor;
-	else
-		warning("setCursor(%d)", cursor);
-}
-
-void ScummEngine::setCursorHotspot(int x, int y) {
-	_cursor.hotspotX = x;
-	_cursor.hotspotY = y;
-}
-
-void ScummEngine::updateCursor() {
-	_system->setMouseCursor(_grabbedCursor, _cursor.width, _cursor.height,
-							_cursor.hotspotX, _cursor.hotspotY);
-}
-
-void ScummEngine::animateCursor() {
-	if (_cursor.animate) {
-		if (!(_cursor.animateIndex & 0x1)) {
-			decompressDefaultCursor((_cursor.animateIndex >> 1) & 3);
-		}
-		_cursor.animateIndex++;
-	}
-}
-
-void ScummEngine::useBompCursor(const byte *im, int width, int height) {
+void ScummEngine_v6::useBompCursor(const byte *im, int width, int height) {
 	uint size;
 
 	width *= 8;
@@ -205,7 +259,7 @@
 	updateCursor();
 }
 
-void ScummEngine::decompressDefaultCursor(int idx) {
+void ScummEngine::setBuiltinCursor(int idx) {
 	int i, j;
 	byte color;
 
@@ -217,6 +271,9 @@
 		color = default_cursor_colors[idx];
 
 	// FIXME: None of the stock cursors are right for Loom. Why is that?
+	// Fingolfing says: because it sets different cursor shapes --
+	// check the SO_CURSOR_IMAGE opcode in script_v5.cpp; if we implement
+	// that, this problem should be gone...
 
 	if (_gameId == GID_LOOM || _gameId == GID_LOOM256) {
 		int w = 0;
@@ -300,32 +357,4 @@
 	updateCursor();
 }
 
-void ScummEngine::makeCursorColorTransparent(int a) {
-	int i, size;
-
-	size = _cursor.width * _cursor.height;
-
-	for (i = 0; i < size; i++)
-		if (_grabbedCursor[i] == (byte)a)
-			_grabbedCursor[i] = 0xFF;
-
-	updateCursor();
-}
-
-void ScummEngine::grabCursorFromBuffer(byte *ptr, int width, int height) {
-	uint size;
-
-	size = width * height;
-	if (size > sizeof(_grabbedCursor))
-		error("grabCursor: grabbed cursor too big");
-
-	_cursor.width = width;
-	_cursor.height = height;
-	_cursor.animate = 0;
-
-	memcpy(_grabbedCursor, ptr, width * height);
-
-	updateCursor();
-}
-
 } // End of namespace Scumm

Index: intern.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/intern.h,v
retrieving revision 2.177
retrieving revision 2.178
diff -u -d -r2.177 -r2.178
--- intern.h	14 Aug 2004 15:14:00 -0000	2.177
+++ intern.h	22 Aug 2004 23:37:59 -0000	2.178
@@ -331,6 +331,8 @@
 public:
 	ScummEngine_v6(GameDetector *detector, OSystem *syst, const ScummGameSettings &gs);
 
+	virtual void scummInit();
+
 protected:
 	virtual void setupOpcodes();
 	virtual void executeOpcode(byte i);
@@ -354,6 +356,10 @@
 
 	void shuffleArray(int num, int minIdx, int maxIdx);
 
+	void setCursorFromImg(uint img, uint room, uint imgindex);
+	void useIm01Cursor(const byte *im, int w, int h);
+	void useBompCursor(const byte *im, int w, int h);
+
 	/* Version 6 script opcodes */
 	void o6_setBlastObjectWindow();
 	void o6_pushByte();

Index: object.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/object.cpp,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- object.cpp	14 Aug 2004 19:41:59 -0000	1.176
+++ object.cpp	22 Aug 2004 23:37:59 -0000	1.177
@@ -1366,54 +1366,6 @@
 	return getDist(x, y, x2, y2) * 0xFF / ((i + j) / 2);
 }
 
-void ScummEngine::setCursorImg(uint img, uint room, uint imgindex) {
-	int w, h;
-	const byte *dataptr, *bomp;
-	uint32 size;
-	FindObjectInRoom foir;
-
-	if (room == (uint) - 1)
-		room = getObjectRoom(img);
-
-	findObjectInRoom(&foir, foCodeHeader | foImageHeader | foCheckAlreadyLoaded, img, room);
-
-	if (_version == 8) {
-		setCursorHotspot(READ_LE_UINT32(&foir.imhd->v8.hotspot[0].x),
-		                  READ_LE_UINT32(&foir.imhd->v8.hotspot[0].y));
-		w = READ_LE_UINT32(&foir.imhd->v8.width) / 8;
-		h = READ_LE_UINT32(&foir.imhd->v8.height) / 8;
-	} else if (_version == 7) {
-		setCursorHotspot(READ_LE_UINT16(&foir.imhd->v7.hotspot[0].x),
-		                  READ_LE_UINT16(&foir.imhd->v7.hotspot[0].y));
-		w = READ_LE_UINT16(&foir.imhd->v7.width) / 8;
-		h = READ_LE_UINT16(&foir.imhd->v7.height) / 8;
-	} else {
-		if (!(_features & GF_HUMONGOUS))
-			setCursorHotspot(READ_LE_UINT16(&foir.imhd->old.hotspot[0].x),
-		        	          READ_LE_UINT16(&foir.imhd->old.hotspot[0].y));
-		w = READ_LE_UINT16(&foir.cdhd->v6.w) / 8;
-		h = READ_LE_UINT16(&foir.cdhd->v6.h) / 8;
-	}
-
-	dataptr = getObjectImage(foir.obim, imgindex);
-	assert(dataptr);
-	if (_version == 8) {
-		bomp = dataptr;
-	} else {
-		size = READ_BE_UINT32(dataptr + 4);
-		if (size > sizeof(_grabbedCursor))
-			error("setCursorImg: Cursor image too large");
-		
-		bomp = findResource(MKID('BOMP'), dataptr);
-	}
-
-	if (bomp != NULL)
-		useBompCursor(bomp, w, h);
-	else
-		useIm01Cursor(dataptr, w, h);
-
-}
-
 void ScummEngine::nukeFlObjects(int min, int max) {
 	ObjectData *od;
 	int i;

Index: resource_v7he.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/resource_v7he.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- resource_v7he.cpp	13 Jul 2004 10:45:47 -0000	1.6
+++ resource_v7he.cpp	22 Aug 2004 23:37:59 -0000	1.7
@@ -67,7 +67,7 @@
 				 &keycolor);
 
 	_vm->setCursorHotspot(hotspot_x, hotspot_y);
-	_vm->grabCursorFromBuffer(cursor, w, h);
+	_vm->setCursorFromBuffer(cursor, w, h, w);
 	free(cursorRes);
 	free(cursor);
 }

Index: script_v5.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v5.cpp,v
retrieving revision 1.258
retrieving revision 1.259
diff -u -d -r1.258 -r1.259
--- script_v5.cpp	22 Aug 2004 11:33:11 -0000	1.258
+++ script_v5.cpp	22 Aug 2004 23:37:59 -0000	1.259
@@ -675,15 +675,14 @@
 		_userPut--;
 		break;
 	case 10:		// SO_CURSOR_IMAGE
-		i = getVarOrDirectByte(PARAM_1);
-		j = getVarOrDirectByte(PARAM_2);
-		// cursor image in both Looms is based on image from charset
-		// omit for now.
-		// FIXME: Actually: is this opcode ever called by a non-Loom game?
-		// Which V3-V5 game besides Loom makes use of custom cursors, ever?
+		i = getVarOrDirectByte(PARAM_1);	// Cursor number
+		j = getVarOrDirectByte(PARAM_2);	// Charset letter to use
+		// Cursor image in both Looms are based on images from charset.
+		// For now we don't handle them.
 		if (_gameId != GID_LOOM && _gameId != GID_LOOM256) {
-			warning("setCursorImg called - tell Fingolfin where you saw this!");
-			setCursorImg(i, j, 1);
+			// FIXME: Actually: is this opcode ever called by a non-Loom game?
+			// Which V3-V5 game besides Loom makes use of custom cursors, ever?
+			warning("V3--V5 SO_CURSOR_IMAGE(%d,%d) called - tell Fingolfin where you saw this!", i, j);
 		}
 		break;
 	case 11:		// SO_CURSOR_HOTSPOT

Index: script_v6.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v6.cpp,v
retrieving revision 1.381
retrieving revision 1.382
diff -u -d -r1.381 -r1.382
--- script_v6.cpp	22 Aug 2004 15:02:53 -0000	1.381
+++ script_v6.cpp	22 Aug 2004 23:38:00 -0000	1.382
@@ -976,7 +976,7 @@
 	case 0x99: 		// SO_CURSOR_IMAGE Set cursor image
 		{
 			int room, obj = popRoomAndObj(&room);
-			setCursorImg(obj, room, 1);
+			setCursorFromImg(obj, room, 1);
 			break;
 		}
 	case 0x9A:		// SO_CURSOR_HOTSPOT Set cursor hotspot
@@ -992,7 +992,7 @@
 			_charsetColorMap[i] = _charsetData[_string[1]._default.charset][i] = (unsigned char)args[i];
 		break;
 	case 0xD6:		// SO_CURSOR_TRANSPARENT Set cursor transparent color
-		makeCursorColorTransparent(pop());
+		setCursorTransparency(pop());
 		break;
 	default:
 		error("o6_cursorCommand: default case %x", subOp);
@@ -2567,7 +2567,7 @@
 			}
 			break;
 		case 12:
-			setCursorImg(args[1], (uint) - 1, args[2]);
+			setCursorFromImg(args[1], (uint) - 1, args[2]);
 			break;
 		case 13:
 			derefActor(args[1], "o6_kernelSetFunctions:13")->remapActorPalette(args[2], args[3], args[4], -1);

Index: script_v7he.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v7he.cpp,v
retrieving revision 2.34
retrieving revision 2.35
diff -u -d -r2.34 -r2.35
--- script_v7he.cpp	22 Aug 2004 09:47:12 -0000	2.34
+++ script_v7he.cpp	22 Aug 2004 23:38:00 -0000	2.35
@@ -749,7 +749,7 @@
 			_charsetColorMap[i] = _charsetData[_string[1]._default.charset][i] = (unsigned char)args[i];
 		break;
 	case 0xD6:		// SO_CURSOR_TRANSPARENT Set cursor transparent color
-		makeCursorColorTransparent(pop());
+		setCursorTransparency(pop());
 		break;
 	default:
 		error("o6_cursorCommand: default case %x", subOp);

Index: script_v8.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/script_v8.cpp,v
retrieving revision 2.268
retrieving revision 2.269
diff -u -d -r2.268 -r2.269
--- script_v8.cpp	22 Aug 2004 09:30:08 -0000	2.268
+++ script_v8.cpp	22 Aug 2004 23:38:00 -0000	2.269
@@ -730,7 +730,7 @@
 			int idx = pop();
 			int room, obj;
 			obj = popRoomAndObj(&room);
-			setCursorImg(obj, room, idx);
+			setCursorFromImg(obj, room, idx);
 		}
 		break;
 	case 0xE5:		// SO_CURSOR_HOTSPOT Set cursor hotspot
@@ -738,7 +738,7 @@
 		setCursorHotspot(pop(), a);
 		break;
 	case 0xE6:		// SO_CURSOR_TRANSPARENT Set cursor transparent color
-		makeCursorColorTransparent(pop());
+		setCursorTransparency(pop());
 		break;
 	case 0xE7: {	// SO_CHARSET_SET
 		int charset = pop();

Index: scumm.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.cpp,v
retrieving revision 1.131
retrieving revision 1.132
diff -u -d -r1.131 -r1.132
--- scumm.cpp	22 Aug 2004 08:59:33 -0000	1.131
+++ scumm.cpp	22 Aug 2004 23:38:00 -0000	1.132
@@ -1245,7 +1245,7 @@
 		_flashlight.buffer = NULL;
 	}
 
-	// HACK curcor hotspot is wrong
+	// HACK cursor hotspot is wrong
 	// Original games used 
 	// setCursorHotspot(8, 7);
 	if (_gameId == GID_FUNPACK)
@@ -1306,6 +1306,15 @@
 	_lastSaveTime = _system->get_msecs();
 }
 
+void ScummEngine_v6::scummInit() {
+	ScummEngine::scummInit();
+
+	if (_gameId == GID_TENTACLE && res.roomno[rtRoom][60]) {
+		// HACK: For DOTT we manually set the default cursor. See also bug #786994
+		setCursorFromImg(697, 60, 1);
+		setCursorTransparency(1);
+	}
+}
 
 void ScummEngine::initScummVars() {
 

Index: scumm.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/scumm/scumm.h,v
retrieving revision 1.445
retrieving revision 1.446
diff -u -d -r1.445 -r1.446
--- scumm.h	22 Aug 2004 09:38:18 -0000	1.445
+++ scumm.h	22 Aug 2004 23:38:00 -0000	1.446
@@ -374,7 +374,7 @@
 	virtual ~ScummEngine();
 
 	// Init functions
-	void scummInit();
+	virtual void scummInit();
 	void initScummVars();
 	virtual void setupScummVars();
 
@@ -937,17 +937,13 @@
 	void desaturatePalette(int hueScale, int satScale, int lightScale, int startColor, int endColor);
 
 	void setCursor(int cursor);
-	void setCursorImg(uint img, uint room, uint imgindex);
 	void setCursorHotspot(int x, int y);
-	void grabCursor(int x, int y, int w, int h);
-	void grabCursor(byte *ptr, int width, int height);
-	void grabCursorFromBuffer(byte *ptr, int width, int height);
-	void makeCursorColorTransparent(int a);
+	void setCursorTransparency(int a);
 	void setupCursor();
-	void decompressDefaultCursor(int index);
-	void useIm01Cursor(const byte *im, int w, int h);
-	void useBompCursor(const byte *im, int w, int h);
 
+	void setBuiltinCursor(int index);
+	void grabCursor(int x, int y, int w, int h);
+	void setCursorFromBuffer(byte *ptr, int width, int height, int pitch);
 
 public:
 	void markRectAsDirty(VirtScreenNumber virt, int left, int right, int top, int bottom, int dirtybit = 0);





More information about the Scummvm-git-logs mailing list