From 563d890991026b268b420ad65cc55508f1a4c622 Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Wed, 3 Feb 2016 00:26:35 +0100 Subject: AGI: Fix regression of have.key changes original commit 8269a94bcd55200f7ae8aba00c7b6fd0d37b9a37 Now hopefully properly implemented. Adjusted a few more inaccuracies (we set v19 to 0, where we shouldn't have) --- engines/agi/agi.h | 5 +---- engines/agi/cycle.cpp | 29 ++++++++++------------------- engines/agi/op_test.cpp | 34 ++++++++++++---------------------- engines/agi/text.cpp | 2 -- 4 files changed, 23 insertions(+), 47 deletions(-) diff --git a/engines/agi/agi.h b/engines/agi/agi.h index 801d807291..df40344177 100644 --- a/engines/agi/agi.h +++ b/engines/agi/agi.h @@ -389,8 +389,7 @@ enum CycleInnerLoopType { CYCLE_INNERLOOP_INVENTORY = 2, CYCLE_INNERLOOP_MENU_VIA_KEYBOARD = 3, CYCLE_INNERLOOP_MENU_VIA_MOUSE = 4, - CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT = 5, - CYCLE_INNERLOOP_HAVEKEY = 6 + CYCLE_INNERLOOP_SYSTEMUI_SELECTSAVEDGAMESLOT = 5 }; enum State { @@ -872,8 +871,6 @@ public: uint8 testController(uint8); uint8 testCompareStrings(uint8, uint8); - void testHaveKeyCharPress(uint16 newChar); - // View private: diff --git a/engines/agi/cycle.cpp b/engines/agi/cycle.cpp index e2b6e0a065..c9f109b8b3 100644 --- a/engines/agi/cycle.cpp +++ b/engines/agi/cycle.cpp @@ -176,7 +176,6 @@ void AgiEngine::interpretCycle() { // If main_cycle returns false, don't process more events! int AgiEngine::mainCycle(bool onlyCheckForEvents) { uint16 key; - byte keyAscii; ScreenObjEntry *screenObjEgo = &_game.screenObjTable[SCREENOBJECTS_EGO_ENTRY]; if (!onlyCheckForEvents) { @@ -219,19 +218,18 @@ int AgiEngine::mainCycle(bool onlyCheckForEvents) { } } - keyAscii = key & 0xFF; - if (keyAscii) { - setVar(VM_VAR_KEY, keyAscii); - } - handleMouseClicks(key); if (!cycleInnerLoopIsActive()) { // no inner loop active at the moment, regular processing + if (key) { + setVar(VM_VAR_KEY, key & 0xFF); if (!handleController(key)) { - if ((key) && (_text->promptIsEnabled())) { - _text->promptCharPress(key); + if (key) { + if (_text->promptIsEnabled()) { + _text->promptCharPress(key); + } } } } @@ -239,7 +237,6 @@ int AgiEngine::mainCycle(bool onlyCheckForEvents) { } else { // inner loop active // call specific workers - setVar(VM_VAR_KEY, 0); // clear keys, they must not be passed to the scripts _game.keypress = 0; switch (_game.cycleInnerLoopType) { @@ -272,22 +269,16 @@ int AgiEngine::mainCycle(bool onlyCheckForEvents) { } break; - case CYCLE_INNERLOOP_HAVEKEY: - if (key) { - testHaveKeyCharPress(key); - } - break; - default: break; } } - if (_menu->delayedExecuteActive()) { - _menu->execute(); - } - if (!onlyCheckForEvents) { + if (_menu->delayedExecuteActive()) { + _menu->execute(); + } + if (_game.msgBoxTicks > 0) _game.msgBoxTicks--; } diff --git a/engines/agi/op_test.cpp b/engines/agi/op_test.cpp index 359077807b..ca473fe618 100644 --- a/engines/agi/op_test.cpp +++ b/engines/agi/op_test.cpp @@ -119,29 +119,19 @@ void condController(AgiGame *state, AgiEngine *vm, uint8 *p) { } void condHaveKey(AgiGame *state, AgiEngine *vm, uint8 *p) { - if (!vm->getVar(VM_VAR_KEY)) { - // Only wait for key when there is not already one set by scripts - vm->cycleInnerLoopActive(CYCLE_INNERLOOP_HAVEKEY); - do { - // Only check for events here, without updating the game cycle, - // otherwise the animations in some games are drawn too quickly - // like, for example, Manannan's lightnings in the intro of KQ3 - // and the bullets opened in the logo of PQ1, during its intro. - // Fixes bug #3600733 - vm->mainCycle(true); - } while (vm->cycleInnerLoopIsActive() && !(vm->shouldQuit() || vm->_restartGame)); + if (vm->getVar(VM_VAR_KEY)) { + state->testResult = 1; + return; } - - state->testResult = 1; -} - -void AgiEngine::testHaveKeyCharPress(uint16 newChar) { - // pass key to scripts - setVar(VM_VAR_KEY, newChar); - - // Exit on any key press - cycleInnerLoopInactive(); - debugC(5, kDebugLevelScripts | kDebugLevelInput, "keypress = %02x", newChar); + // Only check for key when there is not already one set by scripts + uint16 key = vm->doPollKeyboard(); + if (key) { + debugC(5, kDebugLevelScripts | kDebugLevelInput, "keypress = %02x", key); + vm->setVar(VM_VAR_KEY, key); + state->testResult = 1; + return; + } + state->testResult = 0; } void condSaid(AgiGame *state, AgiEngine *vm, uint8 *p) { diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp index be8dfb2760..cb172ea718 100644 --- a/engines/agi/text.cpp +++ b/engines/agi/text.cpp @@ -350,7 +350,6 @@ bool TextMgr::messageBox(const char *textPtr) { if (_vm->getVar(VM_VAR_WINDOW_RESET) == 0) { int userKey; - _vm->setVar(VM_VAR_KEY, 0); userKey = _vm->waitKey(); closeWindow(); @@ -363,7 +362,6 @@ bool TextMgr::messageBox(const char *textPtr) { // timed window debugC(3, kDebugLevelText, "f15==0, v21==%d => timed", _vm->getVar(VM_VAR_WINDOW_RESET)); _vm->_game.msgBoxTicks = _vm->getVar(VM_VAR_WINDOW_RESET) * 10; - _vm->setVar(VM_VAR_KEY, 0); do { if (_vm->getFlag(VM_FLAG_RESTORE_JUST_RAN)) -- cgit v1.2.3