Removed several goto statements

svn-id: r26763
This commit is contained in:
Filippos Karapetis 2007-05-06 10:35:47 +00:00
parent 8a48951370
commit dc1e1a3f11
3 changed files with 79 additions and 64 deletions

View File

@ -74,21 +74,21 @@ int AgiEngine::checkCollision(VtEntry *v) {
continue;
/* Same y, return error! */
if (v->yPos == u->yPos)
goto return_1;
if (v->yPos == u->yPos) {
debugC(4, kDebugLevelSprites, "check returns 1 (object %d)", v->entry);
return 1;
}
/* Crossed the baseline, return error! */
if ((v->yPos > u->yPos && v->yPos2 < u->yPos2) ||
(v->yPos < u->yPos && v->yPos2 > u->yPos2)) {
goto return_1;
debugC(4, kDebugLevelSprites, "check returns 1 (object %d)", v->entry);
return 1;
}
}
return 0;
return_1:
debugC(4, kDebugLevelSprites, "check returns 1 (object %d)", v->entry);
return 1;
}
int AgiEngine::checkPriority(VtEntry *v) {
@ -104,8 +104,15 @@ int AgiEngine::checkPriority(VtEntry *v) {
water = 0;
pass = 1;
if (v->priority == 0x0f)
goto check_ego;
if (v->priority == 0x0f) {
// Check ego
if (v->entry == 0) {
setflag(fEgoTouchedP2, trigger ? true : false);
setflag(fEgoWater, water ? true : false);
}
return pass;
}
water = 1;
@ -147,7 +154,7 @@ int AgiEngine::checkPriority(VtEntry *v) {
pass = 0;
}
check_ego:
// Check ego
if (v->entry == 0) {
setflag(fEgoTouchedP2, trigger ? true : false);
setflag(fEgoWater, water ? true : false);

View File

@ -91,18 +91,21 @@ int AgiEngine::showItems() {
void AgiEngine::selectItems(int n) {
int fsel = 0;
bool exit_select = false;
for (;;) {
while (!exit_select) {
if (n > 0)
printItem(fsel, STATUS_BG, STATUS_FG);
switch (waitAnyKey()) {
case KEY_ENTER:
setvar(vSelItem, _intobj[fsel]);
goto exit_select;
exit_select = true;
break;
case KEY_ESCAPE:
setvar(vSelItem, 0xff);
goto exit_select;
exit_select = true;
break;
case KEY_UP:
if (fsel >= 2)
fsel -= 2;
@ -127,19 +130,20 @@ void AgiEngine::selectItems(int n) {
showItems();
printItem(fsel, STATUS_BG, STATUS_FG);
_gfx->doUpdate();
goto exit_select;
exit_select = true;
}
break;
}
default:
break;
}
showItems();
_gfx->doUpdate();
if (!exit_select) {
showItems();
_gfx->doUpdate();
}
}
exit_select:
debugC(6, kDebugLevelInventory, "selected: %d", fsel);
}

View File

@ -229,8 +229,9 @@ int AgiEngine::testIfCode(int lognum) {
uint8 orTest = false;
uint16 lastIp = ip;
uint8 p[16] = { 0 };
bool end_test = false;
while (retval && !game.quitProgNow) {
while (retval && !game.quitProgNow && !end_test) {
if (_debug.enabled && (_debug.logic0 || lognum))
debugConsole(lognum, lTEST_MODE, NULL);
@ -240,7 +241,8 @@ int AgiEngine::testIfCode(int lognum) {
switch (op) {
case 0xFF: /* END IF, TEST true */
goto end_test;
end_test = true;
break;
case 0xFD:
notTest = !notTest;
continue;
@ -251,7 +253,7 @@ int AgiEngine::testIfCode(int lognum) {
if (orTest) {
ec = false;
retval = false;
goto end_test;
end_test = true;
}
orTest = true;
@ -259,7 +261,8 @@ int AgiEngine::testIfCode(int lognum) {
case 0x00:
/* return true? */
goto end_test;
end_test = true;
break;
case 0x01:
ec = testEqual(p[0], p[1]);
if (p[0] == 11)
@ -333,62 +336,63 @@ int AgiEngine::testIfCode(int lognum) {
break;
default:
ec = false;
goto end_test;
end_test = true;
}
if (op <= 0x12)
ip += logicNamesTest[op].numArgs;
if (!end_test) {
if (op <= 0x12)
ip += logicNamesTest[op].numArgs;
/* exchange ec value */
if (notTest)
ec = !ec;
/* exchange ec value */
if (notTest)
ec = !ec;
/* not is only enabled for 1 test command */
notTest = false;
/* not is only enabled for 1 test command */
notTest = false;
if (orTest && ec) {
/* a true inside an OR statement passes
* ENTIRE statement scan for end of OR
*/
if (orTest && ec) {
/* a true inside an OR statement passes
* ENTIRE statement scan for end of OR
*/
/* CM: test for opcode < 0xfc changed from 'op' to
* '*(code+ip)', to avoid problem with the 0xfd (NOT)
* opcode byte. Changed a bad ip += ... ip++ construct.
* This should fix the crash with Larry's logic.0 code:
*
* if ((isset(4) ||
* !isset(2) ||
* v30 == 2 ||
* v30 == 1)) {
* goto Label1;
* }
*
* The bytecode is:
* ff fc 07 04 fd 07 02 01 1e 02 01 1e 01 fc ff
*/
/* CM: test for opcode < 0xfc changed from 'op' to
* '*(code+ip)', to avoid problem with the 0xfd (NOT)
* opcode byte. Changed a bad ip += ... ip++ construct.
* This should fix the crash with Larry's logic.0 code:
*
* if ((isset(4) ||
* !isset(2) ||
* v30 == 2 ||
* v30 == 1)) {
* goto Label1;
* }
*
* The bytecode is:
* ff fc 07 04 fd 07 02 01 1e 02 01 1e 01 fc ff
*/
/* find end of OR */
while (*(code + ip) != 0xFC) {
if (*(code + ip) == 0x0E) { /* said */
/* find end of OR */
while (*(code + ip) != 0xFC) {
if (*(code + ip) == 0x0E) { /* said */
ip++;
/* cover count + ^words */
ip += 1 + ((*(code + ip)) * 2);
continue;
}
if (*(code + ip) < 0xFC)
ip += logicNamesTest[*(code + ip)].numArgs;
ip++;
/* cover count + ^words */
ip += 1 + ((*(code + ip)) * 2);
continue;
}
if (*(code + ip) < 0xFC)
ip += logicNamesTest[*(code + ip)].numArgs;
ip++;
}
ip++;
orTest = false;
retval = true;
} else {
retval = orTest ? retval || ec : retval && ec;
orTest = false;
retval = true;
} else {
retval = orTest ? retval || ec : retval && ec;
}
}
}
end_test:
/* if false, scan for end of IP? */
if (retval)