[Scummvm-cvs-logs] SF.net SVN: scummvm: [32850] scummvm/trunk/engines/cine/various.cpp

buddha_ at users.sourceforge.net buddha_ at users.sourceforge.net
Mon Jun 30 19:24:24 CEST 2008


Revision: 32850
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32850&view=rev
Author:   buddha_
Date:     2008-06-30 10:24:23 -0700 (Mon, 30 Jun 2008)

Log Message:
-----------
Fixed addAni (A test before using resetGfxEntityEntry was incorrect). Also added comments and checked that most 8-bit values used in this function are used as signed integers.

Modified Paths:
--------------
    scummvm/trunk/engines/cine/various.cpp

Modified: scummvm/trunk/engines/cine/various.cpp
===================================================================
--- scummvm/trunk/engines/cine/various.cpp	2008-06-30 08:46:20 UTC (rev 32849)
+++ scummvm/trunk/engines/cine/various.cpp	2008-06-30 17:24:23 UTC (rev 32850)
@@ -1682,33 +1682,49 @@
 	return returnVar;
 }
 
-uint16 addAni(uint16 param1, uint16 objIdx, const byte *ptr, SeqListElement &element, uint16 param3, int16 *param4) {
-	const byte *currentPtr = ptr;
-	const byte *ptrData;
-	const byte *ptr2;
+uint16 addAni(uint16 param1, uint16 objIdx, const byte *ptrByte, SeqListElement &element, uint16 param3, int16 *param4) {
+	const int8 *ptr = (const int8 *)ptrByte;
+	const int8 *ptrData;
+	const int8 *ptr2;
 	int16 di;
 
+	// In the original an error string is set and 0 is returned if the following doesn't hold
 	assert(ptr);
-	assert(param4);
 
-	dummyU16 = READ_BE_UINT16((currentPtr + param1 * 2) + 8);
-
+	// We probably could just use a local variable here instead of the dummyU16 but
+	// haven't checked if this has any side-effects so keeping it this way still.
+	dummyU16 = READ_BE_UINT16(ptr + param1 * 2 + 8);
 	ptrData = ptr + dummyU16;
 
+	// In the original an error string is set and 0 is returned if the following doesn't hold
 	assert(*ptrData);
 
 	di = (objectTable[objIdx].costume + 1) % (*ptrData);
-	ptr2 = (ptrData + (di * 8)) + 1;
+	++ptrData; // Jump over the just read byte
+	// Here ptr2 seems to be indexing a table of structs (8 bytes per struct):
+	//	struct {
+	//		int8 x;			// 0 (Used with checkCollision)
+	//		int8 y;			// 1 (Used with checkCollision)
+	//		int8 numZones;	// 2 (Used with checkCollision)
+	//		int8 var3;		// 3 (Not used in this function)
+	//		int8 xAdd;		// 4 (Used with an object)
+	//		int8 yAdd;		// 5 (Used with an object)
+	//		int8 maskAdd;	// 6 (Used with an object)
+	//		int8 frameAdd;	// 7 (Used with an object)
+	//	};
+	ptr2 = ptrData + di * 8;
 
+	// We might probably safely discard the AND by 1 here because
+	// at least in the original checkCollision returns always 0 or 1.
 	if ((checkCollision(objIdx, ptr2[0], ptr2[1], ptr2[2], ptr[0]) & 1)) {
 		return 0;
 	}
 
-	objectTable[objIdx].x += (int8)ptr2[4];
-	objectTable[objIdx].y += (int8)ptr2[5];
-	objectTable[objIdx].mask += (int8)ptr2[6];
+	objectTable[objIdx].x += ptr2[4];
+	objectTable[objIdx].y += ptr2[5];
+	objectTable[objIdx].mask += ptr2[6];
 
-	if (objectTable[objIdx].frame) {
+	if (ptr2[6]) {
 		resetGfxEntityEntry(objIdx);
 	}
 
@@ -1717,6 +1733,7 @@
 	if (param3 || !element.var14) {
 		objectTable[objIdx].costume = di;
 	} else {
+		assert(param4);
 		*param4 = di;
 	}
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list