[Scummvm-git-logs] scummvm master -> 9b27495b8c38959858b7973b427e3cc6d75fdda5

dreammaster noreply at scummvm.org
Thu May 14 11:44:22 UTC 2026


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

Summary:
9b27495b8c MADS: PHANTOM: More of animview anim_timer function and support methods


Commit: 9b27495b8c38959858b7973b427e3cc6d75fdda5
    https://github.com/scummvm/scummvm/commit/9b27495b8c38959858b7973b427e3cc6d75fdda5
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-05-14T21:43:06+10:00

Commit Message:
MADS: PHANTOM: More of animview anim_timer function and support methods

Changed paths:
    engines/mads/madsv2/animview/anim_timer.cpp
    engines/mads/madsv2/animview/animview.cpp
    engines/mads/madsv2/animview/animview.h
    engines/mads/madsv2/core/anim.h
    engines/mads/madsv2/core/pal.cpp
    engines/mads/madsv2/core/pal.h


diff --git a/engines/mads/madsv2/animview/anim_timer.cpp b/engines/mads/madsv2/animview/anim_timer.cpp
index a5835dc8065..f371a411a2e 100644
--- a/engines/mads/madsv2/animview/anim_timer.cpp
+++ b/engines/mads/madsv2/animview/anim_timer.cpp
@@ -23,25 +23,47 @@
 #include "mads/madsv2/animview/animview.h"
 #include "mads/madsv2/animview/functions.h"
 #include "mads/madsv2/core/cycle.h"
+#include "mads/madsv2/core/matte.h"
+#include "mads/madsv2/core/mcga.h"
+#include "mads/madsv2/core/pal.h"
 #include "mads/madsv2/engine.h"
 
 namespace MADS {
 namespace MADSV2 {
 namespace AnimView {
 
-static int normalTimer1;
-static int slow_frames, fast_frames, iffy_frames;
+static const byte FX_TIMES[16] = {
+	0, 110, 110, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, 0, 0, 0
+};
+constexpr int sound_var1 = 49;
+
+constexpr int MESSAGES_COUNT = 8;
+static int messageHandle[MESSAGES_COUNT];
+
+static int paletteHandle;
+static int palIndex1, palIndex2;
+static int matteId;
+static int normalTimer1, messageCount;
+static int frameViewX, frameViewY;
+static int currentViewX, currentViewY;
 
 void anim_timer_init() {
+	paletteHandle = 0;
+	palIndex1 = palIndex2 = 0;
+	matteId = 0;
+	normalTimer1 = messageCount = 0;
+	frameViewX = frameViewY = 0;
+	currentViewX = currentViewY = 0;
 	normalTimer1 = 0;
-	slow_frames = fast_frames = iffy_frames = 0;
 }
 
 void anim_timer() {
 	bool flag = false;
-	int currTimer = g_system->getMillis();
+	uint32 currTimer = g_system->getMillis();
+	Speech *speech;
+	int sound, count;
 
-	if (current_error_code || speechNum)
+	if (current_error_code || speechStream)
 		goto done;
 	if (currentFrame < 0 || currentFrame >= maxFrame)
 		goto done;
@@ -60,12 +82,100 @@ void anim_timer() {
 		if (peelFlag && timer2 >= currTimer && timer1 <= currTimer) {
 			anim_peel();
 
+			timer2 += current_anim->misc_peel_rate;
+
+			if (timer1 <= currTimer) {
+				matte_frame(runFx, false);
+			}
 		}
+
+		if (timer1 < currTimer)
+			goto done;
+	} else {
+		uint32 time = timer1 - FX_TIMES[runFx];
+		if (time > currTimer)
+			goto done;
+	}
+
+	sound = current_anim->frame[currentFrame].sound;
+	if (sound && runFx == 0)
+		g_engine->_soundManager->command(sound);
+
+	if (speechIndex != -1)
+		goto block2;
+	speechIndex = current_anim->frame[currentFrame].speech;
+	if (speechIndex == -1)
+		goto block2;
+
+	speech = &current_anim->speech[speechIndex];
+	flag = (speech->display_condition & 0x4000) &&
+		(speech->display_condition & 0x800) &&
+		(speech->resource_id >= 0);
+
+	if (speech->sound && (!flag || sound_var1 == 49)) {
+		g_engine->_soundManager->command(speech->sound);
+	}
+
+	if (flag) {
+		speechStream = speech->speech;
+		speechFlags = speech->flags;
+		goto done;
 	}
 
 block1:
-	warning("TODO: block1");
+	speechLoops = flag ? current_anim->speech[speechIndex].speech_loops :
+		current_anim->speech[speechIndex].non_speech_loops;
+	runVal6 = 0;
+	runVal7 = -1;
+
+	speech = &current_anim->speech[speechIndex];
+	if (!loadFontFlag && (speech->display_condition & 0x8000) &&
+			(speech->display_condition & 0x2000)) {
+		paletteHandle = pal_alloc_color(-1, 0, &palIndex1, &speech->color[0]);
+		paletteHandle = pal_alloc_color(paletteHandle, -1, &palIndex2, &speech->color[1]);
+
+		mcga_setpal_range(&master_palette, MIN(palIndex1, palIndex2), ABS(palIndex2 - palIndex1));
+		runVal8 = -1;
+		matteId = matte_add_message(current_anim->font, speech->text,
+			speech->x, speech->y, (palIndex2 << 8) | palIndex1,
+			current_anim->font_auto_spacing);
+		messageCount = 0;
+
+		for (count = 0; count < current_anim->num_speech; ++count) {
+			Speech *s = &current_anim->speech[count];
+			if (count != speechIndex && messageCount < MESSAGES_COUNT &&
+					s->first_frame <= currentFrame && s->last_frame > currentFrame) {
+				messageHandle[messageCount++] = matte_add_message(current_anim->font, s->text,
+					s->x, s->y, (palIndex2 << 8) | palIndex1,
+					current_anim->font_auto_spacing);
+			}
+		}
+	}
+
 block2:
+	frameViewX = current_anim->frame[currentFrame].view_x;
+	frameViewY = current_anim->frame[currentFrame].view_y;
+
+	if (frameViewX != currentViewX || frameViewY != currentViewY) {
+		if (!picture_map.one_to_one) {
+			tile_pan(&picture_map, frameViewX, frameViewY);
+			tile_pan(&depth_map, frameViewX, frameViewY);
+
+		}
+
+		image_marker = 1;
+		image_list[0].flags = IMAGE_REFRESH;
+		image_list[0].segment_id = 0xff;
+		currentViewX = frameViewX;
+		currentViewY = frameViewY;
+	} else {
+		for (count = 0; count < image_marker; ++count) {
+			if (image_list[count].flags == IMAGE_REFRESH)
+				image_list[count].flags = IMAGE_ERASE;
+		}
+	}
+
+	// TODO: More block 2 stuff
 	warning("TODO: block2");
 
 done:
diff --git a/engines/mads/madsv2/animview/animview.cpp b/engines/mads/madsv2/animview/animview.cpp
index 9f47fc0c4d2..88ab83bf4e7 100644
--- a/engines/mads/madsv2/animview/animview.cpp
+++ b/engines/mads/madsv2/animview/animview.cpp
@@ -46,7 +46,8 @@ namespace AnimView {
 
 constexpr bool in_mads_mode = true;
 
-int speechNum;
+Audio::AudioStream *speechStream;
+int speechFlags;
 int current_error_code;
 int currentFrame;
 int minFrame, maxFrame;
@@ -59,6 +60,10 @@ int runFx;
 uint32 timer1, timer2;
 AnimPtr current_anim;
 AnimInterPtr current_anim_inter;
+int speechIndex;
+int speechLoops;
+int runVal6, runVal7, runVal8;
+int loadFontFlag;
 
 static const byte FX_TIMES[16] = {
 	0, 110, 110, 64, 64, 64, 64, 64, 64, 64, 64, 0, 0, 0
@@ -86,10 +91,7 @@ static byte *largeBuffer, *largeBufferEnd;
 static byte *largeBuffer1, *largeBuffer2;
 static bool hasAnimInited;
 static int runVal1, runVal2, runVal3;
-static int runVal4, runVal5, runVal6;
-static int runVal7, runVal8;
 static int runVal12;
-static int loadFontFlag;
 static int error_code;
 static bool wait_for_music_at_end;
 
@@ -129,8 +131,9 @@ static void init_globals() {
 	timer1 = timer2 = 0;
 	runVal1 = 0;
 	runVal2 = runVal3 = -1;
-	runVal4 = runVal5 = runVal6 = 0;
-	runVal7 = runVal8 = speechNum = 0;
+	speechIndex = speechLoops = runVal6 = 0;
+	runVal7 = runVal8 = 0;
+	speechStream = nullptr;
 	timerFlag1 = false;
 	runVal12 = 0;
 	loadFontFlag = 0;
@@ -193,11 +196,11 @@ static void run_animation(int animIndex) {
 	if (animIndex == 0)
 		timer1 = g_system->getMillis();
 
-	runVal4 = -1;
+	speechIndex = -1;
 	loadFontFlag = current_anim->load_flags & AA_LOAD_FONT;
 
-	runVal5 = runVal6 = runVal7 = runVal8 = 0;
-	speechNum = 0;
+	speechLoops = runVal6 = runVal7 = runVal8 = 0;
+	speechStream = 0;
 	timerFlag1 = false;
 
 	if (current_anim->background_type == AA_INTERFACE) {
@@ -227,16 +230,17 @@ static void run_animation(int animIndex) {
 
 	// Main animation loop
 	while (currentFrame < maxFrame && !current_error_code) {
-		if (speechNum) {
+		if (speechStream) {
 			if (!(current_anim->load_flags & AA_LOAD_SPEECH)) {
-				char speechName[80];
-				MADS_FORMAT(speechName, current_anim->speech_file);
+				//char speechName[80];
+				//MADS_FORMAT(speechName, current_anim->speech_file);
 
-				speech_play(speechName, speechNum);
+				g_engine->playSpeech(speechStream);
+				//speech_play(speechName, speechStream);
 			}
 
 			timerFlag1 = true;
-			speechNum = 0;
+			speechStream = 0;
 		}
 
 		if (foundSeries) {
diff --git a/engines/mads/madsv2/animview/animview.h b/engines/mads/madsv2/animview/animview.h
index 060cd56c003..3cff1643c13 100644
--- a/engines/mads/madsv2/animview/animview.h
+++ b/engines/mads/madsv2/animview/animview.h
@@ -22,15 +22,16 @@
 #ifndef MADSV2_ANIMVIEW_H
 #define MADSV2_ANIMVIEW_H
 
-#include "common/scummsys.h"
+#include "audio/audiostream.h"
 #include "mads/madsv2/core/anim.h"
 
 namespace MADS {
 namespace MADSV2 {
 namespace AnimView {
 
-// Variables shared with anim_timer.cpp
-extern int speechNum;
+// Variables shared with other AnimView namespace files
+extern Audio::AudioStream *speechStream;
+extern int speechFlags;
 extern int current_error_code;
 extern int currentFrame, minFrame, maxFrame;
 extern bool foundSeries;
@@ -42,6 +43,10 @@ extern int runFx;
 extern uint32 timer1, timer2;;
 extern AnimPtr current_anim;
 extern AnimInterPtr current_anim_inter;
+extern int speechIndex;
+extern int speechLoops;
+extern int runVal6, runVal7, runVal8;
+extern int loadFontFlag;
 
 
 // Main animview function
diff --git a/engines/mads/madsv2/core/anim.h b/engines/mads/madsv2/core/anim.h
index 711599ea5da..6e31deb707a 100644
--- a/engines/mads/madsv2/core/anim.h
+++ b/engines/mads/madsv2/core/anim.h
@@ -278,7 +278,7 @@ typedef FrameEdit *FrameEditPtr;
 
 struct Frame {
 	byte sound;         /* what sound cue to play                             */
-	byte speech;        /* what speech record to activate                     */
+	int8 speech;        /* what speech record to activate                     */
 	word ticks;         /* how many ticks for this frame (before? after?)     */
 	word view_x;        /* where the pan set currently                        */
 	word view_y;
diff --git a/engines/mads/madsv2/core/pal.cpp b/engines/mads/madsv2/core/pal.cpp
index 7b82d0b437f..9d381650806 100644
--- a/engines/mads/madsv2/core/pal.cpp
+++ b/engines/mads/madsv2/core/pal.cpp
@@ -690,5 +690,83 @@ void init_pal() {
 	pal_manager_colors = 0;
 }
 
+int pal_alloc_color(int slot, int allow_shared, int *out_index, const RGBcolor *color) {
+	int slot_num;
+
+	if (slot < 0) {
+		slot_num = -10;
+		int i = 0;
+		int *p = flag_used;
+		while (p < flag_used + PAL_MAXFLAGS) {
+			if (*p == 0) {
+				slot_num = i;
+				break;
+			}
+			i++;
+			p++;
+		}
+		if (slot_num < 0) {
+			error_report(-5, 2, 3, 1, 0);
+			return slot_num;
+		}
+	} else {
+		slot_num = slot;
+	}
+
+	long mask = 1L << slot_num;
+
+	byte *pal_ptr = &master_palette[0].r;
+	dword *status = color_status;
+	int color_index = 0;
+	bool found = false;
+
+	// First pass: look for an existing palette entry with a matching color
+	while (status < (color_status + 256)) {
+		if (!((*status & 1) && !allow_shared) && !(*status & 2)) {
+			if (memcmp(color, pal_ptr, 3) == 0) {
+				*status |= mask;
+				if (out_index)
+					*out_index = color_index;
+				found = true;
+			}
+		}
+		pal_ptr += 3;
+		status++;
+		color_index++;
+		if (found)
+			break;
+	}
+
+	if (!found) {
+		// Second pass: allocate a free palette entry and install the color
+		color_index = 0;
+		pal_ptr = &master_palette[0].r;
+		status = color_status;
+		bool allocated = false;
+
+		while (status < (color_status + 256)) {
+			if (*status == 0) {
+				memcpy(pal_ptr, color, 3);
+				*status |= mask;
+				if (out_index)
+					*out_index = color_index;
+				allocated = true;
+			}
+			pal_ptr += 3;
+			status++;
+			color_index++;
+			if (allocated)
+				break;
+		}
+
+		if (!allocated) {
+			error_report(-6, 2, 3, 1, 0);
+			slot_num = -11;
+		}
+	}
+
+	return slot_num;
+}
+
 } // namespace MADSV2
 } // namespace MADS
diff --git a/engines/mads/madsv2/core/pal.h b/engines/mads/madsv2/core/pal.h
index 7289979d2b1..4d15543ae87 100644
--- a/engines/mads/madsv2/core/pal.h
+++ b/engines/mads/madsv2/core/pal.h
@@ -166,6 +166,12 @@ extern void pal_change_color(int color, int r, int g, int b);
 
 extern void init_pal();
 
+/**
+ * Given a slot and an RGB triple, it either finds an existing palette entry
+ * for that color and claims it for the slot, or allocates a fresh one
+ */
+extern int pal_alloc_color(int slot, int allow_shared, int *out_index, const RGBcolor *color);
+
 } // namespace MADSV2
 } // namespace MADS
 




More information about the Scummvm-git-logs mailing list