From a1e43850d11b926a46825ca5dff057c59cfb858b Mon Sep 17 00:00:00 2001 From: Martin Gerhardy Date: Sat, 24 Oct 2020 13:31:56 +0200 Subject: [PATCH] TWINE: cleanup and more keymapper actions connected --- engines/twine/extra.cpp | 5 +++-- engines/twine/input.h | 2 -- engines/twine/menu.cpp | 24 +++--------------------- engines/twine/menuoptions.cpp | 19 +------------------ engines/twine/movements.cpp | 8 ++++---- engines/twine/movements.h | 4 ++++ engines/twine/twine.cpp | 3 +-- engines/twine/twine.h | 1 - 8 files changed, 16 insertions(+), 50 deletions(-) diff --git a/engines/twine/extra.cpp b/engines/twine/extra.cpp index 22231b77aef..09bef1b3d16 100644 --- a/engines/twine/extra.cpp +++ b/engines/twine/extra.cpp @@ -25,6 +25,7 @@ #include "twine/collision.h" #include "twine/gamestate.h" #include "twine/grid.h" +#include "twine/input.h" #include "twine/interface.h" #include "twine/movements.h" #include "twine/redraw.h" @@ -861,9 +862,9 @@ void Extra::processExtras() { // if hero touch extra if (_engine->_collision->checkExtraCollisionWithActors(extra, -1) == 0) { // FIXME: add constant for sample index - _engine->_sound->playSample(97, 0x1000, 1, extra->x, extra->y, extra->z, -1); + _engine->_sound->playSample(97, 4096, 1, extra->x, extra->y, extra->z); - if (extra->info1 > 1 && !(_engine->loopPressedKey & 2)) { + if (extra->info1 > 1 && !_engine->_input->isActionActive(TwinEActionType::MoveBackward)) { _engine->_renderer->projectPositionOnScreen(extra->x - _engine->_grid->cameraX, extra->y - _engine->_grid->cameraY, extra->z - _engine->_grid->cameraZ); _engine->_redraw->addOverlay(koNumber, extra->info1, _engine->_renderer->projPosX, _engine->_renderer->projPosY, 158, koNormal, 2); } diff --git a/engines/twine/input.h b/engines/twine/input.h index 442ef384f80..fed8d80baa6 100644 --- a/engines/twine/input.h +++ b/engines/twine/input.h @@ -167,8 +167,6 @@ public: int16 internalKeyCode = 0; int16 currentKey = 0; int16 key = 0; - int32 heroPressedKey = 0; - int32 heroPressedKey2 = 0; int16 leftMouse = 0; int16 rightMouse = 0; diff --git a/engines/twine/menu.cpp b/engines/twine/menu.cpp index c6069251d44..44065671042 100644 --- a/engines/twine/menu.cpp +++ b/engines/twine/menu.cpp @@ -447,7 +447,6 @@ int32 Menu::processMenu(int16 *menuSettings) { _engine->_screens->loadMenuImage(false); do { _engine->readKeys(); - _engine->_input->key = _engine->_input->pressedKey; if (_engine->_input->toggleActionIfActive(TwinEActionType::UIDown)) { currentButton++; @@ -972,7 +971,6 @@ void Menu::drawInventoryItems() { } void Menu::processInventoryMenu() { - int32 di = 1; int32 tmpAlphaLight = _engine->_scene->alphaLight; int32 tmpBetaLight = _engine->_scene->betaLight; @@ -1000,25 +998,9 @@ void Menu::processInventoryMenu() { _engine->readKeys(); int32 prevSelectedItem = inventorySelectedItem; - if (!di) { - _engine->_input->key = _engine->_input->pressedKey; - _engine->loopPressedKey = _engine->_input->skippedKey; - _engine->loopCurrentKey = _engine->_input->internalKeyCode; - - if (_engine->_input->key != 0 || _engine->_input->skippedKey != 0) { - di = 1; - } - } else { - _engine->loopCurrentKey = 0; - _engine->_input->key = 0; - _engine->loopPressedKey = 0; - if (!_engine->_input->pressedKey && !_engine->_input->skippedKey) { - di = 0; - } - } - - if (_engine->loopCurrentKey == 1 || _engine->loopPressedKey & 0x20) + if (_engine->_input->toggleAbortAction() || _engine->_input->isActionActive(TwinEActionType::ExecuteBehaviourAction)) { break; + } if (_engine->_input->toggleActionIfActive(TwinEActionType::UIDown)) { inventorySelectedItem++; @@ -1107,7 +1089,7 @@ void Menu::processInventoryMenu() { _engine->_text->initTextBank(_engine->_text->currentTextBank + 3); - while (_engine->_input->internalKeyCode != 0 && _engine->_input->skippedKey != 0) { + while (!_engine->_input->toggleAbortAction()) { _engine->readKeys(); _engine->_system->delayMillis(1); _engine->flip(); // TODO: needed? diff --git a/engines/twine/menuoptions.cpp b/engines/twine/menuoptions.cpp index f5cfd3d71ac..1efca7fec02 100644 --- a/engines/twine/menuoptions.cpp +++ b/engines/twine/menuoptions.cpp @@ -93,10 +93,8 @@ void MenuOptions::newGame() { } void MenuOptions::showCredits() { - int32 tmpShadowMode; - canShowCredits = 1; - tmpShadowMode = _engine->cfgfile.ShadowMode; + int32 tmpShadowMode = _engine->cfgfile.ShadowMode; _engine->cfgfile.ShadowMode = 0; _engine->_gameState->initEngineVars(); _engine->_scene->currentSceneIdx = 119; @@ -229,21 +227,6 @@ void MenuOptions::newGameMenu() { if (_engine->gameEngineLoop()) { showCredits(); } - - _engine->_screens->copyScreen(_engine->frontVideoBuffer, _engine->workVideoBuffer); - // TODO: recheck this - do { - _engine->readKeys(); - do { - _engine->readKeys(); - if (_engine->shouldQuit()) { - break; - } - } while (_engine->_input->skippedKey != 0); - if (_engine->shouldQuit()) { - break; - } - } while (_engine->_input->internalKeyCode != 0); } } diff --git a/engines/twine/movements.cpp b/engines/twine/movements.cpp index a72b23c30c4..3f373e465a9 100644 --- a/engines/twine/movements.cpp +++ b/engines/twine/movements.cpp @@ -279,7 +279,7 @@ void Movements::processActorMovements(int32 actorIdx) { moveActor(actor->angle, actor->angle + tempAngle, actor->speed, &actor->move); - _engine->_input->heroPressedKey = _engine->_input->key; + heroPressedKey = _engine->_input->key; } else { if (!actor->staticFlags.bIsSpriteActor) { if (actor->controlMode != kManual) { @@ -386,7 +386,7 @@ void Movements::processActorMovements(int32 actorIdx) { heroMoved = 0; // don't break animation } - if (_engine->_input->key != _engine->_input->heroPressedKey || _engine->loopPressedKey != _engine->_input->heroPressedKey2) { + if (_engine->_input->key != heroPressedKey || _engine->loopPressedKey != heroPressedKey2) { if (heroMoved) { _engine->_animations->initAnim(kStanding, 0, 255, actorIdx); } @@ -436,8 +436,8 @@ void Movements::processActorMovements(int32 actorIdx) { moveActor(actor->angle, actor->angle + tempAngle, actor->speed, &actor->move); - _engine->_input->heroPressedKey = _engine->_input->key; - _engine->_input->heroPressedKey2 = _engine->loopPressedKey; + heroPressedKey = _engine->_input->key; + heroPressedKey2 = _engine->loopPressedKey; break; case kFollow: { diff --git a/engines/twine/movements.h b/engines/twine/movements.h index dea9d79d070..1ea548709ba 100644 --- a/engines/twine/movements.h +++ b/engines/twine/movements.h @@ -45,6 +45,10 @@ class TwinEEngine; class Movements { private: TwinEEngine *_engine; + + int32 heroPressedKey = 0; + int32 heroPressedKey2 = 0; + public: Movements(TwinEEngine *engine); /** Hero moved */ diff --git a/engines/twine/twine.cpp b/engines/twine/twine.cpp index 35c61aa3367..16e1baac026 100644 --- a/engines/twine/twine.cpp +++ b/engines/twine/twine.cpp @@ -339,9 +339,8 @@ int32 TwinEEngine::runGameEngine() { // mainLoopInteration previousLoopPressedKey = loopPressedKey; _input->key = _input->pressedKey; loopPressedKey = _input->skippedKey; - loopCurrentKey = _input->internalKeyCode; - _debug->processDebug(loopCurrentKey); + _debug->processDebug(_input->internalKeyCode); if (_menuOptions->canShowCredits != 0) { // TODO: if current music playing != 8, than play_track(8); diff --git a/engines/twine/twine.h b/engines/twine/twine.h index 3505e0444b6..67c3fbe3c5b 100644 --- a/engines/twine/twine.h +++ b/engines/twine/twine.h @@ -228,7 +228,6 @@ public: int32 loopPressedKey = 0; int32 previousLoopPressedKey = 0; - int32 loopCurrentKey = 0; int32 loopInventoryItem = 0; int32 loopActorStep = 0;