From 3ca0b304cf29f12d5fb3cadccb18689306d33ff8 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Mon, 15 Aug 2011 08:52:11 +0200 Subject: MOHAWK: Implement fading for Myst Demo --- engines/mohawk/graphics.cpp | 42 ++++++++++++++++++++++++++++++++-- engines/mohawk/graphics.h | 1 + engines/mohawk/myst_stacks/demo.cpp | 9 +++++--- engines/mohawk/myst_stacks/preview.cpp | 10 +++++--- engines/mohawk/myst_stacks/slides.cpp | 2 +- 5 files changed, 55 insertions(+), 9 deletions(-) (limited to 'engines/mohawk') diff --git a/engines/mohawk/graphics.cpp b/engines/mohawk/graphics.cpp index 35c9d478d8..c4326d175f 100644 --- a/engines/mohawk/graphics.cpp +++ b/engines/mohawk/graphics.cpp @@ -672,12 +672,50 @@ void MystGraphics::simulatePreviousDrawDelay(const Common::Rect &dest) { _nextAllowedDrawTime = time + _constantDrawDelay + dest.height() * dest.width() / _proportionalDrawDelay; } +void MystGraphics::copyBackBufferToScreenWithSaturation(int16 saturation) { + Graphics::Surface *screen = _vm->_system->lockScreen(); + + for (uint16 y = 0; y < _viewport.height(); y++) + for (uint16 x = 0; x < _viewport.width(); x++) { + uint32 color; + uint8 r, g, b; + + if (_pixelFormat.bytesPerPixel == 2) + color = *(const uint16 *)_backBuffer->getBasePtr(x, y); + else + color = *(const uint32 *)_backBuffer->getBasePtr(x, y); + + _pixelFormat.colorToRGB(color, r, g, b); + + r = CLIP((int16)r - saturation, 0, 255); + g = CLIP((int16)g - saturation, 0, 255); + b = CLIP((int16)b - saturation, 0, 255); + + color = _pixelFormat.RGBToColor(r, g, b); + + if (_pixelFormat.bytesPerPixel == 2) { + uint16 *dst = (uint16 *)screen->getBasePtr(x, y); + *dst = color; + } else { + uint32 *dst = (uint32 *)screen->getBasePtr(x, y); + *dst = color; + } + } + + _vm->_system->unlockScreen(); + _vm->_system->updateScreen(); +} + void MystGraphics::fadeToBlack() { - // TODO: Implement + for (int16 i = 0; i < 256; i += 32) { + copyBackBufferToScreenWithSaturation(i); + } } void MystGraphics::fadeFromBlack() { - // TODO: Implement + for (int16 i = 256; i >= 0; i -= 32) { + copyBackBufferToScreenWithSaturation(i); + } } #endif // ENABLE_MYST diff --git a/engines/mohawk/graphics.h b/engines/mohawk/graphics.h index 96357bbff1..463608a2aa 100644 --- a/engines/mohawk/graphics.h +++ b/engines/mohawk/graphics.h @@ -136,6 +136,7 @@ protected: MohawkSurface *decodeImage(uint16 id); MohawkEngine *getVM() { return (MohawkEngine *)_vm; } void simulatePreviousDrawDelay(const Common::Rect &dest); + void copyBackBufferToScreenWithSaturation(int16 saturation); private: MohawkEngine_Myst *_vm; diff --git a/engines/mohawk/myst_stacks/demo.cpp b/engines/mohawk/myst_stacks/demo.cpp index c9e806655e..fbad7dc384 100644 --- a/engines/mohawk/myst_stacks/demo.cpp +++ b/engines/mohawk/myst_stacks/demo.cpp @@ -84,7 +84,10 @@ void Demo::o_stopIntro(uint16 op, uint16 var, uint16 argc, uint16 *argv) { void Demo::o_fadeFromBlack(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Fade from black", op); - _vm->_gfx->fadeFromBlack(); + + // FIXME: This glitches when enabled. The backbuffer is drawn to screen, + // and then the fading occurs, causing the background to appear for one frame. + // _vm->_gfx->fadeFromBlack(); } void Demo::o_fadeToBlack(uint16 op, uint16 var, uint16 argc, uint16 *argv) { @@ -101,14 +104,14 @@ void Demo::returnToMenu_run() { switch (_returnToMenuStep){ case 0: _vm->_gfx->fadeToBlack(); - _vm->changeToCard(2003, true); + _vm->changeToCard(2003, false); _vm->_gfx->fadeFromBlack(); _returnToMenuStep++; break; case 1: _vm->_gfx->fadeToBlack(); - _vm->changeToCard(2001, true); + _vm->changeToCard(2001, false); _vm->_gfx->fadeFromBlack(); _vm->_cursor->showCursor(); diff --git a/engines/mohawk/myst_stacks/preview.cpp b/engines/mohawk/myst_stacks/preview.cpp index 1b72c85d96..31e22bb8c5 100644 --- a/engines/mohawk/myst_stacks/preview.cpp +++ b/engines/mohawk/myst_stacks/preview.cpp @@ -85,7 +85,10 @@ void Preview::o_fadeToBlack(uint16 op, uint16 var, uint16 argc, uint16 *argv) { void Preview::o_fadeFromBlack(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Fade from black", op); - _vm->_gfx->fadeFromBlack(); + + // FIXME: This glitches when enabled. The backbuffer is drawn to screen, + // and then the fading occurs, causing the background to appear for one frame. + // _vm->_gfx->fadeFromBlack(); } void Preview::o_stayHere(uint16 op, uint16 var, uint16 argc, uint16 *argv) { @@ -99,6 +102,7 @@ void Preview::o_stayHere(uint16 op, uint16 var, uint16 argc, uint16 *argv) { void Preview::o_speechStop(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Speech stop", op); + _vm->_sound->stopSound(3001); _speechRunning = false; _globals.currentAge = 2; } @@ -143,7 +147,7 @@ void Preview::speech_run() { case 2: // Go to Myst if (_currentCue >= 2) { _vm->_gfx->fadeToBlack(); - _vm->changeToCard(3002, true); + _vm->changeToCard(3002, false); _vm->_gfx->fadeFromBlack(); _speechStep++; @@ -186,7 +190,7 @@ void Preview::speech_run() { break; _vm->_gfx->fadeToBlack(); - _vm->changeToCard(3005, true); + _vm->changeToCard(3005, false); _vm->_gfx->fadeFromBlack(); _speechNextTime = time + 1000; _speechStep++; diff --git a/engines/mohawk/myst_stacks/slides.cpp b/engines/mohawk/myst_stacks/slides.cpp index 943cb90071..794793e49c 100644 --- a/engines/mohawk/myst_stacks/slides.cpp +++ b/engines/mohawk/myst_stacks/slides.cpp @@ -63,7 +63,7 @@ void Slides::runPersistentScripts() { // Used on Cards... if (_vm->_system->getMillis() > _nextCardTime) { _vm->_gfx->fadeToBlack(); - _vm->changeToCard(_nextCardID, true); + _vm->changeToCard(_nextCardID, false); _vm->_gfx->fadeFromBlack(); } } -- cgit v1.2.3