diff options
-rw-r--r-- | engines/mohawk/riven.cpp | 5 | ||||
-rw-r--r-- | engines/mohawk/riven.h | 1 | ||||
-rw-r--r-- | engines/mohawk/riven_card.cpp | 5 | ||||
-rw-r--r-- | engines/mohawk/riven_external.cpp | 34 | ||||
-rw-r--r-- | engines/mohawk/riven_graphics.cpp | 53 | ||||
-rw-r--r-- | engines/mohawk/riven_graphics.h | 7 | ||||
-rw-r--r-- | engines/mohawk/riven_scripts.cpp | 28 | ||||
-rw-r--r-- | engines/mohawk/riven_scripts.h | 4 |
8 files changed, 68 insertions, 69 deletions
diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp index 3ea5d16795..b7ff1c38ed 100644 --- a/engines/mohawk/riven.cpp +++ b/engines/mohawk/riven.cpp @@ -408,7 +408,6 @@ void MohawkEngine_Riven::refreshCard() { loadHotspots(_card->getId()); - _gfx->_updatesEnabled = true; _gfx->clearWaterEffects(); _video->stopVideos(); @@ -993,10 +992,6 @@ void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) { _zipModeData.push_back(zip); } -void MohawkEngine_Riven::runUpdateScreenScript() { - _card->runScript(kCardUpdateScript); -} - bool ZipMode::operator== (const ZipMode &z) const { return z.name == name && z.id == id; } diff --git a/engines/mohawk/riven.h b/engines/mohawk/riven.h index a61c4b0a54..55661617b0 100644 --- a/engines/mohawk/riven.h +++ b/engines/mohawk/riven.h @@ -174,7 +174,6 @@ public: void refreshCard(); Common::String getName(uint16 nameResource, uint16 nameID); Common::String getStackName(uint16 stack) const; - void runUpdateScreenScript(); RivenCard *getCurCard() const { return _card; } uint16 getCurStack() const { return _curStack; } uint16 matchRMAPToCard(uint32); diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp index 54b588c2a0..9bb5a2e91a 100644 --- a/engines/mohawk/riven_card.cpp +++ b/engines/mohawk/riven_card.cpp @@ -23,7 +23,7 @@ #include "mohawk/riven_card.h" #include "mohawk/riven_graphics.h" -#include "mohawk/sound.h" +#include "mohawk/riven_sound.h" #include "mohawk/resource.h" #include "mohawk/riven.h" @@ -55,11 +55,12 @@ void RivenCard::open() { _vm->_activatedPLST = false; _vm->_activatedSLST = false; + _vm->_gfx->beginScreenUpdate(); runScript(kCardLoadScript); defaultLoadScript(); initializeZipMode(); - _vm->_gfx->updateScreen(); + _vm->_gfx->applyScreenUpdate(true); runScript(kCardOpenScript); } diff --git a/engines/mohawk/riven_external.cpp b/engines/mohawk/riven_external.cpp index 1027052461..72c944f52e 100644 --- a/engines/mohawk/riven_external.cpp +++ b/engines/mohawk/riven_external.cpp @@ -486,7 +486,7 @@ void RivenExternal::xaatrusbookprevpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(1); - _vm->_gfx->updateScreen(); + _vm->_card->drawPicture(page); } void RivenExternal::xaatrusbooknextpage(uint16 argc, uint16 *argv) { @@ -506,7 +506,7 @@ void RivenExternal::xaatrusbooknextpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(0); - _vm->_gfx->updateScreen(); + _vm->_card->drawPicture(page); } void RivenExternal::xacathopenbook(uint16 argc, uint16 *argv) { @@ -572,7 +572,7 @@ void RivenExternal::xacathbookprevpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(3); - _vm->_gfx->updateScreen(); + _vm->_card->drawPicture(page); } void RivenExternal::xacathbooknextpage(uint16 argc, uint16 *argv) { @@ -589,7 +589,7 @@ void RivenExternal::xacathbooknextpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(2); - _vm->_gfx->updateScreen(); + _vm->_card->drawPicture(page); } void RivenExternal::xtrapbookback(uint16 argc, uint16 *argv) { @@ -749,7 +749,7 @@ void RivenExternal::xblabbookprevpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(1); - _vm->_gfx->updateScreen(); + _vm->_card->drawPicture(page); } void RivenExternal::xblabbooknextpage(uint16 argc, uint16 *argv) { @@ -766,7 +766,7 @@ void RivenExternal::xblabbooknextpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(0); - _vm->_gfx->updateScreen(); + _vm->_card->drawPicture(page); } void RivenExternal::xsoundplug(uint16 argc, uint16 *argv) { @@ -950,7 +950,6 @@ void RivenExternal::xbait(uint16 argc, uint16 *argv) { if (_vm->_hotspots[9].rect.contains(_vm->_system->getEventManager()->getMousePos())) { _vm->_vars["bbait"] = 1; _vm->getCurCard()->drawPicture(4); - _vm->_gfx->updateScreen(); _vm->_hotspots[3].enabled = false; // Disable bait hotspot _vm->_hotspots[9].enabled = true; // Enable baitplate hotspot } @@ -983,9 +982,8 @@ void RivenExternal::xbfreeytram(uint16 argc, uint16 *argv) { void RivenExternal::xbaitplate(uint16 argc, uint16 *argv) { // Remove the pellet from the plate and put it in your hand - _vm->getCurCard()->drawPicture(3); _vm->_cursor->setCursor(kRivenPelletCursor); - _vm->_gfx->updateScreen(); + _vm->getCurCard()->drawPicture(3); // Loop until the player lets go (or quits) Common::Event event; @@ -1011,7 +1009,6 @@ void RivenExternal::xbaitplate(uint16 argc, uint16 *argv) { if (_vm->_hotspots[9].rect.contains(_vm->_system->getEventManager()->getMousePos())) { _vm->_vars["bbait"] = 1; _vm->getCurCard()->drawPicture(4); - _vm->_gfx->updateScreen(); _vm->_hotspots[3].enabled = false; // Disable bait hotspot _vm->_hotspots[9].enabled = true; // Enable baitplate hotspot } else { @@ -1427,21 +1424,18 @@ void RivenExternal::xglviewer(uint16 argc, uint16 *argv) { // And update the screen with the new image _vm->getCurCard()->drawPicture(curPos + 2); - _vm->_gfx->updateScreen(); } void RivenExternal::xglview_villageon(uint16 argc, uint16 *argv) { // Turn on the left viewer to 'village mode' _vm->_vars["glview"] = 2; _vm->getCurCard()->drawPicture(_vm->_vars["glviewpos"] + 2); - _vm->_gfx->updateScreen(); } void RivenExternal::xglview_villageoff(uint16 argc, uint16 *argv) { // Turn off the left viewer when in 'village mode' (why is this external?) _vm->_vars["glview"] = 0; _vm->getCurCard()->drawPicture(1); - _vm->_gfx->updateScreen(); } static void catherineViewerIdleTimer(MohawkEngine_Riven *vm) { @@ -1518,7 +1512,6 @@ void RivenExternal::xglview_prisonon(uint16 argc, uint16 *argv) { // Otherwise, just redraw the imager timeUntilNextMovie = _vm->_rnd->getRandomNumberRng(10, 20) * 1000; _vm->getCurCard()->drawPicture(8); - _vm->_gfx->updateScreen(); } // Create the timer for the next video @@ -1542,7 +1535,6 @@ void RivenExternal::xglview_prisonoff(uint16 argc, uint16 *argv) { // Redraw the viewer _vm->getCurCard()->drawPicture(1); - _vm->_gfx->updateScreen(); } // ------------------------------------------------------------------------------------ @@ -2109,8 +2101,7 @@ void RivenExternal::xbookclick(uint16 argc, uint16 *argv) { _vm->_scriptMan->stopAllScripts(); // Stop all running scripts (so we don't remain in the cage) _vm->_video->stopVideos(); // Stop all videos _vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor - _vm->getCurCard()->drawPicture(3); // Black out the screen - _vm->_gfx->updateScreen(); // Update the screen + _vm->getCurCard()->drawPicture(3); // Black out the screen _vm->_sound->playSound(0); // Play the link sound _vm->_video->activateMLST(7, _vm->getCurCard()->getId()); // Activate Gehn Link Video _vm->_video->playMovieBlockingRiven(1); // Play Gehn Link Video @@ -2199,7 +2190,7 @@ void RivenExternal::xogehnbookprevpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(1); - _vm->_gfx->updateScreen(); + _vm->_card->drawPicture(page); } void RivenExternal::xogehnbooknextpage(uint16 argc, uint16 *argv) { @@ -2216,7 +2207,7 @@ void RivenExternal::xogehnbooknextpage(uint16 argc, uint16 *argv) { // Now update the screen :) _vm->_gfx->scheduleTransition(0); - _vm->_gfx->updateScreen(); + _vm->_card->drawPicture(page); } uint16 RivenExternal::getComboDigit(uint32 correctCombo, uint32 digit) { @@ -2662,10 +2653,6 @@ void RivenExternal::drawMarbles() { void RivenExternal::xdrawmarbles(uint16 argc, uint16 *argv) { // Draw marbles in the closeup drawMarbles(); - - // We have to re-enable the updates here - // Would be really nice if the scripts did this for us, but alas... - _vm->_gfx->_updatesEnabled = true; } void RivenExternal::xtakeit(uint16 argc, uint16 *argv) { @@ -2686,7 +2673,6 @@ void RivenExternal::xtakeit(uint16 argc, uint16 *argv) { // Redraw the background _vm->getCurCard()->drawPicture(1); - _vm->_gfx->updateScreen(); // Loop until the player lets go (or quits) Common::Event event; diff --git a/engines/mohawk/riven_graphics.cpp b/engines/mohawk/riven_graphics.cpp index 34da11f6b7..e0cfa365c1 100644 --- a/engines/mohawk/riven_graphics.cpp +++ b/engines/mohawk/riven_graphics.cpp @@ -46,7 +46,8 @@ RivenGraphics::RivenGraphics(MohawkEngine_Riven* vm) : GraphicsManager(), _vm(vm _mainScreen = new Graphics::Surface(); _mainScreen->create(608, 392, _pixelFormat); - _updatesEnabled = true; + _screenUpdateNesting = 0; + _screenUpdateRunning = false; _scheduledTransition = -1; // no transition _dirtyScreen = false; _inventoryDrawn = false; @@ -72,6 +73,8 @@ MohawkSurface *RivenGraphics::decodeImage(uint16 id) { void RivenGraphics::copyImageToScreen(uint16 image, uint32 left, uint32 top, uint32 right, uint32 bottom) { Graphics::Surface *surface = findImage(image)->getSurface(); + beginScreenUpdate(); + // Clip the width to fit on the screen. Fixes some images. if (left + surface->w > 608) surface->w = 608 - left; @@ -80,24 +83,20 @@ void RivenGraphics::copyImageToScreen(uint16 image, uint32 left, uint32 top, uin memcpy(_mainScreen->getBasePtr(left, i + top), surface->getBasePtr(0, i), surface->w * surface->format.bytesPerPixel); _dirtyScreen = true; + applyScreenUpdate(); } void RivenGraphics::updateScreen(Common::Rect updateRect) { - if (_updatesEnabled) { - _vm->runUpdateScreenScript(); - _vm->_sound->triggerDrawSound(); - - if (_dirtyScreen) { - // Copy to screen if there's no transition. Otherwise transition. ;) - if (_scheduledTransition < 0) - _vm->_system->copyRectToScreen(_mainScreen->getBasePtr(updateRect.left, updateRect.top), _mainScreen->pitch, updateRect.left, updateRect.top, updateRect.width(), updateRect.height()); - else - runScheduledTransition(); + if (_dirtyScreen) { + // Copy to screen if there's no transition. Otherwise transition. ;) + if (_scheduledTransition < 0) + _vm->_system->copyRectToScreen(_mainScreen->getBasePtr(updateRect.left, updateRect.top), _mainScreen->pitch, updateRect.left, updateRect.top, updateRect.width(), updateRect.height()); + else + runScheduledTransition(); - // Finally, update the screen. - _vm->_system->updateScreen(); - _dirtyScreen = false; - } + // Finally, update the screen. + _vm->_system->updateScreen(); + _dirtyScreen = false; } } @@ -417,4 +416,28 @@ void RivenGraphics::updateCredits() { } } +void RivenGraphics::beginScreenUpdate() { + _screenUpdateNesting++; +} + +void RivenGraphics::applyScreenUpdate(bool force) { + if (force) { + _screenUpdateNesting = 0; + } else { + _screenUpdateNesting--; + } + + // The screen is only updated when the outermost screen update ends + if (_screenUpdateNesting <= 0 && !_screenUpdateRunning) { + _screenUpdateRunning = true; + + _vm->getCurCard()->runScript(kCardUpdateScript); + _vm->_sound->triggerDrawSound(); + updateScreen(); + + _screenUpdateNesting = 0; + _screenUpdateRunning = false; + } +} + } // End of namespace Mohawk diff --git a/engines/mohawk/riven_graphics.h b/engines/mohawk/riven_graphics.h index a90c288d60..614f9abbe7 100644 --- a/engines/mohawk/riven_graphics.h +++ b/engines/mohawk/riven_graphics.h @@ -34,9 +34,12 @@ public: RivenGraphics(MohawkEngine_Riven *vm); ~RivenGraphics(); + // Screen updates + void beginScreenUpdate(); + void applyScreenUpdate(bool force = false); + void copyImageToScreen(uint16 image, uint32 left, uint32 top, uint32 right, uint32 bottom); void updateScreen(Common::Rect updateRect = Common::Rect(0, 0, 608, 392)); - bool _updatesEnabled; void drawRect(Common::Rect rect, bool active); void drawImageRect(uint16 id, Common::Rect srcRect, Common::Rect dstRect); void drawExtrasImage(uint16 id, Common::Rect dstRect); @@ -68,6 +71,8 @@ protected: private: MohawkEngine_Riven *_vm; MohawkBitmap *_bitmapDecoder; + int _screenUpdateNesting; + bool _screenUpdateRunning; // Water Effects struct SFXERecord { diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp index 68a2152d01..068f0024af 100644 --- a/engines/mohawk/riven_scripts.cpp +++ b/engines/mohawk/riven_scripts.cpp @@ -241,8 +241,8 @@ void RivenSimpleCommand::setupOpcodes() { OPCODE(transition), OPCODE(refreshCard), // 0x14 (20 decimal) - OPCODE(disableScreenUpdate), - OPCODE(enableScreenUpdate), + OPCODE(beginScreenUpdate), + OPCODE(applyScreenUpdate), OPCODE(empty), // Empty OPCODE(empty), // Empty // 0x18 (24 decimal) @@ -290,9 +290,6 @@ void RivenSimpleCommand::drawBitmap(uint16 op, uint16 argc, uint16 *argv) { _vm->_gfx->copyImageToScreen(argv[0], 0, 0, 608, 392); else // Copy the image to a certain part of the screen _vm->_gfx->copyImageToScreen(argv[0], argv[1], argv[2], argv[3], argv[4]); - - // Now, update the screen - _vm->_gfx->updateScreen(); } // Command 2: go to card (card id) @@ -443,17 +440,16 @@ void RivenSimpleCommand::refreshCard(uint16 op, uint16 argc, uint16 *argv) { _vm->refreshCard(); } -// Command 20: disable screen update -void RivenSimpleCommand::disableScreenUpdate(uint16 op, uint16 argc, uint16 *argv) { +// Command 20: begin screen update +void RivenSimpleCommand::beginScreenUpdate(uint16 op, uint16 argc, uint16 *argv) { debug(2, "Screen update disabled"); - _vm->_gfx->_updatesEnabled = false; + _vm->_gfx->beginScreenUpdate(); } -// Command 21: enable screen update -void RivenSimpleCommand::enableScreenUpdate(uint16 op, uint16 argc, uint16 *argv) { +// Command 21: apply screen update +void RivenSimpleCommand::applyScreenUpdate(uint16 op, uint16 argc, uint16 *argv) { debug(2, "Screen update enabled"); - _vm->_gfx->_updatesEnabled = true; - _vm->_gfx->updateScreen(); + _vm->_gfx->applyScreenUpdate(); } // Command 24: increment variable (variable, value) @@ -573,13 +569,7 @@ void RivenSimpleCommand::activatePLST(uint16 op, uint16 argc, uint16 *argv) { _vm->_activatedPLST = true; RivenCard::Picture picture = _vm->getCurCard()->getPicture(argv[0]); - _vm->_gfx->copyImageToScreen(picture.id, picture.rect.left, picture.rect.top, picture.rect.right, picture.rect.bottom); - - // An update is automatically sent here as long as it's not a load or update script and updates are enabled. - // TODO: Fix the graphics manager - //if (_scriptType != kCardLoadScript && _scriptType != kCardUpdateScript) - _vm->_gfx->updateScreen(); } // Command 40: activate SLST record (card ambient sound lists) @@ -589,8 +579,8 @@ void RivenSimpleCommand::activateSLST(uint16 op, uint16 argc, uint16 *argv) { if (_vm->getCurStack() == kStackTspit && _vm->getCurCardRMAP() == 0x6e9a && argv[0] == 2) return; - _vm->_sound->playSLST(argv[0], _vm->getCurCard()->getId()); _vm->_activatedSLST = true; + _vm->_sound->playSLST(argv[0], _vm->getCurCard()->getId()); } // Command 41: activate MLST record and play diff --git a/engines/mohawk/riven_scripts.h b/engines/mohawk/riven_scripts.h index fd47a108be..b05b99ed28 100644 --- a/engines/mohawk/riven_scripts.h +++ b/engines/mohawk/riven_scripts.h @@ -212,8 +212,8 @@ private: DECLARE_OPCODE(runExternalCommand); DECLARE_OPCODE(transition); DECLARE_OPCODE(refreshCard); - DECLARE_OPCODE(disableScreenUpdate); - DECLARE_OPCODE(enableScreenUpdate); + DECLARE_OPCODE(beginScreenUpdate); + DECLARE_OPCODE(applyScreenUpdate); DECLARE_OPCODE(incrementVariable); DECLARE_OPCODE(changeStack); DECLARE_OPCODE(disableMovie); |