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

dreammaster noreply at scummvm.org
Sun Oct 20 03:50:39 UTC 2024


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

Summary:
d6f1d6dea6 M4: RIDDLE: Fix rtoss error when resource name isn't in table
c83c29c6af M4: RIDDLE: Add debug code for dumping resourcing table between rooms
2202ca333b M4: RIDDLE: Properly toss digi resources in Digi::unload_sounds
caf06a0b20 M4: RIDDLE: Resource hashes aren't based on lowercasing first


Commit: d6f1d6dea672602172e14b9ba1775c071de620bf
    https://github.com/scummvm/scummvm/commit/d6f1d6dea672602172e14b9ba1775c071de620bf
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2024-10-19T20:50:04-07:00

Commit Message:
M4: RIDDLE: Fix rtoss error when resource name isn't in table

Changed paths:
    engines/m4/mem/res.cpp


diff --git a/engines/m4/mem/res.cpp b/engines/m4/mem/res.cpp
index 04a4a55f79f..4bf6402be8f 100644
--- a/engines/m4/mem/res.cpp
+++ b/engines/m4/mem/res.cpp
@@ -174,8 +174,11 @@ void Resources::rtoss(const Common::String &resourceName) {
 
 	/* check if resource is in resource table */
 	if (_resources[hash_val].Flags) {
-		while (_resources[hash_val].Flags && !lowerName.equals(_resources[hash_val].name))
-			hash_val = (hash_val + 1) & (HASHSIZE - 1);
+		int ctr = 0;
+		while (ctr++ <= HASHSIZE && _resources[hash_val].Flags &&
+				!lowerName.equals(_resources[hash_val].name)) {
+			hash_val = (hash_val + 1) % HASHSIZE;
+		}
 		resEntry = &_resources[hash_val];
 	}
 


Commit: c83c29c6af583ca1f1f9871bfffc980093199cf9
    https://github.com/scummvm/scummvm/commit/c83c29c6af583ca1f1f9871bfffc980093199cf9
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2024-10-19T20:50:04-07:00

Commit Message:
M4: RIDDLE: Add debug code for dumping resourcing table between rooms

Changed paths:
    engines/m4/core/rooms.cpp
    engines/m4/mem/res.cpp
    engines/m4/mem/res.h


diff --git a/engines/m4/core/rooms.cpp b/engines/m4/core/rooms.cpp
index 434a0b40cc6..874528c1bb9 100644
--- a/engines/m4/core/rooms.cpp
+++ b/engines/m4/core/rooms.cpp
@@ -222,6 +222,9 @@ void Sections::m4EndScene() {
 	ClearWSAssets(_WS_ASSET_DATA, 0, 255);
 	ClearWSAssets(_WS_ASSET_CELS, 0, 255);
 
+	// Dump a list of any resources remaining in memory
+	_G(resources).dumpResources();
+
 	// Reload the walker and show scripts.
 	if (!LoadWSAssets("walker script", &_G(master_palette)[0]))
 		error_show(FL, 'FNF!', "walker script");
diff --git a/engines/m4/mem/res.cpp b/engines/m4/mem/res.cpp
index 4bf6402be8f..d5558be293d 100644
--- a/engines/m4/mem/res.cpp
+++ b/engines/m4/mem/res.cpp
@@ -46,15 +46,13 @@ Resources::Entry *Resources::findAndSetResEntry(const Common::String &resourceNa
 
 	Common::String resName = resourceName;
 	resName.toLowercase();
-	hash_val = hash(resName);
+	orig_hash_val = hash_val = hash(resName);
 
 	// If empty slot at this hash, then we're done
 	if (!_resources[hash_val].Flags)
 		goto got_one;
 
 	// Flags is set, so scan until Flags is clear, or the resource name strings match
-	orig_hash_val = hash_val;
-
 	while ((_resources[hash_val].Flags & FULLY_BUFFERED)
 			&& !resName.equalsIgnoreCase(_resources[hash_val].name)) {
 		// if we searched every entry to no avail:
@@ -174,12 +172,13 @@ void Resources::rtoss(const Common::String &resourceName) {
 
 	/* check if resource is in resource table */
 	if (_resources[hash_val].Flags) {
-		int ctr = 0;
-		while (ctr++ <= HASHSIZE && _resources[hash_val].Flags &&
-				!lowerName.equals(_resources[hash_val].name)) {
-			hash_val = (hash_val + 1) % HASHSIZE;
+		for (int ctr = 0; ctr <= HASHSIZE && _resources[hash_val].Flags;
+				++ctr, hash_val = (hash_val + 1) % HASHSIZE) {
+			if (lowerName.equals(_resources[hash_val].name)) {
+				resEntry = &_resources[hash_val];
+				break;
+			}
 		}
-		resEntry = &_resources[hash_val];
 	}
 
 	if (!resEntry)
@@ -193,6 +192,9 @@ void Resources::rtoss(const Common::String &resourceName) {
 	}
 
 	if (resEntry->Flags & MARKED_PURGE)
+		// This is actually okay. In Riddle, for example, "show script"
+		// is assigned to multiple MACH slots, and in ClearWSAssets will
+		// pass it to rtoss for each entry
 		term_message("multiple rtoss: %s", resourceName.c_str());
 	else
 		term_message("rtossing: %s", resourceName.c_str());
@@ -230,6 +232,19 @@ bool Resources::do_file(MemHandle buffer) {
 	return result;
 }
 
+void Resources::dumpResources() {
+	if (gDebugLevel >= 2) {
+		debug(2, "List of active resources:");
+		for (int i = 0; i < MAX_RESOURCES; ++i) {
+			Entry &entry = _resources[i];
+			if (entry.Flags != 0 && (entry.Flags & MARKED_PURGE) == 0)
+				debug(2, "#%d - %s", i, entry.name.c_str());
+		}
+
+		debugN(2, "\n");
+	}
+}
+
 MemHandle rget(const Common::String &resourceName, int32 *resourceSize) {
 	return _G(resources).rget(resourceName, resourceSize);
 }
diff --git a/engines/m4/mem/res.h b/engines/m4/mem/res.h
index 57977839e9a..f9e284451ec 100644
--- a/engines/m4/mem/res.h
+++ b/engines/m4/mem/res.h
@@ -52,6 +52,11 @@ public:
 
 	MemHandle rget(const Common::String &resourceName, int32 *resourceSize);
 	void rtoss(const Common::String &resourceName);
+
+	/**
+	 * Dumps a list of any active resources
+	 */
+	void dumpResources();
 };
 
 MemHandle rget(const Common::String &resourceName, int32 *ResourceSize);


Commit: 2202ca333b4a95bd36a0f12b5279190f52a69add
    https://github.com/scummvm/scummvm/commit/2202ca333b4a95bd36a0f12b5279190f52a69add
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2024-10-19T20:50:04-07:00

Commit Message:
M4: RIDDLE: Properly toss digi resources in Digi::unload_sounds

Changed paths:
    engines/m4/platform/sound/digi.cpp


diff --git a/engines/m4/platform/sound/digi.cpp b/engines/m4/platform/sound/digi.cpp
index 027afff8181..ae0a2491007 100644
--- a/engines/m4/platform/sound/digi.cpp
+++ b/engines/m4/platform/sound/digi.cpp
@@ -48,8 +48,10 @@ void Digi::loadFootstepSounds(const char **names) {
 void Digi::unload_sounds() {
 	_mixer->stopAll();
 
-	for (auto it = _sounds.begin(); it != _sounds.end(); ++it)
+	for (auto it = _sounds.begin(); it != _sounds.end(); ++it) {
+		rtoss(it->_value._filename);
 		free(it->_value._data);
+	}
 
 	_sounds.clear();
 }


Commit: caf06a0b201f485aad1edd7b3a5f41e46cd09858
    https://github.com/scummvm/scummvm/commit/caf06a0b201f485aad1edd7b3a5f41e46cd09858
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2024-10-19T20:50:04-07:00

Commit Message:
M4: RIDDLE: Resource hashes aren't based on lowercasing first

This difference becomes critical for the beginning of the game,
as if you play all the way through the intro sequence, there are
previously tossed resources at certain indexes, resulting in
one of the series for Mei being loaded at a different index.
And of course, the damn game just has to have a series_unload
call buried in the guts of room 304 that has a harcoded index
of 221, resulting in the wrong series being unloaded and causing
crashes later on. Took me a whole day to track the damn thing down.

Changed paths:
    engines/m4/burger/vars.cpp
    engines/m4/mem/res.cpp
    engines/m4/mem/res.h


diff --git a/engines/m4/burger/vars.cpp b/engines/m4/burger/vars.cpp
index a2f033c0c89..5aefd5abd7b 100644
--- a/engines/m4/burger/vars.cpp
+++ b/engines/m4/burger/vars.cpp
@@ -77,6 +77,7 @@ static const ConverterEntry ASCII_CONVERTERS[] = {
 
 Vars::Vars() {
 	g_vars = this;
+	_resources.setUseLowercase(true);
 
 	Inventory *inv = new Inventory();
 	_inventory = inv;
diff --git a/engines/m4/mem/res.cpp b/engines/m4/mem/res.cpp
index d5558be293d..64cb6089994 100644
--- a/engines/m4/mem/res.cpp
+++ b/engines/m4/mem/res.cpp
@@ -45,7 +45,8 @@ Resources::Entry *Resources::findAndSetResEntry(const Common::String &resourceNa
 	Entry *res = nullptr;
 
 	Common::String resName = resourceName;
-	resName.toLowercase();
+	if (_useLowercase)
+		resName.toLowercase();
 	orig_hash_val = hash_val = hash(resName);
 
 	// If empty slot at this hash, then we're done
@@ -54,7 +55,7 @@ Resources::Entry *Resources::findAndSetResEntry(const Common::String &resourceNa
 
 	// Flags is set, so scan until Flags is clear, or the resource name strings match
 	while ((_resources[hash_val].Flags & FULLY_BUFFERED)
-			&& !resName.equalsIgnoreCase(_resources[hash_val].name)) {
+			&& !resName.equals(_resources[hash_val].name)) {
 		// if we searched every entry to no avail:
 		if ((hash_val = (hash_val + 1) & (HASHSIZE - 1)) == orig_hash_val)
 			goto test4;
@@ -164,17 +165,17 @@ MemHandle Resources::rget(const Common::String &resourceName, int32 *resourceSiz
 void Resources::rtoss(const Common::String &resourceName) {
 	int hash_val;
 	Entry *resEntry = nullptr;
-	Common::String lowerName;
+	Common::String resName = resourceName;
 
-	lowerName = resourceName;
-	lowerName.toLowercase();
-	hash_val = hash(lowerName);
+	if (_useLowercase)
+		resName.toLowercase();
+	hash_val = hash(resName);
 
-	/* check if resource is in resource table */
+	// Check if resource is in resource table
 	if (_resources[hash_val].Flags) {
 		for (int ctr = 0; ctr <= HASHSIZE && _resources[hash_val].Flags;
 				++ctr, hash_val = (hash_val + 1) % HASHSIZE) {
-			if (lowerName.equals(_resources[hash_val].name)) {
+			if (resName.equals(_resources[hash_val].name)) {
 				resEntry = &_resources[hash_val];
 				break;
 			}
diff --git a/engines/m4/mem/res.h b/engines/m4/mem/res.h
index f9e284451ec..30dcd1ae503 100644
--- a/engines/m4/mem/res.h
+++ b/engines/m4/mem/res.h
@@ -41,6 +41,7 @@ class Resources {
 private:
 	Entry _resources[MAX_RESOURCES];
 	SysFile *_fp = nullptr;
+	bool _useLowercase = false;
 
 	Entry *findAndSetResEntry(const Common::String &resourceName);
 	int hash(const Common::String &sym) const;
@@ -49,6 +50,9 @@ private:
 
 public:
 	~Resources();
+	void setUseLowercase(bool flag) {
+		_useLowercase = flag;
+	}
 
 	MemHandle rget(const Common::String &resourceName, int32 *resourceSize);
 	void rtoss(const Common::String &resourceName);




More information about the Scummvm-git-logs mailing list