From 45b4989b55a043a9d2f1806db375d9f91476ed89 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 27 May 2015 22:36:51 -0400 Subject: SHERLOCK: Implement RT scrolling code --- engines/sherlock/people.cpp | 1 + engines/sherlock/people.h | 2 ++ engines/sherlock/scene.cpp | 37 ++++++++++++++++++++++++++++++++++++- engines/sherlock/scene.h | 2 +- engines/sherlock/screen.cpp | 2 ++ engines/sherlock/screen.h | 6 +++--- engines/sherlock/user_interface.cpp | 25 +++++++++++++++++++++++++ engines/sherlock/user_interface.h | 8 ++++++++ 8 files changed, 78 insertions(+), 5 deletions(-) diff --git a/engines/sherlock/people.cpp b/engines/sherlock/people.cpp index 6beae4817e..f8dd8e299b 100644 --- a/engines/sherlock/people.cpp +++ b/engines/sherlock/people.cpp @@ -97,6 +97,7 @@ People::People(SherlockEngine *vm) : _vm(vm), _player(_data[0]) { _hSavedFacing = -1; _forceWalkReload = false; _useWalkLib = false; + _walkControl = 0; _portrait._sequences = new byte[32]; } diff --git a/engines/sherlock/people.h b/engines/sherlock/people.h index 272c418a42..f4aba5aa98 100644 --- a/engines/sherlock/people.h +++ b/engines/sherlock/people.h @@ -114,6 +114,8 @@ public: int _holmesQuotient; bool _forceWalkReload; bool _useWalkLib; + + int _walkControl; public: People(SherlockEngine *vm); ~People(); diff --git a/engines/sherlock/scene.cpp b/engines/sherlock/scene.cpp index 18690fb414..06bbabf6e0 100644 --- a/engines/sherlock/scene.cpp +++ b/engines/sherlock/scene.cpp @@ -1740,7 +1740,7 @@ void TattooScene::doBgAnimCheckCursor() { } } -void TattooScene::doBgAnimHandleMask() { +void TattooScene::doBgAnimEraseBackground() { TattooEngine &vm = *((TattooEngine *)_vm); People &people = *_vm->_people; Screen &screen = *_vm->_screen; @@ -1813,6 +1813,37 @@ void TattooScene::doBgAnimHandleMask() { if (vm._creditsActive) vm.eraseCredits(); } + + for (uint idx = 0; idx < _bgShapes.size(); ++idx) { + Object &obj = _bgShapes[idx]; + + if (obj._type == NO_SHAPE && (obj._flags & 1) == 0) { + screen._backBuffer1.blitFrom(screen._backBuffer2, obj._position, obj.getNoShapeBounds()); + + obj._oldPosition = obj._position; + obj._oldSize = obj._noShapeSize; + } + } + + // Adjust the Target Scroll if needed + if ((people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - screen._currentScroll) < + (SHERLOCK_SCREEN_WIDTH / 8) && people[people._walkControl]._delta.x < 0) { + + screen._targetScroll = (short)(people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - + SHERLOCK_SCREEN_WIDTH / 8 - 250); + if (screen._targetScroll < 0) + screen._targetScroll = 0; + } + + if ((people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - screen._currentScroll) > (SHERLOCK_SCREEN_WIDTH / 4 * 3) + && people[people._walkControl]._delta.x > 0) + screen._targetScroll = (short)(people[people._walkControl]._position.x / FIXED_INT_MULTIPLIER - + SHERLOCK_SCREEN_WIDTH / 4 * 3 + 250); + + if (screen._targetScroll > screen._scrollSize) + screen._targetScroll = screen._scrollSize; + + ui.doScroll(); } void TattooScene::doBgAnim() { @@ -1827,6 +1858,7 @@ void TattooScene::doBgAnim() { screen.setDisplayBounds(Common::Rect(0, 0, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCENE_HEIGHT)); talk._talkToAbort = false; + // Check the characters and sprites for updates for (int idx = 0; idx < MAX_CHARACTERS; ++idx) { if (people[idx]._type == CHARACTER) people[idx].checkSprite(); @@ -1836,6 +1868,9 @@ void TattooScene::doBgAnim() { if (_bgShapes[idx]._type == ACTIVE_BG_SHAPE) _bgShapes[idx].checkObject(); } + + // Erase any affected background areas + doBgAnimEraseBackground(); } } // End of namespace Tattoo diff --git a/engines/sherlock/scene.h b/engines/sherlock/scene.h index 1bd23fcde7..ce0785063d 100644 --- a/engines/sherlock/scene.h +++ b/engines/sherlock/scene.h @@ -351,7 +351,7 @@ private: private: void doBgAnimCheckCursor(); - void doBgAnimHandleMask(); + void doBgAnimEraseBackground(); protected: /** * Checks all the background shapes. If a background shape is animating, diff --git a/engines/sherlock/screen.cpp b/engines/sherlock/screen.cpp index 4dd91cfa78..350341f608 100644 --- a/engines/sherlock/screen.cpp +++ b/engines/sherlock/screen.cpp @@ -45,8 +45,10 @@ Screen::Screen(SherlockEngine *vm) : Surface(g_system->getWidth(), g_system->get _fadeBytesRead = _fadeBytesToRead = 0; _oldFadePercent = 0; _scrollSize = 0; + _scrollSpeed = 0; _currentScroll = 0; _targetScroll = 0; + _flushScreen = false; } Screen::~Screen() { diff --git a/engines/sherlock/screen.h b/engines/sherlock/screen.h index e730329ab4..ae368cf633 100644 --- a/engines/sherlock/screen.h +++ b/engines/sherlock/screen.h @@ -71,8 +71,6 @@ private: int _oldFadePercent; byte _lookupTable[PALETTE_COUNT]; byte _lookupTable1[PALETTE_COUNT]; - int _scrollSize; - int _targetScroll; private: /** * Merges together overlapping dirty areas of the screen @@ -101,7 +99,9 @@ public: byte _cMap[PALETTE_SIZE]; byte _sMap[PALETTE_SIZE]; byte _tMap[PALETTE_SIZE]; - int _currentScroll; + int _currentScroll, _targetScroll; + int _scrollSize, _scrollSpeed; + bool _flushScreen; public: Screen(SherlockEngine *vm); virtual ~Screen(); diff --git a/engines/sherlock/user_interface.cpp b/engines/sherlock/user_interface.cpp index 06ec62b6a2..5858daffc5 100644 --- a/engines/sherlock/user_interface.cpp +++ b/engines/sherlock/user_interface.cpp @@ -2352,6 +2352,31 @@ void TattooUserInterface::doBgAnimRestoreUI() { screen.restoreBackground(scene._activeCAnim._removeBounds); } +void TattooUserInterface::doScroll() { + Screen &screen = *_vm->_screen; + int oldScroll = screen._currentScroll; + + // If we're already at the target scroll position, nothing needs to be done + if (screen._targetScroll == screen._currentScroll) + return; + + screen._flushScreen = true; + if (screen._targetScroll > screen._currentScroll) { + screen._currentScroll += screen._scrollSpeed; + if (screen._currentScroll > screen._targetScroll) + screen._currentScroll = screen._targetScroll; + } else if (screen._targetScroll < screen._currentScroll) { + screen._currentScroll -= screen._scrollSpeed; + if (screen._currentScroll < screen._targetScroll) + screen._currentScroll = screen._targetScroll; + } + + if (_menuBuffer != nullptr) + _menuBounds.translate(screen._currentScroll - oldScroll, 0); + if (_invMenuBuffer != nullptr) + _invMenuBounds.translate(screen._currentScroll - oldScroll, 0); +} + } // End of namespace Tattoo } // End of namespace Sherlock diff --git a/engines/sherlock/user_interface.h b/engines/sherlock/user_interface.h index 7a640efea1..dfd6d02efd 100644 --- a/engines/sherlock/user_interface.h +++ b/engines/sherlock/user_interface.h @@ -333,7 +333,15 @@ private: public: TattooUserInterface(SherlockEngine *vm); + /** + * Handles restoring any areas of the back buffer that were/are covered by UI elements + */ void doBgAnimRestoreUI(); + + /** + * Checks to see if the screen needs to be scrolled. If so, scrolls it towards the target position + */ + void doScroll(); public: virtual ~TattooUserInterface() {} -- cgit v1.2.3