aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra
diff options
context:
space:
mode:
authorJohannes Schickel2011-11-04 20:01:57 +0100
committerJohannes Schickel2011-11-04 20:01:57 +0100
commit4410e6123868ee549e8997bad97cf768edbdf3ae (patch)
treed62cafd472b55404373f7be3e1fdaf00775ecae9 /engines/kyra
parent4232610c20d652aec84bab014e9ba93d4b07db44 (diff)
downloadscummvm-rg350-4410e6123868ee549e8997bad97cf768edbdf3ae.tar.gz
scummvm-rg350-4410e6123868ee549e8997bad97cf768edbdf3ae.tar.bz2
scummvm-rg350-4410e6123868ee549e8997bad97cf768edbdf3ae.zip
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.
Diffstat (limited to 'engines/kyra')
-rw-r--r--engines/kyra/scene_v1.cpp54
1 files changed, 20 insertions, 34 deletions
diff --git a/engines/kyra/scene_v1.cpp b/engines/kyra/scene_v1.cpp
index 059c42ec5e..cef472682e 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