Skip to content

Commit

Permalink
SHERLOCK: Implement RT scrolling code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed May 28, 2015
1 parent 0d4163c commit 45b4989
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 5 deletions.
1 change: 1 addition & 0 deletions engines/sherlock/people.cpp
Expand Up @@ -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];
}
Expand Down
2 changes: 2 additions & 0 deletions engines/sherlock/people.h
Expand Up @@ -114,6 +114,8 @@ class People {
int _holmesQuotient;
bool _forceWalkReload;
bool _useWalkLib;

int _walkControl;
public:
People(SherlockEngine *vm);
~People();
Expand Down
37 changes: 36 additions & 1 deletion engines/sherlock/scene.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion engines/sherlock/scene.h
Expand Up @@ -351,7 +351,7 @@ class TattooScene : public Scene {
private:
void doBgAnimCheckCursor();

void doBgAnimHandleMask();
void doBgAnimEraseBackground();
protected:
/**
* Checks all the background shapes. If a background shape is animating,
Expand Down
2 changes: 2 additions & 0 deletions engines/sherlock/screen.cpp
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions engines/sherlock/screen.h
Expand Up @@ -71,8 +71,6 @@ class Screen : public Surface {
int _oldFadePercent;
byte _lookupTable[PALETTE_COUNT];
byte _lookupTable1[PALETTE_COUNT];
int _scrollSize;
int _targetScroll;
private:
/**
* Merges together overlapping dirty areas of the screen
Expand Down Expand Up @@ -101,7 +99,9 @@ class Screen : public Surface {
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();
Expand Down
25 changes: 25 additions & 0 deletions engines/sherlock/user_interface.cpp
Expand Up @@ -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
8 changes: 8 additions & 0 deletions engines/sherlock/user_interface.h
Expand Up @@ -333,7 +333,15 @@ class TattooUserInterface : public UserInterface {
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() {}

Expand Down

0 comments on commit 45b4989

Please sign in to comment.