[Scummvm-git-logs] scummvm master -> b486e15a6161002cb7933738d26e500ff758809c

mduggan noreply at scummvm.org
Sun Jun 30 21:43:38 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b486e15a61 DGDS: Support vertical flip properly on sprite draw


Commit: b486e15a6161002cb7933738d26e500ff758809c
    https://github.com/scummvm/scummvm/commit/b486e15a6161002cb7933738d26e500ff758809c
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2024-07-01T07:42:52+10:00

Commit Message:
DGDS: Support vertical flip properly on sprite draw

This fixes the Dynamix star in HoC and Beamish intros

Changed paths:
    engines/dgds/image.cpp
    engines/dgds/image.h
    engines/dgds/ttm.cpp


diff --git a/engines/dgds/image.cpp b/engines/dgds/image.cpp
index 41680980aee..251cf8372ad 100644
--- a/engines/dgds/image.cpp
+++ b/engines/dgds/image.cpp
@@ -235,7 +235,7 @@ void Image::loadBitmap(const Common::String &filename) {
 	delete fileStream;
 }
 
-void Image::drawBitmap(uint frameno, int x, int y, const Common::Rect &drawWin, Graphics::ManagedSurface &destSurf, bool flip, int dstWidth, int dstHeight) const {
+void Image::drawBitmap(uint frameno, int x, int y, const Common::Rect &drawWin, Graphics::ManagedSurface &destSurf, ImageFlipMode flipMode, int dstWidth, int dstHeight) const {
 	if (frameno >= _frames.size()) {
 		warning("drawBitmap: Trying to draw frame %d from a %d frame image %s!", frameno, _frames.size(), _filename.c_str());
 		return;
@@ -258,31 +258,27 @@ void Image::drawBitmap(uint frameno, int x, int y, const Common::Rect &drawWin,
 		return;
 
 	const byte *src = (const byte *)srcFrame->getBasePtr(0, 0);
-	// Note: this is not super optimized, but it's easy to understand at least..
+
+	// Note: this is not particularly optimized, written to be easier to understand
+
 	byte *dst = (byte *)destSurf.getBasePtr(x, y);
 
 	for (int i = 0; i < dstHeight; ++i) {
-		if (y + i < drawWin.top || y + i >= drawWin.bottom) {
-			dst += destSurf.pitch;
-			continue;
-		}
-
-		const byte *srcRow = src + srcFrame->pitch * (i * srcHeight / dstHeight);
+		const byte *srcRow = src;
+		if (flipMode & kImageFlipV)
+			srcRow += srcFrame->pitch * ((dstHeight - i - 1) * srcHeight / dstHeight);
+		else
+			srcRow += srcFrame->pitch * (i * srcHeight / dstHeight);
 
 		for (int j = 0; j < dstWidth; ++j) {
-			if (flip) {
-				if (x + j < drawWin.left || x + j >= drawWin.right)
-					continue;
-				int srcX = (dstWidth - j - 1) * srcWidth / dstWidth;
-				if (srcRow[srcX])
-					dst[j] = srcRow[srcX];
-			} else {
-				if (x + j < drawWin.left || x + j >= drawWin.right)
-					continue;
-				int srcX = j * srcWidth / dstWidth;
-				if (srcRow[srcX])
-					dst[j] = srcRow[srcX];
-			}
+			int srcX;
+			if (flipMode & kImageFlipH)
+				srcX = (dstWidth - j - 1) * srcWidth / dstWidth;
+			else
+				srcX = j * srcWidth / dstWidth;
+
+			if (srcRow[srcX] && clippedDestRect.contains(j + x, i + y))
+				dst[j] = srcRow[srcX];
 		}
 		dst += destSurf.pitch;
 	}
diff --git a/engines/dgds/image.h b/engines/dgds/image.h
index 5a76bbce779..eac6a7529fb 100644
--- a/engines/dgds/image.h
+++ b/engines/dgds/image.h
@@ -41,6 +41,13 @@ class Decompressor;
 class DgdsChunkReader;
 class ResourceManager;
 
+enum ImageFlipMode {
+	kImageFlipNone = 0,
+	kImageFlipH = 1,
+	kImageFlipV = 2,
+	kImageFlipHV = 3,
+};
+
 class Image {
 public:
 	Image(ResourceManager *resourceMan, Decompressor *decompressor);
@@ -50,7 +57,7 @@ public:
 
 	void loadBitmap(const Common::String &filename);
 	int frameCount(const Common::String &filename);
-	void drawBitmap(uint frameno, int x, int y, const Common::Rect &drawWin, Graphics::ManagedSurface &dst, bool flip = false, int dstWidth = 0, int dstHeight = 0) const;
+	void drawBitmap(uint frameno, int x, int y, const Common::Rect &drawWin, Graphics::ManagedSurface &dst, ImageFlipMode flip = kImageFlipNone, int dstWidth = 0, int dstHeight = 0) const;
 
 	Common::SharedPtr<Graphics::ManagedSurface> getSurface(uint frameno) const;
 
diff --git a/engines/dgds/ttm.cpp b/engines/dgds/ttm.cpp
index 96245ab6806..f11919d7b41 100644
--- a/engines/dgds/ttm.cpp
+++ b/engines/dgds/ttm.cpp
@@ -194,8 +194,9 @@ static const char *ttmOpName(uint16 op) {
 	case 0xa400: return "DRAW FILLED CIRCLE";
 	case 0xa420: return "DRAW EMPTY CIRCLE";
 	case 0xa500: return "DRAW BMP";
-	case 0xa520: return "DRAW SPRITE FLIP";
-	case 0xa530: return "DRAW BMP4";
+	case 0xa510: return "DRAW SPRITE FLIPV";
+	case 0xa520: return "DRAW SPRITE FLIPH";
+	case 0xa530: return "DRAW SPRITE FLIPHV";
 	case 0xa600: return "DRAW GETPUT";
 	case 0xb000: return "INIT CREDITS SCROLL";
 	case 0xb010: return "DRAW CREDITS SCROLL";
@@ -219,7 +220,6 @@ static const char *ttmOpName(uint16 op) {
 	case 0x00C0: return "FREE BACKGROUND";
 	case 0x0230: return "reset current music?";
 	case 0x1310: return "STOP SFX";
-	case 0xa510: return "DRAW SPRITE1";
 	case 0xb600: return "DRAW SCREEN";
 	case 0xc020: return "LOAD_SAMPLE";
 	case 0xc030: return "SELECT_SAMPLE";
@@ -744,20 +744,10 @@ void TTMInterpreter::handleOperation(TTMEnviro &env, TTMSeq &seq, uint16 op, byt
 	case 0xa300:
 		doDrawDialogForStrings(env, seq, ivals[0], ivals[1], ivals[2], ivals[3]);
 		break;
-	case 0xa510:
-		// DRAW SPRITE x,y:int  .. how different from 0xa500??
-		// FALL THROUGH
-	case 0xa520:
-		// DRAW SPRITE FLIP: x,y:int
-		// FALL THROUGH
-	case 0xa530:
-		// CHINA
-		// DRAW BMP4:	x,y,tile-id,bmp-id:int	[-n,+n] (CHINA)
-		// arguments similar to DRAW BMP but it draws the same BMP multiple times with radial symmetry?
-		// you can see this in the Dynamix logo star.
-		// FALL THROUGH FOR NOW
-	case 0xa500: {
-		// DRAW BMP: x,y,tile-id,bmp-id:int [-n,+n] (CHINA)
+	case 0xa500: // DRAW SPRITE: x,y,tile-id,bmp-id:int [-n,+n]
+	case 0xa510: // DRAW SPRITE FLIP V x,y:int
+	case 0xa520: // DRAW SPRITE FLIP H: x,y:int
+	case 0xa530: { // DRAW SPRITE FLIP HV: x,y,tile-id,bmp-id:int	[-n,+n] (CHINA)
 		int frameno;
 		int bmpNo;
 		int dstWidth = 0;
@@ -775,10 +765,17 @@ void TTMInterpreter::handleOperation(TTMEnviro &env, TTMSeq &seq, uint16 op, byt
 			bmpNo = seq._currentBmpId;
 		}
 
-		// DRAW BMP: x,y:int [-n,+n] (RISE)
+		ImageFlipMode flipMode = kImageFlipNone;
+		if (op == 0xa510)
+			flipMode = kImageFlipV;
+		else if (op == 0xa520)
+			flipMode = kImageFlipH;
+		else if (op == 0xa530)
+			flipMode = kImageFlipHV;
+
 		Common::SharedPtr<Image> img = env._scriptShapes[bmpNo];
 		if (img)
-			img->drawBitmap(frameno, ivals[0], ivals[1], seq._drawWin, _vm->_compositionBuffer, op == 0xa520, dstWidth, dstHeight);
+			img->drawBitmap(frameno, ivals[0], ivals[1], seq._drawWin, _vm->_compositionBuffer, flipMode, dstWidth, dstHeight);
 		else
 			warning("Trying to draw image %d in env %d which is not loaded", bmpNo, env._enviro);
 		break;




More information about the Scummvm-git-logs mailing list