[Scummvm-cvs-logs] scummvm master -> 4410e6123868ee549e8997bad97cf768edbdf3ae

lordhoto lordhoto at gmail.com
Fri Nov 4 20:03:53 CET 2011


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
4410e61238 KYRA: Simplify getMoveTableSize.


Commit: 4410e6123868ee549e8997bad97cf768edbdf3ae
    https://github.com/scummvm/scummvm/commit/4410e6123868ee549e8997bad97cf768edbdf3ae
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-11-04T12:01:57-07:00

Commit Message:
KYRA: Simplify getMoveTableSize.

This also removes two FIXME comments. The original did the same checks as we
had before, but as PVS-Studio noticed the expression was excessive. I changed
it to a simpler expression now and removed the FIXMEs.

Changed paths:
    engines/kyra/scene_v1.cpp



diff --git a/engines/kyra/scene_v1.cpp b/engines/kyra/scene_v1.cpp
index 059c42e..cef4726 100644
--- a/engines/kyra/scene_v1.cpp
+++ b/engines/kyra/scene_v1.cpp
@@ -277,7 +277,7 @@ void KyraEngine_v1::changePosTowardsFacing(int &x, int &y, int facing) {
 }
 
 int KyraEngine_v1::getMoveTableSize(int *moveTable) {
-	int retValue = 0;
+	int tableSize = 0;
 	if (moveTable[0] == 8)
 		return 0;
 
@@ -298,11 +298,11 @@ int KyraEngine_v1::getMoveTableSize(int *moveTable) {
 	int *oldPosition = moveTable;
 	int *tempPosition = moveTable;
 	int *curPosition = moveTable + 1;
-	retValue = 1;
+	tableSize = 1;
 
 	while (*curPosition != 8) {
 		if (*oldPosition == facingTable[*curPosition]) {
-			retValue -= 2;
+			tableSize -= 2;
 			*oldPosition = 9;
 			*curPosition = 9;
 
@@ -314,7 +314,7 @@ int KyraEngine_v1::getMoveTableSize(int *moveTable) {
 
 			if (tempPosition == moveTable && *tempPosition == 9) {
 				// FIXME: This check is odd. Perhaps it should check if *tempPosition == 9 ?
-				while (*tempPosition != 8 && *tempPosition == 9)
+				while (*tempPosition == 9)
 					++tempPosition;
 
 				if (*tempPosition == 8)
@@ -322,54 +322,40 @@ int KyraEngine_v1::getMoveTableSize(int *moveTable) {
 			}
 
 			oldPosition = tempPosition;
-			curPosition = oldPosition+1;
+			curPosition = oldPosition + 1;
 
-			// FIXME: This check is odd. Perhaps it should check if *tempPosition == 9 ?
-			while (*curPosition != 8 && *curPosition == 9)
+			while (*curPosition == 9)
 				++curPosition;
-
-			continue;
-		}
-
-		if (unkTable[*curPosition+((*oldPosition)*8)] != -1) {
-			--retValue;
-			*oldPosition = unkTable[*curPosition+((*oldPosition)*8)];
+		} else if (unkTable[*curPosition + *oldPosition * 8] != -1) {
+			--tableSize;
+			*oldPosition = unkTable[*curPosition + *oldPosition * 8];
 			*curPosition = 9;
 
 			if (tempPosition != oldPosition) {
 				curPosition = oldPosition;
 				oldPosition = tempPosition;
-				while (true) {
-					if (tempPosition == moveTable)
-						break;
-
+				while (tempPosition != moveTable) {
 					--tempPosition;
 					if (*tempPosition != 9)
 						break;
-
 				}
 			} else {
-				while (true) {
+				do {
 					++curPosition;
-					if (*curPosition != 9)
-						break;
-				}
+				} while (*curPosition == 9);
 			}
-			continue;
-		}
-
-		tempPosition = oldPosition;
-		oldPosition = curPosition;
-		++retValue;
+		} else {
+			tempPosition = oldPosition;
+			oldPosition = curPosition;
+			++tableSize;
 
-		while (true) {
-			++curPosition;
-			if (*curPosition != 9)
-				break;
+			do {
+				++curPosition;
+			} while (*curPosition == 9);
 		}
 	}
 
-	return retValue;
+	return tableSize;
 }
 
 } // End of namespace Kyra






More information about the Scummvm-git-logs mailing list