From 765f976008d2021cc53ce714cbec3e2160d5ef74 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Thu, 15 May 2008 01:18:26 +0000 Subject: * Cleanup of input code. * Removed old timer routines. svn-id: r32135 --- engines/parallaction/callables_ns.cpp | 10 +----- engines/parallaction/gui_ns.cpp | 6 +--- engines/parallaction/input.cpp | 49 ++++++++++-------------------- engines/parallaction/input.h | 4 +-- engines/parallaction/parallaction.cpp | 52 +++++++++++++++++--------------- engines/parallaction/parallaction.h | 4 --- engines/parallaction/parallaction_ns.cpp | 2 +- 7 files changed, 49 insertions(+), 78 deletions(-) (limited to 'engines/parallaction') diff --git a/engines/parallaction/callables_ns.cpp b/engines/parallaction/callables_ns.cpp index 402f69c99d..68e6a70ffb 100644 --- a/engines/parallaction/callables_ns.cpp +++ b/engines/parallaction/callables_ns.cpp @@ -468,7 +468,6 @@ void Parallaction_ns::_c_endIntro(void *parm) { debugC(1, kDebugExec, "endIntro()"); - uint32 event; uint id[2]; for (uint16 _si = 0; _si < 6; _si++) { id[0] = _gfx->createLabel(_menuFont, _credits[_si]._role, 1); @@ -479,14 +478,7 @@ void Parallaction_ns::_c_endIntro(void *parm) { _gfx->updateScreen(); - for (uint16 v2 = 0; v2 < 100; v2++) { - _input->readInput(); - event = _input->getLastButtonEvent(); - if (event == kMouseLeftUp) - break; - - waitTime( 1 ); - } + _input->waitForButtonEvent(kMouseLeftUp, 5500); _gfx->freeLabels(); } diff --git a/engines/parallaction/gui_ns.cpp b/engines/parallaction/gui_ns.cpp index 91cc77e823..1d4d44fa46 100644 --- a/engines/parallaction/gui_ns.cpp +++ b/engines/parallaction/gui_ns.cpp @@ -213,11 +213,7 @@ int Parallaction_ns::guiNewGame() { _input->waitForButtonEvent(kMouseLeftUp | kMouseRightUp); uint32 event = _input->getLastButtonEvent(); -/* - do { - _input->readInput(); - } while (_mouseButtons != kMouseLeftUp && _mouseButtons != kMouseRightUp); -*/ + _input->showCursor(true); _gfx->freeLabels(); diff --git a/engines/parallaction/input.cpp b/engines/parallaction/input.cpp index dc26debba7..28d0ad888d 100644 --- a/engines/parallaction/input.cpp +++ b/engines/parallaction/input.cpp @@ -83,7 +83,7 @@ uint16 Input::readInput() { // TODO: don't quit() here, just have caller routines to check // on kEngineQuit and exit gracefully to allow the engine to shut down _engineFlags |= kEngineQuit; - g_system->quit(); + _vm->_system->quit(); break; default: @@ -101,17 +101,26 @@ uint16 Input::readInput() { } // FIXME: see comment for readInput() -void Input::waitForButtonEvent(uint32 buttonEventMask) { +void Input::waitForButtonEvent(uint32 buttonEventMask, int32 timeout) { if (buttonEventMask == kMouseNone) { _mouseButtons = kMouseNone; // don't wait on nothing return; } - do { - readInput(); - g_system->delayMillis(30); - } while ((_mouseButtons & buttonEventMask) == 0); + const int32 LOOP_RESOLUTION = 30; + if (timeout <= 0) { + do { + readInput(); + _vm->_system->delayMillis(LOOP_RESOLUTION); + } while ((_mouseButtons & buttonEventMask) == 0); + } else { + do { + readInput(); + _vm->_system->delayMillis(LOOP_RESOLUTION); + timeout -= LOOP_RESOLUTION; + } while ((timeout > 0) && (_mouseButtons & buttonEventMask) == 0); + } } @@ -121,38 +130,12 @@ void Input::waitUntilLeftClick() { do { readInput(); _vm->_gfx->updateScreen(); - g_system->delayMillis(30); + _vm->_system->delayMillis(30); } while (_mouseButtons != kMouseLeftUp); return; } -void Parallaction::runGame() { - - InputData *data = _input->updateInput(); - if (data->_event != kEvNone) { - processInput(data); - } - - runPendingZones(); - - if (_engineFlags & kEngineChangeLocation) { - changeLocation(_location._name); - } - - - _gfx->beginFrame(); - - if (_input->_inputMode == Input::kInputModeGame) { - runScripts(); - walk(); - drawAnimations(); - } - - // change this to endFrame? - updateView(); - -} void Input::updateGameInput() { diff --git a/engines/parallaction/input.h b/engines/parallaction/input.h index 3d072384a2..46dbb08c4e 100644 --- a/engines/parallaction/input.h +++ b/engines/parallaction/input.h @@ -68,6 +68,7 @@ class Input { uint16 _mouseButtons; bool _mouseHidden; + ZonePtr _hoverZone; public: enum { @@ -94,13 +95,12 @@ public: } int _inputMode; - ZonePtr _hoverZone; InventoryItem _activeItem; uint16 readInput(); InputData* updateInput(); void waitUntilLeftClick(); - void waitForButtonEvent(uint32 buttonEventMask); + void waitForButtonEvent(uint32 buttonEventMask, int32 timeout = -1); uint32 getLastButtonEvent() { return _mouseButtons; } void stopHovering() { diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index eb766661c3..d66b1af1f1 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -153,29 +153,6 @@ void Parallaction::updateView() { } -uint32 Parallaction::getElapsedTime() { - return g_system->getMillis() - _baseTime; -} - -void Parallaction::resetTimer() { - _baseTime = g_system->getMillis(); - return; -} - - -void Parallaction::waitTime(uint32 t) { - - uint32 v4 = 0; - - while (v4 < t * (1000 / 18.2)) { - v4 = getElapsedTime(); - } - - resetTimer(); - - return; -} - void Parallaction::freeCharacter() { debugC(1, kDebugExec, "freeCharacter()"); @@ -370,6 +347,33 @@ void Parallaction::processInput(InputData *data) { return; } +void Parallaction::runGame() { + + InputData *data = _input->updateInput(); + if (data->_event != kEvNone) { + processInput(data); + } + + runPendingZones(); + + if (_engineFlags & kEngineChangeLocation) { + changeLocation(_location._name); + } + + + _gfx->beginFrame(); + + if (_input->_inputMode == Input::kInputModeGame) { + runScripts(); + walk(); + drawAnimations(); + } + + // change this to endFrame? + updateView(); + +} + @@ -409,8 +413,8 @@ void Parallaction::doLocationEnterTransition() { for (uint16 _si = 0; _si<6; _si++) { pal.fadeTo(_gfx->_palette, 4); _gfx->setPalette(pal); - waitTime( 1 ); _gfx->updateScreen(); + g_system->delayMillis(20); } _gfx->setPalette(_gfx->_palette); diff --git a/engines/parallaction/parallaction.h b/engines/parallaction/parallaction.h index 4a14201164..f639185580 100644 --- a/engines/parallaction/parallaction.h +++ b/engines/parallaction/parallaction.h @@ -259,8 +259,6 @@ public: Input *_input; - void waitTime(uint32 t); - OpcodeSet _commandOpcodes; struct ParallactionStruct1 { @@ -368,8 +366,6 @@ protected: // members void initGlobals(); void runGame(); void updateView(); - uint32 getElapsedTime(); - void resetTimer(); void scheduleLocationSwitch(const char *location); void doLocationEnterTransition(); diff --git a/engines/parallaction/parallaction_ns.cpp b/engines/parallaction/parallaction_ns.cpp index 81141454b6..8e0f83d46d 100644 --- a/engines/parallaction/parallaction_ns.cpp +++ b/engines/parallaction/parallaction_ns.cpp @@ -299,7 +299,7 @@ void Parallaction_ns::changeLocation(char *location) { _gfx->setFloatingLabel(0); _gfx->freeLabels(); - _input->_hoverZone = nullZonePtr; + _input->stopHovering(); if (_engineFlags & kEngineBlockInput) { setArrowCursor(); } -- cgit v1.2.3