diff options
-rw-r--r-- | engines/agi/cycle.cpp | 75 | ||||
-rw-r--r-- | engines/agi/menu.cpp | 129 | ||||
-rw-r--r-- | engines/agi/preagi_winnie.cpp | 61 | ||||
-rw-r--r-- | engines/agi/predictive.cpp | 34 | ||||
-rw-r--r-- | engines/agi/saveload.cpp | 189 | ||||
-rw-r--r-- | engines/agi/text.cpp | 22 | ||||
-rw-r--r-- | engines/draci/walking.cpp | 12 | ||||
-rw-r--r-- | engines/drascula/animation.cpp | 49 | ||||
-rw-r--r-- | engines/drascula/drascula.h | 1 | ||||
-rw-r--r-- | engines/lure/hotspots.cpp | 295 | ||||
-rw-r--r-- | engines/lure/menu.cpp | 63 | ||||
-rw-r--r-- | engines/sky/logic.cpp | 340 | ||||
-rw-r--r-- | engines/sword25/gfx/image/art.cpp | 136 | ||||
-rw-r--r-- | engines/tinsel/saveload.cpp | 35 | ||||
-rw-r--r-- | engines/toon/path.cpp | 9 | ||||
-rw-r--r-- | engines/toon/toon.cpp | 12 |
16 files changed, 747 insertions, 715 deletions
diff --git a/engines/agi/cycle.cpp b/engines/agi/cycle.cpp index 99649fb437..5daadbd1df 100644 --- a/engines/agi/cycle.cpp +++ b/engines/agi/cycle.cpp @@ -248,44 +248,47 @@ int AgiEngine::mainCycle() { if (kascii) setvar(vKey, kascii); -process_key: - - switch (_game.inputMode) { - case INPUT_NORMAL: - if (!handleController(key)) { - if (key == 0 || !_game.inputEnabled) - break; - handleKeys(key); - - // if ESC pressed, activate menu before - // accept.input from the interpreter cycle - // sets the input mode to normal again - // (closes: #540856) - if (key == KEY_ESCAPE) { - key = 0; - goto process_key; + bool restartProcessKey; + do { + restartProcessKey = false; + + switch (_game.inputMode) { + case INPUT_NORMAL: + if (!handleController(key)) { + if (key == 0 || !_game.inputEnabled) + break; + handleKeys(key); + + // if ESC pressed, activate menu before + // accept.input from the interpreter cycle + // sets the input mode to normal again + // (closes: #540856) + if (key == KEY_ESCAPE) { + key = 0; + restartProcessKey = true; + } + + // commented out to close Sarien bug #438872 + //if (key) + // _game.keypress = key; } - - // commented out to close Sarien bug #438872 - //if (key) - // _game.keypress = key; + break; + case INPUT_GETSTRING: + handleController(key); + handleGetstring(key); + setvar(vKey, 0); // clear ENTER key + break; + case INPUT_MENU: + _menu->keyhandler(key); + _gfx->doUpdate(); + return false; + case INPUT_NONE: + handleController(key); + if (key) + _game.keypress = key; + break; } - break; - case INPUT_GETSTRING: - handleController(key); - handleGetstring(key); - setvar(vKey, 0); // clear ENTER key - break; - case INPUT_MENU: - _menu->keyhandler(key); - _gfx->doUpdate(); - return false; - case INPUT_NONE: - handleController(key); - if (key) - _game.keypress = key; - break; - } + } while (restartProcessKey); _gfx->doUpdate(); if (_game.msgBoxTicks > 0) diff --git a/engines/agi/menu.cpp b/engines/agi/menu.cpp index b504cd3e30..cac1701596 100644 --- a/engines/agi/menu.cpp +++ b/engines/agi/menu.cpp @@ -279,6 +279,7 @@ bool Menu::keyhandler(int key) { static int clockVal; static int menuActive = false; static int buttonUsed = 0; + bool exitMenu = false; if (!_vm->getflag(fMenusWork) && !(_vm->getFeatures() & GF_MENUS)) return false; @@ -288,9 +289,8 @@ bool Menu::keyhandler(int key) { _vm->_game.clockEnabled = false; drawMenuBar(); } - // + // Mouse handling - // if (_vm->_mouse.button) { int hmenu, vmenu; @@ -372,83 +372,84 @@ bool Menu::keyhandler(int key) { debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); _vm->_game.controllerOccured[d->event] = true; _vm->_menuSelected = true; - - goto exit_menu; + break; } } } - goto exit_menu; + exitMenu = true; } } - if (!menuActive) { - if (_hCurMenu >= 0) { - drawMenuHilite(_hCurMenu); - drawMenuOption(_hCurMenu); - if (!buttonUsed && _vCurMenu >= 0) - drawMenuOptionHilite(_hCurMenu, _vCurMenu); + if (!exitMenu) { + if (!menuActive) { + if (_hCurMenu >= 0) { + drawMenuHilite(_hCurMenu); + drawMenuOption(_hCurMenu); + if (!buttonUsed && _vCurMenu >= 0) + drawMenuOptionHilite(_hCurMenu, _vCurMenu); + } + menuActive = true; } - menuActive = true; - } - switch (key) { - case KEY_ESCAPE: - debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ESCAPE"); - goto exit_menu; - case KEY_ENTER: - { - debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ENTER"); - AgiMenuOption* d = getMenuOption(_hCurMenu, _vCurMenu); - - if (d->enabled) { - debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); - _vm->_game.controllerOccured[d->event] = true; - _vm->_menuSelected = true; - goto exit_menu; + switch (key) { + case KEY_ESCAPE: + debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ESCAPE"); + exitMenu = true; + break; + case KEY_ENTER: + { + debugC(6, kDebugLevelMenu | kDebugLevelInput, "KEY_ENTER"); + AgiMenuOption* d = getMenuOption(_hCurMenu, _vCurMenu); + + if (d->enabled) { + debugC(6, kDebugLevelMenu | kDebugLevelInput, "event %d registered", d->event); + _vm->_game.controllerOccured[d->event] = true; + _vm->_menuSelected = true; + exitMenu = true; + } + break; } - break; - } - case KEY_DOWN: - case KEY_UP: - _vCurMenu += key == KEY_DOWN ? 1 : -1; + case KEY_DOWN: + case KEY_UP: + _vCurMenu += key == KEY_DOWN ? 1 : -1; - if (_vCurMenu < 0) - _vCurMenu = _vMaxMenu[_hCurMenu]; - if (_vCurMenu > _vMaxMenu[_hCurMenu]) - _vCurMenu = 0; + if (_vCurMenu < 0) + _vCurMenu = _vMaxMenu[_hCurMenu]; + if (_vCurMenu > _vMaxMenu[_hCurMenu]) + _vCurMenu = 0; - drawMenuOption(_hCurMenu); - drawMenuOptionHilite(_hCurMenu, _vCurMenu); - break; - case KEY_RIGHT: - case KEY_LEFT: - _hCurMenu += key == KEY_RIGHT ? 1 : -1; - - if (_hCurMenu < 0) - _hCurMenu = _hMaxMenu; - if (_hCurMenu > _hMaxMenu) - _hCurMenu = 0; - - _vCurMenu = 0; - newMenuSelected(_hCurMenu); - drawMenuOptionHilite(_hCurMenu, _vCurMenu); - break; - } + drawMenuOption(_hCurMenu); + drawMenuOptionHilite(_hCurMenu, _vCurMenu); + break; + case KEY_RIGHT: + case KEY_LEFT: + _hCurMenu += key == KEY_RIGHT ? 1 : -1; - return true; + if (_hCurMenu < 0) + _hCurMenu = _hMaxMenu; + if (_hCurMenu > _hMaxMenu) + _hCurMenu = 0; -exit_menu: - buttonUsed = 0; - _picture->showPic(); - _vm->writeStatus(); + _vCurMenu = 0; + newMenuSelected(_hCurMenu); + drawMenuOptionHilite(_hCurMenu, _vCurMenu); + break; + } + } - _vm->setvar(vKey, 0); - _vm->_game.keypress = 0; - _vm->_game.clockEnabled = clockVal; - _vm->oldInputMode(); + if (exitMenu) { + buttonUsed = 0; + _picture->showPic(); + _vm->writeStatus(); - debugC(3, kDebugLevelMenu, "exit_menu: input mode reset to %d", _vm->_game.inputMode); - menuActive = false; + _vm->setvar(vKey, 0); + _vm->_game.keypress = 0; + _vm->_game.clockEnabled = clockVal; + _vm->oldInputMode(); + + debugC(3, kDebugLevelMenu, "exit_menu: input mode reset to %d", _vm->_game.inputMode); + menuActive = false; + } return true; } diff --git a/engines/agi/preagi_winnie.cpp b/engines/agi/preagi_winnie.cpp index cc5c2470ae..53863a8c7e 100644 --- a/engines/agi/preagi_winnie.cpp +++ b/engines/agi/preagi_winnie.cpp @@ -1006,36 +1006,47 @@ void WinnieEngine::gameLoop() { WTP_ROOM_HDR hdr; uint8 *roomdata = (uint8 *)malloc(4096); int iBlock; + uint8 decodePhase = 0; -phase0: - if (!_gameStateWinnie.nObjMiss && (_room == IDI_WTP_ROOM_PICNIC)) - _room = IDI_WTP_ROOM_PARTY; + while (!shouldQuit()) { + if (decodePhase == 0) { + if (!_gameStateWinnie.nObjMiss && (_room == IDI_WTP_ROOM_PICNIC)) + _room = IDI_WTP_ROOM_PARTY; - readRoom(_room, roomdata, hdr); - drawRoomPic(); - _gfx->doUpdate(); + readRoom(_room, roomdata, hdr); + drawRoomPic(); + _gfx->doUpdate(); + decodePhase = 1; + } -phase1: - if (getObjInRoom(_room)) { - printObjStr(getObjInRoom(_room), IDI_WTP_OBJ_DESC); - getSelection(kSelAnyKey); - } + if (decodePhase == 1) { + if (getObjInRoom(_room)) { + printObjStr(getObjInRoom(_room), IDI_WTP_OBJ_DESC); + getSelection(kSelAnyKey); + } + decodePhase = 2; + } -phase2: - for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { - if (parser(hdr.ofsDesc[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_BACK) - goto phase1; - } + if (decodePhase == 2) { + for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { + if (parser(hdr.ofsDesc[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_BACK) { + decodePhase = 1; + break; + } + } + if (decodePhase == 2) + decodePhase = 3; + } - while (!shouldQuit()) { - for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { - switch (parser(hdr.ofsBlock[iBlock] - _roomOffset, iBlock, roomdata)) { - case IDI_WTP_PAR_GOTO: - goto phase0; - break; - case IDI_WTP_PAR_BACK: - goto phase2; - break; + if (decodePhase == 3) { + for (iBlock = 0; iBlock < IDI_WTP_MAX_BLOCK; iBlock++) { + if (parser(hdr.ofsBlock[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_GOTO) { + decodePhase = 0; + break; + } else if (parser(hdr.ofsBlock[iBlock] - _roomOffset, iBlock, roomdata) == IDI_WTP_PAR_BACK) { + decodePhase = 2; + break; + } } } } diff --git a/engines/agi/predictive.cpp b/engines/agi/predictive.cpp index edfe83b1cb..3290068d5a 100644 --- a/engines/agi/predictive.cpp +++ b/engines/agi/predictive.cpp @@ -96,8 +96,6 @@ void bringWordtoTop(char *str, int wordnum) { } bool AgiEngine::predictiveDialog() { - int key = 0, active = -1, lastactive = 0; - bool rc = false; uint8 x; int y; int bx[17], by[17]; @@ -105,7 +103,6 @@ bool AgiEngine::predictiveDialog() { char temp[MAXWORDLEN + 1], repeatcount[MAXWORDLEN]; AgiBlock tmpwindow; bool navigationwithkeys = false; - bool processkey; const char *buttonStr[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }; const char *buttons[] = { @@ -189,8 +186,11 @@ bool AgiEngine::predictiveDialog() { int mode = kModePre; bool needRefresh = true; - - while (!shouldQuit()) { + int active = -1, lastactive = 0; + bool rc = false; + bool closeDialog = false; + bool enterPredictiveResult = false; + while (!closeDialog && !shouldQuit()) { if (needRefresh) { for (int i = 0; buttons[i]; i++) { int color1 = colors[i * 2]; @@ -234,9 +234,10 @@ bool AgiEngine::predictiveDialog() { _gfx->doUpdate(); } + bool processkey = false; + pollTimer(); - key = doPollKeyboard(); - processkey = false; + int key = doPollKeyboard(); switch (key) { case KEY_ENTER: if (navigationwithkeys) { @@ -251,7 +252,8 @@ bool AgiEngine::predictiveDialog() { break; case KEY_ESCAPE: rc = false; - goto getout; + closeDialog = true; + break; case BUTTON_LEFT: navigationwithkeys = false; for (int i = 0; buttons[i]; i++) { @@ -361,7 +363,7 @@ bool AgiEngine::predictiveDialog() { break; } - if (processkey) { + if (processkey && !closeDialog) { if (active >= 0) { needRefresh = true; lastactive = active; @@ -442,7 +444,8 @@ bool AgiEngine::predictiveDialog() { if (mode == kModePre && _predictiveDictActLine && numMatchingWords > 1 && _wordNumber != 0) bringWordtoTop(_predictiveDictActLine, _wordNumber); rc = true; - goto press; + enterPredictiveResult = true; + closeDialog = true; } else if (active == 14) { // Mode mode++; if (mode > kModeAbc) @@ -456,17 +459,18 @@ bool AgiEngine::predictiveDialog() { _currentWord.clear(); memset(repeatcount, 0, sizeof(repeatcount)); } else { - goto press; + enterPredictiveResult = true; + closeDialog = true; } } } } - press: - Common::strlcpy(_predictiveResult, prefix.c_str(), sizeof(_predictiveResult)); - Common::strlcat(_predictiveResult, _currentWord.c_str(), sizeof(_predictiveResult)); + if (enterPredictiveResult) { + Common::strlcpy(_predictiveResult, prefix.c_str(), sizeof(_predictiveResult)); + Common::strlcat(_predictiveResult, _currentWord.c_str(), sizeof(_predictiveResult)); + } - getout: // if another window was shown, bring it up again if (!tmpwindow.active) closeWindow(); diff --git a/engines/agi/saveload.cpp b/engines/agi/saveload.cpp index 1bcabd507f..00d6a1c8dd 100644 --- a/engines/agi/saveload.cpp +++ b/engines/agi/saveload.cpp @@ -609,8 +609,8 @@ int AgiEngine::selectSlot() { AllowSyntheticEvents on(this); int oldFirstSlot = _firstSlot + 1; int oldActive = active + 1; - - while (!(shouldQuit() || _restartGame)) { + bool exitSelectSlot = false; + while (!exitSelectSlot && !(shouldQuit() || _restartGame)) { int sbPos = 0; // Use the extreme scrollbar positions only if the extreme @@ -661,119 +661,122 @@ int AgiEngine::selectSlot() { // out of the dead loop if (getflag(fRestoreJustRan)) { rc = -2; - goto getout; + exitSelectSlot = true; } - switch (key) { - case KEY_ENTER: - rc = active; - strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN); - goto press; - case KEY_ESCAPE: - rc = -1; - goto getout; - case BUTTON_LEFT: - if (_gfx->testButton(buttonX[0], buttonY, buttonText[0])) { + if (!exitSelectSlot) { + switch (key) { + case KEY_ENTER: rc = active; strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN); - goto press; - } - if (_gfx->testButton(buttonX[1], buttonY, buttonText[1])) { + debugC(8, kDebugLevelMain | kDebugLevelInput, "Button pressed: %d", rc); + exitSelectSlot = true; + break; + case KEY_ESCAPE: rc = -1; - goto getout; - } - slotClicked = ((int)_mouse.y - 1) / CHAR_COLS - (vm + 4); - xmin = (hm + 1) * CHAR_COLS; - xmax = xmin + CHAR_COLS * 34; - if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) { - if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) - active = slotClicked; - } - xmin = (hm + 36) * CHAR_COLS; - xmax = xmin + CHAR_COLS; - if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) { - if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) { - if (slotClicked == 0) - keyEnqueue(KEY_UP); - else if (slotClicked == NUM_VISIBLE_SLOTS - 1) - keyEnqueue(KEY_DOWN); - else if (slotClicked < sbPos) - keyEnqueue(KEY_UP_RIGHT); - else if (slotClicked > sbPos) - keyEnqueue(KEY_DOWN_RIGHT); + exitSelectSlot = true; + break; + case BUTTON_LEFT: + if (_gfx->testButton(buttonX[0], buttonY, buttonText[0])) { + rc = active; + strncpy(_game.strings[MAX_STRINGS], desc[i], MAX_STRINGLEN); + debugC(8, kDebugLevelMain | kDebugLevelInput, "Button pressed: %d", rc); + exitSelectSlot = true; + } else if (_gfx->testButton(buttonX[1], buttonY, buttonText[1])) { + rc = -1; + exitSelectSlot = true; + } else { + slotClicked = ((int)_mouse.y - 1) / CHAR_COLS - (vm + 4); + xmin = (hm + 1) * CHAR_COLS; + xmax = xmin + CHAR_COLS * 34; + if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) { + if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) + active = slotClicked; + } + xmin = (hm + 36) * CHAR_COLS; + xmax = xmin + CHAR_COLS; + if ((int)_mouse.x >= xmin && (int)_mouse.x <= xmax) { + if (slotClicked >= 0 && slotClicked < NUM_VISIBLE_SLOTS) { + if (slotClicked == 0) + keyEnqueue(KEY_UP); + else if (slotClicked == NUM_VISIBLE_SLOTS - 1) + keyEnqueue(KEY_DOWN); + else if (slotClicked < sbPos) + keyEnqueue(KEY_UP_RIGHT); + else if (slotClicked > sbPos) + keyEnqueue(KEY_DOWN_RIGHT); + } + } } - } - break; - case KEY_DOWN: - active++; - if (active >= NUM_VISIBLE_SLOTS) { - if (_firstSlot + NUM_VISIBLE_SLOTS < NUM_SLOTS) { + break; + + case KEY_DOWN: + active++; + if (active >= NUM_VISIBLE_SLOTS) { + if (_firstSlot + NUM_VISIBLE_SLOTS < NUM_SLOTS) { + _firstSlot++; + for (i = 1; i < NUM_VISIBLE_SLOTS; i++) + memcpy(desc[i - 1], desc[i], sizeof(desc[0])); + getSavegameDescription(_firstSlot + NUM_VISIBLE_SLOTS - 1, desc[NUM_VISIBLE_SLOTS - 1]); + } + active = NUM_VISIBLE_SLOTS - 1; + } + break; + case KEY_UP: + active--; + if (active < 0) { + active = 0; + if (_firstSlot > 0) { + _firstSlot--; + for (i = NUM_VISIBLE_SLOTS - 1; i > 0; i--) + memcpy(desc[i], desc[i - 1], sizeof(desc[0])); + getSavegameDescription(_firstSlot, desc[0]); + } + } + break; + + // Page Up/Down and mouse wheel scrolling all leave 'active' + // unchanged so that a visible slot will remain selected. + + case WHEEL_DOWN: + if (_firstSlot < NUM_SLOTS - NUM_VISIBLE_SLOTS) { _firstSlot++; for (i = 1; i < NUM_VISIBLE_SLOTS; i++) memcpy(desc[i - 1], desc[i], sizeof(desc[0])); getSavegameDescription(_firstSlot + NUM_VISIBLE_SLOTS - 1, desc[NUM_VISIBLE_SLOTS - 1]); } - active = NUM_VISIBLE_SLOTS - 1; - } - break; - case KEY_UP: - active--; - if (active < 0) { - active = 0; + break; + case WHEEL_UP: if (_firstSlot > 0) { _firstSlot--; for (i = NUM_VISIBLE_SLOTS - 1; i > 0; i--) memcpy(desc[i], desc[i - 1], sizeof(desc[0])); getSavegameDescription(_firstSlot, desc[0]); } + break; + case KEY_DOWN_RIGHT: + // This is probably triggered by Page Down. + _firstSlot += NUM_VISIBLE_SLOTS; + if (_firstSlot > NUM_SLOTS - NUM_VISIBLE_SLOTS) { + _firstSlot = NUM_SLOTS - NUM_VISIBLE_SLOTS; + } + for (i = 0; i < NUM_VISIBLE_SLOTS; i++) + getSavegameDescription(_firstSlot + i, desc[i]); + break; + case KEY_UP_RIGHT: + // This is probably triggered by Page Up. + _firstSlot -= NUM_VISIBLE_SLOTS; + if (_firstSlot < 0) { + _firstSlot = 0; + } + for (i = 0; i < NUM_VISIBLE_SLOTS; i++) + getSavegameDescription(_firstSlot + i, desc[i]); + break; } - break; - - // Page Up/Down and mouse wheel scrolling all leave 'active' - // unchanged so that a visible slot will remain selected. - - case WHEEL_DOWN: - if (_firstSlot < NUM_SLOTS - NUM_VISIBLE_SLOTS) { - _firstSlot++; - for (i = 1; i < NUM_VISIBLE_SLOTS; i++) - memcpy(desc[i - 1], desc[i], sizeof(desc[0])); - getSavegameDescription(_firstSlot + NUM_VISIBLE_SLOTS - 1, desc[NUM_VISIBLE_SLOTS - 1]); - } - break; - case WHEEL_UP: - if (_firstSlot > 0) { - _firstSlot--; - for (i = NUM_VISIBLE_SLOTS - 1; i > 0; i--) - memcpy(desc[i], desc[i - 1], sizeof(desc[0])); - getSavegameDescription(_firstSlot, desc[0]); - } - break; - case KEY_DOWN_RIGHT: - // This is probably triggered by Page Down. - _firstSlot += NUM_VISIBLE_SLOTS; - if (_firstSlot > NUM_SLOTS - NUM_VISIBLE_SLOTS) { - _firstSlot = NUM_SLOTS - NUM_VISIBLE_SLOTS; - } - for (i = 0; i < NUM_VISIBLE_SLOTS; i++) - getSavegameDescription(_firstSlot + i, desc[i]); - break; - case KEY_UP_RIGHT: - // This is probably triggered by Page Up. - _firstSlot -= NUM_VISIBLE_SLOTS; - if (_firstSlot < 0) { - _firstSlot = 0; - } - for (i = 0; i < NUM_VISIBLE_SLOTS; i++) - getSavegameDescription(_firstSlot + i, desc[i]); - break; } _gfx->doUpdate(); } -press: - debugC(8, kDebugLevelMain | kDebugLevelInput, "Button pressed: %d", rc); - -getout: closeWindow(); _noSaveLoadAllowed = false; diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp index 3247862e32..1886a74ab1 100644 --- a/engines/agi/text.cpp +++ b/engines/agi/text.cpp @@ -340,8 +340,6 @@ int AgiEngine::messageBox(const char *s) { int AgiEngine::selectionBox(const char *m, const char **b) { int numButtons = 0; int x, y, i, s; - int key, active = 0; - int rc = -1; int bx[5], by[5]; _noSaveLoadAllowed = true; @@ -380,7 +378,9 @@ int AgiEngine::selectionBox(const char *m, const char **b) { AllowSyntheticEvents on(this); debugC(4, kDebugLevelText, "selectionBox(): waiting..."); - while (!(shouldQuit() || _restartGame)) { + int key, active = 0; + int rc = -1; + while (rc == -1 && !(shouldQuit() || _restartGame)) { for (i = 0; b[i]; i++) _gfx->drawCurrentStyleButton(bx[i], by[i], b[i], i == active, false, i == 0); @@ -389,10 +389,8 @@ int AgiEngine::selectionBox(const char *m, const char **b) { switch (key) { case KEY_ENTER: rc = active; - goto press; - case KEY_ESCAPE: - rc = -1; - goto getout; + debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc); + break; case KEY_RIGHT: active++; if (active >= numButtons) @@ -407,7 +405,8 @@ int AgiEngine::selectionBox(const char *m, const char **b) { for (i = 0; b[i]; i++) { if (_gfx->testButton(bx[i], by[i], b[i])) { rc = active = i; - goto press; + debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc); + break; } } break; @@ -418,12 +417,11 @@ int AgiEngine::selectionBox(const char *m, const char **b) { break; } _gfx->doUpdate(); - } -press: - debugC(4, kDebugLevelText, "selectionBox(): Button pressed: %d", rc); + if (key == KEY_ESCAPE) + break; + } -getout: closeWindow(); debugC(2, kDebugLevelText, "selectionBox(): Result = %d", rc); diff --git a/engines/draci/walking.cpp b/engines/draci/walking.cpp index 9a66c6163a..f1ae769d80 100644 --- a/engines/draci/walking.cpp +++ b/engines/draci/walking.cpp @@ -729,20 +729,18 @@ Movement WalkingState::transitionBetweenAnimations(Movement previous, Movement n Movement WalkingState::animationForSightDirection(SightDirection dir, const Common::Point &hero, const Common::Point &mouse, const WalkingPath &path, Movement startingDirection) { switch (dir) { + case kDirectionLeft: + return kStopLeft; + case kDirectionRight: + return kStopRight; case kDirectionMouse: if (mouse.x < hero.x) { return kStopLeft; } else if (mouse.x > hero.x) { return kStopRight; - } else { - goto defaultCase; } - case kDirectionLeft: - return kStopLeft; - case kDirectionRight: - return kStopRight; + // fall-through here intentional default: { -defaultCase: // Find the last horizontal direction on the path. int i = path.size() - 1; while (i >= 0 && path[i].x == hero.x) { diff --git a/engines/drascula/animation.cpp b/engines/drascula/animation.cpp index c4a8d3eb01..43799f7944 100644 --- a/engines/drascula/animation.cpp +++ b/engines/drascula/animation.cpp @@ -748,6 +748,19 @@ void DrasculaEngine::animation_14_2() { loadPic(99, backSurface); } +void DrasculaEngine::asco() { + loadPic(roomDisk, drawSurface3); + loadPic(roomNumber, bgSurface, HALF_PAL); + black(); + updateRoom(); + updateScreen(); + fadeFromBlack(0); + if (roomMusic != 0) + playMusic(roomMusic); + else + stopMusic(); +} + // The drunk tells us about Von Braun void DrasculaEngine::animation_16_2() { debug(4, "animation_16_2()"); @@ -763,8 +776,10 @@ void DrasculaEngine::animation_16_2() { else playMusic(32); - if (getScan() != 0) - goto asco; + if (getScan() != 0) { + asco(); + return; + } color_abc(kColorDarkGreen); @@ -778,16 +793,20 @@ void DrasculaEngine::animation_16_2() { centerText(_texthis[i], 180, 180); updateScreen(); - if (getScan() != 0) - goto asco; + if (getScan() != 0) { + asco(); + return; + } delay(3000); if (i < 4) { fadeToBlack(1); - if (getScan() != 0) - goto asco; + if (getScan() != 0) { + asco(); + return; + } clearRoom(); } @@ -800,25 +819,17 @@ void DrasculaEngine::animation_16_2() { copyBackground(0, 0, 0, l, 320, 200 - l, drawSurface3, screenSurface); copyBackground(0, 200 - l, 0, 0, 320, l, bgSurface, screenSurface); updateScreen(); - if (getScan() != 0) - goto asco; + if (getScan() != 0) { + asco(); + return; + } } pause(5); fadeToBlack(2); clearRoom(); -asco: - loadPic(roomDisk, drawSurface3); - loadPic(roomNumber, bgSurface, HALF_PAL); - black(); - updateRoom(); - updateScreen(); - fadeFromBlack(0); - if (roomMusic != 0) - playMusic(roomMusic); - else - stopMusic(); + asco(); } void DrasculaEngine::animation_20_2() { diff --git a/engines/drascula/drascula.h b/engines/drascula/drascula.h index 6f98c50fdc..2d1954e3ca 100644 --- a/engines/drascula/drascula.h +++ b/engines/drascula/drascula.h @@ -664,6 +664,7 @@ public: void animation_12_2(); void animation_13_2(); void animation_14_2(); + void asco(); void animation_16_2(); void animation_20_2(); void animation_23_2(); diff --git a/engines/lure/hotspots.cpp b/engines/lure/hotspots.cpp index 207c125a0c..2f6d0f23aa 100644 --- a/engines/lure/hotspots.cpp +++ b/engines/lure/hotspots.cpp @@ -4164,6 +4164,7 @@ PathFinderResult PathFinder::process() { bool altFlag; uint16 *pCurrent; PathFinderResult result = PF_UNFINISHED; + bool skipToFinalStep = false; if (!_inProgress) { // Following code only done during first call to method @@ -4186,188 +4187,190 @@ PathFinderResult PathFinder::process() { _inProgress = false; result = PF_OK; - goto final_step; - } - - // Path finding + skipToFinalStep = true; + } else { + // Path finding - _destX >>= 3; - _destY >>= 3; - _pSrc = &_layer[(_yCurrent + 1) * DECODED_PATHS_WIDTH + 1 + _xCurrent]; - _pDest = &_layer[(_yDestCurrent + 1) * DECODED_PATHS_WIDTH + 1 + _xDestCurrent]; + _destX >>= 3; + _destY >>= 3; + _pSrc = &_layer[(_yCurrent + 1) * DECODED_PATHS_WIDTH + 1 + _xCurrent]; + _pDest = &_layer[(_yDestCurrent + 1) * DECODED_PATHS_WIDTH + 1 + _xDestCurrent]; - // Flag starting/ending cells - *_pSrc = 1; - _destOccupied = *_pDest != 0; - result = _destOccupied ? PF_DEST_OCCUPIED : PF_OK; - *_pDest = 0; + // Flag starting/ending cells + *_pSrc = 1; + _destOccupied = *_pDest != 0; + result = _destOccupied ? PF_DEST_OCCUPIED : PF_OK; + *_pDest = 0; - // Set up the current pointer, adjusting away from edges if necessary + // Set up the current pointer, adjusting away from edges if necessary - if (_xCurrent >= _xDestCurrent) { - _xChangeInc = -1; - _xChangeStart = ROOM_PATHS_WIDTH; - } else { - _xChangeInc = 1; - _xChangeStart = 1; - } + if (_xCurrent >= _xDestCurrent) { + _xChangeInc = -1; + _xChangeStart = ROOM_PATHS_WIDTH; + } else { + _xChangeInc = 1; + _xChangeStart = 1; + } - if (_yCurrent >= _yDestCurrent) { - _yChangeInc = -1; - _yChangeStart = ROOM_PATHS_HEIGHT; - } else { - _yChangeInc = 1; - _yChangeStart = 1; + if (_yCurrent >= _yDestCurrent) { + _yChangeInc = -1; + _yChangeStart = ROOM_PATHS_HEIGHT; + } else { + _yChangeInc = 1; + _yChangeStart = 1; + } } } - // Major loop to populate data - _cellPopulated = false; - - while (1) { - // Loop through to process cells in the given area - if (!returnFlag) _yCtr = 0; - while (returnFlag || (_yCtr < ROOM_PATHS_HEIGHT)) { - if (!returnFlag) _xCtr = 0; + if (!skipToFinalStep) { + // Major loop to populate data + _cellPopulated = false; - while (returnFlag || (_xCtr < ROOM_PATHS_WIDTH)) { - if (!returnFlag) { - processCell(&_layer[(_yChangeStart + _yCtr * _yChangeInc) * DECODED_PATHS_WIDTH + - (_xChangeStart + _xCtr * _xChangeInc)]); - if (breakFlag && (_countdownCtr <= 0)) return PF_UNFINISHED; - } else { - returnFlag = false; + while (1) { + // Loop through to process cells in the given area + if (!returnFlag) _yCtr = 0; + while (returnFlag || (_yCtr < ROOM_PATHS_HEIGHT)) { + if (!returnFlag) _xCtr = 0; + + while (returnFlag || (_xCtr < ROOM_PATHS_WIDTH)) { + if (!returnFlag) { + processCell(&_layer[(_yChangeStart + _yCtr * _yChangeInc) * DECODED_PATHS_WIDTH + + (_xChangeStart + _xCtr * _xChangeInc)]); + if (breakFlag && (_countdownCtr <= 0)) return PF_UNFINISHED; + } else { + returnFlag = false; + } + ++_xCtr; } - ++_xCtr; + ++_yCtr; } - ++_yCtr; - } - // If the destination cell has been filled in, then break out of loop - if (*_pDest != 0) break; + // If the destination cell has been filled in, then break out of loop + if (*_pDest != 0) break; - if (_cellPopulated) { - // At least one cell populated, so go repeat loop - _cellPopulated = false; - } else { - result = PF_PART_PATH; - scanFlag = true; - break; + if (_cellPopulated) { + // At least one cell populated, so go repeat loop + _cellPopulated = false; + } else { + result = PF_PART_PATH; + scanFlag = true; + break; + } } - } - _inProgress = false; + _inProgress = false; - if (scanFlag || _destOccupied) { - // Adjust the end point if necessary to stop character walking into occupied area + if (scanFlag || _destOccupied) { + // Adjust the end point if necessary to stop character walking into occupied area - // Restore destination's occupied state if necessary - if (_destOccupied) { - *_pDest = 0xffff; - _destOccupied = false; - } + // Restore destination's occupied state if necessary + if (_destOccupied) { + *_pDest = 0xffff; + _destOccupied = false; + } - // Scan through lines - v = 0xff; - pTemp = _pDest; - scanLine(_destX, -1, pTemp, v); - scanLine(ROOM_PATHS_WIDTH - _destX, 1, pTemp, v); - scanLine(_destY, -DECODED_PATHS_WIDTH, pTemp, v); - scanLine(ROOM_PATHS_HEIGHT - _destY, DECODED_PATHS_WIDTH, pTemp, v); + // Scan through lines + v = 0xff; + pTemp = _pDest; + scanLine(_destX, -1, pTemp, v); + scanLine(ROOM_PATHS_WIDTH - _destX, 1, pTemp, v); + scanLine(_destY, -DECODED_PATHS_WIDTH, pTemp, v); + scanLine(ROOM_PATHS_HEIGHT - _destY, DECODED_PATHS_WIDTH, pTemp, v); + + if (pTemp == _pDest) { + clear(); + return PF_NO_WALK; + } - if (pTemp == _pDest) { - clear(); - return PF_NO_WALK; + _pDest = pTemp; } - _pDest = pTemp; - } + // ****DEBUG**** + if (_hotspot->hotspotId() == PLAYER_ID) { + for (int ctr = 0; ctr < DECODED_PATHS_WIDTH * DECODED_PATHS_HEIGHT; ++ctr) + Room::getReference().tempLayer[ctr] = _layer[ctr]; + } - // ****DEBUG**** - if (_hotspot->hotspotId() == PLAYER_ID) { - for (int ctr = 0; ctr < DECODED_PATHS_WIDTH * DECODED_PATHS_HEIGHT; ++ctr) - Room::getReference().tempLayer[ctr] = _layer[ctr]; - } + // Determine the walk path by working backwards from the destination, adding in the + // walking steps in reverse order until source is reached + int stageCtr; + for (stageCtr = 0; stageCtr < 3; ++stageCtr) { + // Clear out any previously determined directions + clear(); - // Determine the walk path by working backwards from the destination, adding in the - // walking steps in reverse order until source is reached - int stageCtr; - for (stageCtr = 0; stageCtr < 3; ++stageCtr) { - // Clear out any previously determined directions - clear(); + altFlag = stageCtr == 1; + pCurrent = _pDest; + + numSteps = 0; + currDirection = NO_DIRECTION; + while (1) { + v = *pCurrent - 1; + if (v == 0) break; + + newDirection = NO_DIRECTION; + if (!altFlag && (currDirection != LEFT) && (currDirection != RIGHT)) { + // Standard order direction checking + if (*(pCurrent - DECODED_PATHS_WIDTH) == v) newDirection = DOWN; + else if (*(pCurrent + DECODED_PATHS_WIDTH) == v) newDirection = UP; + else if (*(pCurrent + 1) == v) newDirection = LEFT; + else if (*(pCurrent - 1) == v) newDirection = RIGHT; + } else { + // Alternate order direction checking + if (*(pCurrent + 1) == v) newDirection = LEFT; + else if (*(pCurrent - 1) == v) newDirection = RIGHT; + else if (*(pCurrent - DECODED_PATHS_WIDTH) == v) newDirection = DOWN; + else if (*(pCurrent + DECODED_PATHS_WIDTH) == v) newDirection = UP; + } + if (newDirection == NO_DIRECTION) + error("Path finding process failed"); - altFlag = stageCtr == 1; - pCurrent = _pDest; + // Process for the specified direction + if (newDirection != currDirection) add(newDirection, 0); - numSteps = 0; - currDirection = NO_DIRECTION; - while (1) { - v = *pCurrent - 1; - if (v == 0) break; - - newDirection = NO_DIRECTION; - if (!altFlag && (currDirection != LEFT) && (currDirection != RIGHT)) { - // Standard order direction checking - if (*(pCurrent - DECODED_PATHS_WIDTH) == v) newDirection = DOWN; - else if (*(pCurrent + DECODED_PATHS_WIDTH) == v) newDirection = UP; - else if (*(pCurrent + 1) == v) newDirection = LEFT; - else if (*(pCurrent - 1) == v) newDirection = RIGHT; - } else { - // Alternate order direction checking - if (*(pCurrent + 1) == v) newDirection = LEFT; - else if (*(pCurrent - 1) == v) newDirection = RIGHT; - else if (*(pCurrent - DECODED_PATHS_WIDTH) == v) newDirection = DOWN; - else if (*(pCurrent + DECODED_PATHS_WIDTH) == v) newDirection = UP; - } - if (newDirection == NO_DIRECTION) - error("Path finding process failed"); - - // Process for the specified direction - if (newDirection != currDirection) add(newDirection, 0); + switch (newDirection) { + case UP: + pCurrent += DECODED_PATHS_WIDTH; + break; - switch (newDirection) { - case UP: - pCurrent += DECODED_PATHS_WIDTH; - break; + case DOWN: + pCurrent -= DECODED_PATHS_WIDTH; + break; - case DOWN: - pCurrent -= DECODED_PATHS_WIDTH; - break; + case LEFT: + ++pCurrent; + break; - case LEFT: - ++pCurrent; - break; + case RIGHT: + --pCurrent; + break; - case RIGHT: - --pCurrent; - break; + default: + break; + } - default: - break; + ++numSteps; + top().rawSteps() += 8; + currDirection = newDirection; } - ++numSteps; - top().rawSteps() += 8; - currDirection = newDirection; + if (stageCtr == 0) + // Save the number of steps needed + savedSteps = numSteps; + if ((stageCtr == 1) && (numSteps <= savedSteps)) + // Less steps were needed, so break out + break; } - if (stageCtr == 0) - // Save the number of steps needed - savedSteps = numSteps; - if ((stageCtr == 1) && (numSteps <= savedSteps)) - // Less steps were needed, so break out - break; - } - - // Add final movement if necessary + // Add final movement if necessary - if (result == PF_OK) { - if (_xDestPos < 0) - addBack(LEFT, -_xDestPos); - else if (_xDestPos > 0) - addBack(RIGHT, _xDestPos); + if (result == PF_OK) { + if (_xDestPos < 0) + addBack(LEFT, -_xDestPos); + else if (_xDestPos > 0) + addBack(RIGHT, _xDestPos); + } } -final_step: + // Final Step if (_xPos < 0) add(RIGHT, -_xPos); else if (_xPos > 0) add(LEFT, _xPos); diff --git a/engines/lure/menu.cpp b/engines/lure/menu.cpp index 9919471c76..61de2bf165 100644 --- a/engines/lure/menu.cpp +++ b/engines/lure/menu.cpp @@ -515,7 +515,9 @@ uint16 PopupMenu::Show(int numEntries, const char *actions[]) { r.top = Surface::textY(); r.bottom = s->height() - Surface::textY() + 1; - for (;;) { + bool bailOut = false; + + while (!bailOut) { if (refreshFlag) { // Set up the contents of the menu s->fillRect(r, bgColor); @@ -546,8 +548,8 @@ uint16 PopupMenu::Show(int numEntries, const char *actions[]) { while (e.pollEvent()) { if (engine.shouldQuit()) { selectedIndex = 0xffff; - goto bail_out; - + bailOut = true; + break; } else if (e.type() == Common::EVENT_WHEELUP) { // Scroll upwards if (selectedIndex > 0) { @@ -571,10 +573,12 @@ uint16 PopupMenu::Show(int numEntries, const char *actions[]) { ++selectedIndex; refreshFlag = true; } else if ((keycode == Common::KEYCODE_RETURN) || (keycode == Common::KEYCODE_KP_ENTER)) { - goto bail_out; + bailOut = true; + break; } else if (keycode == Common::KEYCODE_ESCAPE) { selectedIndex = 0xffff; - goto bail_out; + bailOut = true; + break; } #ifdef LURE_CLICKABLE_MENUS @@ -586,46 +590,51 @@ uint16 PopupMenu::Show(int numEntries, const char *actions[]) { if (r.contains(x, y)) { selectedIndex = (y - r.top) / FONT_HEIGHT; if (e.type() == Common::EVENT_LBUTTONDOWN) - goto bail_out; + bailOut = true; + break; } #else } else if ((e.type() == Common::EVENT_LBUTTONDOWN) || (e.type() == Common::EVENT_MBUTTONDOWN)) { //mouse.waitForRelease(); - goto bail_out; + bailOut = true; + break; #endif } else if (e.type() == Common::EVENT_RBUTTONDOWN) { mouse.waitForRelease(); selectedIndex = 0xffff; - goto bail_out; + bailOut = true; + break; } } + if (!bailOut) { #ifndef LURE_CLICKABLE_MENUS - // Warping the mouse to "neutral" even if the top/bottom menu - // entry has been reached has both pros and cons. It makes the - // menu behave a bit more sensibly, but it also makes it harder - // to move the mouse pointer out of the ScummVM window. - - if (mouse.y() < yMiddle - POPMENU_CHANGE_SENSITIVITY) { - if (selectedIndex > 0) { - --selectedIndex; - refreshFlag = true; - } - mouse.setPosition(FULL_SCREEN_WIDTH / 2, yMiddle); - } else if (mouse.y() > yMiddle + POPMENU_CHANGE_SENSITIVITY) { - if (selectedIndex < numEntries - 1) { - ++selectedIndex; - refreshFlag = true; + // Warping the mouse to "neutral" even if the top/bottom menu + // entry has been reached has both pros and cons. It makes the + // menu behave a bit more sensibly, but it also makes it harder + // to move the mouse pointer out of the ScummVM window. + + if (mouse.y() < yMiddle - POPMENU_CHANGE_SENSITIVITY) { + if (selectedIndex > 0) { + --selectedIndex; + refreshFlag = true; + } + mouse.setPosition(FULL_SCREEN_WIDTH / 2, yMiddle); + } else if (mouse.y() > yMiddle + POPMENU_CHANGE_SENSITIVITY) { + if (selectedIndex < numEntries - 1) { + ++selectedIndex; + refreshFlag = true; + } + mouse.setPosition(FULL_SCREEN_WIDTH / 2, yMiddle); } - mouse.setPosition(FULL_SCREEN_WIDTH / 2, yMiddle); - } #endif - system.delayMillis(20); + system.delayMillis(20); + } } -bail_out: + // bailOut delete s; #ifndef LURE_CLICKABLE_MENUS diff --git a/engines/sky/logic.cpp b/engines/sky/logic.cpp index a69ba793f2..86c8828e5a 100644 --- a/engines/sky/logic.cpp +++ b/engines/sky/logic.cpp @@ -1232,191 +1232,197 @@ uint16 Logic::mouseScript(uint32 scrNum, Compact *scriptComp) { * @return 0 if script finished. Else offset where to continue. */ uint16 Logic::script(uint16 scriptNo, uint16 offset) { -script: - /// process a script - /// low level interface to interpreter + bool restartScript; - uint16 moduleNo = scriptNo >> 12; - uint16 *scriptData = _moduleList[moduleNo]; // get module address + do { + restartScript = false; - if (!scriptData) { // We need to load the script module - _moduleList[moduleNo] = _skyDisk->loadScriptFile(moduleNo + F_MODULE_0); - scriptData = _moduleList[moduleNo]; // module has been loaded - } + /// process a script + /// low level interface to interpreter - uint16 *moduleStart = scriptData; + uint16 moduleNo = scriptNo >> 12; + uint16 *scriptData = _moduleList[moduleNo]; // get module address - debug(3, "Doing Script: %d:%d:%x", moduleNo, scriptNo & 0xFFF, offset ? (offset - moduleStart[scriptNo & 0xFFF]) : 0); + if (!scriptData) { // We need to load the script module + _moduleList[moduleNo] = _skyDisk->loadScriptFile(moduleNo + F_MODULE_0); + scriptData = _moduleList[moduleNo]; // module has been loaded + } - // WORKAROUND for bug #3149412: "Invalid Mode when giving shades to travel agent" - // Using the dark glasses on Trevor (travel agent) multiple times in succession would - // wreck the trevor compact's mode, as the script in question doesn't account for using - // this item at this point in the game (you will only have it here if you play the game - // in an unusual way) and thus would loop indefinitely / never drop out. - // To prevent this, we trigger the generic response by pretending we're using an item - // which the script /does/ handle. - if (scriptNo == TREVOR_SPEECH && _scriptVariables[OBJECT_HELD] == IDO_SHADES) - _scriptVariables[OBJECT_HELD] = IDO_GLASS; + uint16 *moduleStart = scriptData; + debug(3, "Doing Script: %d:%d:%x", moduleNo, scriptNo & 0xFFF, offset ? (offset - moduleStart[scriptNo & 0xFFF]) : 0); - // Check whether we have an offset or what - if (offset) - scriptData = moduleStart + offset; - else - scriptData += scriptData[scriptNo & 0x0FFF]; + // WORKAROUND for bug #3149412: "Invalid Mode when giving shades to travel agent" + // Using the dark glasses on Trevor (travel agent) multiple times in succession would + // wreck the trevor compact's mode, as the script in question doesn't account for using + // this item at this point in the game (you will only have it here if you play the game + // in an unusual way) and thus would loop indefinitely / never drop out. + // To prevent this, we trigger the generic response by pretending we're using an item + // which the script /does/ handle. + if (scriptNo == TREVOR_SPEECH && _scriptVariables[OBJECT_HELD] == IDO_SHADES) + _scriptVariables[OBJECT_HELD] = IDO_GLASS; - uint32 a = 0, b = 0, c = 0; - uint16 command, s; - for (;;) { - command = *scriptData++; // get a command - Debug::script(command, scriptData); - - switch (command) { - case 0: // push_variable - push( _scriptVariables[*scriptData++ / 4] ); - break; - case 1: // less_than - a = pop(); - b = pop(); - if (a > b) - push(1); - else - push(0); - break; - case 2: // push_number - push(*scriptData++); - break; - case 3: // not_equal - a = pop(); - b = pop(); - if (a != b) - push(1); - else - push(0); - break; - case 4: // if_and - a = pop(); - b = pop(); - if (a && b) - push(1); - else - push(0); - break; - case 5: // skip_zero - s = *scriptData++; - - a = pop(); - if (!a) - scriptData += s / 2; - break; - case 6: // pop_var - b = _scriptVariables[*scriptData++ / 4] = pop(); - break; - case 7: // minus - a = pop(); - b = pop(); - push(b-a); - break; - case 8: // plus - a = pop(); - b = pop(); - push(b+a); - break; - case 9: // skip_always - s = *scriptData++; - scriptData += s / 2; - break; - case 10: // if_or - a = pop(); - b = pop(); - if (a || b) - push(1); - else - push(0); - break; - case 11: // call_mcode - { - a = *scriptData++; - assert(a <= 3); - // No, I did not forget the "break"s - switch (a) { - case 3: - c = pop(); - case 2: - b = pop(); - case 1: - a = pop(); - } - - uint16 mcode = *scriptData++ / 4; // get mcode number - Debug::mcode(mcode, a, b, c); + // Check whether we have an offset or what + if (offset) + scriptData = moduleStart + offset; + else + scriptData += scriptData[scriptNo & 0x0FFF]; - Compact *saveCpt = _compact; - bool ret = (this->*_mcodeTable[mcode]) (a, b, c); - _compact = saveCpt; + uint32 a = 0, b = 0, c = 0; + uint16 command, s; - if (!ret) - return (scriptData - moduleStart); - } - break; - case 12: // more_than - a = pop(); - b = pop(); - if (a < b) - push(1); - else - push(0); - break; - case 14: // switch - c = s = *scriptData++; // get number of cases + while(!restartScript) { + command = *scriptData++; // get a command + Debug::script(command, scriptData); - a = pop(); // and value to switch on + switch (command) { + case 0: // push_variable + push( _scriptVariables[*scriptData++ / 4] ); + break; + case 1: // less_than + a = pop(); + b = pop(); + if (a > b) + push(1); + else + push(0); + break; + case 2: // push_number + push(*scriptData++); + break; + case 3: // not_equal + a = pop(); + b = pop(); + if (a != b) + push(1); + else + push(0); + break; + case 4: // if_and + a = pop(); + b = pop(); + if (a && b) + push(1); + else + push(0); + break; + case 5: // skip_zero + s = *scriptData++; - do { - if (a == *scriptData) { - scriptData += scriptData[1] / 2; - scriptData++; - break; + a = pop(); + if (!a) + scriptData += s / 2; + break; + case 6: // pop_var + b = _scriptVariables[*scriptData++ / 4] = pop(); + break; + case 7: // minus + a = pop(); + b = pop(); + push(b-a); + break; + case 8: // plus + a = pop(); + b = pop(); + push(b+a); + break; + case 9: // skip_always + s = *scriptData++; + scriptData += s / 2; + break; + case 10: // if_or + a = pop(); + b = pop(); + if (a || b) + push(1); + else + push(0); + break; + case 11: // call_mcode + { + a = *scriptData++; + assert(a <= 3); + // No, I did not forget the "break"s + switch (a) { + case 3: + c = pop(); + case 2: + b = pop(); + case 1: + a = pop(); + } + + uint16 mcode = *scriptData++ / 4; // get mcode number + Debug::mcode(mcode, a, b, c); + + Compact *saveCpt = _compact; + bool ret = (this->*_mcodeTable[mcode]) (a, b, c); + _compact = saveCpt; + + if (!ret) + return (scriptData - moduleStart); } - scriptData += 2; - } while (--s); - - if (s == 0) - scriptData += *scriptData / 2; // use the default - break; - case 15: // push_offset - push( *(uint16 *)_skyCompact->getCompactElem(_compact, *scriptData++) ); - break; - case 16: // pop_offset - // pop a value into a compact - *(uint16 *)_skyCompact->getCompactElem(_compact, *scriptData++) = (uint16)pop(); - break; - case 17: // is_equal - a = pop(); - b = pop(); - if (a == b) - push(1); - else - push(0); - break; - case 18: { // skip_nz - int16 t = *scriptData++; + break; + case 12: // more_than + a = pop(); + b = pop(); + if (a < b) + push(1); + else + push(0); + break; + case 14: // switch + c = s = *scriptData++; // get number of cases + + a = pop(); // and value to switch on + + do { + if (a == *scriptData) { + scriptData += scriptData[1] / 2; + scriptData++; + break; + } + scriptData += 2; + } while (--s); + + if (s == 0) + scriptData += *scriptData / 2; // use the default + break; + case 15: // push_offset + push( *(uint16 *)_skyCompact->getCompactElem(_compact, *scriptData++) ); + break; + case 16: // pop_offset + // pop a value into a compact + *(uint16 *)_skyCompact->getCompactElem(_compact, *scriptData++) = (uint16)pop(); + break; + case 17: // is_equal a = pop(); - if (a) - scriptData += t / 2; + b = pop(); + if (a == b) + push(1); + else + push(0); + break; + case 18: { // skip_nz + int16 t = *scriptData++; + a = pop(); + if (a) + scriptData += t / 2; + break; + } + case 13: + case 19: // script_exit + return 0; + case 20: // restart_script + offset = 0; + restartScript = true; break; + default: + error("Unknown script command: %d", command); } - case 13: - case 19: // script_exit - return 0; - case 20: // restart_script - offset = 0; - goto script; - default: - error("Unknown script command: %d", command); } - } + } while (restartScript); } bool Logic::fnCacheChip(uint32 a, uint32 b, uint32 c) { diff --git a/engines/sword25/gfx/image/art.cpp b/engines/sword25/gfx/image/art.cpp index 2ba102e779..3944a207c8 100644 --- a/engines/sword25/gfx/image/art.cpp +++ b/engines/sword25/gfx/image/art.cpp @@ -328,18 +328,6 @@ static void art_vpath_render_bez(ArtVpath **p_vpath, int *pn, int *pn_max, double x2, double y2, double x3, double y3, double flatness) { - double x3_0, y3_0; - double z3_0_dot; - double z1_dot, z2_dot; - double z1_perp, z2_perp; - double max_perp_sq; - - double x_m, y_m; - double xa1, ya1; - double xa2, ya2; - double xb1, yb1; - double xb2, yb2; - /* It's possible to optimize this routine a fair amount. First, once the _dot conditions are met, they will also be met in @@ -363,11 +351,13 @@ static void art_vpath_render_bez(ArtVpath **p_vpath, int *pn, int *pn_max, */ - x3_0 = x3 - x0; - y3_0 = y3 - y0; + bool subDivide = false; + + double x3_0 = x3 - x0; + double y3_0 = y3 - y0; - /* z3_0_dot is dist z0-z3 squared */ - z3_0_dot = x3_0 * x3_0 + y3_0 * y3_0; + // z3_0_dot is dist z0-z3 squared + double z3_0_dot = x3_0 * x3_0 + y3_0 * y3_0; if (z3_0_dot < 0.001) { /* if start and end point are almost identical, the flatness tests @@ -375,72 +365,68 @@ static void art_vpath_render_bez(ArtVpath **p_vpath, int *pn, int *pn_max, * the other two control points are the same as the start point, * too. */ - if (hypot(x1 - x0, y1 - y0) < 0.001 - && hypot(x2 - x0, y2 - y0) < 0.001) - goto nosubdivide; - else - goto subdivide; - } - - /* we can avoid subdivision if: - - z1 has distance no more than flatness from the z0-z3 line - - z1 is no more z0'ward than flatness past z0-z3 - - z1 is more z0'ward than z3'ward on the line traversing z0-z3 - - and correspondingly for z2 */ - - /* perp is distance from line, multiplied by dist z0-z3 */ - max_perp_sq = flatness * flatness * z3_0_dot; - - z1_perp = (y1 - y0) * x3_0 - (x1 - x0) * y3_0; - if (z1_perp * z1_perp > max_perp_sq) - goto subdivide; + if (!(hypot(x1 - x0, y1 - y0) < 0.001 + && hypot(x2 - x0, y2 - y0) < 0.001)) + subDivide = true; + } else { + /* we can avoid subdivision if: - z2_perp = (y3 - y2) * x3_0 - (x3 - x2) * y3_0; - if (z2_perp * z2_perp > max_perp_sq) - goto subdivide; + z1 has distance no more than flatness from the z0-z3 line - z1_dot = (x1 - x0) * x3_0 + (y1 - y0) * y3_0; - if (z1_dot < 0 && z1_dot * z1_dot > max_perp_sq) - goto subdivide; + z1 is no more z0'ward than flatness past z0-z3 - z2_dot = (x3 - x2) * x3_0 + (y3 - y2) * y3_0; - if (z2_dot < 0 && z2_dot * z2_dot > max_perp_sq) - goto subdivide; + z1 is more z0'ward than z3'ward on the line traversing z0-z3 - if (z1_dot + z1_dot > z3_0_dot) - goto subdivide; + and correspondingly for z2 */ - if (z2_dot + z2_dot > z3_0_dot) - goto subdivide; + // perp is distance from line, multiplied by dist z0-z3 + double max_perp_sq = flatness * flatness * z3_0_dot; + double z1_perp = (y1 - y0) * x3_0 - (x1 - x0) * y3_0; + if (z1_perp * z1_perp > max_perp_sq) { + subDivide = true; + } else { + double z2_perp = (y3 - y2) * x3_0 - (x3 - x2) * y3_0; + if (z2_perp * z2_perp > max_perp_sq) { + subDivide = true; + } else { + double z1_dot = (x1 - x0) * x3_0 + (y1 - y0) * y3_0; + if (z1_dot < 0 && z1_dot * z1_dot > max_perp_sq) { + subDivide = true; + } else { + double z2_dot = (x3 - x2) * x3_0 + (y3 - y2) * y3_0; + if (z2_dot < 0 && z2_dot * z2_dot > max_perp_sq) + subDivide = true; + else if (z1_dot + z1_dot > z3_0_dot) + subDivide = true; + else if (z2_dot + z2_dot > z3_0_dot) + subDivide = true; + } + } + } + } -nosubdivide: - /* don't subdivide */ - art_vpath_add_point(p_vpath, pn, pn_max, - ART_LINETO, x3, y3); - return; - -subdivide: - - xa1 = (x0 + x1) * 0.5; - ya1 = (y0 + y1) * 0.5; - xa2 = (x0 + 2 * x1 + x2) * 0.25; - ya2 = (y0 + 2 * y1 + y2) * 0.25; - xb1 = (x1 + 2 * x2 + x3) * 0.25; - yb1 = (y1 + 2 * y2 + y3) * 0.25; - xb2 = (x2 + x3) * 0.5; - yb2 = (y2 + y3) * 0.5; - x_m = (xa2 + xb1) * 0.5; - y_m = (ya2 + yb1) * 0.5; - - art_vpath_render_bez(p_vpath, pn, pn_max, - x0, y0, xa1, ya1, xa2, ya2, x_m, y_m, flatness); - art_vpath_render_bez(p_vpath, pn, pn_max, - x_m, y_m, xb1, yb1, xb2, yb2, x3, y3, flatness); + if (subDivide) { + double xa1 = (x0 + x1) * 0.5; + double ya1 = (y0 + y1) * 0.5; + double xa2 = (x0 + 2 * x1 + x2) * 0.25; + double ya2 = (y0 + 2 * y1 + y2) * 0.25; + double xb1 = (x1 + 2 * x2 + x3) * 0.25; + double yb1 = (y1 + 2 * y2 + y3) * 0.25; + double xb2 = (x2 + x3) * 0.5; + double yb2 = (y2 + y3) * 0.5; + double x_m = (xa2 + xb1) * 0.5; + double y_m = (ya2 + yb1) * 0.5; + + art_vpath_render_bez(p_vpath, pn, pn_max, + x0, y0, xa1, ya1, xa2, ya2, x_m, y_m, flatness); + art_vpath_render_bez(p_vpath, pn, pn_max, + x_m, y_m, xb1, yb1, xb2, yb2, x3, y3, flatness); + } else { + // don't subdivide + art_vpath_add_point(p_vpath, pn, pn_max, + ART_LINETO, x3, y3); + } } /** diff --git a/engines/tinsel/saveload.cpp b/engines/tinsel/saveload.cpp index a0801d8247..8664cd5f15 100644 --- a/engines/tinsel/saveload.cpp +++ b/engines/tinsel/saveload.cpp @@ -486,6 +486,16 @@ static bool DoRestore() { return !failed; } +static void SaveFailure(Common::OutSaveFile *f) { + if (f) { + delete f; + _vm->getSaveFileMan()->removeSavefile(SaveSceneName); + SaveSceneName = NULL; // Invalidate save name + } + GUI::MessageDialog dialog(_("Failed to save game state to file.")); + dialog.runModal(); +} + /** * DoSave */ @@ -524,8 +534,10 @@ static void DoSave() { f = _vm->getSaveFileMan()->openForSaving(SaveSceneName); Common::Serializer s(0, f); - if (f == NULL) - goto save_failure; + if (f == NULL) { + SaveFailure(f); + return; + } // Write out a savegame header SaveGameHeader hdr; @@ -536,29 +548,22 @@ static void DoSave() { hdr.desc[SG_DESC_LEN - 1] = 0; g_system->getTimeAndDate(hdr.dateTime); if (!syncSaveGameHeader(s, hdr) || f->err()) { - goto save_failure; + SaveFailure(f); + return; } DoSync(s); // Write out the special Id for Discworld savegames f->writeUint32LE(0xFEEDFACE); - if (f->err()) - goto save_failure; + if (f->err()) { + SaveFailure(f); + return; + } f->finalize(); delete f; SaveSceneName = NULL; // Invalidate save name - return; - -save_failure: - if (f) { - delete f; - _vm->getSaveFileMan()->removeSavefile(SaveSceneName); - SaveSceneName = NULL; // Invalidate save name - } - GUI::MessageDialog dialog(_("Failed to save game state to file.")); - dialog.runModal(); } /** diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp index 60ca007930..2dd5fc45e2 100644 --- a/engines/toon/path.cpp +++ b/engines/toon/path.cpp @@ -322,9 +322,10 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) { int32 endY = MIN<int32>(curY + 1, _height - 1); int32 startX = MAX<int32>(curX - 1, 0); int32 startY = MAX<int32>(curY - 1, 0); + bool next = false; - for (int32 px = startX; px <= endX; px++) { - for (int py = startY; py <= endY; py++) { + for (int32 px = startX; px <= endX && !next; px++) { + for (int py = startY; py <= endY && !next; py++) { if (px != curX || py != curY) { wei = ((abs(px - curX) + abs(py - curY))); @@ -336,7 +337,7 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) { sq[curPNode] = sum; _heap->push(px, py, sq[curPNode] + newWeight); if (!newWeight) - goto next; // we found it ! + next = true; // we found it ! } } } @@ -344,8 +345,6 @@ int32 PathFinding::findPath(int32 x, int32 y, int32 destx, int32 desty) { } } -next: - // let's see if we found a result ! if (!_gridTemp[destx + desty * _width]) { // didn't find anything diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp index 13f702e3dd..99932362af 100644 --- a/engines/toon/toon.cpp +++ b/engines/toon/toon.cpp @@ -2297,8 +2297,7 @@ void ToonEngine::processConversationClick(Conversation *conv, int32 status) { if (v8 == -1) { _gameState->_mouseHidden = false; } else { -retry: - while (1) { + while (v8 != -1) { v7 += 1; int16 *v14 = (int16 *)((char *)_conversationData + v8); @@ -2315,15 +2314,10 @@ retry: v8 = READ_LE_INT16(v7); if (v8 == -1) return; - - goto retry; + else + break; // restarts while loop; } } - - if (v8 != -1) - continue; - - break; } } } |