aboutsummaryrefslogtreecommitdiff
path: root/engines/hopkins/graphics.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2013-03-09 22:04:41 -0500
committerPaul Gilbert2013-03-09 22:04:41 -0500
commit3d06a93be163d9cc99d5c06036408e3020d5e76e (patch)
treeb227a72f56d95e02698d9f797a2cb340cd128ee6 /engines/hopkins/graphics.cpp
parent55c024494d80b343fc23d8e534153fd9c873f040 (diff)
downloadscummvm-rg350-3d06a93be163d9cc99d5c06036408e3020d5e76e.tar.gz
scummvm-rg350-3d06a93be163d9cc99d5c06036408e3020d5e76e.tar.bz2
scummvm-rg350-3d06a93be163d9cc99d5c06036408e3020d5e76e.zip
HOPKINS: Merged dirty/refresh rect rect adding into a single method
Diffstat (limited to 'engines/hopkins/graphics.cpp')
-rw-r--r--engines/hopkins/graphics.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp
index b5c0660a3a..af142ac2c3 100644
--- a/engines/hopkins/graphics.cpp
+++ b/engines/hopkins/graphics.cpp
@@ -1105,19 +1105,8 @@ void GraphicsManager::addDirtyRect(int x1, int y1, int x2, int y2) {
x2 = CLIP(x2, _minX, _maxX);
y2 = CLIP(y2, _minY, _maxY);
- Common::Rect newRect(x1, y1, x2, y2);
- if (!newRect.isValidRect())
- return;
-
- // Don't bother adding the rect if it's contained within another existing one
- for (uint rectIndex = 0; rectIndex < _dirtyRects.size(); ++rectIndex) {
- const Common::Rect &r = _dirtyRects[rectIndex];
- if (r.contains(newRect))
- return;
- }
-
- assert(_dirtyRects.size() < DIRTY_RECTS_SIZE);
- _dirtyRects.push_back(newRect);
+ if ((x2 > x1) && (y2 > y1))
+ addRectToArray(_dirtyRects, Common::Rect(x1, y1, x2, y2));
}
// Add a refresh rect
@@ -1127,12 +1116,25 @@ void GraphicsManager::addRefreshRect(int x1, int y1, int x2, int y2) {
x2 = MIN(x2, SCREEN_WIDTH);
y2 = MIN(y2, SCREEN_HEIGHT);
- if ((x2 > x1) && (y2 > y1)) {
- Common::Rect r(x1, y1, x2, y2);
+ if ((x2 > x1) && (y2 > y1))
+ addRectToArray(_refreshRects, Common::Rect(x1, y1, x2, y2));
+}
- assert(_refreshRects.size() < DIRTY_RECTS_SIZE);
- _refreshRects.push_back(r);
+void GraphicsManager::addRectToArray(Common::Array<Common::Rect> &rects, const Common::Rect &newRect) {
+ // Scan for an intersection with existing rects
+ for (uint rectIndex = 0; rectIndex < rects.size(); ++rectIndex) {
+ Common::Rect &r = rects[rectIndex];
+
+ if (r.intersects(newRect)) {
+ // Rect either intersects or is completely inside existing one, so extend existing one as necessary
+ r.extend(newRect);
+ return;
+ }
}
+
+ // Ensure that the rect list doesn't get too big, and add the new one in
+ assert(_refreshRects.size() < DIRTY_RECTS_SIZE);
+ rects.push_back(newRect);
}
// Draw any game dirty rects onto the screen intermediate surface