aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sword2/driver/d_draw.h1
-rw-r--r--sword2/driver/rdwin.cpp15
-rw-r--r--sword2/driver/render.cpp26
-rw-r--r--sword2/driver/sprite.cpp12
4 files changed, 27 insertions, 27 deletions
diff --git a/sword2/driver/d_draw.h b/sword2/driver/d_draw.h
index 326862772e..1177b3e6b7 100644
--- a/sword2/driver/d_draw.h
+++ b/sword2/driver/d_draw.h
@@ -193,6 +193,7 @@ public:
int32 setMenuIcon(uint8 menu, uint8 pocket, byte *icon);
void closeMenuImmediately(void);
+ void markAsDirty(int16 x0, int16 y0, int16 x1, int16 y1);
void updateDisplay(bool redrawScene = true);
void setWindowName(const char *windowName);
void setNeedFullRedraw(void);
diff --git a/sword2/driver/rdwin.cpp b/sword2/driver/rdwin.cpp
index 025b99b164..e6bdc9cccd 100644
--- a/sword2/driver/rdwin.cpp
+++ b/sword2/driver/rdwin.cpp
@@ -76,6 +76,21 @@ void Graphics::setNeedFullRedraw(void) {
}
/**
+ * Mark an area of the screen as dirty, first generation.
+ */
+
+void Graphics::markAsDirty(int16 x0, int16 y0, int16 x1, int16 y1) {
+ int16 gridX0 = x0 / CELLWIDE;
+ int16 gridY0 = y0 / CELLDEEP;
+ int16 gridX1 = x1 / CELLWIDE;
+ int16 gridY1 = y1 / CELLDEEP;
+
+ for (int16 i = gridY0; i <= gridY1; i++)
+ for (int16 j = gridX0; j <= gridX1; j++)
+ _dirtyGrid[i * _gridWide + j] = 2;
+}
+
+/**
* This function has two purposes: It redraws the scene, and it handles input
* events, palette fading, etc. It should be called at a high rate (> 20 per
* second), but the scene is usually only redrawn about 12 times per second,
diff --git a/sword2/driver/render.cpp b/sword2/driver/render.cpp
index a6d83e615c..e76bdf7369 100644
--- a/sword2/driver/render.cpp
+++ b/sword2/driver/render.cpp
@@ -338,8 +338,10 @@ void Graphics::plotPoint(uint16 x, uint16 y, uint8 colour) {
newx = x - _scrollX;
newy = y - _scrollY;
- if (newx >= 0 && newx < RENDERWIDE && newy >= 0 && newy < RENDERDEEP)
+ if (newx >= 0 && newx < RENDERWIDE && newy >= 0 && newy < RENDERDEEP) {
buf[newy * RENDERWIDE + newx] = colour;
+ markAsDirty(newx, newy + 40, newx, newy + 40);
+ }
}
/**
@@ -366,17 +368,13 @@ void Graphics::drawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) {
x0 -= _scrollX;
y0 -= _scrollY;
- // Lock the surface if we're rendering to the back buffer.
+ markAsDirty(MIN(x0, x1), MIN(y0, y1) + 40, MAX(x0, x1), MAX(y0, y1) + 40);
- //Make sure we're going from left to right
+ // Make sure we're going from left to right
if (x1 < x0) {
- x = x1;
- x1 = x0;
- x0 = x;
- y = y1;
- y1 = y0;
- y0 = y;
+ SWAP(x0, x1);
+ SWAP(y0, y1);
}
dx = x1 - x0;
@@ -443,15 +441,11 @@ void Graphics::drawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) {
}
}
} else {
- //OK, y is now going to be the single increment.
+ // OK, y is now going to be the single increment.
// Ensure the line is going top to bottom
if (y1 < y0) {
- x = x1;
- x1 = x0;
- x0 = x;
- y = y1;
- y1 = y0;
- y0 = y;
+ SWAP(x0, x1);
+ SWAP(y0, y1);
}
dx = x1 - x0;
dy = y1 - y0;
diff --git a/sword2/driver/sprite.cpp b/sword2/driver/sprite.cpp
index 597d63f712..776c1d9d55 100644
--- a/sword2/driver/sprite.cpp
+++ b/sword2/driver/sprite.cpp
@@ -613,17 +613,7 @@ int32 Graphics::drawSprite(SpriteInfo *s) {
if (freeSprite)
free(sprite);
- // Mark the approximate area of the sprite as "dirty", first generation
-
- int16 gridX1 = rd.left / CELLWIDE;
- int16 gridY1 = rd.top / CELLDEEP;
- int16 gridX2 = (rd.right - 1) / CELLWIDE;
- int16 gridY2 = (rd.bottom - 1) / CELLDEEP;
-
- for (i = gridY1; i <= gridY2; i++)
- for (j = gridX1; j <= gridX2; j++)
- _dirtyGrid[i * _gridWide + j] = 2;
-
+ markAsDirty(rd.left, rd.top, rd.right - 1, rd.bottom - 1);
return RD_OK;
}