Skip to content

Commit

Permalink
SCI32: Fix terrible rendering performance when vsync is enabled
Browse files Browse the repository at this point in the history
More than one call to OSystem::updateScreen per frame on systems
with vsync ruins performance because the call is blocked until
the next vsync interval.

This also fixes bad rendering performance with the OpenGL backend.
  • Loading branch information
csnover committed May 6, 2017
1 parent 91df45c commit 8b49313
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
5 changes: 4 additions & 1 deletion engines/sci/graphics/cursor32.cpp
Expand Up @@ -122,7 +122,6 @@ void GfxCursor32::drawToHardware(const DrawRegion &source) {
byte *sourcePixel = source.data + (sourceYOffset * source.rect.width()) + sourceXOffset;

g_system->copyRectToScreen(sourcePixel, source.rect.width(), drawRect.left, drawRect.top, drawRect.width(), drawRect.height());
g_system->updateScreen();
}

void GfxCursor32::unhide() {
Expand Down Expand Up @@ -381,6 +380,10 @@ void GfxCursor32::deviceMoved(Common::Point &position) {
position.y = _restrictedArea.bottom - 1;
}

if (_position == position) {
return;
}

_position = position;

g_system->warpMouse(position.x, position.y);
Expand Down
4 changes: 2 additions & 2 deletions engines/sci/graphics/frameout.cpp
Expand Up @@ -439,7 +439,7 @@ void GfxFrameout::frameOut(const bool shouldShowBits, const Common::Rect &eraseR
robotPlayer.frameAlmostVisible();
}

_palette->updateHardware(!shouldShowBits);
_palette->updateHardware();

if (shouldShowBits) {
showBits();
Expand Down Expand Up @@ -547,7 +547,7 @@ void GfxFrameout::palMorphFrameOut(const int8 *styleRanges, PlaneShowStyle *show

_palette->submit(nextPalette);
_palette->updateFFrame();
_palette->updateHardware(false);
_palette->updateHardware();
showBits();
}

Expand Down
6 changes: 1 addition & 5 deletions engines/sci/graphics/palette32.cpp
Expand Up @@ -455,7 +455,7 @@ void GfxPalette32::updateFFrame() {
g_sci->_gfxRemap32->remapAllTables(_nextPalette != _currentPalette);
}

void GfxPalette32::updateHardware(const bool updateScreen) {
void GfxPalette32::updateHardware() {
if (_currentPalette == _nextPalette && !_gammaChanged) {
return;
}
Expand Down Expand Up @@ -494,10 +494,6 @@ void GfxPalette32::updateHardware(const bool updateScreen) {
}

g_system->getPaletteManager()->setPalette(bpal, 0, 256);
if (updateScreen) {
g_system->updateScreen();
}

_gammaChanged = false;
}

Expand Down
5 changes: 1 addition & 4 deletions engines/sci/graphics/palette32.h
Expand Up @@ -240,11 +240,8 @@ class GfxPalette32 {
/**
* Copies all entries from `nextPalette` to `currentPalette` and updates the
* backend's raw palette.
*
* @param updateScreen If true, this call will also tell the backend to draw
* to the screen.
*/
void updateHardware(const bool updateScreen = true);
void updateHardware();

private:
ResourceManager *_resMan;
Expand Down
8 changes: 8 additions & 0 deletions engines/sci/sci.cpp
Expand Up @@ -816,6 +816,14 @@ void SciEngine::sleep(uint32 msecs) {
for (;;) {
// let backend process events and update the screen
_eventMan->getSciEvent(SCI_EVENT_PEEK);
#ifdef ENABLE_SCI32
// If a game is in a wait loop, kFrameOut is not called, but mouse
// movement is still occurring and the screen needs to be updated to
// reflect it
if (getSciVersion() >= SCI_VERSION_2) {
g_system->updateScreen();
}
#endif
time = g_system->getMillis();
if (time + 10 < wakeUpTime) {
g_system->delayMillis(10);
Expand Down

0 comments on commit 8b49313

Please sign in to comment.