aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2012-12-15 19:52:27 +0200
committerFilippos Karapetis2012-12-15 19:52:27 +0200
commit6f81d914f2e5acfb3b31cae86cb61121ff5624ed (patch)
tree95fef646f382431d53ab592c5904ac64c7ba3931
parent96397a5741e6495cb7f9494841ff5b815bc96bda (diff)
downloadscummvm-rg350-6f81d914f2e5acfb3b31cae86cb61121ff5624ed.tar.gz
scummvm-rg350-6f81d914f2e5acfb3b31cae86cb61121ff5624ed.tar.bz2
scummvm-rg350-6f81d914f2e5acfb3b31cae86cb61121ff5624ed.zip
TINSEL: Fix sprite clipping in DW1 Mac
-rw-r--r--engines/tinsel/graphics.cpp69
1 files changed, 47 insertions, 22 deletions
diff --git a/engines/tinsel/graphics.cpp b/engines/tinsel/graphics.cpp
index b23f6bc8a4..91dfd76b98 100644
--- a/engines/tinsel/graphics.cpp
+++ b/engines/tinsel/graphics.cpp
@@ -215,16 +215,12 @@ static void t0WrtNonZero(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP, bool apply
* Straight rendering with transparency support, Mac variant
*/
static void MacDrawTiles(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP, bool applyClipping) {
- // TODO: Finish off clipping
+ int yClip = 0;
if (applyClipping) {
// Adjust the height down to skip any bottom clipping
pObj->height -= pObj->botClip;
-
- // Make adjustment for the top clipping row
- srcP += sizeof(uint16) * ((pObj->width + 3) >> 2) * (pObj->topClip >> 2);
- pObj->height -= pObj->topClip;
- pObj->topClip %= 4;
+ yClip = pObj->topClip;
}
// Simple RLE-like scheme: the two first bytes of each data chunk determine
@@ -234,32 +230,61 @@ static void MacDrawTiles(DRAWOBJECT *pObj, uint8 *srcP, uint8 *destP, bool apply
// Vertical loop
for (int y = 0; y < pObj->height; ++y) {
+ // Get the start of the next line output
+ uint8 *tempDest = destP;
+
+ int leftClip = applyClipping ? pObj->leftClip : 0;
+ int rightClip = applyClipping ? pObj->rightClip : 0;
+
// Horizontal loop
for (int x = 0; x < pObj->width; ) {
byte repeatBytes = *srcP++;
- if (repeatBytes > 0) {
- byte fillColor = *srcP++;
- if (fillColor > 0) // color 0 is transparent
- memset(destP, fillColor, repeatBytes);
- destP += repeatBytes;
- x += repeatBytes;
+
+ if (repeatBytes) {
+ uint clipAmount = MIN<int>(repeatBytes, leftClip);
+ leftClip -= clipAmount;
+ x += clipAmount;
+
+ // Repeat of a given color
+ byte color = *srcP++;
+ int runLength = repeatBytes - clipAmount;
+
+ int rptLength = MAX(MIN(runLength, pObj->width - rightClip - x), 0);
+ if (yClip == 0) {
+ if (color != 0)
+ memset(tempDest, color, rptLength);
+ tempDest += rptLength;
+ }
+
+ x += runLength;
} else {
+ // Copy a specified sequence length of pixels
byte copyBytes = *srcP++;
- for (int z = 0; z < copyBytes; ++z) {
- if (*srcP > 0) // color 0 is transparent
- *destP = *srcP;
- srcP++;
- destP++;
+
+ uint clipAmount = MIN<int>(copyBytes, leftClip);
+ leftClip -= clipAmount;
+ x += clipAmount;
+
+ srcP += clipAmount;
+
+ int runLength = copyBytes - clipAmount;
+ int rptLength = MAX(MIN(runLength, pObj->width - rightClip - x), 0);
+ if (yClip == 0) {
+ memmove(tempDest, srcP, rptLength);
+ tempDest += rptLength;
}
- // Round up to the next even number
- if (copyBytes % 2)
- srcP++;
- x += copyBytes;
+
+ int overflow = (copyBytes % 2) == 0 ? 0 : 2 - (copyBytes % 2);
+ x += runLength;
+ srcP += runLength + overflow;
}
} // horizontal loop
// Move to next line
- destP += (SCREEN_WIDTH - pObj->width);
+ if (yClip > 0)
+ --yClip;
+ else
+ destP += SCREEN_WIDTH;
} // vertical loop
}