Skip to content

Commit dc0254c

Browse files
committed
PEGASUS: Implement very basic screen updating (new API)
1 parent 1ac6aba commit dc0254c

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

engines/pegasus/elements.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ DropHighlight::DropHighlight(const tDisplayElementID id) : DisplayElement(id) {
163163
}
164164

165165
void DropHighlight::draw(const Common::Rect &) {
166-
Graphics::Surface *screen = g_system->lockScreen();
166+
Graphics::Surface *screen = ((PegasusEngine *)g_engine)->_gfx->getWorkArea();
167167

168168
// Since this is only used in two different ways, I'm only
169169
// going to implement it in those two ways. Deal with it.
@@ -181,8 +181,6 @@ void DropHighlight::draw(const Common::Rect &) {
181181
screen->vLine(rect.left - 1, rect.top + 1, rect.bottom - 2, _highlightColor);
182182
screen->vLine(rect.right, rect.top + 1, rect.bottom - 2, _highlightColor);
183183
}
184-
185-
g_system->unlockScreen();
186184
}
187185

188186
EnergyBar::EnergyBar(const tDisplayElementID id) : DisplayElement(id) {
@@ -225,11 +223,8 @@ void EnergyBar::draw(const Common::Rect &r) {
225223
Common::Rect levelRect;
226224
calcLevelRect(levelRect);
227225

228-
if (r.intersects(levelRect)) {
229-
Graphics::Surface *screen = g_system->lockScreen();
230-
screen->fillRect(levelRect, _barColor);
231-
g_system->lockScreen();
232-
}
226+
if (r.intersects(levelRect))
227+
((PegasusEngine *)g_engine)->_gfx->getWorkArea()->fillRect(levelRect, _barColor);
233228
}
234229

235230
void EnergyBar::calcLevelRect(Common::Rect &r) const {

engines/pegasus/graphics.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ namespace Pegasus {
3535
GraphicsManager::GraphicsManager(PegasusEngine *vm) : _vm(vm) {
3636
initGraphics(640, 480, true, NULL);
3737

38+
if (_vm->_system->getScreenFormat().bytesPerPixel == 1)
39+
error("No true color mode available");
40+
3841
// Old
3942
_pictDecoder = new Graphics::PictDecoder(_vm->_system->getScreenFormat());
4043

@@ -45,6 +48,7 @@ GraphicsManager::GraphicsManager(PegasusEngine *vm) : _vm(vm) {
4548
_backLayer = kMinAvailableOrder;
4649
_frontLayer = kMaxAvailableOrder;
4750
_firstDisplayElement = _lastDisplayElement = 0;
51+
_workArea.create(640, 480, _vm->_system->getScreenFormat());
4852
}
4953

5054
GraphicsManager::~GraphicsManager() {
@@ -57,6 +61,9 @@ GraphicsManager::~GraphicsManager() {
5761
delete _cache[i].surface;
5862
}
5963
}
64+
65+
// New
66+
_workArea.free();
6067
}
6168

6269
Graphics::Surface *GraphicsManager::decodeImage(const Common::String &filename) {
@@ -272,5 +279,35 @@ void GraphicsManager::removeDisplayElement(DisplayElement *oldElement) {
272279
oldElement->_nextElement = 0;
273280
oldElement->_elementIsDisplaying = false;
274281
}
282+
283+
void GraphicsManager::updateDisplay() {
284+
// TODO: Check for cursor move/change
285+
286+
bool screenDirty = false;
287+
288+
if (!_dirtyRect.isEmpty()) {
289+
for (DisplayElement *runner = _firstDisplayElement; runner != 0; runner = runner->_nextElement) {
290+
Common::Rect bounds;
291+
runner->getBounds(bounds);
292+
293+
// TODO: Better logic; it does a bit more work than it probably needs to
294+
// but it should work fine for now.
295+
if (bounds.intersects(_dirtyRect) && runner->validToDraw(_backLayer, _frontLayer))
296+
runner->draw(bounds);
297+
}
298+
299+
// Copy only the dirty rect to the screen
300+
g_system->copyRectToScreen((byte *)_workArea.pixels, _workArea.pitch, _dirtyRect.left, _dirtyRect.top, _dirtyRect.width(), _dirtyRect.height());
301+
302+
// Mark the screen as dirty
303+
screenDirty = true;
304+
305+
// Clear the dirty rect
306+
_dirtyRect = Common::Rect();
307+
}
308+
309+
if (screenDirty)
310+
g_system->updateScreen();
311+
}
275312

276313
} // End of namespace Pegasus

engines/pegasus/graphics.h

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class GraphicsManager {
6666
void invalRect(const Common::Rect &rect);
6767
tDisplayOrder getBackOfActiveLayer() const { return _backLayer; }
6868
tDisplayOrder getFrontOfActiveLayer() const { return _frontLayer; }
69+
void updateDisplay();
70+
Graphics::Surface *getWorkArea() { return &_workArea; }
71+
6972
private:
7073
PegasusEngine *_vm;
7174

@@ -79,6 +82,7 @@ class GraphicsManager {
7982
Common::Rect _dirtyRect;
8083
tDisplayOrder _backLayer, _frontLayer;
8184
DisplayElement *_firstDisplayElement, *_lastDisplayElement;
85+
Graphics::Surface _workArea;
8286
};
8387

8488
} // End of namespace Pegasus

0 commit comments

Comments
 (0)