Skip to content

Commit

Permalink
PEGASUS: Update the GraphicsManager a bit
Browse files Browse the repository at this point in the history
- Only update the screen if we drew something to it, not if a dirty rect was present.
- Add ability to clear the screen.
  • Loading branch information
Matthew Hoops committed Sep 26, 2011
1 parent 515b250 commit 85e7d2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
22 changes: 16 additions & 6 deletions engines/pegasus/graphics.cpp
Expand Up @@ -44,6 +44,7 @@ GraphicsManager::GraphicsManager(PegasusEngine *vm) : _vm(vm) {
_firstDisplayElement = _lastDisplayElement = 0;
_workArea.create(640, 480, _vm->_system->getScreenFormat());
_lastMousePosition = Common::Point(-1, -1);
_modifiedScreen = false;
}

GraphicsManager::~GraphicsManager() {
Expand Down Expand Up @@ -162,22 +163,31 @@ void GraphicsManager::updateDisplay() {

// TODO: Better logic; it does a bit more work than it probably needs to
// but it should work fine for now.
if (bounds.intersects(_dirtyRect) && runner->validToDraw(_backLayer, _frontLayer))
if (bounds.intersects(_dirtyRect) && runner->validToDraw(_backLayer, _frontLayer)) {
runner->draw(bounds);
screenDirty = true;
}
}

// Copy only the dirty rect to the screen
g_system->copyRectToScreen((byte *)_workArea.getBasePtr(_dirtyRect.left, _dirtyRect.top), _workArea.pitch, _dirtyRect.left, _dirtyRect.top, _dirtyRect.width(), _dirtyRect.height());

// Mark the screen as dirty
screenDirty = true;
if (screenDirty)
g_system->copyRectToScreen((byte *)_workArea.getBasePtr(_dirtyRect.left, _dirtyRect.top), _workArea.pitch, _dirtyRect.left, _dirtyRect.top, _dirtyRect.width(), _dirtyRect.height());

// Clear the dirty rect
_dirtyRect = Common::Rect();
}

if (screenDirty)
if (screenDirty || _modifiedScreen)
g_system->updateScreen();

_modifiedScreen = false;
}

void GraphicsManager::clearScreen() {
Graphics::Surface *screen = g_system->lockScreen();
screen->fillRect(Common::Rect(0, 0, 640, 480), g_system->getScreenFormat().RGBToColor(0, 0, 0));
g_system->unlockScreen();
_modifiedScreen = true;
}

} // End of namespace Pegasus
2 changes: 2 additions & 0 deletions engines/pegasus/graphics.h
Expand Up @@ -52,10 +52,12 @@ class GraphicsManager {
tDisplayOrder getFrontOfActiveLayer() const { return _frontLayer; }
void updateDisplay();
Graphics::Surface *getWorkArea() { return &_workArea; }
void clearScreen();

private:
PegasusEngine *_vm;

bool _modifiedScreen;
Common::Rect _dirtyRect;
tDisplayOrder _backLayer, _frontLayer;
DisplayElement *_firstDisplayElement, *_lastDisplayElement;
Expand Down

0 comments on commit 85e7d2d

Please sign in to comment.