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

sev- noreply at scummvm.org
Thu Jun 29 22:36:21 UTC 2023


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

Summary:
a62b7985b5 DIRECTOR: Modernized some loops
7baba61852 DIRECTOR: Modernized rest of the loops
4743694cf1 GOB: Replace non-unicode characters in extra fields in detection with Unicode
95d8cf840c DIRECTOR: _allOpenResFiles -> _allSeenResFiles
9aa0958736 DIRECTOR: Properly keep track of open resource files and their precedence


Commit: a62b7985b5146cb927e15f4fb74676cc79909ad0
    https://github.com/scummvm/scummvm/commit/a62b7985b5146cb927e15f4fb74676cc79909ad0
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-06-29T17:35:06+02:00

Commit Message:
DIRECTOR: Modernized some loops

Changed paths:
    engines/director/cast.cpp
    engines/director/castmember/filmloop.cpp
    engines/director/cursor.cpp
    engines/director/lingo/lingo-builtins.cpp
    engines/director/lingo/lingo-bytecode.cpp
    engines/director/lingo/lingo-code.cpp
    engines/director/lingo/lingo-codegen.cpp
    engines/director/sound.cpp
    engines/director/window.cpp


diff --git a/engines/director/cast.cpp b/engines/director/cast.cpp
index ce75af2d1d6..c7567cdbf76 100644
--- a/engines/director/cast.cpp
+++ b/engines/director/cast.cpp
@@ -85,24 +85,24 @@ Cast::Cast(Movie *movie, uint16 castLibID, bool isShared, bool isExternal) {
 
 Cast::~Cast() {
 	if (_loadedStxts)
-		for (Common::HashMap<int, const Stxt *>::iterator it = _loadedStxts->begin(); it != _loadedStxts->end(); ++it)
-			delete it->_value;
+		for (auto &it : *_loadedStxts)
+			delete it._value;
 
 	if (_loadedCast)
-		for (Common::HashMap<int, CastMember *>::iterator it = _loadedCast->begin(); it != _loadedCast->end(); ++it)
-			if (it->_value) {
-				delete it->_value;
-				it->_value = nullptr;
+		for (auto &it : *_loadedCast)
+			if (it._value) {
+				delete it._value;
+				it._value = nullptr;
 			}
 
-	for (Common::HashMap<uint16, CastMemberInfo *>::iterator it = _castsInfo.begin(); it != _castsInfo.end(); ++it)
-		delete it->_value;
+	for (auto &it : _castsInfo)
+		delete it._value;
 
-	for (FontXPlatformMap::iterator it = _fontXPlatformMap.begin(); it != _fontXPlatformMap.end(); ++it)
-		delete it->_value;
+	for (auto &it : _fontXPlatformMap)
+		delete it._value;
 
-	for (FontMap::iterator it = _fontMap.begin(); it != _fontMap.end(); ++it)
-		delete it->_value;
+	for (auto &it : _fontMap)
+		delete it._value;
 
 	delete _loadedStxts;
 	delete _loadedCast;
@@ -133,8 +133,8 @@ CastMember *Cast::getCastMember(int castId, bool load) {
 
 void Cast::releaseCastMemberWidget() {
 	if (_loadedCast)
-		for (Common::HashMap<int, CastMember *>::iterator it = _loadedCast->begin(); it != _loadedCast->end(); ++it)
-			it->_value->releaseWidget();
+		for (auto &it : *_loadedCast)
+			it._value->releaseWidget();
 }
 
 CastMember *Cast::getCastMemberByNameAndType(const Common::String &name, CastType type) {
@@ -531,8 +531,8 @@ void Cast::loadCast() {
 
 	if (_castArchive->hasResource(MKTAG('X', 'C', 'O', 'D'), -1)) {
 		Common::Array<uint16> xcod = _castArchive->getResourceIDList(MKTAG('X', 'C', 'O', 'D'));
-		for (Common::Array<uint16>::iterator iterator = xcod.begin(); iterator != xcod.end(); ++iterator) {
-			Resource res = _castArchive->getResourceDetail(MKTAG('X', 'C', 'O', 'D'), *iterator);
+		for (auto &iterator : xcod) {
+			Resource res = _castArchive->getResourceDetail(MKTAG('X', 'C', 'O', 'D'), iterator);
 			debug(0, "Detected XObject '%s'", res.name.c_str());
 			g_lingo->openXLib(res.name, kXObj);
 		}
@@ -542,8 +542,8 @@ void Cast::loadCast() {
 	if (cinf.size() > 0) {
 		debugC(2, kDebugLoading, "****** Loading %d CastLibInfos Cinf", cinf.size());
 
-		for (Common::Array<uint16>::iterator iterator = cinf.begin(); iterator != cinf.end(); ++iterator) {
-			loadCastLibInfo(*(r = _castArchive->getResource(MKTAG('C', 'i', 'n', 'f'), *iterator)), *iterator);
+		for (auto &iterator : cinf) {
+			loadCastLibInfo(*(r = _castArchive->getResource(MKTAG('C', 'i', 'n', 'f'), iterator)), iterator);
 			delete r;
 		}
 	}
@@ -552,8 +552,8 @@ void Cast::loadCast() {
 	if (vwci.size() > 0) {
 		debugC(2, kDebugLoading, "****** Loading %d CastInfos VWCI", vwci.size());
 
-		for (Common::Array<uint16>::iterator iterator = vwci.begin(); iterator != vwci.end(); ++iterator) {
-			loadCastInfo(*(r = _castArchive->getResource(MKTAG('V', 'W', 'C', 'I'), *iterator)), *iterator - _castIDoffset);
+		for (auto &iterator : vwci) {
+			loadCastInfo(*(r = _castArchive->getResource(MKTAG('V', 'W', 'C', 'I'), iterator)), iterator - _castIDoffset);
 			delete r;
 		}
 	}
@@ -567,14 +567,14 @@ void Cast::loadCast() {
 
 		int idx = 0;
 
-		for (Common::Array<uint16>::iterator iterator = cast.begin(); iterator != cast.end(); ++iterator) {
-			Resource res = _castArchive->getResourceDetail(MKTAG('C', 'A', 'S', 't'), *iterator);
+		for (auto &iterator : cast) {
+			Resource res = _castArchive->getResourceDetail(MKTAG('C', 'A', 'S', 't'), iterator);
 			// Only load cast members which belong to the requested library ID.
 			// External casts only have one library ID, so instead
 			// we use the movie's mapping.
 			if (res.libId != _castLibID && !_isExternal)
 				continue;
-			Common::SeekableReadStreamEndian *stream = _castArchive->getResource(MKTAG('C', 'A', 'S', 't'), *iterator);
+			Common::SeekableReadStreamEndian *stream = _castArchive->getResource(MKTAG('C', 'A', 'S', 't'), iterator);
 			loadCastData(*stream, res.castId, &res);
 			delete stream;
 
@@ -615,18 +615,18 @@ void Cast::loadCast() {
 
 	_loadedStxts = new Common::HashMap<int, const Stxt *>();
 
-	for (Common::Array<uint16>::iterator iterator = stxt.begin(); iterator != stxt.end(); ++iterator) {
-		_loadedStxts->setVal(*iterator - _castIDoffset,
-				 new Stxt(this, *(r = _castArchive->getResource(MKTAG('S','T','X','T'), *iterator))));
+	for (auto &iterator : stxt) {
+		_loadedStxts->setVal(iterator - _castIDoffset,
+				 new Stxt(this, *(r = _castArchive->getResource(MKTAG('S','T','X','T'), iterator))));
 
 		delete r;
 
 		// Try to load movie script, it starts with a comment
 		if (_version < kFileVer400) {
 			if (debugChannelSet(-1, kDebugFewFramesOnly))
-				warning("Compiling STXT %d", *iterator);
+				warning("Compiling STXT %d", iterator);
 
-			loadScriptV2(*(r = _castArchive->getResource(MKTAG('S','T','X','T'), *iterator)), *iterator - _castIDoffset);
+			loadScriptV2(*(r = _castArchive->getResource(MKTAG('S','T','X','T'), iterator)), iterator - _castIDoffset);
 			delete r;
 		}
 
@@ -1073,8 +1073,8 @@ void Cast::loadLingoContext(Common::SeekableReadStreamEndian &stream) {
 		}
 
 		// actually define scripts
-		for (ScriptContextHash::iterator it = _lingoArchive->lctxContexts.begin(); it != _lingoArchive->lctxContexts.end(); ++it) {
-			ScriptContext *script = it->_value;
+		for (auto &it : _lingoArchive->lctxContexts) {
+			ScriptContext *script = it._value;
 			if (script->_id >= 0 && !script->isFactory()) {
 				if (_lingoArchive->getScriptContext(script->_scriptType, script->_id)) {
 					error("Cast::loadLingoContext: Script already defined for type %s, id %d", scriptType2str(script->_scriptType), script->_id);
diff --git a/engines/director/castmember/filmloop.cpp b/engines/director/castmember/filmloop.cpp
index a3e04796fc2..add4897f098 100644
--- a/engines/director/castmember/filmloop.cpp
+++ b/engines/director/castmember/filmloop.cpp
@@ -71,14 +71,14 @@ Common::Array<Channel> *FilmLoopCastMember::getSubChannels(Common::Rect &bbox, C
 
 	// get the list of sprite IDs for this frame
 	Common::Array<int> spriteIds;
-	for (Common::HashMap<int, Director::Sprite>::iterator iter = _frames[channel->_filmLoopFrame].sprites.begin(); iter != _frames[channel->_filmLoopFrame].sprites.end(); ++iter) {
-		spriteIds.push_back(iter->_key);
+	for (auto &iter : _frames[channel->_filmLoopFrame].sprites) {
+		spriteIds.push_back(iter._key);
 	}
 	Common::sort(spriteIds.begin(), spriteIds.end());
 
 	// copy the sprites in order to the list
-	for (Common::Array<int>::iterator iter = spriteIds.begin(); iter != spriteIds.end(); ++iter) {
-		Sprite src = _frames[channel->_filmLoopFrame].sprites[*iter];
+	for (auto &iter : spriteIds) {
+		Sprite src = _frames[channel->_filmLoopFrame].sprites[iter];
 		if (!src._cast)
 			continue;
 		// translate sprite relative to the global bounding box
@@ -213,20 +213,20 @@ void FilmLoopCastMember::loadFilmLoopData(Common::SeekableReadStreamEndian &stre
 			frameSize -= msgWidth;
 		}
 
-		for (Common::HashMap<int, Sprite>::iterator s = newFrame.sprites.begin(); s != newFrame.sprites.end(); ++s) {
-			debugC(5, kDebugLoading, "loadFilmLoopData: Sprite: channel %d, castId %s, bbox %d %d %d %d", s->_key,
-					s->_value._castId.asString().c_str(), s->_value._startPoint.x, s->_value._startPoint.y,
-					s->_value._width, s->_value._height);
+		for (auto &s : newFrame.sprites) {
+			debugC(5, kDebugLoading, "loadFilmLoopData: Sprite: channel %d, castId %s, bbox %d %d %d %d", s._key,
+					s._value._castId.asString().c_str(), s._value._startPoint.x, s._value._startPoint.y,
+					s._value._width, s._value._height);
 
-			Common::Point topLeft = s->_value._startPoint;
-			if (s->_value._cast) {
-				topLeft -= s->_value._cast->getRegistrationOffset(s->_value._width, s->_value._height);
+			Common::Point topLeft = s._value._startPoint;
+			if (s._value._cast) {
+				topLeft -= s._value._cast->getRegistrationOffset(s._value._width, s._value._height);
 			}
 			Common::Rect spriteBbox(
 				topLeft.x,
 				topLeft.y,
-				topLeft.x + s->_value._width,
-				topLeft.y + s->_value._height
+				topLeft.x + s._value._width,
+				topLeft.y + s._value._height
 			);
 			if (!((spriteBbox.width() == 0) && (spriteBbox.height() == 0))) {
 				if ((_initialRect.width() == 0) && (_initialRect.height() == 0)) {
@@ -355,30 +355,30 @@ void FilmLoopCastMember::loadFilmLoopDataV4(Common::SeekableReadStreamEndian &st
 			newFrame.sprites.setVal(channel, sprite);
 		}
 
-		for (Common::HashMap<int, Sprite>::iterator s = newFrame.sprites.begin(); s != newFrame.sprites.end(); ++s) {
-			debugC(5, kDebugLoading, "loadFilmLoopDataV4: Sprite: channel %d, castId %s, bbox %d %d %d %d", s->_key,
-					s->_value._castId.asString().c_str(), s->_value._startPoint.x, s->_value._startPoint.y,
-					s->_value._width, s->_value._height);
+		for (auto &s : newFrame.sprites) {
+			debugC(5, kDebugLoading, "loadFilmLoopDataV4: Sprite: channel %d, castId %s, bbox %d %d %d %d", s._key,
+					s._value._castId.asString().c_str(), s._value._startPoint.x, s._value._startPoint.y,
+					s._value._width, s._value._height);
 
-			if (s->_key == -1) {
+			if (s._key == -1) {
 				debugC(5, kDebugLoading, "loadFilmLoopDataV4: Skipping channel -1");
-				if (s->_value._startPoint.x != 0 || s->_value._startPoint.y != 0 || s->_value._width != 0 ||
-						 (s->_value._height != -256 && s->_value._height != 0))
-					warning("BUILDBOT: loadFilmLoopDataV4: Malformed VWSC resource: Sprite: channel %d, castId %s, bbox %d %d %d %d", s->_key,
-						s->_value._castId.asString().c_str(), s->_value._startPoint.x, s->_value._startPoint.y,
-						s->_value._width, s->_value._height);
+				if (s._value._startPoint.x != 0 || s._value._startPoint.y != 0 || s._value._width != 0 ||
+						 (s._value._height != -256 && s._value._height != 0))
+					warning("BUILDBOT: loadFilmLoopDataV4: Malformed VWSC resource: Sprite: channel %d, castId %s, bbox %d %d %d %d", s._key,
+						s._value._castId.asString().c_str(), s._value._startPoint.x, s._value._startPoint.y,
+						s._value._width, s._value._height);
 				continue;
 			}
 
-			Common::Point topLeft = s->_value._startPoint;
-			if (s->_value._cast) {
-				topLeft -= s->_value._cast->getRegistrationOffset(s->_value._width, s->_value._height);
+			Common::Point topLeft = s._value._startPoint;
+			if (s._value._cast) {
+				topLeft -= s._value._cast->getRegistrationOffset(s._value._width, s._value._height);
 			}
 			Common::Rect spriteBbox(
 				topLeft.x,
 				topLeft.y,
-				topLeft.x + s->_value._width,
-				topLeft.y + s->_value._height
+				topLeft.x + s._value._width,
+				topLeft.y + s._value._height
 			);
 			if (!((spriteBbox.width() == 0) && (spriteBbox.height() == 0))) {
 				if ((_initialRect.width() == 0) && (_initialRect.height() == 0)) {
diff --git a/engines/director/cursor.cpp b/engines/director/cursor.cpp
index df7b63e1c44..7ca2b1ce50d 100644
--- a/engines/director/cursor.cpp
+++ b/engines/director/cursor.cpp
@@ -184,8 +184,8 @@ void Cursor::readFromResource(Datum resourceId) {
 				break;
 		}
 
-		for (Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>::iterator it = g_director->_allOpenResFiles.begin(); it != g_director->_allOpenResFiles.end(); ++it) {
-			readSuccessful = readFromArchive(it->_value, resourceId.asInt());
+		for (auto &it : g_director->_allOpenResFiles) {
+			readSuccessful = readFromArchive(it._value, resourceId.asInt());
 			if (readSuccessful)
 				break;
 		}
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index ea11f38ecf6..b8c2f1f9bd0 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1315,8 +1315,8 @@ void LB::b_showResFile(int nargs) {
 	if (nargs)
 		g_lingo->pop();
 	Common::String out;
-	for (auto it = g_director->_allOpenResFiles.begin(); it != g_director->_allOpenResFiles.end(); it++)
-		out += it->_key + "\n";
+	for (auto &it : g_director->_allOpenResFiles)
+		out += it._key + "\n";
 	g_debugger->debugLogFile(out, false);
 }
 
@@ -1324,8 +1324,8 @@ void LB::b_showXlib(int nargs) {
 	if (nargs)
 		g_lingo->pop();
 	Common::String out;
-	for (auto it = g_lingo->_openXLibs.begin(); it != g_lingo->_openXLibs.end(); it++)
-		out += it->_key + "\n";
+	for (auto &it : g_lingo->_openXLibs)
+		out += it._key + "\n";
 	g_debugger->debugLogFile(out, false);
 }
 
@@ -1333,8 +1333,8 @@ void LB::b_xFactoryList(int nargs) {
 	g_lingo->pop();
 	Datum d("");
 
-	for (auto it = g_lingo->_openXLibs.begin(); it != g_lingo->_openXLibs.end(); it++)
-		*d.u.s += it->_key + "\n";
+	for (auto &it : g_lingo->_openXLibs)
+		*d.u.s += it._key + "\n";
 	g_lingo->push(d);
 }
 
diff --git a/engines/director/lingo/lingo-bytecode.cpp b/engines/director/lingo/lingo-bytecode.cpp
index 13c17f3513c..76a4429221f 100644
--- a/engines/director/lingo/lingo-bytecode.cpp
+++ b/engines/director/lingo/lingo-bytecode.cpp
@@ -314,8 +314,8 @@ void Lingo::initBytecode() {
 	bool bailout = false;
 
 	// Build reverse hashmap
-	for (FuncHash::iterator it = _functions.begin(); it != _functions.end(); ++it)
-		list[(inst)it->_key] = true;
+	for (auto &it : _functions)
+		list[(inst)it._key] = true;
 
 	for (LingoV4Bytecode *op = lingoV4; op->opcode; op++) {
 		_lingoV4[op->opcode] = op;
@@ -1615,9 +1615,9 @@ ScriptContext *LingoCompiler::compileLingoV4(Common::SeekableReadStreamEndian &s
 
 	if (!_assemblyContext->isFactory()) {
 		// Register this context's functions with the containing archive.
-		for (SymbolHash::iterator it = _assemblyContext->_functionHandlers.begin(); it != _assemblyContext->_functionHandlers.end(); ++it) {
-			if (!_assemblyArchive->functionHandlers.contains(it->_key)) {
-				_assemblyArchive->functionHandlers[it->_key] = it->_value;
+		for (auto &it : _assemblyContext->_functionHandlers) {
+			if (!_assemblyArchive->functionHandlers.contains(it._key)) {
+				_assemblyArchive->functionHandlers[it._key] = it._value;
 			}
 		}
 	}
diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp
index d7b1ceba252..c28f7c20142 100644
--- a/engines/director/lingo/lingo-code.cpp
+++ b/engines/director/lingo/lingo-code.cpp
@@ -183,8 +183,8 @@ void Lingo::initFuncs() {
 }
 
 void Lingo::cleanupFuncs() {
-	for (FuncHash::iterator it = _functions.begin(); it != _functions.end(); ++it)
-		delete it->_value;
+	for (auto &it : _functions)
+		delete it._value;
 }
 
 void Lingo::push(Datum d) {
@@ -286,8 +286,8 @@ void Lingo::pushContext(const Symbol funcSym, bool allowRetVal, Datum defaultRet
 		}
 	}
 	if (funcSym.varNames) {
-		for (Common::Array<Common::String>::iterator it = funcSym.varNames->begin(); it != funcSym.varNames->end(); ++it) {
-			Common::String name = *it;
+		for (auto &it : *funcSym.varNames) {
+			Common::String name = it;
 			if (!localvars->contains(name)) {
 				(*localvars)[name] = Datum();
 			} else {
diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp
index 809fe67696a..eb52461f8bc 100644
--- a/engines/director/lingo/lingo-codegen.cpp
+++ b/engines/director/lingo/lingo-codegen.cpp
@@ -187,9 +187,9 @@ ScriptContext *LingoCompiler::compileLingo(const Common::U32String &code, LingoA
 		currentFunc.anonymous = anonymous;
 		Common::Array<Common::String> *argNames = new Common::Array<Common::String>;
 		Common::Array<Common::String> *varNames = new Common::Array<Common::String>;
-		for (Common::HashMap<Common::String, VarType, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>::iterator it = _methodVars->begin(); it != _methodVars->end(); ++it) {
-			if (it->_value == kVarLocal)
-				varNames->push_back(Common::String(it->_key));
+		for (auto &it : *_methodVars) {
+			if (it._value == kVarLocal)
+				varNames->push_back(Common::String(it._key));
 		}
 
 		if (debugChannelSet(1, kDebugCompile)) {
@@ -216,9 +216,9 @@ ScriptContext *LingoCompiler::compileLingo(const Common::U32String &code, LingoA
 
 	// Register this context's functions with the containing archive.
 	if (_assemblyArchive) {
-		for (SymbolHash::iterator it = _assemblyContext->_functionHandlers.begin(); it != _assemblyContext->_functionHandlers.end(); ++it) {
-			if (!_assemblyArchive->functionHandlers.contains(it->_key)) {
-				_assemblyArchive->functionHandlers[it->_key] = it->_value;
+		for (auto &it : _assemblyContext->_functionHandlers) {
+			if (!_assemblyArchive->functionHandlers.contains(it._key)) {
+				_assemblyArchive->functionHandlers[it._key] = it._value;
 			}
 		}
 	}
@@ -469,9 +469,9 @@ bool LingoCompiler::visitHandlerNode(HandlerNode *node) {
 		argNames->push_back(Common::String((*node->args)[i]->c_str()));
 	}
 	Common::Array<Common::String> *varNames = new Common::Array<Common::String>;
-	for (Common::HashMap<Common::String, VarType, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>::iterator it = _methodVars->begin(); it != _methodVars->end(); ++it) {
-		if (it->_value == kVarLocal)
-			varNames->push_back(Common::String(it->_key));
+	for (auto &it : *_methodVars) {
+		if (it._value == kVarLocal)
+			varNames->push_back(Common::String(it._key));
 	}
 
 	if (debugChannelSet(1, kDebugCompile)) {
diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index f4bc277f289..d50d4d8a8b9 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -367,12 +367,12 @@ void DirectorSound::loadSampleSounds(uint type) {
 	uint id = 0xFF;
 	Archive *archive = nullptr;
 
-	for (Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>::iterator it = g_director->_allOpenResFiles.begin(); it != g_director->_allOpenResFiles.end(); ++it) {
-		Common::Array<uint16> idList = it->_value->getResourceIDList(tag);
+	for (auto &it : g_director->_allOpenResFiles) {
+		Common::Array<uint16> idList = it._value->getResourceIDList(tag);
 		for (uint j = 0; j < idList.size(); j++) {
 			if ((idList[j] & 0xFF) == type) {
 				id = idList[j];
-				archive = it->_value;
+				archive = it._value;
 				break;
 			}
 		}
@@ -573,10 +573,10 @@ void DirectorSound::playFPlaySound() {
 	Archive *archive = nullptr;
 
 	// iterate opened ResFiles
-	for (Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo>::iterator it = g_director->_allOpenResFiles.begin(); it != g_director->_allOpenResFiles.end(); ++it) {
-		id = it->_value->findResourceID(tag, sndName, true);
+	for (auto &it : g_director->_allOpenResFiles) {
+		id = it._value->findResourceID(tag, sndName, true);
 		if (id != 0xFFFF) {
-			archive = it->_value;
+			archive = it._value;
 			break;
 		}
 	}
diff --git a/engines/director/window.cpp b/engines/director/window.cpp
index 5caea873f8c..d1285c60c55 100644
--- a/engines/director/window.cpp
+++ b/engines/director/window.cpp
@@ -357,6 +357,7 @@ void Window::loadNewSharedCast(Cast *previousSharedCast) {
 
 	// Clean up the previous sharedCast
 	if (previousSharedCast) {
+		g_director->_allOpenResFiles.erase(previousSharedCastPath);
 		delete previousSharedCast;
 	}
 


Commit: 7baba618528e5234fa69908f99d5d95d738d7d77
    https://github.com/scummvm/scummvm/commit/7baba618528e5234fa69908f99d5d95d738d7d77
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-06-29T23:22:38+02:00

Commit Message:
DIRECTOR: Modernized rest of the loops

Changed paths:
    engines/director/archive.cpp
    engines/director/fonts.cpp
    engines/director/lingo/lingo-builtins.cpp
    engines/director/lingo/lingo-codegen.cpp
    engines/director/lingo/lingo-events.cpp
    engines/director/lingo/lingo-object.cpp
    engines/director/lingo/lingo.cpp
    engines/director/resource.cpp
    engines/director/score.cpp
    engines/director/tests.cpp
    engines/director/transitions.cpp
    engines/director/util.cpp
    engines/director/window.cpp


diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp
index 097b44e2c67..8c43c0962bd 100644
--- a/engines/director/archive.cpp
+++ b/engines/director/archive.cpp
@@ -569,8 +569,8 @@ RIFXArchive::RIFXArchive() : Archive() {
 }
 
 RIFXArchive::~RIFXArchive() {
-	for (Common::HashMap<uint32, byte *>::iterator it = _ilsData.begin(); it != _ilsData.end(); it++)
-		free(it->_value);
+	for (auto &it : _ilsData)
+		free(it._value);
 }
 
 bool RIFXArchive::openStream(Common::SeekableReadStream *stream, uint32 startOffset) {
diff --git a/engines/director/fonts.cpp b/engines/director/fonts.cpp
index 0ff4423b796..0b4019c4e52 100644
--- a/engines/director/fonts.cpp
+++ b/engines/director/fonts.cpp
@@ -430,8 +430,8 @@ bool Cast::readFXmpLine(Common::SeekableReadStreamEndian &stream) {
 				_fontXPlatformMap[fromFont] = info;
 				debugC(3, kDebugLoading, "Cast::readFXmpLine: Mapping Win font '%s' to Mac font '%s'", fromFont.c_str(), info->toFont.c_str());
 				debugC(4, kDebugLoading, "  Remap characters: %d", info->remapChars);
-				for (FontSizeMap::iterator it = info->sizeMap.begin(); it != info->sizeMap.end(); ++it) {
-					debugC(4, kDebugLoading, "  Mapping size %d to %d", it->_key, it->_value);
+				for (auto &it : info->sizeMap) {
+					debugC(4, kDebugLoading, "  Mapping size %d to %d", it._key, it._value);
 				}
 			}
 		} else {
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index b8c2f1f9bd0..e021885f42c 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1839,9 +1839,9 @@ void LB::b_alert(int nargs) {
 }
 
 void LB::b_clearGlobals(int nargs) {
-	for (DatumHash::iterator it = g_lingo->_globalvars.begin(); it != g_lingo->_globalvars.end(); it++) {
-		if (!it->_value.ignoreGlobal) {
-			g_lingo->_globalvars.erase(it);
+	for (auto &it : g_lingo->_globalvars) {
+		if (!it._value.ignoreGlobal) {
+			g_lingo->_globalvars.erase(it._key);
 		}
 	}
 }
diff --git a/engines/director/lingo/lingo-codegen.cpp b/engines/director/lingo/lingo-codegen.cpp
index eb52461f8bc..941eeeb337e 100644
--- a/engines/director/lingo/lingo-codegen.cpp
+++ b/engines/director/lingo/lingo-codegen.cpp
@@ -447,12 +447,12 @@ bool LingoCompiler::visitHandlerNode(HandlerNode *node) {
 	for (uint i = 0; i < node->args->size(); i++) {
 		registerMethodVar(*(*node->args)[i], kVarArgument);
 	}
-	for (VarTypeHash::iterator i = mainMethodVars->begin(); i != mainMethodVars->end(); ++i) {
-		if (i->_value == kVarGlobal)
-			registerMethodVar(i->_key, kVarGlobal);
+	for (auto &i : *mainMethodVars) {
+		if (i._value == kVarGlobal)
+			registerMethodVar(i._key, kVarGlobal);
 	}
-	for (DatumHash::iterator i = _assemblyContext->_properties.begin(); i != _assemblyContext->_properties.end(); ++i) {
-		registerMethodVar(i->_key, _inFactory ? kVarInstance : kVarProperty);
+	for (auto &i : _assemblyContext->_properties) {
+		registerMethodVar(i._key, _inFactory ? kVarInstance : kVarProperty);
 	}
 
 	COMPILE_LIST(node->stmts);
diff --git a/engines/director/lingo/lingo-events.cpp b/engines/director/lingo/lingo-events.cpp
index d19dea4e9b0..821c712c360 100644
--- a/engines/director/lingo/lingo-events.cpp
+++ b/engines/director/lingo/lingo-events.cpp
@@ -184,19 +184,17 @@ void Movie::queueMovieEvent(Common::Queue<LingoEvent> &queue, LEvent event, int
 
 	// FIXME: shared cast movie scripts could come before main movie ones
 	LingoArchive *mainArchive = getMainLingoArch();
-	for (ScriptContextHash::iterator it = mainArchive->scriptContexts[kMovieScript].begin();
-			it != mainArchive->scriptContexts[kMovieScript].end(); ++it) {
-		if (it->_value->_eventHandlers.contains(event)) {
-			queue.push(LingoEvent(event, eventId, kMovieScript, CastMemberID(it->_key, DEFAULT_CAST_LIB), false));
+	for (auto &it : mainArchive->scriptContexts[kMovieScript]) {
+		if (it._value->_eventHandlers.contains(event)) {
+			queue.push(LingoEvent(event, eventId, kMovieScript, CastMemberID(it._key, DEFAULT_CAST_LIB), false));
 			return;
 		}
 	}
 	LingoArchive *sharedArchive = getSharedLingoArch();
 	if (sharedArchive) {
-		for (ScriptContextHash::iterator it = sharedArchive->scriptContexts[kMovieScript].begin();
-				it != sharedArchive->scriptContexts[kMovieScript].end(); ++it) {
-			if (it->_value->_eventHandlers.contains(event)) {
-				queue.push(LingoEvent(event, eventId, kMovieScript, CastMemberID(it->_key, DEFAULT_CAST_LIB), false));
+		for (auto &it : sharedArchive->scriptContexts[kMovieScript]) {
+			if (it._value->_eventHandlers.contains(event)) {
+				queue.push(LingoEvent(event, eventId, kMovieScript, CastMemberID(it._key, DEFAULT_CAST_LIB), false));
 				return;
 			}
 		}
diff --git a/engines/director/lingo/lingo-object.cpp b/engines/director/lingo/lingo-object.cpp
index cb14f3a63e9..a6b63673b2c 100644
--- a/engines/director/lingo/lingo-object.cpp
+++ b/engines/director/lingo/lingo-object.cpp
@@ -294,16 +294,16 @@ void Lingo::closeXLib(Common::String name) {
 }
 
 void Lingo::closeOpenXLibs() {
-	for (OpenXLibsHash::iterator it = _openXLibs.begin(); it != _openXLibs.end(); ++it) {
-		closeXLib(it->_key);
+	for (auto &it : _openXLibs) {
+		closeXLib(it._key);
 	}
 }
 
 void Lingo::reloadOpenXLibs() {
 	OpenXLibsHash openXLibsCopy = _openXLibs;
-	for (OpenXLibsHash::iterator it = openXLibsCopy.begin(); it != openXLibsCopy.end(); ++it) {
-		closeXLib(it->_key);
-		openXLib(it->_key, it->_value);
+	for (auto &it : openXLibsCopy) {
+		closeXLib(it._key);
+		openXLib(it._key, it._value);
 	}
 }
 
@@ -329,13 +329,13 @@ ScriptContext::ScriptContext(Common::String name, ScriptType type, int id)
 ScriptContext::ScriptContext(const ScriptContext &sc) : Object<ScriptContext>(sc) {
 	_scriptType = sc._scriptType;
 	_functionNames = sc._functionNames;
-	for (SymbolHash::iterator it = sc._functionHandlers.begin(); it != sc._functionHandlers.end(); ++it) {
-		_functionHandlers[it->_key] = it->_value;
-		_functionHandlers[it->_key].ctx = this;
+	for (auto &it : sc._functionHandlers) {
+		_functionHandlers[it._key] = it._value;
+		_functionHandlers[it._key].ctx = this;
 	}
-	for (Common::HashMap<uint32, Symbol>::iterator it = sc._eventHandlers.begin(); it != sc._eventHandlers.end(); ++it) {
-		_eventHandlers[it->_key] = it->_value;
-		_eventHandlers[it->_key].ctx = this;
+	for (auto &it : sc._eventHandlers) {
+		_eventHandlers[it._key] = it._value;
+		_eventHandlers[it._key].ctx = this;
 	}
 	_constants = sc._constants;
 	_properties = sc._properties;
@@ -655,13 +655,13 @@ void LM::m_forget(int nargs) {
 		windowList->arr.remove_at(i);
 
 	// remove me from global vars
-	for (DatumHash::iterator it = g_lingo->_globalvars.begin(); it != g_lingo->_globalvars.end(); ++it) {
-		if (it->_value.type != OBJECT || it->_value.u.obj->getObjType() != kWindowObj)
+	for (auto &it : g_lingo->_globalvars) {
+		if (it._value.type != OBJECT || it._value.u.obj->getObjType() != kWindowObj)
 			continue;
 
 		Window *window = static_cast<Window *>(windowList->arr[i].u.obj);
 		if (window == me)
-			g_lingo->_globalvars[it->_key] = 0;
+			g_lingo->_globalvars[it._key] = 0;
 	}
 }
 
diff --git a/engines/director/lingo/lingo.cpp b/engines/director/lingo/lingo.cpp
index f13273184b1..db0f39c810b 100644
--- a/engines/director/lingo/lingo.cpp
+++ b/engines/director/lingo/lingo.cpp
@@ -244,16 +244,16 @@ void Lingo::reloadBuiltIns() {
 LingoArchive::~LingoArchive() {
 	// First cleanup the ScriptContexts that are only in LctxContexts.
 	// LctxContexts has a huge overlap with scriptContexts.
-	for (ScriptContextHash::iterator it = lctxContexts.begin(); it != lctxContexts.end(); ++it){
-		ScriptContext *script = it->_value;
+	for (auto &it : lctxContexts){
+		ScriptContext *script = it._value;
 		if (script->getOnlyInLctxContexts()) {
 			script->decRefCount();
 		}
 	}
 
 	for (int i = 0; i <= kMaxScriptType; i++) {
-		for (ScriptContextHash::iterator it = scriptContexts[i].begin(); it != scriptContexts[i].end(); ++it) {
-			it->_value->decRefCount();
+		for (auto &it : scriptContexts[i]) {
+			it._value->decRefCount();
 		}
 	}
 
@@ -297,14 +297,14 @@ Common::String LingoArchive::formatFunctionList(const char *prefix) {
 		result += Common::String::format("%s%s:\n", prefix, scriptType2str((ScriptType)i));
 		if (scriptContexts[i].size() == 0)
 			result += Common::String::format("%s  [empty]\n", prefix);
-		for (ScriptContextHash::iterator it = scriptContexts[i].begin(); it != scriptContexts[i].end(); ++it) {
-			result += Common::String::format("%s  %d", prefix, it->_key);
-			CastMemberInfo *cmi = cast->getCastMemberInfo(it->_key);
+		for (auto &it : scriptContexts[i]) {
+			result += Common::String::format("%s  %d", prefix, it._key);
+			CastMemberInfo *cmi = cast->getCastMemberInfo(it._key);
 			if (cmi && !cmi->name.empty()) {
 				result += Common::String::format(" \"%s\"", cmi->name.c_str());
 			}
 			result += ":\n";
-			result += (*it->_value).formatFunctionList(Common::String::format("%s    ", prefix).c_str());
+			result += it._value->formatFunctionList(Common::String::format("%s    ", prefix).c_str());
 		}
 	}
 	result += Common::String::format("%sFactories:\n", prefix);
@@ -1359,8 +1359,8 @@ void Lingo::runTests() {
 	if (startMovie.size() > 0) {
 		fileList.push_back(startMovie);
 	} else {
-		for (Common::ArchiveMemberList::iterator it = fsList.begin(); it != fsList.end(); ++it)
-			fileList.push_back((*it)->getName());
+		for (auto &it : fsList)
+			fileList.push_back(it->getName());
 	}
 
 	Common::sort(fileList.begin(), fileList.end());
@@ -1454,8 +1454,8 @@ Common::String Lingo::formatAllVars() {
 
 	result += Common::String("  Local vars:\n");
 	if (_state->localVars) {
-		for (DatumHash::iterator i = _state->localVars->begin(); i != _state->localVars->end(); ++i) {
-			result += Common::String::format("    %s - [%s] %s\n", (*i)._key.c_str(), (*i)._value.type2str(), (*i)._value.asString(true).c_str());
+		for (auto &i : *_state->localVars) {
+			result += Common::String::format("    %s - [%s] %s\n", i._key.c_str(), i._value.type2str(), i._value.asString(true).c_str());
 		}
 	} else {
 		result += Common::String("    (no local vars)\n");
@@ -1465,15 +1465,15 @@ Common::String Lingo::formatAllVars() {
 	if (_state->me.type == OBJECT && _state->me.u.obj->getObjType() & (kFactoryObj | kScriptObj)) {
 		ScriptContext *script = static_cast<ScriptContext *>(_state->me.u.obj);
 		result += Common::String("  Instance/property vars: \n");
-		for (DatumHash::iterator i = script->_properties.begin(); i != script->_properties.end(); ++i) {
-			result += Common::String::format("    %s - [%s] %s\n", (*i)._key.c_str(), (*i)._value.type2str(), (*i)._value.asString(true).c_str());
+		for (auto &i : script->_properties) {
+			result += Common::String::format("    %s - [%s] %s\n", i._key.c_str(), i._value.type2str(), i._value.asString(true).c_str());
 		}
 		result += Common::String("\n");
 	}
 
 	result += Common::String("  Global vars:\n");
-	for (DatumHash::iterator i = _globalvars.begin(); i != _globalvars.end(); ++i) {
-		result += Common::String::format("    %s - [%s] %s\n", (*i)._key.c_str(), (*i)._value.type2str(), (*i)._value.asString(true).c_str());
+	for (auto &i : _globalvars) {
+		result += Common::String::format("    %s - [%s] %s\n", i._key.c_str(), i._value.type2str(), i._value.asString(true).c_str());
 	}
 	result += Common::String("\n");
 	return result;
diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp
index 49cee89591f..00d8da96050 100644
--- a/engines/director/resource.cpp
+++ b/engines/director/resource.cpp
@@ -121,8 +121,8 @@ void Window::probeResources(Archive *archive) {
 
 		if (archive->hasResource(MKTAG('v', 'e', 'r', 's'), -1)) {
 			Common::Array<uint16> vers = archive->getResourceIDList(MKTAG('v', 'e', 'r', 's'));
-			for (Common::Array<uint16>::iterator iterator = vers.begin(); iterator != vers.end(); ++iterator) {
-				Common::SeekableReadStreamEndian *vvers = archive->getResource(MKTAG('v', 'e', 'r', 's'), *iterator);
+			for (auto &iterator : vers) {
+				Common::SeekableReadStreamEndian *vvers = archive->getResource(MKTAG('v', 'e', 'r', 's'), iterator);
 				Common::MacResManager::MacVers *v = Common::MacResManager::parseVers(vvers);
 
 				debug(0, "Detected vers %d.%d %s.%d region %d '%s' '%s'", v->majorVer, v->minorVer, v->devStr.c_str(),
@@ -176,24 +176,24 @@ void Window::probeResources(Archive *archive) {
 		if (resFork->openFile(archive->getPathName())) {
 			if (resFork->hasResource(MKTAG('X', 'C', 'O', 'D'), -1)) {
 				Common::Array<uint16> xcod = resFork->getResourceIDList(MKTAG('X', 'C', 'O', 'D'));
-				for (Common::Array<uint16>::iterator iterator = xcod.begin(); iterator != xcod.end(); ++iterator) {
-					Resource res = resFork->getResourceDetail(MKTAG('X', 'C', 'O', 'D'), *iterator);
+				for (auto &iterator : xcod) {
+					Resource res = resFork->getResourceDetail(MKTAG('X', 'C', 'O', 'D'), iterator);
 					debug(0, "Detected XObject '%s'", res.name.c_str());
 					g_lingo->openXLib(res.name, kXObj);
 				}
 			}
 			if (resFork->hasResource(MKTAG('X', 'C', 'M', 'D'), -1)) {
 				Common::Array<uint16> xcmd = resFork->getResourceIDList(MKTAG('X', 'C', 'M', 'D'));
-				for (Common::Array<uint16>::iterator iterator = xcmd.begin(); iterator != xcmd.end(); ++iterator) {
-					Resource res = resFork->getResourceDetail(MKTAG('X', 'C', 'M', 'D'), *iterator);
+				for (auto &iterator : xcmd) {
+					Resource res = resFork->getResourceDetail(MKTAG('X', 'C', 'M', 'D'), iterator);
 					debug(0, "Detected XCMD '%s'", res.name.c_str());
 					g_lingo->openXLib(res.name, kXObj);
 				}
 			}
 			if (resFork->hasResource(MKTAG('X', 'F', 'C', 'N'), -1)) {
 				Common::Array<uint16> xfcn = resFork->getResourceIDList(MKTAG('X', 'F', 'C', 'N'));
-				for (Common::Array<uint16>::iterator iterator = xfcn.begin(); iterator != xfcn.end(); ++iterator) {
-					Resource res = resFork->getResourceDetail(MKTAG('X', 'F', 'C', 'N'), *iterator);
+				for (auto &iterator : xfcn) {
+					Resource res = resFork->getResourceDetail(MKTAG('X', 'F', 'C', 'N'), iterator);
 					debug(0, "Detected XFCN '%s'", res.name.c_str());
 					g_lingo->openXLib(res.name, kXObj);
 				}
diff --git a/engines/director/score.cpp b/engines/director/score.cpp
index efa8b8033ed..318c80cb0a4 100644
--- a/engines/director/score.cpp
+++ b/engines/director/score.cpp
@@ -97,8 +97,8 @@ Score::~Score() {
 		delete _channels[i];
 
 	if (_labels)
-		for (Common::SortedArray<Label *>::iterator it = _labels->begin(); it != _labels->end(); ++it)
-			delete *it;
+		for (auto &it : *_labels)
+			delete it;
 
 	delete _labels;
 }
@@ -139,9 +139,9 @@ uint16 Score::getLabel(Common::String &label) {
 		return 0;
 	}
 
-	for (Common::SortedArray<Label *>::iterator i = _labels->begin(); i != _labels->end(); ++i) {
-		if ((*i)->name.equalsIgnoreCase(label)) {
-			return (*i)->number;
+	for (auto &i : *_labels) {
+		if (i->name.equalsIgnoreCase(label)) {
+			return i->number;
 		}
 	}
 
@@ -151,8 +151,8 @@ uint16 Score::getLabel(Common::String &label) {
 Common::String *Score::getLabelList() {
 	Common::String *res = new Common::String;
 
-	for (Common::SortedArray<Label *>::iterator i = _labels->begin(); i != _labels->end(); ++i) {
-		*res += (*i)->name;
+	for (auto &i : *_labels) {
+		*res += i->name;
 		*res += '\n';
 	}
 
@@ -160,9 +160,9 @@ Common::String *Score::getLabelList() {
 }
 
 Common::String *Score::getFrameLabel(uint id) {
-	for (Common::SortedArray<Label *>::iterator i = _labels->begin(); i != _labels->end(); ++i) {
-		if ((*i)->number == id) {
-			return new Common::String((*i)->name);
+	for (auto &i : *_labels) {
+		if (i->number == id) {
+			return new Common::String(i->name);
 			break;
 		}
 	}
@@ -193,16 +193,14 @@ void Score::gotoLoop() {
 }
 
 int Score::getCurrentLabelNumber() {
-	Common::SortedArray<Label *>::iterator i;
-
 	if (!_labels)
 		return 0;
 
 	int frame = 0;
 
-	for (i = _labels->begin(); i != _labels->end(); ++i) {
-		if ((*i)->number <= _currentFrame)
-			frame = (*i)->number;
+	for (auto &i : *_labels) {
+		if (i->number <= _currentFrame)
+			frame = i->number;
 	}
 
 	return frame;
@@ -419,10 +417,9 @@ void Score::update() {
 		}
 	}
 
-	Common::SortedArray<Label *>::iterator i;
 	if (_labels != nullptr) {
-		for (i = _labels->begin(); i != _labels->end(); ++i) {
-			if ((*i)->number == _currentFrame) {
+		for (auto &i : *_labels) {
+			if (i->number == _currentFrame) {
 				_currentLabel = _currentFrame;
 			}
 		}
@@ -1514,11 +1511,9 @@ void Score::loadLabels(Common::SeekableReadStreamEndian &stream) {
 		stringPos = nextStringPos;
 	}
 
-	Common::SortedArray<Label *>::iterator j;
-
 	debugC(2, kDebugLoading, "****** Loading labels");
-	for (j = _labels->begin(); j != _labels->end(); ++j) {
-		debugC(2, kDebugLoading, "Frame %d, Label '%s', Comment '%s'", (*j)->number, utf8ToPrintable((*j)->name).c_str(), (*j)->comment.c_str());
+	for (auto &j : *_labels) {
+		debugC(2, kDebugLoading, "Frame %d, Label '%s', Comment '%s'", j->number, utf8ToPrintable(j->name).c_str(), j->comment.c_str());
 	}
 }
 
@@ -1573,19 +1568,17 @@ void Score::loadActions(Common::SeekableReadStreamEndian &stream) {
 		}
 	}
 
-	Common::HashMap<uint16, Common::String>::iterator j;
-
 	if (ConfMan.getBool("dump_scripts"))
-		for (j = _actions.begin(); j != _actions.end(); ++j) {
-			if (!j->_value.empty())
-				_movie->getCast()->dumpScript(j->_value.c_str(), kScoreScript, j->_key);
+		for (auto &j : _actions) {
+			if (!j._value.empty())
+				_movie->getCast()->dumpScript(j._value.c_str(), kScoreScript, j._key);
 		}
 
-	for (j = _actions.begin(); j != _actions.end(); ++j) {
-		if (!scriptRefs[j->_key]) {
+	for (auto &j : _actions) {
+		if (!scriptRefs[j._key]) {
 			// Check if it is empty
 			bool empty = true;
-			Common::U32String u32Script(j->_value);
+			Common::U32String u32Script(j._value);
 			for (const Common::u32char_type_t *ptr = u32Script.c_str(); *ptr; ptr++)
 				if (!(*ptr == ' ' || *ptr == '-' || *ptr == '\n' || *ptr == '\r' || *ptr == '\t' || *ptr == CONTINUATION)) {
 					empty = false;
@@ -1593,14 +1586,14 @@ void Score::loadActions(Common::SeekableReadStreamEndian &stream) {
 				}
 
 			if (!empty)
-				warning("Action id %d is not referenced, the code is:\n-----\n%s\n------", j->_key, j->_value.c_str());
+				warning("Action id %d is not referenced, the code is:\n-----\n%s\n------", j._key, j._value.c_str());
 
 			continue;
 		}
-		if (!j->_value.empty()) {
-			_movie->getMainLingoArch()->addCode(j->_value, kScoreScript, j->_key);
+		if (!j._value.empty()) {
+			_movie->getMainLingoArch()->addCode(j._value, kScoreScript, j._key);
 
-			processImmediateFrameScript(j->_value, j->_key);
+			processImmediateFrameScript(j._value, j._key);
 		}
 	}
 
diff --git a/engines/director/tests.cpp b/engines/director/tests.cpp
index bf851644024..faecddd4903 100644
--- a/engines/director/tests.cpp
+++ b/engines/director/tests.cpp
@@ -149,9 +149,9 @@ void Window::testFonts() {
 
 	Common::MacResIDArray fonds = fontFile->getResIDArray(MKTAG('F','O','N','D'));
 	if (fonds.size() > 0) {
-		for (Common::Array<uint16>::iterator iterator = fonds.begin(); iterator != fonds.end(); ++iterator) {
-			Common::SeekableReadStream *stream = fontFile->getResource(MKTAG('F', 'O', 'N', 'D'), *iterator);
-			Common::String name = fontFile->getResName(MKTAG('F', 'O', 'N', 'D'), *iterator);
+		for (auto &iterator : fonds) {
+			Common::SeekableReadStream *stream = fontFile->getResource(MKTAG('F', 'O', 'N', 'D'), iterator);
+			Common::String name = fontFile->getResName(MKTAG('F', 'O', 'N', 'D'), iterator);
 
 			debug("Font: %s", name.c_str());
 
diff --git a/engines/director/transitions.cpp b/engines/director/transitions.cpp
index 1ae88595f3d..7dc4260497f 100644
--- a/engines/director/transitions.cpp
+++ b/engines/director/transitions.cpp
@@ -200,8 +200,8 @@ void Window::playTransition(uint frame, uint16 transDuration, uint8 transArea, u
 
 		clipRect = *_dirtyRects.begin();
 
-		for (Common::List<Common::Rect>::iterator i = _dirtyRects.begin(); i != _dirtyRects.end(); ++i)
-			clipRect.extend(*i);
+		for (auto &i : _dirtyRects)
+			clipRect.extend(i);
 
 		// Ensure we redraw any other sprites intersecting the non-clip area.
 		_dirtyRects.clear();
diff --git a/engines/director/util.cpp b/engines/director/util.cpp
index f005d405c87..f77a98160fb 100644
--- a/engines/director/util.cpp
+++ b/engines/director/util.cpp
@@ -556,18 +556,18 @@ bool testPath(Common::String &path, bool directory) {
 			continue;
 
 		bool exists = false;
-		for (Common::FSList::iterator i = fslist.begin(); i != fslist.end(); ++i) {
+		for (auto &i : fslist) {
 			// for each element in the path, choose the first FSNode
 			// with a case-insensitive matching name
-			if (i->getName().equalsIgnoreCase(token)) {
+			if (i.getName().equalsIgnoreCase(token)) {
 				// If this the final path component, check if we're allowed to match with a directory
-				node = Common::FSNode(*i);
+				node = Common::FSNode(i);
 				if (directory_list.empty() && !directory && node.isDirectory()) {
 					continue;
 				}
 
 				exists = true;
-				newPath += i->getName();
+				newPath += i.getName();
 				if (!directory_list.empty())
 					newPath += (g_director->_dirSeparator);
 
diff --git a/engines/director/window.cpp b/engines/director/window.cpp
index d1285c60c55..6672b0f8f13 100644
--- a/engines/director/window.cpp
+++ b/engines/director/window.cpp
@@ -131,13 +131,13 @@ bool Window::render(bool forceRedraw, Graphics::ManagedSurface *blitTo) {
 		blitTo = _composeSurface;
 	Channel *hiliteChannel = _currentMovie->getScore()->getChannelById(_currentMovie->_currentHiliteChannelId);
 
-	for (Common::List<Common::Rect>::iterator i = _dirtyRects.begin(); i != _dirtyRects.end(); i++) {
-		const Common::Rect &r = *i;
+	for (auto &i : _dirtyRects) {
+		const Common::Rect &r = i;
 		_dirtyChannels = _currentMovie->getScore()->getSpriteIntersections(r);
 
 		bool shouldClear = true;
-		for (Common::List<Channel *>::iterator j = _dirtyChannels.begin(); j != _dirtyChannels.end(); j++) {
-			if ((*j)->_visible && r == (*j)->getBbox() && (*j)->isTrail()) {
+		for (auto &j : _dirtyChannels) {
+			if (j->_visible && r == j->getBbox() && j->isTrail()) {
 				shouldClear = false;
 				break;
 			}
@@ -147,8 +147,8 @@ bool Window::render(bool forceRedraw, Graphics::ManagedSurface *blitTo) {
 			blitTo->fillRect(r, _stageColor);
 
 		for (int pass = 0; pass < 2; pass++) {
-			for (Common::List<Channel *>::iterator j = _dirtyChannels.begin(); j != _dirtyChannels.end(); j++) {
-				if ((*j)->isActiveVideo() && (*j)->isVideoDirectToStage()) {
+			for (auto &j : _dirtyChannels) {
+				if (j->isActiveVideo() && j->isVideoDirectToStage()) {
 					if (pass == 0)
 						continue;
 				} else {
@@ -156,15 +156,15 @@ bool Window::render(bool forceRedraw, Graphics::ManagedSurface *blitTo) {
 						continue;
 				}
 
-				if ((*j)->_visible) {
-					if ((*j)->hasSubChannels()) {
-						Common::Array<Channel> *list = (*j)->getSubChannels();
-						for (Common::Array<Channel>::iterator k = list->begin(); k != list->end(); k++) {
-							inkBlitFrom(&(*k), r, blitTo);
+				if (j->_visible) {
+					if (j->hasSubChannels()) {
+						Common::Array<Channel> *list = j->getSubChannels();
+						for (auto &k : *list) {
+							inkBlitFrom(&k, r, blitTo);
 						}
 					} else {
-						inkBlitFrom(*j, r, blitTo);
-						if ((*j) == hiliteChannel)
+						inkBlitFrom(j, r, blitTo);
+						if (j == hiliteChannel)
 							invertChannel(hiliteChannel, r);
 					}
 				}


Commit: 4743694cf1ae2fbeac20f3427ffc7ec42cdd8575
    https://github.com/scummvm/scummvm/commit/4743694cf1ae2fbeac20f3427ffc7ec42cdd8575
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-06-29T23:22:54+02:00

Commit Message:
GOB: Replace non-unicode characters in extra fields in detection with Unicode

Changed paths:
    engines/gob/detection/tables_playtoons.h


diff --git a/engines/gob/detection/tables_playtoons.h b/engines/gob/detection/tables_playtoons.h
index fc15e778641..78971a7960c 100644
--- a/engines/gob/detection/tables_playtoons.h
+++ b/engines/gob/detection/tables_playtoons.h
@@ -44,7 +44,7 @@
 {
 	{
 		"playtoons1",
-		"Pack mes histoires anim\xE9""es",
+		"Pack mes histoires animées",
 		AD_ENTRY2s("playtoon.stk",	"55f0293202963854192e39474e214f5f", 30448474,
 				   "archi.stk",		"8d44b2a0d4e3139471213f9f0ed21e81", 5524674),
 		FR_FRA,
@@ -296,7 +296,7 @@
 {
 	{
 		"playtoons3",
-		"Pack mes histoires anim\xE9""es",
+		"Pack mes histoires animées",
 		AD_ENTRY2s("playtoon.stk",	"55f0293202963854192e39474e214f5f", 30448474,
 				   "chato.stk",		"4fa4ed96a427c344e9f916f9f236598d", 6033793),
 		FR_FRA,


Commit: 95d8cf840c58907c3200d84b943e50e26c0e544c
    https://github.com/scummvm/scummvm/commit/95d8cf840c58907c3200d84b943e50e26c0e544c
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-06-29T23:22:54+02:00

Commit Message:
DIRECTOR: _allOpenResFiles -> _allSeenResFiles

Changed paths:
    engines/director/cursor.cpp
    engines/director/director.cpp
    engines/director/director.h
    engines/director/lingo/lingo-builtins.cpp
    engines/director/resource.cpp
    engines/director/sound.cpp
    engines/director/tests.cpp
    engines/director/window.cpp


diff --git a/engines/director/cursor.cpp b/engines/director/cursor.cpp
index 7ca2b1ce50d..6e90523d08c 100644
--- a/engines/director/cursor.cpp
+++ b/engines/director/cursor.cpp
@@ -184,7 +184,7 @@ void Cursor::readFromResource(Datum resourceId) {
 				break;
 		}
 
-		for (auto &it : g_director->_allOpenResFiles) {
+		for (auto &it : g_director->_allSeenResFiles) {
 			readSuccessful = readFromArchive(it._value, resourceId.asInt());
 			if (readSuccessful)
 				break;
diff --git a/engines/director/director.cpp b/engines/director/director.cpp
index 954479a51d0..41426496a35 100644
--- a/engines/director/director.cpp
+++ b/engines/director/director.cpp
@@ -150,7 +150,7 @@ DirectorEngine::~DirectorEngine() {
 	delete _wm;
 	delete _surface;
 
-	for (auto &it : _allOpenResFiles) {
+	for (auto &it : _allSeenResFiles) {
 		delete it._value;
 	}
 
diff --git a/engines/director/director.h b/engines/director/director.h
index e6e970218a3..c45d8014ca9 100644
--- a/engines/director/director.h
+++ b/engines/director/director.h
@@ -253,7 +253,7 @@ public:
 	Common::List<Common::String> _extraSearchPath;
 
 	// Owner of all Archive objects.
-	Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _allOpenResFiles;
+	Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _allSeenResFiles;
 	// Handles to resource files that were opened by OpenResFile.
 	Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _openResFiles;
 
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index e021885f42c..d8f4a5cf989 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1246,11 +1246,11 @@ void LB::b_openResFile(int nargs) {
  		return;
  	}
 
-	if (!g_director->_allOpenResFiles.contains(resPath)) {
+	if (!g_director->_allSeenResFiles.contains(resPath)) {
 		MacArchive *arch = new MacArchive();
 		if (arch->openFile(pathMakeRelative(resPath))) {
 			g_director->_openResFiles.setVal(resPath, arch);
-			g_director->_allOpenResFiles.setVal(resPath, arch);
+			g_director->_allSeenResFiles.setVal(resPath, arch);
 		} else {
 			delete arch;
 		}
@@ -1315,7 +1315,7 @@ void LB::b_showResFile(int nargs) {
 	if (nargs)
 		g_lingo->pop();
 	Common::String out;
-	for (auto &it : g_director->_allOpenResFiles)
+	for (auto &it : g_director->_allSeenResFiles)
 		out += it._key + "\n";
 	g_debugger->debugLogFile(out, false);
 }
diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp
index 00d8da96050..f009835ca96 100644
--- a/engines/director/resource.cpp
+++ b/engines/director/resource.cpp
@@ -209,8 +209,8 @@ Archive *DirectorEngine::openArchive(const Common::String path) {
 	// If the archive is already open, don't reopen it;
 	// just init from the existing archive. This prevents errors that
 	// can happen when trying to load the same archive more than once.
-	if (_allOpenResFiles.contains(path)) {
-		return _allOpenResFiles.getVal(path);
+	if (_allSeenResFiles.contains(path)) {
+		return _allSeenResFiles.getVal(path);
 	}
 
 	Archive *result = nullptr;
@@ -227,7 +227,7 @@ Archive *DirectorEngine::openArchive(const Common::String path) {
 		}
 	}
 	result->setPathName(path);
-	_allOpenResFiles.setVal(path, result);
+	_allSeenResFiles.setVal(path, result);
 
 	return result;
 }
diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index d50d4d8a8b9..329e85b090b 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -367,7 +367,7 @@ void DirectorSound::loadSampleSounds(uint type) {
 	uint id = 0xFF;
 	Archive *archive = nullptr;
 
-	for (auto &it : g_director->_allOpenResFiles) {
+	for (auto &it : g_director->_allSeenResFiles) {
 		Common::Array<uint16> idList = it._value->getResourceIDList(tag);
 		for (uint j = 0; j < idList.size(); j++) {
 			if ((idList[j] & 0xFF) == type) {
@@ -573,7 +573,7 @@ void DirectorSound::playFPlaySound() {
 	Archive *archive = nullptr;
 
 	// iterate opened ResFiles
-	for (auto &it : g_director->_allOpenResFiles) {
+	for (auto &it : g_director->_allSeenResFiles) {
 		id = it._value->findResourceID(tag, sndName, true);
 		if (id != 0xFFFF) {
 			archive = it._value;
diff --git a/engines/director/tests.cpp b/engines/director/tests.cpp
index faecddd4903..99ac552364a 100644
--- a/engines/director/tests.cpp
+++ b/engines/director/tests.cpp
@@ -304,7 +304,7 @@ void Window::runTests() {
 	initGraphics(640, 480);
 
 	_mainArchive = new RIFXArchive();
-	g_director->_allOpenResFiles.setVal("test.dir", _mainArchive);
+	g_director->_allSeenResFiles.setVal("test.dir", _mainArchive);
 	if (!_mainArchive->openStream(stream, 0)) {
 		error("DirectorEngine::runTests(): Bad movie data");
 	}
diff --git a/engines/director/window.cpp b/engines/director/window.cpp
index 6672b0f8f13..0aef5896375 100644
--- a/engines/director/window.cpp
+++ b/engines/director/window.cpp
@@ -357,7 +357,7 @@ void Window::loadNewSharedCast(Cast *previousSharedCast) {
 
 	// Clean up the previous sharedCast
 	if (previousSharedCast) {
-		g_director->_allOpenResFiles.erase(previousSharedCastPath);
+		g_director->_allSeenResFiles.erase(previousSharedCastPath);
 		delete previousSharedCast;
 	}
 


Commit: 9aa095873683b990ac85b4c06b5fa843dcbd682a
    https://github.com/scummvm/scummvm/commit/9aa095873683b990ac85b4c06b5fa843dcbd682a
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2023-06-30T00:32:57+02:00

Commit Message:
DIRECTOR: Properly keep track of open resource files and their precedence

We used to close resources when we were closing movies, but with making
Archives owned by Director class, we now have list of all _seen_ resources.

This change implements a proper, ordered list of resources which are
overriding the ones loaded earlier.

Fixes cursors in the7colors which were read from previously loaded Shared Casts.
--start-movie=04CLUB:FloorColidor:IntoFloo

Changed paths:
    engines/director/cursor.cpp
    engines/director/director.h
    engines/director/lingo/lingo-builtins.cpp
    engines/director/movie.cpp
    engines/director/resource.cpp
    engines/director/sound.cpp


diff --git a/engines/director/cursor.cpp b/engines/director/cursor.cpp
index 6e90523d08c..99c4113e5b0 100644
--- a/engines/director/cursor.cpp
+++ b/engines/director/cursor.cpp
@@ -184,8 +184,8 @@ void Cursor::readFromResource(Datum resourceId) {
 				break;
 		}
 
-		for (auto &it : g_director->_allSeenResFiles) {
-			readSuccessful = readFromArchive(it._value, resourceId.asInt());
+		for (auto &it : g_director->_allOpenResFiles) {
+			readSuccessful = readFromArchive(g_director->_allSeenResFiles[it], resourceId.asInt());
 			if (readSuccessful)
 				break;
 		}
diff --git a/engines/director/director.h b/engines/director/director.h
index c45d8014ca9..0d707fd8468 100644
--- a/engines/director/director.h
+++ b/engines/director/director.h
@@ -212,6 +212,7 @@ public:
 
 	Archive *createArchive();
 	Archive *openArchive(const Common::String movie);
+	void addArchiveToOpenList(const Common::String path);
 	Archive *loadEXE(const Common::String movie);
 	Archive *loadEXEv3(Common::SeekableReadStream *stream);
 	Archive *loadEXEv4(Common::SeekableReadStream *stream);
@@ -256,6 +257,8 @@ public:
 	Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _allSeenResFiles;
 	// Handles to resource files that were opened by OpenResFile.
 	Common::HashMap<Common::String, Archive *, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> _openResFiles;
+	// List of all currently open resource files
+	Common::List<Common::String> _allOpenResFiles;
 
 	Common::Array<Graphics::WinCursorGroup *> _winCursor;
 
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index d8f4a5cf989..3c9234348db 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1147,6 +1147,9 @@ void LB::b_closeResFile(int nargs) {
 	// closeResFile closes only resource files that were opened with openResFile.
 
 	if (nargs == 0) { // Close all open resource files
+		for (auto &it : g_director->_openResFiles)
+			g_director->_allOpenResFiles.remove(it._key);
+
 		g_director->_openResFiles.clear();
 		return;
 	}
@@ -1156,6 +1159,8 @@ void LB::b_closeResFile(int nargs) {
 
 	if (g_director->_openResFiles.contains(resFileName)) {
 		g_director->_openResFiles.erase(resFileName);
+
+		g_director->_allOpenResFiles.remove(resFileName);
 	}
 }
 
@@ -1251,6 +1256,7 @@ void LB::b_openResFile(int nargs) {
 		if (arch->openFile(pathMakeRelative(resPath))) {
 			g_director->_openResFiles.setVal(resPath, arch);
 			g_director->_allSeenResFiles.setVal(resPath, arch);
+			g_director->addArchiveToOpenList(resPath);
 		} else {
 			delete arch;
 		}
@@ -1315,8 +1321,8 @@ void LB::b_showResFile(int nargs) {
 	if (nargs)
 		g_lingo->pop();
 	Common::String out;
-	for (auto &it : g_director->_allSeenResFiles)
-		out += it._key + "\n";
+	for (auto &it : g_director->_allOpenResFiles)
+		out += it + "\n";
 	g_debugger->debugLogFile(out, false);
 }
 
diff --git a/engines/director/movie.cpp b/engines/director/movie.cpp
index 07f5fa7b254..ac7193f634c 100644
--- a/engines/director/movie.cpp
+++ b/engines/director/movie.cpp
@@ -95,6 +95,10 @@ Movie::Movie(Window *window) {
 }
 
 Movie::~Movie() {
+	if (_sharedCast)
+		g_director->_allOpenResFiles.remove(_sharedCast->getArchive()->getPathName());
+	g_director->_allOpenResFiles.remove(_cast->getArchive()->getPathName());
+
 	delete _cast;
 	delete _sharedCast;
 	delete _score;
@@ -343,6 +347,8 @@ void Movie::clearSharedCast() {
 	if (!_sharedCast)
 		return;
 
+	g_director->_allOpenResFiles.remove(_sharedCast->getArchive()->getPathName());
+
 	delete _sharedCast;
 	_sharedCast = nullptr;
 }
diff --git a/engines/director/resource.cpp b/engines/director/resource.cpp
index f009835ca96..a036b657d38 100644
--- a/engines/director/resource.cpp
+++ b/engines/director/resource.cpp
@@ -203,6 +203,14 @@ void Window::probeResources(Archive *archive) {
 	}
 }
 
+void DirectorEngine::addArchiveToOpenList(const Common::String path) {
+	// First, remove it if it is present
+	_allOpenResFiles.remove(path);
+
+	// And add it to the list front
+	_allOpenResFiles.push_front(path);
+}
+
 Archive *DirectorEngine::openArchive(const Common::String path) {
 	debug(1, "DirectorEngine::openArchive(\"%s\")", path.c_str());
 
@@ -210,6 +218,7 @@ Archive *DirectorEngine::openArchive(const Common::String path) {
 	// just init from the existing archive. This prevents errors that
 	// can happen when trying to load the same archive more than once.
 	if (_allSeenResFiles.contains(path)) {
+		addArchiveToOpenList(path);
 		return _allSeenResFiles.getVal(path);
 	}
 
@@ -229,6 +238,8 @@ Archive *DirectorEngine::openArchive(const Common::String path) {
 	result->setPathName(path);
 	_allSeenResFiles.setVal(path, result);
 
+	addArchiveToOpenList(path);
+
 	return result;
 }
 
diff --git a/engines/director/sound.cpp b/engines/director/sound.cpp
index 329e85b090b..5dda6ded140 100644
--- a/engines/director/sound.cpp
+++ b/engines/director/sound.cpp
@@ -367,12 +367,12 @@ void DirectorSound::loadSampleSounds(uint type) {
 	uint id = 0xFF;
 	Archive *archive = nullptr;
 
-	for (auto &it : g_director->_allSeenResFiles) {
-		Common::Array<uint16> idList = it._value->getResourceIDList(tag);
+	for (auto &it : g_director->_allOpenResFiles) {
+		Common::Array<uint16> idList = g_director->_allSeenResFiles[it]->getResourceIDList(tag);
 		for (uint j = 0; j < idList.size(); j++) {
 			if ((idList[j] & 0xFF) == type) {
 				id = idList[j];
-				archive = it._value;
+				archive = g_director->_allSeenResFiles[it];
 				break;
 			}
 		}
@@ -573,10 +573,10 @@ void DirectorSound::playFPlaySound() {
 	Archive *archive = nullptr;
 
 	// iterate opened ResFiles
-	for (auto &it : g_director->_allSeenResFiles) {
-		id = it._value->findResourceID(tag, sndName, true);
+	for (auto &it : g_director->_allOpenResFiles) {
+		id = g_director->_allSeenResFiles[it]->findResourceID(tag, sndName, true);
 		if (id != 0xFFFF) {
-			archive = it._value;
+			archive = g_director->_allSeenResFiles[it];
 			break;
 		}
 	}




More information about the Scummvm-git-logs mailing list