DIRECTOR: Get rid of busy wait for click loop

This commit is contained in:
djsrv 2020-08-04 15:14:05 -04:00
parent 5e96518ba7
commit a7ca8a0b2c
4 changed files with 37 additions and 41 deletions

View File

@ -217,7 +217,6 @@ public:
// events.cpp
void processEvents();
uint32 getMacTicks();
void waitForClick();
public:
RandomState _rnd;

View File

@ -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

View File

@ -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;

View File

@ -134,6 +134,8 @@ public:
PlayState _playState;
uint32 _nextFrameTime;
int _waitForChannel;
bool _waitForClick;
bool _waitForClickCursor;
int _activeFade;
Cursor *_currentCursor;