From a7ca8a0b2c8db3379a06173dccb107e8dc76bb9f Mon Sep 17 00:00:00 2001 From: djsrv Date: Tue, 4 Aug 2020 15:14:05 -0400 Subject: [PATCH] DIRECTOR: Get rid of busy wait for click loop --- engines/director/director.h | 1 - engines/director/events.cpp | 59 +++++++++++++------------------------ engines/director/score.cpp | 16 +++++++++- engines/director/score.h | 2 ++ 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/engines/director/director.h b/engines/director/director.h index 920a10a4db3..c3e41bc17f6 100644 --- a/engines/director/director.h +++ b/engines/director/director.h @@ -217,7 +217,6 @@ public: // events.cpp void processEvents(); uint32 getMacTicks(); - void waitForClick(); public: RandomState _rnd; diff --git a/engines/director/events.cpp b/engines/director/events.cpp index 495d156245b..15d1c749db8 100644 --- a/engines/director/events.cpp +++ b/engines/director/events.cpp @@ -139,26 +139,31 @@ bool Movie::processEvent(Common::Event &event) { return true; case Common::EVENT_LBUTTONDOWN: - pos = _stage->getMousePos(); + if (sc->_waitForClick) { + sc->_waitForClick = false; + _vm->setCursor(kCursorDefault); + } else { + pos = _stage->getMousePos(); - // D3 doesn't have both mouse up and down. - // But we still want to know if the mouse is down for press effects. - spriteId = sc->getMouseSpriteIDFromPos(pos); - _currentClickOnSpriteId = sc->getActiveSpriteIDFromPos(pos); + // D3 doesn't have both mouse up and down. + // But we still want to know if the mouse is down for press effects. + spriteId = sc->getMouseSpriteIDFromPos(pos); + _currentClickOnSpriteId = sc->getActiveSpriteIDFromPos(pos); - if (spriteId > 0 && sc->_channels[spriteId]->_sprite->shouldHilite()) - g_director->getCurrentStage()->invertChannel(sc->_channels[spriteId]); + if (spriteId > 0 && sc->_channels[spriteId]->_sprite->shouldHilite()) + g_director->getCurrentStage()->invertChannel(sc->_channels[spriteId]); - _lastEventTime = g_director->getMacTicks(); - _lastClickTime = _lastEventTime; - _lastClickPos = pos; + _lastEventTime = g_director->getMacTicks(); + _lastClickTime = _lastEventTime; + _lastClickPos = pos; - debugC(3, kDebugEvents, "event: Button Down @(%d, %d), movie '%s', sprite id: %d", pos.x, pos.y, _macName.c_str(), spriteId); - registerEvent(kEventMouseDown, spriteId); + debugC(3, kDebugEvents, "event: Button Down @(%d, %d), movie '%s', sprite id: %d", pos.x, pos.y, _macName.c_str(), spriteId); + registerEvent(kEventMouseDown, spriteId); - if (sc->_channels[spriteId]->_sprite->_moveable) { - _draggingSpritePos = _stage->getMousePos(); - _currentDraggedChannel = sc->_channels[spriteId]; + if (sc->_channels[spriteId]->_sprite->_moveable) { + _draggingSpritePos = _stage->getMousePos(); + _currentDraggedChannel = sc->_channels[spriteId]; + } } return true; @@ -209,28 +214,4 @@ bool Movie::processEvent(Common::Event &event) { return false; } -void DirectorEngine::waitForClick() { - setCursor(kCursorMouseUp); - - bool cursor = false; - uint32 nextTime = g_system->getMillis() + 1000; - - while (!processQuitEvent(true)) { - g_system->updateScreen(); - g_system->delayMillis(10); - - if (g_system->getMillis() >= nextTime) { - nextTime = g_system->getMillis() + 1000; - - setCursor(kCursorDefault); - - setCursor(cursor ? kCursorMouseDown : kCursorMouseUp); - - cursor = !cursor; - } - } - - setCursor(kCursorDefault); -} - } // End of namespace Director diff --git a/engines/director/score.cpp b/engines/director/score.cpp index 27890b1fbec..033d3d0d0b4 100644 --- a/engines/director/score.cpp +++ b/engines/director/score.cpp @@ -68,6 +68,8 @@ Score::Score(Movie *movie) { _currentLabel = 0; _nextFrameTime = 0; _waitForChannel = 0; + _waitForClick = false; + _waitForClickCursor = false; _activeFade = 0; _playState = kPlayNotStarted; @@ -297,6 +299,16 @@ void Score::update() { _waitForChannel = 0; } + + if (_waitForClick) { + if (g_system->getMillis() >= _nextFrameTime + 1000) { + _waitForClickCursor = !_waitForClickCursor; + _vm->setCursor(kCursorDefault); + _vm->setCursor(_waitForClickCursor ? kCursorMouseDown : kCursorMouseUp); + _nextFrameTime = g_system->getMillis(); + } + return; + } if (g_system->getMillis() < _nextFrameTime && !_nextFrame) return; @@ -404,7 +416,9 @@ void Score::update() { // TODO Wait for channel tempo - 135 warning("STUB: tempo >= 136"); } else if (tempo == 128) { - _vm->waitForClick(); + _waitForClick = true; + _waitForClickCursor = false; + _vm->setCursor(kCursorMouseUp); } else if (tempo == 135) { // Wait for sound channel 1 _waitForChannel = 1; diff --git a/engines/director/score.h b/engines/director/score.h index a9cd7714346..c6a5fd78abd 100644 --- a/engines/director/score.h +++ b/engines/director/score.h @@ -134,6 +134,8 @@ public: PlayState _playState; uint32 _nextFrameTime; int _waitForChannel; + bool _waitForClick; + bool _waitForClickCursor; int _activeFade; Cursor *_currentCursor;