[Scummvm-git-logs] scummvm master -> 0e9a6ccdd698a44c76be7eeb51d3818877b04bbe

dreammaster noreply at scummvm.org
Sun Feb 11 04:33:57 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:
0e9a6ccdd6 M4: Adding shadows rendering


Commit: 0e9a6ccdd698a44c76be7eeb51d3818877b04bbe
    https://github.com/scummvm/scummvm/commit/0e9a6ccdd698a44c76be7eeb51d3818877b04bbe
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2024-02-10T20:32:53-08:00

Commit Message:
M4: Adding shadows rendering

The shadowing alpha blending seems okay, but there still seems
to be an issue with the shadows getting incorrectly clipped

Changed paths:
    engines/m4/graphics/gr_sprite.cpp
    engines/m4/graphics/gr_surface.cpp
    engines/m4/graphics/gr_surface.h
    engines/m4/wscript/ws_hal.cpp


diff --git a/engines/m4/graphics/gr_sprite.cpp b/engines/m4/graphics/gr_sprite.cpp
index 9e2f0e97a8a..7be5ee9db21 100644
--- a/engines/m4/graphics/gr_sprite.cpp
+++ b/engines/m4/graphics/gr_sprite.cpp
@@ -163,7 +163,8 @@ uint8 gr_sprite_draw(DrawRequest *drawReq) {
 	M4Surface dst(*drawReq->Dest);
 	dst.draw(source, drawReq->x, drawReq->y, drawReq->scaleX > 0,
 		drawReq->srcDepth ? drawReq->depthCode : nullptr, drawReq->srcDepth,
-		shadow ? drawReq->ICT : nullptr);
+		shadow ? drawReq->ICT : nullptr,
+		drawReq->Pal);
 
 	if (shadowBuff)
 		mem_free(shadowBuff);
diff --git a/engines/m4/graphics/gr_surface.cpp b/engines/m4/graphics/gr_surface.cpp
index aad787333fb..778c87ce81d 100644
--- a/engines/m4/graphics/gr_surface.cpp
+++ b/engines/m4/graphics/gr_surface.cpp
@@ -102,7 +102,8 @@ void M4Surface::rleDraw(const byte *src, int x, int y) {
 }
 
 void M4Surface::draw(const Buffer &src, int x, int y, bool forwards,
-		const byte *depthCodes, int srcDepth, const byte *inverseColorTable) {
+		const byte *depthCodes, int srcDepth, const byte *inverseColorTable,
+		const byte *palette) {
 	if ((src.encoding & 0x7f) == RLE8) {
 		// The standard case of RLE sprite drawing onto screen can directly
 		// use RLE decompression for performance
@@ -114,16 +115,16 @@ void M4Surface::draw(const Buffer &src, int x, int y, bool forwards,
 			// All other RLE drawing first decompresses the sprite, and then does
 			// the various clipping, reverse, etc. on that
 			M4Surface tmp(src.data, src.w, src.h);
-			drawInner(tmp, depthCodes, x, y, forwards, srcDepth, inverseColorTable);
+			drawInner(tmp, depthCodes, x, y, forwards, srcDepth, palette, inverseColorTable);
 		}
 	} else {
 		// Uncompressed images get passed to inner drawing
-		drawInner(src, depthCodes, x, y, forwards, srcDepth, inverseColorTable);
+		drawInner(src, depthCodes, x, y, forwards, srcDepth, palette, inverseColorTable);
 	}
 }
 
-void M4Surface::drawInner(const Buffer &src, const byte *depthCodes,
-		int x, int y, bool forwards, int srcDepth, const byte *inverseColorTable) {
+void M4Surface::drawInner(const Buffer &src, const byte *depthCodes, int x, int y,
+		bool forwards, int srcDepth, const byte *palette, const byte *inverseColorTable) {
 	assert((src.encoding & 0x7f) == NO_COMPRESS);
 
 	for (int srcY = 0; srcY < src.h; ++srcY, ++y) {
@@ -139,6 +140,7 @@ void M4Surface::drawInner(const Buffer &src, const byte *depthCodes,
 		const byte *depthP = depthCodes ? depthCodes + y * w + x : nullptr;
 		int deltaX = forwards ? 1 : -1;
 		int destX = x;
+		uint32 adjusted, total;
 
 		for (int srcX = 0; srcX < src.w; ++srcX, srcP += deltaX, ++destX) {
 			if (destX >= w)
@@ -148,10 +150,40 @@ void M4Surface::drawInner(const Buffer &src, const byte *depthCodes,
 			byte v = *srcP;
 			byte depth = depthP ? *depthP & 0xf : 0;
 			if (destX >= 0 && v != 0 && (!depthP || depth == 0 || srcDepth < depth)) {
-				if (inverseColorTable)
-					v = inverseColorTable[v];
-
-				*destP = v;
+				if (inverseColorTable) {
+					// Handling for shadows
+					if (v == 128)
+						continue;
+
+					const byte *palP = palette + *destP * 3;
+					uint rgb = (uint32)palP[0] | ((uint32)palP[1] << 8) |
+						((uint32)palP[2] << 16);
+					rgb >>= 2;
+
+					// Red component
+					adjusted = (rgb & 0xff) * v;
+					adjusted = MIN(adjusted >> 8, 31U);
+					total = adjusted << 10;
+
+					// Green component
+					rgb >>= 8;
+					adjusted = (rgb & 0xff) * v;
+					adjusted = MIN(adjusted >> 8, 31U);
+					total |= (adjusted << 5);
+
+					// Blue component
+					rgb >>= 8;
+					adjusted = (rgb & 0xff) * v;
+					adjusted = MIN(adjusted >> 8, 31U);
+					total |= adjusted;
+
+					// Write out pixel from inverse table
+					*destP = inverseColorTable[total];
+
+				} else {
+					// Normal pixel
+					*destP = v;
+				}
 			}
 
 			++destP;
diff --git a/engines/m4/graphics/gr_surface.h b/engines/m4/graphics/gr_surface.h
index d0628ab5efd..bc5ed9f0170 100644
--- a/engines/m4/graphics/gr_surface.h
+++ b/engines/m4/graphics/gr_surface.h
@@ -32,7 +32,7 @@ private:
 	DisposeAfterUse::Flag _disposeAfterUse = DisposeAfterUse::NO;
 
 	void drawInner(const Buffer &src, const byte *depthCodes, int x, int y,
-		bool forwards, int srcDepth, const byte *inverseColorTable);
+		bool forwards, int srcDepth, const byte *palette, const byte *inverseColorTable);
 
 public:
 	M4Surface() : Buffer() {}
@@ -53,7 +53,7 @@ public:
 	 */
 	void draw(const Buffer &src, int x, int y, bool forwards = true,
 		const byte *depthCodes = nullptr, int srcDepth = -1,
-		const byte *inverseColorTable = nullptr);
+		const byte *inverseColorTable = nullptr, const byte *palette = nullptr);
 };
 
 } // namespace M4
diff --git a/engines/m4/wscript/ws_hal.cpp b/engines/m4/wscript/ws_hal.cpp
index 5650ee31243..f3a90f694f2 100644
--- a/engines/m4/wscript/ws_hal.cpp
+++ b/engines/m4/wscript/ws_hal.cpp
@@ -355,7 +355,7 @@ void ws_DoDisplay(Buffer *background, int16 *depth_table, Buffer *screenCodeBuff
 		myCCB = myAnim8->myCCB;
 
 		if (myCCB && myCCB->source && (!(myCCB->flags & CCB_NO_DRAW))) {
-			if ((myCCB->flags & CCB_REDRAW) && (greyMode || !(myCCB->source->encoding & 0x80))) {
+			if ((myCCB->flags & CCB_REDRAW) && (!greyMode || !(myCCB->source->encoding & 0x80))) {
 				// Draw the sprite
 				drawSprite(myCCB, myAnim8, halScrnBuf, screenCodeBuff, myPalette, ICT);
 			}




More information about the Scummvm-git-logs mailing list