aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2013-03-09 22:04:41 -0500
committerPaul Gilbert2013-03-09 22:04:41 -0500
commit3d06a93be163d9cc99d5c06036408e3020d5e76e (patch)
treeb227a72f56d95e02698d9f797a2cb340cd128ee6
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
-rw-r--r--engines/hopkins/graphics.cpp36
-rw-r--r--engines/hopkins/graphics.h1
2 files changed, 20 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
diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h
index 3739bbf3a3..45bc202d59 100644
--- a/engines/hopkins/graphics.h
+++ b/engines/hopkins/graphics.h
@@ -130,6 +130,7 @@ public:
void addDirtyRect(int x1, int y1, int x2, int y2);
void addDirtyRect(const Common::Rect &r) { addDirtyRect(r.left, r.top, r.right, r.bottom); }
void addRefreshRect(int x1, int y1, int x2, int y2);
+ void addRectToArray(Common::Array<Common::Rect> &rects, const Common::Rect &newRect);
void displayDirtyRects();
void displayRefreshRects();
void copySurface(const byte *surface, int x1, int y1, int width, int height, byte *destSurface, int destX, int destY);