From d65140d6b58330e8c00c5bdd1360186b5657e868 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Mon, 24 Sep 2007 20:26:27 +0000 Subject: - reworked input handling - implement changing movement destination while moving svn-id: r29093 --- engines/kyra/kyra_v2.cpp | 36 ++++++++++++++++++++++++++++++++++-- engines/kyra/kyra_v2.h | 10 +++++++++- engines/kyra/scene_v2.cpp | 5 +++++ 3 files changed, 48 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/kyra/kyra_v2.cpp b/engines/kyra/kyra_v2.cpp index 8d2a7714fe..011e3cb48d 100644 --- a/engines/kyra/kyra_v2.cpp +++ b/engines/kyra/kyra_v2.cpp @@ -278,13 +278,18 @@ void KyraEngine_v2::runLoop() { _quitFlag = false; while (!_quitFlag) { //XXX + int inputFlag = checkInput(0/*dword_324C5*/); + removeInputTop(); + update(); + if (inputFlag == 198 || inputFlag == 199) { _unk3 = _handItemSet; Common::Point mouse = getMousePos(); handleInput(mouse.x, mouse.y); } + //XXX } } @@ -353,6 +358,8 @@ void KyraEngine_v2::handleInput(int x, int y) { } int KyraEngine_v2::update() { + updateInput(); + refreshAnimObjectsIfNeed(); updateMouse(); updateSpecialSceneScripts(); @@ -362,6 +369,7 @@ int KyraEngine_v2::update() { //sub_1574C(); //XXX _screen->updateScreen(); + return 0; } @@ -474,10 +482,22 @@ void KyraEngine_v2::updateMouse() { } } -int KyraEngine_v2::checkInput(void *p) { +void KyraEngine_v2::updateInput() { Common::Event event; + + while (_eventMan->pollEvent(event)) + _eventList.push_back(event); +} + +int KyraEngine_v2::checkInput(void *p) { + updateInput(); + int keys = 0; - while (_eventMan->pollEvent(event)) { + + while (_eventList.size()) { + Common::Event event = *_eventList.begin(); + bool breakLoop = false; + switch (event.type) { case Common::EVENT_KEYDOWN: if (event.kbd.keycode == Common::KEYCODE_RETURN) @@ -487,10 +507,12 @@ int KyraEngine_v2::checkInput(void *p) { if (event.kbd.keycode == 'd') _debugger->attach(); } + breakLoop = true; break; case Common::EVENT_LBUTTONUP: keys = 198; + breakLoop = true; break; case Common::EVENT_QUIT: @@ -503,12 +525,22 @@ int KyraEngine_v2::checkInput(void *p) { if (_debugger->isAttached()) _debugger->onFrame(); + + if (breakLoop) + break; + + _eventList.erase(_eventList.begin()); } _system->delayMillis(10); return keys; } +void KyraEngine_v2::removeInputTop() { + if (_eventList.begin() != _eventList.end()) + _eventList.erase(_eventList.begin()); +} + void KyraEngine_v2::cleanup() { delete [] _gamePlayBuffer; delete [] _unkBuf500Bytes; diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h index a530d6c687..4e9210a503 100644 --- a/engines/kyra/kyra_v2.h +++ b/engines/kyra/kyra_v2.h @@ -30,6 +30,8 @@ #include "kyra/script.h" #include "kyra/screen_v2.h" +#include "common/list.h" + namespace Kyra { enum kSequences { @@ -165,9 +167,15 @@ protected: void updateMouse(); int checkInput(void *p); + void removeInputTop(); void handleInput(int x, int y); - + int inputSceneChange(int x, int y, int unk1, int unk2); + + // - Input + void updateInput(); + + Common::List _eventList; // gfx/animation specific uint8 *_gamePlayBuffer; diff --git a/engines/kyra/scene_v2.cpp b/engines/kyra/scene_v2.cpp index 7863fa6638..a08be8ceb5 100644 --- a/engines/kyra/scene_v2.cpp +++ b/engines/kyra/scene_v2.cpp @@ -271,6 +271,11 @@ int KyraEngine_v2::trySceneChange(int *moveTable, int unk1, int updateChar) { if (ret) ++moveTable; + // TODO: check this again + int inputFlag = checkInput(0/*dword_324C5*/); + if (inputFlag == 198 || inputFlag == 199) + break; + ++updateType; if (!updateType) { update(); -- cgit v1.2.3