[Scummvm-cvs-logs] CVS: scummvm/kyra kyra.cpp,1.60,1.61 screen.cpp,1.15,1.16 screen.h,1.11,1.12

Johannes Schickel lordhoto at users.sourceforge.net
Sat Oct 22 06:04:09 CEST 2005


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

Modified Files:
	kyra.cpp screen.cpp screen.h 
Log Message:
Made the shape handling endian safe, also renamned some functions and
variables. (mostly the *Helper functions and decodeShape -> encodeShape)
But kept mouse handling.


Index: kyra.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/kyra.cpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- kyra.cpp	22 Oct 2005 00:24:07 -0000	1.60
+++ kyra.cpp	22 Oct 2005 12:59:16 -0000	1.61
@@ -957,15 +957,15 @@
 void KyraEngine::loadMouseShapes() {
 	loadBitmap("MOUSE.CPS", 3, 3, 0);
 	_screen->_curPage = 2;
-	_itemShapes[4] = _screen->decodeShape(0, 0, 8, 10, 0);
-	_itemShapes[5] = _screen->decodeShape(0, 0x17, 0x20, 7, 0);
-	_itemShapes[6] = _screen->decodeShape(0x50, 0x12, 0x10, 9, 0);
-	_itemShapes[7] = _screen->decodeShape(0x60, 0x12, 0x10, 11, 0);
-	_itemShapes[8] = _screen->decodeShape(0x70, 0x12, 0x10, 9, 0);
-	_itemShapes[9] = _screen->decodeShape(0x80, 0x12, 0x10, 11, 0);
-	_itemShapes[10] = _screen->decodeShape(0x90, 0x12, 0x10, 10, 0);
-	_itemShapes[10] = _screen->decodeShape(0x90, 0x12, 0x10, 10, 0);
-	_itemShapes[364] = _screen->decodeShape(0x28, 0, 0x10, 13, 0);
+	_itemShapes[4] = _screen->encodeShape(0, 0, 8, 10, 0);
+	_itemShapes[5] = _screen->encodeShape(0, 0x17, 0x20, 7, 0);
+	_itemShapes[6] = _screen->encodeShape(0x50, 0x12, 0x10, 9, 0);
+	_itemShapes[7] = _screen->encodeShape(0x60, 0x12, 0x10, 11, 0);
+	_itemShapes[8] = _screen->encodeShape(0x70, 0x12, 0x10, 9, 0);
+	_itemShapes[9] = _screen->encodeShape(0x80, 0x12, 0x10, 11, 0);
+	_itemShapes[10] = _screen->encodeShape(0x90, 0x12, 0x10, 10, 0);
+	_itemShapes[10] = _screen->encodeShape(0x90, 0x12, 0x10, 10, 0);
+	_itemShapes[364] = _screen->encodeShape(0x28, 0, 0x10, 13, 0);
 	_screen->setMouseCursor(1, 1, 0);
 	_screen->setMouseCursor(1, 1, _itemShapes[4]);
 	_screen->setShapePages(3, 5);

Index: screen.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/screen.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- screen.cpp	22 Oct 2005 00:24:07 -0000	1.15
+++ screen.cpp	22 Oct 2005 12:59:16 -0000	1.16
@@ -940,8 +940,8 @@
 	}
 }
 
-uint8 *Screen::decodeShape(int x, int y, int w, int h, int flags) {
-	debug(9, "decodeShape(%d, %d, %d, %d, %d)", x, y, w, h, flags);
+uint8 *Screen::encodeShape(int x, int y, int w, int h, int flags) {
+	debug(9, "encodeShape(%d, %d, %d, %d, %d)", x, y, w, h, flags);
 	uint8 *srcPtr = &_pagePtrs[_curPage][y * SCREEN_W + x];
 	int16 shapeSize = 0;
 	uint8 *tmp = srcPtr;
@@ -998,12 +998,12 @@
 	assert(newShape);
 	
 	byte *dst = newShape;
-	*(uint16*)dst = flags & 3; dst += 2;
+	WRITE_LE_UINT16(dst, (flags & 3)); dst += 2;
 	*dst = h; dst += 1;
-	*(uint16*)dst = w; dst += 2;
+	WRITE_LE_UINT16(dst, w); dst += 2;
 	*dst = h; dst += 1;
-	*(uint16*)dst = shapeSize; dst += 2;
-	*(uint16*)dst = shapeSize2; dst += 2;
+	WRITE_LE_UINT16(dst, shapeSize); dst += 2;
+	WRITE_LE_UINT16(dst, shapeSize2); dst += 2;
 
 	byte *src = srcPtr;
 	if (flags & 1) {
@@ -1063,7 +1063,9 @@
 	if (!(flags & 2)) {
 		if (shapeSize > _animBlockSize) {
 			dst = newShape;
-			*(uint16*)dst |= 2;
+			flags = READ_LE_UINT16(dst);
+			flags |= 2;
+			WRITE_LE_UINT16(dst, flags);
 		} else {
 			src = newShape;
 			if (flags & 1) {
@@ -1074,7 +1076,7 @@
 			dst = _animBlockPtr;
 			memcpy(dst, src, shapeSize2);
 			
-			int16 size = decodeShapeHelper(_animBlockPtr, shapePtrBackUp, shapeSize2);
+			int16 size = encodeShapeAndCalculateSize(_animBlockPtr, shapePtrBackUp, shapeSize2);
 			if (size > shapeSize2) {
 				shapeSize -= shapeSize2 - size;
 				newShape = (uint8*)realloc(newShape, shapeSize);
@@ -1084,12 +1086,14 @@
 				src = _animBlockPtr;
 				memcpy(dst, src, shapeSize2);
 				dst = newShape;
-				*(uint16*)dst |= 2;
+				flags = READ_LE_UINT16(dst);
+				flags |= 2;
+				WRITE_LE_UINT16(dst, flags);
 			}
 		}
 	}
 	
-	*(uint16*)(newShape + 6) = shapeSize;
+	WRITE_LE_UINT16((newShape + 6), shapeSize);
 	
 	if (flags & 1) {
 		dst = newShape + 10;
@@ -1100,11 +1104,11 @@
 	return newShape;
 }
 
-int16 Screen::decodeShapeHelper(uint8 *from, uint8 *to, int size_to) {
-	debug(9, "decodeShapeHelper(0x%X, 0x%X, %d)", from, to, size_to);
+int16 Screen::encodeShapeAndCalculateSize(uint8 *from, uint8 *to, int size_to) {
+	debug(9, "encodeShapeAndCalculateSize(0x%X, 0x%X, %d)", from, to, size_to);
 	byte *fromPtrEnd = from + size_to;
-	int var1 = 1;
-	byte *var7 = 0;
+	bool skipPixel = true;
+	byte *tempPtr = 0;
 	byte *toPtr = to;
 	byte *fromPtr = from;
 	byte *toPtr2 = to;
@@ -1115,7 +1119,7 @@
 	while (from < fromPtrEnd) {
 		byte *curToPtr = to;
 		to = fromPtr;
-		int var6 = 1;
+		int size = 1;
 		
 		while (true) {
 			byte curPixel = *from;
@@ -1128,13 +1132,13 @@
 						break;
 				}
 				--to;
-				uint16 size = (to - from);
-				if (size >= 0x41) {
-					var1 = 0;
+				uint16 diffSize = (to - from);
+				if (diffSize >= 0x41) {
+					skipPixel = false;
 					from = to;
 					to = curToPtr;
 					*to++ = 0xFE;
-					WRITE_LE_UINT16(to, size); to += 2;
+					WRITE_LE_UINT16(to, diffSize); to += 2;
 					*to++ = (size >> 8) & 0xFF;
 					curToPtr = to;
 					to = toBackUp;
@@ -1155,7 +1159,7 @@
 						break;
 				}
 				if (*to == curPixel) {
-					if (*(from+var6-1) == *(to+var6-2))
+					if (*(from+size-1) == *(to+size-2))
 						break;
 					
 					byte *fromBackUp = from;
@@ -1170,9 +1174,9 @@
 					from = fromBackUp;
 					int temp = to - toBackUp;
 					to = toBackUp;
-					if (temp >= var6) {
-						var6 = temp;
-						var7 = toBackUp - 1;
+					if (temp >= size) {
+						size = temp;
+						tempPtr = toBackUp - 1;
 					}
 					break;
 				} else {
@@ -1186,33 +1190,33 @@
 		}
 		
 		to = curToPtr;
-		if (var6 > 2) {
+		if (size > 2) {
 			uint16 word = 0;
-			if (var6 <= 0x0A) {
-				uint16 size = from - var7;
+			if (size <= 0x0A) {
+				uint16 diffSize = from - tempPtr;
 				if (size <= 0x0FFF) {
-					byte highByte = ((size & 0xFF00) >> 8) + (((var6 & 0xFF) - 3) << 4);
-					word = ((size & 0xFF) << 8) | highByte;
+					byte highByte = ((diffSize & 0xFF00) >> 8) + (((size & 0xFF) - 3) << 4);
+					word = ((diffSize & 0xFF) << 8) | highByte;
 					WRITE_LE_UINT16(to, word); to += 2;
-					from += var6;
-					var1 = 0;
+					from += size;
+					skipPixel = false;
 					continue;
 				}
 			}
 			
-			if (var6 > 0x40) {
+			if (size > 0x40) {
 				*to++ = 0xFF;
-				WRITE_LE_UINT16(to, var6); to += 2;
+				WRITE_LE_UINT16(to, size); to += 2;
 			} else {
-				*to++ = ((var6 & 0xFF) - 3) | 0xC0;
+				*to++ = ((size & 0xFF) - 3) | 0xC0;
 			}
 			
-			word = var7 - fromPtr;
+			word = tempPtr - fromPtr;
 			WRITE_LE_UINT16(to, word); to += 2;
-			from += var6;
-			var1 = 0;
+			from += size;
+			skipPixel = false;
 		} else {
-			if (var1 == 0) {
+			if (!skipPixel) {
 				toPtr2 = to;
 				*to++ = 0x80;
 			}
@@ -1224,7 +1228,7 @@
 			
 			++(*toPtr2);
 			*to++ = *from++;
-			var1 = 1;			
+			skipPixel = true;			
 		}
 	}
 	*to++ = 0x80;
@@ -1249,18 +1253,21 @@
 }
 
 void Screen::hideMouse() {
+	debug(9, "hideMouse()");
 	// if mouseDisabled
 	//	return
-	hideMouseHelper();
+	restoreMouseRect();
 }
 
 void Screen::showMouse() {
+	debug(9, "showMouse()");
 	// if mouseDisabled
 	//	return
-	showMouseHelper();
+	copyMouseToScreen();
 }
 
 void Screen::setShapePages(int page1, int page2) {
+	debug(9, "setShapePages(%d, %d)", page1, page2);
 	_shapePages[0] = _pagePtrs[page1];
 	_shapePages[1] = _pagePtrs[page2];
 }
@@ -1272,9 +1279,9 @@
 	// if mouseDisabled
 	//	return _mouseShape
 	
-	hideMouseHelper();
+	restoreMouseRect();
 	
-	int mouseRectSize = getRectSize(((*(uint16*)(shape + 3)) >> 3) + 2, shape[5]);
+	int mouseRectSize = getRectSize((READ_LE_UINT16(shape + 3) >> 3) + 2, shape[5]);
 	if (_mouseRectSize < mouseRectSize) {
 		free(_mouseRect);
 		_mouseRect = (uint8*)malloc(mouseRectSize << 3);
@@ -1282,8 +1289,8 @@
 		_mouseRectSize = mouseRectSize;
 	}
 	
-	int shapeSize = *(uint16*)(shape + 8) + 10;
-	if ((*(uint16*)shape) & 1)
+	int shapeSize = READ_LE_UINT16(shape + 8) + 10;
+	if (READ_LE_UINT16(shape) & 1)
 		shapeSize += 16;
 	
 	if (_mouseShapeSize < shapeSize) {
@@ -1296,15 +1303,15 @@
 	byte *dst = _mouseShape;
 	byte *src = shape;
 	
-	if (!((*(uint16*)shape) & 2)) {
+	if (!(READ_LE_UINT16(shape) & 2)) {
 		uint16 newFlags = 0;
-		newFlags = *(uint16*)src | 2; src += 2;
-		*(uint16*)dst = newFlags; dst += 2;
+		newFlags = READ_LE_UINT16(src) | 2; src += 2;
+		WRITE_LE_UINT16(dst, newFlags); dst += 2;
 		memcpy(dst, src, 6);
 		dst += 6;
 		src += 6;
-		int size = *(uint16*)src; src += 2;
-		*(uint16*)dst = size; dst += 2;
+		int size = READ_LE_UINT16(src); src += 2;
+		WRITE_LE_UINT16(dst, size); dst += 2;
 		if (newFlags & 1) {
 			memcpy(dst, src, 8);
 			dst += 16;
@@ -1313,20 +1320,21 @@
 		decodeFrame4(src, _animBlockPtr, size);
 		memcpy(dst, _animBlockPtr, size);
 	} else {
-		int size = *(uint16*)(shape + 6);
+		int size = READ_LE_UINT16(shape + 6);
 		memcpy(dst, src, size);
 	}
 	
 	_mouseXOffset = x; _mouseYOffset = y;
 	_mouseHeight = _mouseShape[5];
-	_mouseWidth = ((*(uint16*)(_mouseShape+3)) >> 3) + 2;
+	_mouseWidth = (READ_LE_UINT16(_mouseShape + 3) >> 3) + 2;
 	
-	showMouseHelper();
+	copyMouseToScreen();
 	
 	return _mouseShape;
 }
 
-void Screen::hideMouseHelper() {
+void Screen::restoreMouseRect() {
+	debug(9, "restoreMouseRect()");
 	// if disableMouse
 	//	return
 	
@@ -1339,7 +1347,8 @@
 	// ++mouseUnk
 }
 
-void Screen::showMouseHelper() {
+void Screen::copyMouseToScreen() {
+	debug(9, "copyMouseToScreen()");
 	// if disableMouse
 	// 	return
 	
@@ -1391,6 +1400,7 @@
 }
 
 void Screen::copyScreenFromRect(int x, int y, int w, int h, uint8 *ptr) {
+	debug(9, "copyScreenFromRect(%d, %d, %d, %d, 0x%X)", x, y, w, h, ptr);
 	x <<= 3; w <<= 3;
 	uint8 *src = ptr;
 	uint8 *dst = &_pagePtrs[0][y * SCREEN_W + x];	
@@ -1398,6 +1408,7 @@
 }
 
 void Screen::copyScreenToRect(int x, int y, int w, int h, uint8 *ptr) {
+	debug(9, "copyScreenToRect(%d, %d, %d, %d, 0x%X)", x, y, w, h, ptr);
 	x <<= 3; w <<= 3;
 	uint8 *src = &_pagePtrs[0][y * SCREEN_W + x];
 	uint8 *dst = ptr;	

Index: screen.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/kyra/screen.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- screen.h	22 Oct 2005 00:24:07 -0000	1.11
+++ screen.h	22 Oct 2005 12:59:16 -0000	1.12
@@ -115,7 +115,7 @@
 	static void decodeFrame4(const uint8 *src, uint8 *dst, uint32 dstSize);
 	static void decodeFrameDelta(uint8 *dst, const uint8 *src);
 	static void decodeFrameDeltaPage(uint8 *dst, const uint8 *src, int pitch);
-	uint8 *decodeShape(int x, int y, int w, int h, int flags);
+	uint8 *encodeShape(int x, int y, int w, int h, int flags);
 	void copyRegionToBuffer(int pageNum, int x, int y, int w, int h, uint8 *dest);
 	
 	int getRectSize(int x, int y);
@@ -132,9 +132,9 @@
 	typedef void (Screen::*DrawShapePlotPixelCallback)(uint8 *dst, uint8 c);
 
 private:
-	int16 decodeShapeHelper(uint8 *from, uint8 *to, int size);
-	void hideMouseHelper();
-	void showMouseHelper();
+	int16 encodeShapeAndCalculateSize(uint8 *from, uint8 *to, int size);
+	void restoreMouseRect();
+	void copyMouseToScreen();
 	void copyScreenFromRect(int x, int y, int w, int h, uint8 *ptr);
 	void copyScreenToRect(int x, int y, int w, int h, uint8 *ptr);
 





More information about the Scummvm-git-logs mailing list