[Scummvm-git-logs] scummvm master -> 2554549b417129d51b7385ef80900c5cd9579309

sluicebox noreply at scummvm.org
Thu Oct 17 20:49:08 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:
2554549b41 SCI: Reduce variable scope


Commit: 2554549b417129d51b7385ef80900c5cd9579309
    https://github.com/scummvm/scummvm/commit/2554549b417129d51b7385ef80900c5cd9579309
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2024-10-17T14:47:43-06:00

Commit Message:
SCI: Reduce variable scope

Changed paths:
    engines/sci/engine/script.cpp
    engines/sci/engine/selector.cpp
    engines/sci/graphics/frameout.cpp
    engines/sci/graphics/paint16.cpp
    engines/sci/graphics/palette32.cpp
    engines/sci/metaengine.cpp
    engines/sci/parser/said.cpp
    engines/sci/parser/vocabulary.cpp
    engines/sci/resource/decompressor.cpp
    engines/sci/sound/drivers/midi.cpp
    engines/sci/sound/midiparser_sci.cpp


diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index 43f0efe0b74..fb237a71617 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -503,16 +503,12 @@ void Script::identifyOffsets() {
 #ifdef ENABLE_SCI32
 	} else if (getSciVersion() == SCI_VERSION_3) {
 		// SCI3
-		uint32 sci3StringOffset = 0;
-		uint32 sci3RelocationOffset = 0;
-		uint32 sci3BoundaryOffset = 0;
-
 		if (_buf->size() < 22)
 			error("Script::identifyOffsets(): script %d smaller than expected SCI3-header", _nr);
 
 		_codeOffset = _buf->getUint32LEAt(0);
-		sci3StringOffset = _buf->getUint32LEAt(4);
-		sci3RelocationOffset = _buf->getUint32LEAt(8);
+		uint32 sci3StringOffset = _buf->getUint32LEAt(4);
+		uint32 sci3RelocationOffset = _buf->getUint32LEAt(8);
 
 		if (sci3RelocationOffset > _buf->size())
 			error("Script::identifyOffsets(): relocation offset is beyond end of script %d", _nr);
@@ -601,7 +597,7 @@ void Script::identifyOffsets() {
 				_offsetLookupStringCount++;
 
 				// SCI3 seems to have aligned all string on DWORD boundaries
-				sci3BoundaryOffset = stringDataPtr - *_buf; // Calculate current offset inside script data
+				uint32 sci3BoundaryOffset = stringDataPtr - *_buf; // Calculate current offset inside script data
 				sci3BoundaryOffset = sci3BoundaryOffset & 3; // Check boundary offset
 				if (sci3BoundaryOffset) {
 					// lower 2 bits are set? Then we have to adjust the offset
diff --git a/engines/sci/engine/selector.cpp b/engines/sci/engine/selector.cpp
index f5aa666d264..d92974e5650 100644
--- a/engines/sci/engine/selector.cpp
+++ b/engines/sci/engine/selector.cpp
@@ -325,7 +325,6 @@ void invokeSelector(EngineState *s, reg_t object, int selectorId,
 
 SelectorType lookupSelector(SegManager *segMan, reg_t obj_location, Selector selectorId, ObjVarRef *varp, reg_t *fptr) {
 	const Object *obj = segMan->getObject(obj_location);
-	int index;
 	bool oldScriptHeader = (getSciVersion() == SCI_VERSION_0_EARLY);
 
 	// Early SCI versions used the LSB in the selector ID as a read/write
@@ -337,7 +336,7 @@ SelectorType lookupSelector(SegManager *segMan, reg_t obj_location, Selector sel
 		error("lookupSelector: Attempt to send to non-object or invalid script. Address %04x:%04x", PRINT_REG(obj_location));
 	}
 
-	index = obj->locateVarSelector(segMan, selectorId);
+	int index = obj->locateVarSelector(segMan, selectorId);
 
 	if (index >= 0) {
 		// Found it as a variable
@@ -362,9 +361,6 @@ SelectorType lookupSelector(SegManager *segMan, reg_t obj_location, Selector sel
 
 		return kSelectorNone;
 	}
-
-
-//	return _lookupSelector_function(segMan, obj, selectorId, fptr);
 }
 
 } // End of namespace Sci
diff --git a/engines/sci/graphics/frameout.cpp b/engines/sci/graphics/frameout.cpp
index 6c95d245250..95e71968021 100644
--- a/engines/sci/graphics/frameout.cpp
+++ b/engines/sci/graphics/frameout.cpp
@@ -1023,9 +1023,9 @@ void GfxFrameout::mergeToShowList(const Common::Rect &drawRect, RectList &showLi
 	mergeList.add(drawRect);
 
 	for (RectList::size_type i = 0; i < mergeList.size(); ++i) {
-		bool didMerge = false;
 		const Common::Rect &r1 = *mergeList[i];
 		if (!r1.isEmpty()) {
+			bool didMerge = false;
 			for (RectList::size_type j = 0; j < showList.size(); ++j) {
 				const Common::Rect &r2 = *showList[j];
 				if (!r2.isEmpty()) {
diff --git a/engines/sci/graphics/paint16.cpp b/engines/sci/graphics/paint16.cpp
index 78f71001e40..51731134c4f 100644
--- a/engines/sci/graphics/paint16.cpp
+++ b/engines/sci/graphics/paint16.cpp
@@ -205,14 +205,13 @@ void GfxPaint16::fillRect(const Common::Rect &rect, int16 drawFlags, byte color,
 	int16 oldPenMode = _ports->_curPort->penMode;
 	_ports->offsetRect(r);
 	int16 x, y;
-	byte curVisual;
 
 	// Doing visual first
 	if (drawFlags & GFX_SCREEN_MASK_VISUAL) {
 		if (oldPenMode == 2) { // invert mode
 			for (y = r.top; y < r.bottom; y++) {
 				for (x = r.left; x < r.right; x++) {
-					curVisual = _screen->getVisual(x, y);
+					byte curVisual = _screen->getVisual(x, y);
 					if (curVisual == color) {
 						_screen->putPixel(x, y, GFX_SCREEN_MASK_VISUAL, priority, 0, 0);
 					} else if (curVisual == priority) {
diff --git a/engines/sci/graphics/palette32.cpp b/engines/sci/graphics/palette32.cpp
index c7d12225918..a9fa2ebd891 100644
--- a/engines/sci/graphics/palette32.cpp
+++ b/engines/sci/graphics/palette32.cpp
@@ -410,10 +410,9 @@ bool GfxPalette32::loadPalette(const GuiResourceId resourceId) {
 int16 GfxPalette32::matchColor(const uint8 r, const uint8 g, const uint8 b) {
 	int16 bestIndex = 0;
 	int bestDifference = 0xFFFFF;
-	int difference;
 
 	for (int i = 0, channelDifference; i < g_sci->_gfxRemap32->getStartColor(); ++i) {
-		difference = _currentPalette.colors[i].r - r;
+		int difference = _currentPalette.colors[i].r - r;
 		difference *= difference;
 		if (bestDifference <= difference) {
 			continue;
diff --git a/engines/sci/metaengine.cpp b/engines/sci/metaengine.cpp
index 5183f086e61..82c04232f9a 100644
--- a/engines/sci/metaengine.cpp
+++ b/engines/sci/metaengine.cpp
@@ -613,8 +613,8 @@ ADDetectedGame SciMetaEngine::fallbackDetectExtern(uint md5Bytes, const FileMap
 	// resources, and it's not possible to detect that easily
 	// Also look for "%J" which is used in japanese games
 	Resource *text = resMan.findResource(ResourceId(kResourceTypeText, 0), false);
-	uint seeker = 0;
 	if (text) {
+		uint seeker = 0;
 		while (seeker < text->size()) {
 			if (text->getUint8At(seeker) == '#')  {
 				if (seeker + 1 < text->size())
diff --git a/engines/sci/parser/said.cpp b/engines/sci/parser/said.cpp
index 39b5c819184..04f899641d7 100644
--- a/engines/sci/parser/said.cpp
+++ b/engines/sci/parser/said.cpp
@@ -1004,7 +1004,6 @@ static int augment_parse_nodes(ParseTreeNode *parseT, ParseTreeNode *saidT) {
 /*******************/
 
 int said(const byte *spec, bool verbose) {
-	int retval;
 	Vocabulary *voc = g_sci->getVocabulary();
 
 	ParseTreeNode *parse_tree_ptr = voc->_parserNodes;
@@ -1015,14 +1014,14 @@ int said(const byte *spec, bool verbose) {
 
 		if (verbose)
 			vocab_dump_parse_tree("Said-tree", said_tree);
-		retval = augment_parse_nodes(parse_tree_ptr, said_tree);
+		int retval = augment_parse_nodes(parse_tree_ptr, said_tree);
 
 		if (!retval)
 			return SAID_NO_MATCH;
-		else if (retval != SAID_PARTIAL_MATCH)
-			return SAID_FULL_MATCH;
-		else
+		else if (retval == SAID_PARTIAL_MATCH)
 			return SAID_PARTIAL_MATCH;
+		else
+			return SAID_FULL_MATCH;
 	}
 
 	return SAID_NO_MATCH;
diff --git a/engines/sci/parser/vocabulary.cpp b/engines/sci/parser/vocabulary.cpp
index c5cdd8998a4..f4d66f82203 100644
--- a/engines/sci/parser/vocabulary.cpp
+++ b/engines/sci/parser/vocabulary.cpp
@@ -90,7 +90,6 @@ void Vocabulary::reset() {
 
 bool Vocabulary::loadParserWords() {
 	char currentWord[VOCAB_MAX_WORDLENGTH] = "";
-	int currentWordPos = 0;
 
 	// First try to load the SCI0 vocab resource.
 	Resource *resource = _resMan->findResource(ResourceId(kResourceTypeVocab, _resourceIdWords), 0);
@@ -138,7 +137,7 @@ bool Vocabulary::loadParserWords() {
 	while (seeker < resource->size()) {
 		byte c;
 
-		currentWordPos = resource->getUint8At(seeker++); // Parts of previous words may be re-used
+		int currentWordPos = resource->getUint8At(seeker++); // Parts of previous words may be re-used
 
 		if (resourceType == kVocabularySCI1) {
 			c = 1;
@@ -205,13 +204,12 @@ void Vocabulary::loadTranslatedWords() {
 		return;
 	
 	char currentWord[VOCAB_MAX_WORDLENGTH] = "";
-	int currentWordPos = 0;
 
 	uint32 seeker = 0;
 	while (seeker < resource->size()) {
 		byte c;
 
-		currentWordPos = resource->getUint8At(seeker++); // Parts of previous words may be re-used
+		int currentWordPos = resource->getUint8At(seeker++); // Parts of previous words may be re-used
 
 		do {
 			if (seeker >= resource->size()) {
@@ -808,7 +806,6 @@ void _vocab_recursive_ptree_dump(ParseTreeNode *tree, int blanks) {
 
 	ParseTreeNode* lbranch = tree->left;
 	ParseTreeNode* rbranch = tree->right;
-	int i;
 
 	if (tree->type == kParseTreeLeafNode) {
 		debugN("vocab_dump_parse_tree: Error: consp is nil\n");
@@ -818,12 +815,12 @@ void _vocab_recursive_ptree_dump(ParseTreeNode *tree, int blanks) {
 	if (lbranch) {
 		if (lbranch->type == kParseTreeBranchNode) {
 			debugN("\n");
-			for (i = 0; i < blanks; i++)
+			for (int i = 0; i < blanks; i++)
 				debugN("    ");
 			debugN("(");
 			_vocab_recursive_ptree_dump(lbranch, blanks + 1);
 			debugN(")\n");
-			for (i = 0; i < blanks; i++)
+			for (int i = 0; i < blanks; i++)
 				debugN("    ");
 		} else
 			debugN("%x", lbranch->value);
@@ -886,7 +883,7 @@ void Vocabulary::printParserNodes(int num) {
 }
 
 int Vocabulary::parseNodes(int *i, int *pos, int type, int nr, int argc, const char **argv) {
-	int nextToken = 0, nextValue = 0, newPos = 0, oldPos = 0;
+	int nextToken = 0, nextValue = 0, oldPos = 0;
 	Console *con = g_sci->getSciDebugger();
 
 	if (type == kParseNil)
@@ -927,7 +924,7 @@ int Vocabulary::parseNodes(int *i, int *pos, int type, int nr, int argc, const c
 			}
 		}
 
-		newPos = parseNodes(i, pos, nextToken, nextValue, argc, argv);
+		int newPos = parseNodes(i, pos, nextToken, nextValue, argc, argv);
 
 		if (newPos == -1)
 			return -1;
diff --git a/engines/sci/resource/decompressor.cpp b/engines/sci/resource/decompressor.cpp
index d7691483a35..e94c210e965 100644
--- a/engines/sci/resource/decompressor.cpp
+++ b/engines/sci/resource/decompressor.cpp
@@ -33,9 +33,8 @@
 
 namespace Sci {
 int Decompressor::unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) {
-	uint32 chunk;
 	while (nPacked && !(src->eos() || src->err())) {
-		chunk = MIN<uint32>(1024, nPacked);
+		uint32 chunk = MIN<uint32>(1024, nPacked);
 		src->read(dest, chunk);
 		nPacked -= chunk;
 		dest += chunk;
@@ -391,11 +390,10 @@ void DecompressorLZW::decodeRLE(byte **rledata, byte **pixeldata, byte *outbuffe
  */
 int DecompressorLZW::getRLEsize(byte *rledata, int dsize) {
 	int pos = 0;
-	byte nextbyte;
 	int size = 0;
 
 	while (pos < dsize) {
-		nextbyte = *(rledata++);
+		byte nextbyte = *(rledata++);
 		pos++;
 		size++;
 
diff --git a/engines/sci/sound/drivers/midi.cpp b/engines/sci/sound/drivers/midi.cpp
index 809ac8ba11b..6daff971663 100644
--- a/engines/sci/sound/drivers/midi.cpp
+++ b/engines/sci/sound/drivers/midi.cpp
@@ -378,8 +378,6 @@ void MidiPlayer_Midi::controlChange(int channel, int control, int value) {
 }
 
 void MidiPlayer_Midi::setPatch(int channel, int patch) {
-	bool resetVol = false;
-
 	assert(channel <= 15);
 
 	// No need to do anything if a patch change is sent on the rhythm channel of an MT-32
@@ -392,8 +390,7 @@ void MidiPlayer_Midi::setPatch(int channel, int patch) {
 		_channels[channel].patch = patch;
 		_channels[channel].velocityMapIdx = _velocityMapIdx[patch];
 
-		if (_channels[channel].mappedPatch == MIDI_UNMAPPED)
-			resetVol = true;
+		bool resetVol = (_channels[channel].mappedPatch == MIDI_UNMAPPED);
 
 		_channels[channel].mappedPatch = patchToSend = _patchMap[patch];
 
diff --git a/engines/sci/sound/midiparser_sci.cpp b/engines/sci/sound/midiparser_sci.cpp
index 3be503eb83c..468e3e5e88b 100644
--- a/engines/sci/sound/midiparser_sci.cpp
+++ b/engines/sci/sound/midiparser_sci.cpp
@@ -167,7 +167,7 @@ void MidiParser_SCI::midiMixChannels() {
 	SciSpan<byte> outData = _mixedData->allocate(totalSize * 2, Common::String::format("mixed sound.%d", _pSnd ? _pSnd->resourceId : -1)); // FIXME: creates overhead and still may be not enough to hold all data
 
 	long ticker = 0;
-	byte channelNr, curDelta;
+	byte channelNr;
 	byte midiCommand = 0, midiParam, globalPrev = 0;
 	long newDelta;
 	SoundResource::Channel *channel;
@@ -177,7 +177,7 @@ void MidiParser_SCI::midiMixChannels() {
 		channel = &_track->channels[channelNr];
 		if (!validateNextRead(channel))
 			break;
-		curDelta = channel->data[channel->curPos++];
+		byte curDelta = channel->data[channel->curPos++];
 		channel->time += (curDelta == 0xF8 ? 240 : curDelta); // when the command is supposed to occur
 		if (curDelta == 0xF8)
 			continue;




More information about the Scummvm-git-logs mailing list