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

dreammaster noreply at scummvm.org
Tue Apr 21 02:27:09 UTC 2026


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

Summary:
48927acc7b MADS: PHANTOM: Fixes to rails nodes weightage calculation
0a29c3af74 MADS: PHANTOM: Add a Matte linked_matte field rather than casting to int and saving it in y


Commit: 48927acc7b41224cc498cce6ce632466b2ffb8cb
    https://github.com/scummvm/scummvm/commit/48927acc7b41224cc498cce6ce632466b2ffb8cb
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-04-21T12:12:20+10:00

Commit Message:
MADS: PHANTOM: Fixes to rails nodes weightage calculation

Pathfinding in MADS consists of rooms having a series of
nodes scattered throughout the room. Walking between two
points have you move to the nearest node, and then through
nodes in sequence in the shortest path to the node nearest
your destination, and then finally your destination.

In Phantom, the previous version of the buffer_legal function
used for calculating whether a path between two nodes is valid
was failing on the walkway when the cutscene of the Phantom
throwing you over starts. This new version is intended to
more accurately reflect the version in the release game,
and fixes the cutscene movement.

Changed paths:
    engines/mads/madsv2/core/buffer.cpp


diff --git a/engines/mads/madsv2/core/buffer.cpp b/engines/mads/madsv2/core/buffer.cpp
index da11790ec70..636d2fc5702 100644
--- a/engines/mads/madsv2/core/buffer.cpp
+++ b/engines/mads/madsv2/core/buffer.cpp
@@ -387,86 +387,77 @@ void buffer_line_xor(Buffer target, int x1, int y1, int x2, int y2) {
 	}
 }
 
+static inline byte ror8(byte val, int count) {
+	count &= 7;          /* ror by 8 is identity; keep in 0..7 */
+	return (val >> count) | (val << (8 - count));
+}
+
 int buffer_legal(const Buffer &walk, int orig_wrap,
-		int x1, int y1, int x2, int y2) {
+	int x1, int y1, int x2, int y2) {
 	word legality = LEGAL;
 	word currently_illegal = false;
 
-	if (walk.data == NULL)                               return legality;
-	if ((x1 < 0) || (x2 < 0) || (y1 < 0) || (y2 < 0)) return legality;
-	if ((x1 >= orig_wrap) || (x2 >= orig_wrap))          return legality;
-	if ((y1 >= walk.y) || (y2 >= walk.y))             return legality;
+	if (walk.data == NULL)                                return legality;
+	if (x1 < 0 || x2 < 0 || y1 < 0 || y2 < 0)          return legality;
+	if (x1 >= orig_wrap || x2 >= orig_wrap)              return legality;
+	if (y1 >= walk.y || y2 >= walk.y)                 return legality;
 
-	int delta_x = abs(x2 - x1);
-	int delta_y = abs(y2 - y1);
-	int x_sign = (x2 >= x1) ? 1 : -1;
-	int y_sign = (y2 >= y1) ? walk.x : -walk.x;
+	int delta_y = y2 - y1;
+	int y_sign = walk.x;
+	if (delta_y < 0) {
+		delta_y = -delta_y; y_sign = -y_sign;
+	}
+
+	int delta_x = x2 - x1;
+	int x_sign = 1;
+	int dAccum = 0;
+
+	if (delta_x < 0) {
+		delta_x = -delta_x;
+		x_sign = -1;
+		dAccum = (delta_y < delta_x) ? delta_x : delta_y;  /* max, not min */
+	}
 
 	int x_count = delta_x + 1;
 	int y_count = delta_y + 1;
-	int dAccum = (delta_x >= delta_y) ? delta_y : delta_x;
 
-	/* Each byte in the walk buffer holds 8 packed single-bit walk codes.
-	   bit_pos counts from 1..8, where 1 means "rotate 1" i.e. the MSB,
-	   and 8 means "rotate 8" i.e. the LSB - matching the ror-by-cl logic. */
 	byte *ptr = walk.data + y1 * walk.x + (x1 / 8);
-	int   bit_pos = 8 - (x1 % 8);   /* CL in the original: inverted bit index */
+	int   bit_pos = 8 - (x1 % 8);   /* cl: 1=MSB side, 8=LSB side */
 
-	for (int col = 0; col < x_count; col++)
-	{
+	for (int col = x_count; col > 0; col--) {
 		dAccum += y_count;
 
-		/* Test the walk-code bit at the current position */
-		byte val = *ptr;
-		bool blocked = ((val >> (bit_pos - 1)) & 1) != 0;  /* ror al,cl then jnc */
-
-		if (blocked)
-		{
-			if (!currently_illegal)
-			{
+		bool blocked = (ror8(*ptr, bit_pos) & 1) != 0;  /* carry from ror */
+		if (blocked) {
+			if (!currently_illegal) {
 				currently_illegal = true;
 				legality -= ILLEGAL;
-				if (legality == 0)
-					return legality;
+				if (legality == 0) return legality;
 			}
-		} else
-		{
+		} else {
 			currently_illegal = false;
 		}
 
-		/* Y steps for this column (Bresenham) */
-		while (dAccum >= x_count)
-		{
+		while (dAccum >= x_count) {
 			dAccum -= x_count;
-
-			val = *ptr;
-			blocked = ((val >> (bit_pos - 1)) & 1) != 0;
-
-			if (blocked)
-			{
-				if (!currently_illegal)
-				{
+			blocked = (ror8(*ptr, bit_pos) & 1) != 0;
+			if (blocked) {
+				if (!currently_illegal) {
 					currently_illegal = true;
 					legality -= ILLEGAL;
-					if (legality == 0)
-						return legality;
+					if (legality == 0) return legality;
 				}
-			} else
-			{
+			} else {
 				currently_illegal = false;
 			}
-
 			ptr += y_sign;
 		}
 
-		/* Advance one pixel in X within the packed byte */
-		bit_pos -= x_sign;
-
-		if (bit_pos < 1 || bit_pos > 8)
-		{
-			ptr += x_sign;           /* crossed a byte boundary */
-			bit_pos += x_sign * 8;       /* wrap bit_pos back into 1..8 */
-		}
+		/* Advance one pixel in X */
+		int new_cl = ((bit_pos - x_sign - 1) & 7) + 1;
+		if ((bit_pos - x_sign - 1) & ~7)
+			ptr += x_sign;
+		bit_pos = new_cl;
 	}
 
 	return legality;


Commit: 0a29c3af748b3f59c85db6ac1c15c38229808df4
    https://github.com/scummvm/scummvm/commit/0a29c3af748b3f59c85db6ac1c15c38229808df4
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-04-21T12:26:45+10:00

Commit Message:
MADS: PHANTOM: Add a Matte linked_matte field rather than casting to int and saving it in y

Changed paths:
    engines/mads/madsv2/core/matte.cpp
    engines/mads/madsv2/core/matte.h


diff --git a/engines/mads/madsv2/core/matte.cpp b/engines/mads/madsv2/core/matte.cpp
index fa4602a7e73..b6e6b5c3835 100644
--- a/engines/mads/madsv2/core/matte.cpp
+++ b/engines/mads/madsv2/core/matte.cpp
@@ -347,6 +347,7 @@ void bound_matte(MattePtr matte, int xs, int ys, int maxx, int maxy) {
 	matte->yc = matte->y + (((matte->ys + 1) >> 1) - 1); /* Set center mark */
 
 	matte->valid = true;
+	matte->linked_matte = nullptr;
 }
 
 /*
@@ -445,14 +446,11 @@ static void combine_mattes(MattePtr matte1, MattePtr matte2) {
 	matte1->yc = matte1->y + (((matte1->ys + 1) >> 1) - 1);
 
 	/* Mark matte2 as EMPTY, but leave behind a pointer to matte1 */
-
 	matte2->valid = false;
-	//matte2->y = (int)matte1;
-	error("FIXME: Horrible non-portable cast from pointer to (int)");
+	matte2->linked_matte = matte1;
 
 	/* Set matte1's update flag TRUE; we need to redraw everything in */
 	/* this matte.                                                    */
-
 	matte1->changed = true;
 }
 
@@ -916,7 +914,8 @@ void matte_frame(int special_effect, int full_screen) {
 			/* Search through the matte list to find the matte of which this */
 			/* image is a part.                                              */
 
-			for (matte2 = matte; !matte2->valid; matte2 = (MattePtr)matte2->y);
+			for (matte2 = matte; !matte2->valid; matte2 = matte2->linked_matte) {
+			}
 
 			/* If its matte is being updated, make a depth list entry for    */
 			/* our sprite.                                                   */
@@ -988,7 +987,9 @@ void matte_frame(int special_effect, int full_screen) {
 	matte = &matte_list[FIRST_MESSAGE_MATTE];
 	for (id = 0; id < MESSAGE_LIST_SIZE; id++) {
 		if (message->active && (message->status >= 0)) {
-			for (matte2 = matte; !matte2->valid; matte2 = (MattePtr)matte2->y);
+			for (matte2 = matte; !matte2->valid; matte2 = matte2->linked_matte) {
+			}
+
 			if (matte2->changed || any_refresh) {
 				high_color = (byte)message->main_color;
 				low_color = (byte)(message->main_color >> 8);
@@ -1181,7 +1182,7 @@ static void make_inter_matte(ImageInterPtr image, MattePtr matte) {
 
 
 void matte_inter_frame(int update_live, int clear_chaff) {
-	register int id;
+	int id;
 	int x, y;
 	int flags;
 	word mirror;
@@ -1189,8 +1190,8 @@ void matte_inter_frame(int update_live, int clear_chaff) {
 	SeriesPtr series;
 	int beware_the_mouse = false;
 	byte new_marker;
-	register MattePtr matte;
-	register MattePtr matte2;
+	MattePtr matte;
+	MattePtr matte2;
 	MattePtr i_am_the_dog_master = NULL;
 	ImageInter *image;
 	ImageInter *image2;
@@ -1286,7 +1287,8 @@ void matte_inter_frame(int update_live, int clear_chaff) {
 			/* Search through the matte list to find the matte of which this */
 			/* image is a part.                                              */
 
-			for (matte2 = matte; !matte2->valid; matte2 = (MattePtr)matte2->y);
+			for (matte2 = matte; !matte2->valid; matte2 = matte2->linked_matte) {
+			}
 
 			if (matte2->changed) {
 				series = series_list[image->series_id];
diff --git a/engines/mads/madsv2/core/matte.h b/engines/mads/madsv2/core/matte.h
index c684830ba5d..22cf0e779e3 100644
--- a/engines/mads/madsv2/core/matte.h
+++ b/engines/mads/madsv2/core/matte.h
@@ -60,14 +60,15 @@ namespace MADSV2 {
 #define MATTE_FX_FAST_AND_FANCY       21
 
 
-typedef struct MatteBuf {
+struct Matte {
 	int x, y;             /* upper left coords    */
 	int xs, ys;             /* sizes                */
 	int xh, yh;             /* half sizes           */
 	int xc, yc;             /* centers              */
 	byte changed;           /* changed this update? */
 	byte valid;             /* contains valid matte?*/
-} Matte;
+	Matte *linked_matte;
+};
 
 typedef Matte *MattePtr;
 




More information about the Scummvm-git-logs mailing list