[Scummvm-git-logs] scummvm master -> 7da3c93c14369f035ff8ad7b7a7166e756009d57

sluicebox noreply at scummvm.org
Fri Nov 3 22:13:51 UTC 2023


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:
c241f21baa SCI: Reduce scope of variables
cd319125ef SCI: More const ref parameters
1f4124b121 SCI: Remove or disable unused functions
7da3c93c14 SCI: Remove unused variable from kDoBresen


Commit: c241f21baa8da902492671d629ee3ece57b90673
    https://github.com/scummvm/scummvm/commit/c241f21baa8da902492671d629ee3ece57b90673
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2023-11-03T15:12:40-07:00

Commit Message:
SCI: Reduce scope of variables

Changed paths:
    engines/sci/console.cpp
    engines/sci/engine/kgraphics.cpp
    engines/sci/engine/kmenu.cpp
    engines/sci/engine/kparse.cpp
    engines/sci/engine/kvideo.cpp
    engines/sci/engine/script.cpp
    engines/sci/engine/script_patches.cpp
    engines/sci/engine/scriptdebug.cpp
    engines/sci/engine/seg_manager.cpp
    engines/sci/engine/state.cpp
    engines/sci/engine/static_selectors.cpp
    engines/sci/engine/workarounds.cpp
    engines/sci/graphics/animate.cpp
    engines/sci/graphics/controls16.cpp
    engines/sci/graphics/cursor.cpp
    engines/sci/graphics/menu.cpp
    engines/sci/graphics/palette.cpp
    engines/sci/graphics/picture.cpp
    engines/sci/graphics/portrait.cpp
    engines/sci/graphics/ports.cpp
    engines/sci/graphics/screen.cpp
    engines/sci/graphics/text16.cpp
    engines/sci/graphics/transitions.cpp
    engines/sci/graphics/view.cpp
    engines/sci/metaengine.cpp
    engines/sci/resource/resource.cpp
    engines/sci/sound/drivers/macmixer.h
    engines/sci/sound/drivers/pcjr.cpp
    engines/sci/sound/music.cpp


diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index c20731620b0..3e41907fa8a 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -1287,15 +1287,14 @@ bool Console::cmdVerifyScripts(int argc, const char **argv) {
 
 	debugPrintf("%d SCI1.1-SCI3 scripts found, performing sanity checks...\n", resources.size());
 
-	Resource *script, *heap;
 	Common::List<ResourceId>::iterator itr;
 	for (itr = resources.begin(); itr != resources.end(); ++itr) {
-		script = _engine->getResMan()->findResource(*itr, false);
+		Resource *script = _engine->getResMan()->findResource(*itr, false);
 		if (!script)
 			debugPrintf("Error: script %d couldn't be loaded\n", itr->getNumber());
 
 		if (getSciVersion() <= SCI_VERSION_2_1_LATE) {
-			heap = _engine->getResMan()->findResource(ResourceId(kResourceTypeHeap, itr->getNumber()), false);
+			Resource *heap = _engine->getResMan()->findResource(ResourceId(kResourceTypeHeap, itr->getNumber()), false);
 			if (!heap)
 				debugPrintf("Error: script %d doesn't have a corresponding heap\n", itr->getNumber());
 
@@ -3671,14 +3670,12 @@ bool Console::cmdStepGlobal(int argc, const char **argv) {
 }
 
 bool Console::cmdStepCallk(int argc, const char **argv) {
-	int callk_index;
-	char *endptr;
-
 	if (argc == 2) {
 		/* Try to convert the parameter to a number. If the conversion stops
 		   before end of string, assume that the parameter is a function name
 		   and scan the function table to find out the index. */
-		callk_index = strtoul(argv[1], &endptr, 0);
+		char *endptr;
+		int callk_index = strtoul(argv[1], &endptr, 0);
 		if (*endptr != '\0') {
 			callk_index = -1;
 			for (uint i = 0; i < _engine->getKernel()->getKernelNamesSize(); i++)
@@ -3864,12 +3861,11 @@ void Console::printKernelCallsFound(int kernelFuncNum, bool showFoundScripts) {
 				uint32 offset = fptr.getOffset();
 				int16 opparams[4];
 				byte extOpcode;
-				byte opcode;
 				uint16 maxJmpOffset = 0;
 
 				for (;;) {
 					offset += readPMachineInstruction(script->getBuf(offset), extOpcode, opparams);
-					opcode = extOpcode >> 1;
+					byte opcode = extOpcode >> 1;
 
 					if (opcode == op_callk) {
 						uint16 kFuncNum = opparams[0];
@@ -5041,12 +5037,11 @@ static int parse_reg_t(EngineState *s, const char *str, reg_t *dest) {
 				if (*endptr)
 					return 1;
 			} else {
-				int val = 0;
 				dest->setSegment(0);
 
 				if (charsCountNumber == charsCount) {
 					// Only numbers in input, assume decimal value
-					val = strtol(str, &endptr, 10);
+					int val = strtol(str, &endptr, 10);
 					if (*endptr)
 						return 1; // strtol failed?
 					dest->setOffset(val);
@@ -5054,7 +5049,7 @@ static int parse_reg_t(EngineState *s, const char *str, reg_t *dest) {
 				} else {
 					// We also got letters, check if there were only hexadecimal letters and '0x' at the start or 'h' at the end
 					if ((charsForceHex) && (!charsCountObject)) {
-						val = strtol(str, &endptr, 16);
+						int val = strtol(str, &endptr, 16);
 						if ((*endptr != 'h') && (*endptr != 0))
 							return 1;
 						dest->setOffset(val);
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 3c72f693432..0ee704e8c46 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -554,7 +554,6 @@ reg_t kOnControl(EngineState *s, int argc, reg_t *argv) {
 
 reg_t kDrawPic(EngineState *s, int argc, reg_t *argv) {
 	GuiResourceId pictureId = argv[0].toUint16();
-	uint16 flags = 0;
 	int16 animationNr = -1;
 	bool animationBlackoutFlag = false;
 	bool mirroredFlag = false;
@@ -562,7 +561,7 @@ reg_t kDrawPic(EngineState *s, int argc, reg_t *argv) {
 	int16 EGApaletteNo = 0; // default needs to be 0
 
 	if (argc >= 2) {
-		flags = argv[1].toUint16();
+		uint16 flags = argv[1].toUint16();
 		if (flags & K_DRAWPIC_FLAGS_ANIMATIONBLACKOUT)
 			animationBlackoutFlag = true;
 		animationNr = flags & 0xFF;
@@ -676,12 +675,11 @@ reg_t kPaletteFindColor(EngineState *s, int argc, reg_t *argv) {
 }
 
 reg_t kPaletteAnimate(EngineState *s, int argc, reg_t *argv) {
-	int16 argNr;
 	bool paletteChanged = false;
 
 	// Palette animation in non-VGA SCI1 games has been removed
 	if (g_sci->_gfxPalette16->getTotalColorCount() == 256) {
-		for (argNr = 0; argNr < argc; argNr += 3) {
+		for (int argNr = 0; argNr < argc; argNr += 3) {
 			uint16 fromColor = argv[argNr].toUint16();
 			uint16 toColor = argv[argNr + 1].toUint16();
 			int16 speed = argv[argNr + 2].toSint16();
@@ -883,7 +881,7 @@ void _k_GenericDrawControl(EngineState *s, reg_t controlObject, bool hilite) {
 	Common::String text;
 	Common::Rect rect;
 	TextAlignment alignment;
-	int16 mode, maxChars, cursorPos, upperPos, listCount, i;
+	int16 mode, maxChars, cursorPos, upperPos, listCount;
 	uint16 upperOffset, cursorOffset;
 	GuiResourceId viewId;
 	int16 loopNo;
@@ -990,7 +988,7 @@ void _k_GenericDrawControl(EngineState *s, reg_t controlObject, bool hilite) {
 			// We create a pointer-list to the different strings, we also find out whats upper and cursor position
 			listSeeker = textReference;
 			listStrings = new Common::String[listCount];
-			for (i = 0; i < listCount; i++) {
+			for (int16 i = 0; i < listCount; i++) {
 				listStrings[i] = s->_segMan->getString(listSeeker);
 				if (listSeeker.getOffset() == upperOffset)
 					upperPos = i;
diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp
index ef44c50e611..1980b1a8070 100644
--- a/engines/sci/engine/kmenu.cpp
+++ b/engines/sci/engine/kmenu.cpp
@@ -41,14 +41,12 @@ reg_t kAddMenu(EngineState *s, int argc, reg_t *argv) {
 reg_t kSetMenu(EngineState *s, int argc, reg_t *argv) {
 	uint16 menuId = argv[0].toUint16() >> 8;
 	uint16 itemId = argv[0].toUint16() & 0xFF;
-	uint16 attributeId;
 	int argPos = 1;
-	reg_t value;
 
 	while (argPos < argc) {
-		attributeId = argv[argPos].toUint16();
+		uint16 attributeId = argv[argPos].toUint16();
 		// Happens in the fanmade game Cascade Quest when loading - bug #5118
-		value = (argPos + 1 < argc) ? argv[argPos + 1] : NULL_REG;
+		reg_t value = (argPos + 1 < argc) ? argv[argPos + 1] : NULL_REG;
 		g_sci->_gfxMenu->kernelSetAttribute(menuId, itemId, attributeId, value);
 		argPos += 2;
 	}
diff --git a/engines/sci/engine/kparse.cpp b/engines/sci/engine/kparse.cpp
index f446576da59..80f8ae4d741 100644
--- a/engines/sci/engine/kparse.cpp
+++ b/engines/sci/engine/kparse.cpp
@@ -161,9 +161,6 @@ reg_t kParse(EngineState *s, int argc, reg_t *argv) {
 reg_t kSetSynonyms(EngineState *s, int argc, reg_t *argv) {
 	SegManager *segMan = s->_segMan;
 	reg_t object = argv[0];
-	List *list;
-	Node *node;
-	int script;
 	int numSynonyms = 0;
 	Vocabulary *voc = g_sci->getVocabulary();
 
@@ -173,15 +170,14 @@ reg_t kSetSynonyms(EngineState *s, int argc, reg_t *argv) {
 
 	voc->clearSynonyms();
 
-	list = s->_segMan->lookupList(readSelector(segMan, object, SELECTOR(elements)));
-	node = s->_segMan->lookupNode(list->first);
+	List *list = s->_segMan->lookupList(readSelector(segMan, object, SELECTOR(elements)));
+	Node *node = s->_segMan->lookupNode(list->first);
 
 	while (node) {
 		reg_t objpos = node->value;
-		int seg;
 
-		script = readSelectorValue(segMan, objpos, SELECTOR(number));
-		seg = s->_segMan->getScriptSegment(script);
+		int script = readSelectorValue(segMan, objpos, SELECTOR(number));
+		int seg = s->_segMan->getScriptSegment(script);
 
 		if (seg > 0)
 			numSynonyms = s->_segMan->getScript(seg)->getSynonymsNr();
diff --git a/engines/sci/engine/kvideo.cpp b/engines/sci/engine/kvideo.cpp
index 403d62ae882..1a67406c4f7 100644
--- a/engines/sci/engine/kvideo.cpp
+++ b/engines/sci/engine/kvideo.cpp
@@ -59,13 +59,12 @@ void playVideo(Video::VideoDecoder &videoDecoder) {
 	uint16 pitch = videoDecoder.getWidth() * bytesPerPixel;
 	uint16 screenWidth = g_sci->_gfxScreen->getDisplayWidth();
 	uint16 screenHeight = g_sci->_gfxScreen->getDisplayHeight();
-	uint32 numPixels;
 
 	if (screenWidth == 640 && width <= 320 && height <= 240) {
 		width *= 2;
 		height *= 2;
 		pitch *= 2;
-		numPixels = width * height * bytesPerPixel;
+		uint32 numPixels = width * height * bytesPerPixel;
 		scaleBuffer->allocate(numPixels, "video scale buffer");
 	}
 
diff --git a/engines/sci/engine/script.cpp b/engines/sci/engine/script.cpp
index 3a0683eeb03..9e59577a9f9 100644
--- a/engines/sci/engine/script.cpp
+++ b/engines/sci/engine/script.cpp
@@ -1039,15 +1039,13 @@ void Script::initializeClasses(SegManager *segMan) {
 	if (!seeker)
 		return;
 
-	uint16 marker;
 	bool isClass = false;
-	uint32 classpos;
 	int16 species = 0;
 
 	for (;;) {
 		// In SCI0-SCI1, this is the segment type. In SCI11, it's a marker (0x1234)
-		marker = seeker.getUint16SEAt(0);
-		classpos = seeker - *_buf;
+		uint16 marker = seeker.getUint16SEAt(0);
+		uint32 classpos = seeker - *_buf;
 
 		if (getSciVersion() <= SCI_VERSION_1_LATE && !marker)
 			break;
diff --git a/engines/sci/engine/script_patches.cpp b/engines/sci/engine/script_patches.cpp
index 624fa48fa07..358b8f0cd7d 100644
--- a/engines/sci/engine/script_patches.cpp
+++ b/engines/sci/engine/script_patches.cpp
@@ -25199,22 +25199,18 @@ int32 ScriptPatcher::findSignature(const SciScriptPatcherEntry *patchEntry, cons
 // Attention: Magic DWord is returned using platform specific byte order. This is done on purpose for performance.
 void ScriptPatcher::calculateMagicDWordAndVerify(const char *signatureDescription, const uint16 *signatureData, bool magicDWordIncluded, uint32 &calculatedMagicDWord, int &calculatedMagicDWordOffset) {
 	Selector curSelector = -1;
-	int magicOffset;
+	int magicOffset = 0;
 	byte magicDWord[4];
 	int magicDWordLeft = 0;
-	uint16 curWord;
-	uint16 curCommand;
-	uint32 curValue;
 	byte byte1 = 0;
 	byte byte2 = 0;
 
 	memset(magicDWord, 0, sizeof(magicDWord));
 
-	curWord = *signatureData;
-	magicOffset = 0;
+	uint16 curWord = *signatureData;
 	while (curWord != SIG_END) {
-		curCommand = curWord & SIG_COMMANDMASK;
-		curValue   = curWord & SIG_VALUEMASK;
+		uint16 curCommand = curWord & SIG_COMMANDMASK;
+		uint32 curValue   = curWord & SIG_VALUEMASK;
 		switch (curCommand) {
 		case SIG_MAGICDWORD: {
 			if (magicDWordIncluded) {
diff --git a/engines/sci/engine/scriptdebug.cpp b/engines/sci/engine/scriptdebug.cpp
index ed1b6dd1264..0131addb066 100644
--- a/engines/sci/engine/scriptdebug.cpp
+++ b/engines/sci/engine/scriptdebug.cpp
@@ -355,7 +355,6 @@ reg_t disassemble(EngineState *s, reg_t pos, const Object *obj, bool printBWTag,
 			int restmod = s->r_rest;
 			int stackframe = (scr[pos.getOffset() + 1] >> 1) + restmod;
 			reg_t *sb = s->xs->sp;
-			uint16 selector;
 			reg_t fun_ref;
 
 			while (stackframe > 0) {
@@ -368,7 +367,7 @@ reg_t disassemble(EngineState *s, reg_t pos, const Object *obj, bool printBWTag,
 				else if (opcode == op_self)
 					called_obj_addr = s->xs->objp;
 
-				selector = sb[- stackframe].getOffset();
+				uint16 selector = sb[- stackframe].getOffset();
 
 				name = s->_segMan->getObjectName(called_obj_addr);
 
diff --git a/engines/sci/engine/seg_manager.cpp b/engines/sci/engine/seg_manager.cpp
index 1b5456bea25..30463d71164 100644
--- a/engines/sci/engine/seg_manager.cpp
+++ b/engines/sci/engine/seg_manager.cpp
@@ -1136,14 +1136,14 @@ void SegManager::uninstantiateScriptSci0(int script_nr) {
 	SegmentId segmentId = getScriptSegment(script_nr);
 	Script *scr = getScript(segmentId);
 	reg_t reg = make_reg(segmentId, oldScriptHeader ? 2 : 0);
-	int objType, objLength = 0;
+	int objLength = 0;
 
 	// Make a pass over the object in order to uninstantiate all superclasses
 
 	while (true) {
 		reg.incOffset(objLength); // Step over the last checked object
 
-		objType = READ_SCI11ENDIAN_UINT16(scr->getBuf(reg.getOffset()));
+		int objType = READ_SCI11ENDIAN_UINT16(scr->getBuf(reg.getOffset()));
 		if (!objType)
 			break;
 		objLength = READ_SCI11ENDIAN_UINT16(scr->getBuf(reg.getOffset() + 2));
diff --git a/engines/sci/engine/state.cpp b/engines/sci/engine/state.cpp
index 0ada203e894..c8185d4dc11 100644
--- a/engines/sci/engine/state.cpp
+++ b/engines/sci/engine/state.cpp
@@ -250,7 +250,6 @@ Common::String SciEngine::getSciLanguageString(const Common::String &str, kLangu
 			// Japanese including Kanji, displayed with system font
 			// Convert half-width characters to full-width equivalents
 			Common::String fullWidth;
-			uint16 mappedChar;
 
 			textPtr += 2; // skip over language splitter
 
@@ -266,7 +265,7 @@ Common::String SciEngine::getSciLanguageString(const Common::String &str, kLangu
 
 				textPtr++;
 
-				mappedChar = s_halfWidthSJISMap[curChar];
+				uint16 mappedChar = s_halfWidthSJISMap[curChar];
 				if (mappedChar) {
 					fullWidth += mappedChar >> 8;
 					fullWidth += mappedChar & 0xFF;
diff --git a/engines/sci/engine/static_selectors.cpp b/engines/sci/engine/static_selectors.cpp
index a8967bc2d73..c33a5ed2aa3 100644
--- a/engines/sci/engine/static_selectors.cpp
+++ b/engines/sci/engine/static_selectors.cpp
@@ -295,10 +295,10 @@ void Kernel::findSpecificSelectors(Common::StringArray &selectorNames) {
 		_segMan->instantiateScript(classReferences[i].script, false);
 
 		const Object *targetClass = _segMan->getObject(_segMan->findObjectByName(classReferences[i].className));
-		int targetSelectorPos = 0;
 		uint selectorOffset = classReferences[i].selectorOffset;
 
 		if (targetClass) {
+			int targetSelectorPos;
 			if (classReferences[i].selectorType == kSelectorMethod) {
 				if (targetClass->getMethodCount() < selectorOffset + 1)
 					error("The %s class has less than %d methods (%d)",
diff --git a/engines/sci/engine/workarounds.cpp b/engines/sci/engine/workarounds.cpp
index 4a24c8685c7..2461b2a9566 100644
--- a/engines/sci/engine/workarounds.cpp
+++ b/engines/sci/engine/workarounds.cpp
@@ -1111,7 +1111,6 @@ SciWorkaroundSolution trackOriginAndFindWorkaround(int index, const SciWorkaroun
 
 	if (workaroundList) {
 		// Search if there is a workaround for this one
-		const SciWorkaroundEntry *workaround;
 		int16 inheritanceLevel = 0;
 		Common::String searchObjectName = g_sci->getSciLanguageString(curObjectName, K_LANG_ENGLISH);
 		reg_t searchObject = lastCall->sendp;
@@ -1120,7 +1119,7 @@ SciWorkaroundSolution trackOriginAndFindWorkaround(int index, const SciWorkaroun
 		bool matched = false;
 
 		do {
-			workaround = workaroundList;
+			const SciWorkaroundEntry *workaround = workaroundList;
 			while (workaround->methodName) {
 				bool objectNameMatches = (workaround->objectName == nullptr) ||
 										 (workaround->objectName == searchObjectName);
diff --git a/engines/sci/graphics/animate.cpp b/engines/sci/graphics/animate.cpp
index 73f1d548e23..8ee952fe7a3 100644
--- a/engines/sci/graphics/animate.cpp
+++ b/engines/sci/graphics/animate.cpp
@@ -135,11 +135,9 @@ void GfxAnimate::disposeLastCast() {
 bool GfxAnimate::invoke(List *list, int argc, reg_t *argv) {
 	reg_t curAddress = list->first;
 	Node *curNode = _s->_segMan->lookupNode(curAddress);
-	reg_t curObject;
-	uint16 signal;
 
 	while (curNode) {
-		curObject = curNode->value;
+		reg_t curObject = curNode->value;
 
 		if (_fastCastEnabled) {
 			// Check if the game has a fastCast object set
@@ -152,7 +150,7 @@ bool GfxAnimate::invoke(List *list, int argc, reg_t *argv) {
 			}
 		}
 
-		signal = readSelectorValue(_s->_segMan, curObject, SELECTOR(signal));
+		uint16 signal = readSelectorValue(_s->_segMan, curObject, SELECTOR(signal));
 		if (!(signal & kSignalFrozen)) {
 			// Call .doit method of that object
 			invokeSelector(_s, curObject, SELECTOR(doit), argc, argv, 0);
diff --git a/engines/sci/graphics/controls16.cpp b/engines/sci/graphics/controls16.cpp
index 6135824fa80..87dc4936d33 100644
--- a/engines/sci/graphics/controls16.cpp
+++ b/engines/sci/graphics/controls16.cpp
@@ -121,10 +121,9 @@ void GfxControls16::drawListControl(Common::Rect rect, reg_t obj, int16 maxChars
 }
 
 void GfxControls16::texteditCursorDraw(Common::Rect rect, const char *text, uint16 curPos) {
-	int16 textWidth, i;
 	if (!_texteditCursorVisible) {
-		textWidth = 0;
-		for (i = 0; i < curPos; i++) {
+		int16 textWidth = 0;
+		for (int16 i = 0; i < curPos; i++) {
 			textWidth += _text16->_font->getCharWidth((unsigned char)text[i]);
 		}
 		if (!g_sci->isLanguageRTL())
@@ -162,7 +161,7 @@ void GfxControls16::kernelTexteditChange(reg_t controlObject, reg_t eventObject)
 	uint16 maxChars = readSelectorValue(_segMan, controlObject, SELECTOR(max));
 	reg_t textReference = readSelector(_segMan, controlObject, SELECTOR(text));
 	Common::String text;
-	uint16 textSize, eventType, eventKey = 0, modifiers = 0;
+	uint16 eventKey = 0, modifiers = 0;
 	bool textChanged = false;
 	bool textAddChar = false;
 	Common::Rect rect;
@@ -174,8 +173,8 @@ void GfxControls16::kernelTexteditChange(reg_t controlObject, reg_t eventObject)
 	uint16 oldCursorPos = cursorPos;
 
 	if (!eventObject.isNull()) {
-		textSize = text.size();
-		eventType = readSelectorValue(_segMan, eventObject, SELECTOR(type));
+		uint16 textSize = text.size();
+		uint16 eventType = readSelectorValue(_segMan, eventObject, SELECTOR(type));
 
 		switch (eventType) {
 		case kSciEventMousePress:
@@ -314,8 +313,8 @@ int GfxControls16::getPicNotValid() {
 void GfxControls16::kernelDrawButton(Common::Rect rect, reg_t obj, const char *text, uint16 languageSplitter, int16 fontId, int16 style, bool hilite) {
 	g_sci->_tts->button(text);
 
-	int16 sci0EarlyPen = 0, sci0EarlyBack = 0;
 	if (!hilite) {
+		int16 sci0EarlyPen = 0, sci0EarlyBack = 0;
 		if (getSciVersion() == SCI_VERSION_0_EARLY) {
 			// SCI0early actually used hardcoded green/black buttons instead of using the port colors
 			sci0EarlyPen = _ports->_curPort->penClr;
diff --git a/engines/sci/graphics/cursor.cpp b/engines/sci/graphics/cursor.cpp
index 5603f078a5a..ae471594b41 100644
--- a/engines/sci/graphics/cursor.cpp
+++ b/engines/sci/graphics/cursor.cpp
@@ -103,15 +103,6 @@ void GfxCursor::purgeCache() {
 }
 
 void GfxCursor::kernelSetShape(GuiResourceId resourceId) {
-	Resource *resource;
-	Common::Point hotspot = Common::Point(0, 0);
-	byte colorMapping[4];
-	int16 x, y;
-	byte color;
-	uint16 maskA, maskB;
-	byte *pOut;
-	int16 heightWidth;
-
 	if (resourceId == -1) {
 		// no resourceId given, so we actually hide the cursor
 		kernelHide();
@@ -119,12 +110,13 @@ void GfxCursor::kernelSetShape(GuiResourceId resourceId) {
 	}
 
 	// Load cursor resource...
-	resource = _resMan->findResource(ResourceId(kResourceTypeCursor, resourceId), false);
+	Resource *resource = _resMan->findResource(ResourceId(kResourceTypeCursor, resourceId), false);
 	if (!resource)
 		error("cursor resource %d not found", resourceId);
 	if (resource->size() != SCI_CURSOR_SCI0_RESOURCESIZE)
 		error("cursor resource %d has invalid size", resourceId);
 
+	Common::Point hotspot;
 	if (getSciVersion() <= SCI_VERSION_01) {
 		// SCI0 cursors contain hotspot flags, not actual hotspot coordinates.
 		// If bit 0 of resourceData[3] is set, the hotspot should be centered,
@@ -137,6 +129,7 @@ void GfxCursor::kernelSetShape(GuiResourceId resourceId) {
 	}
 
 	// Now find out what colors we are supposed to use
+	byte colorMapping[4];
 	colorMapping[0] = 0; // Black is hardcoded
 	colorMapping[1] = _screen->getColorWhite(); // White is also hardcoded
 	colorMapping[2] = SCI_CURSOR_SCI0_TRANSPARENCYCOLOR;
@@ -152,18 +145,18 @@ void GfxCursor::kernelSetShape(GuiResourceId resourceId) {
 	Common::SpanOwner<SciSpan<byte> > rawBitmap;
 	rawBitmap->allocate(SCI_CURSOR_SCI0_HEIGHTWIDTH * SCI_CURSOR_SCI0_HEIGHTWIDTH, resource->name() + " copy");
 
-	pOut = rawBitmap->getUnsafeDataAt(0, SCI_CURSOR_SCI0_HEIGHTWIDTH * SCI_CURSOR_SCI0_HEIGHTWIDTH);
-	for (y = 0; y < SCI_CURSOR_SCI0_HEIGHTWIDTH; y++) {
-		maskA = resource->getUint16LEAt(4 + (y << 1));
-		maskB = resource->getUint16LEAt(4 + 32 + (y << 1));
+	byte *pOut = rawBitmap->getUnsafeDataAt(0, SCI_CURSOR_SCI0_HEIGHTWIDTH * SCI_CURSOR_SCI0_HEIGHTWIDTH);
+	for (int16 y = 0; y < SCI_CURSOR_SCI0_HEIGHTWIDTH; y++) {
+		uint16 maskA = resource->getUint16LEAt(4 + (y << 1));
+		uint16 maskB = resource->getUint16LEAt(4 + 32 + (y << 1));
 
-		for (x = 0; x < SCI_CURSOR_SCI0_HEIGHTWIDTH; x++) {
-			color = (((maskA << x) & 0x8000) | (((maskB << x) >> 1) & 0x4000)) >> 14;
+		for (int16 x = 0; x < SCI_CURSOR_SCI0_HEIGHTWIDTH; x++) {
+			byte color = (((maskA << x) & 0x8000) | (((maskB << x) >> 1) & 0x4000)) >> 14;
 			*pOut++ = colorMapping[color];
 		}
 	}
 
-	heightWidth = SCI_CURSOR_SCI0_HEIGHTWIDTH;
+	int16 heightWidth = SCI_CURSOR_SCI0_HEIGHTWIDTH;
 
 	if (_upscaledHires != GFX_SCREEN_UPSCALED_DISABLED && _upscaledHires != GFX_SCREEN_UPSCALED_480x300) {
 		// Scale cursor by 2x - note: sierra didn't do this, but it looks much better
diff --git a/engines/sci/graphics/menu.cpp b/engines/sci/graphics/menu.cpp
index 6b44a65dee6..facbe297a26 100644
--- a/engines/sci/graphics/menu.cpp
+++ b/engines/sci/graphics/menu.cpp
@@ -74,33 +74,30 @@ void GfxMenu::reset() {
 }
 
 void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t contentVmPtr) {
-	GuiMenuEntry *menuEntry;
 	uint16 itemCount = 0;
-	GuiMenuItemEntry *itemEntry;
-	int contentSize = content.size();
-	int separatorCount;
-	int curPos, beginPos, endPos, tempPos;
-	int tagPos, rightAlignedPos, functionPos, altPos, controlPos;
-	const char *tempPtr;
+	const int contentSize = content.size();
 
 	// Sierra SCI starts with id 1, so we do so as well
-	menuEntry = new GuiMenuEntry(_list.size() + 1);
+	GuiMenuEntry *menuEntry = new GuiMenuEntry(_list.size() + 1);
 	menuEntry->text = title;
 	_list.push_back(menuEntry);
 
-	curPos = 0;
-	uint16 listSize = _list.size();
+	int curPos = 0;
+	const uint16 listSize = _list.size();
 
 	do {
 		itemCount++;
-		itemEntry = new GuiMenuItemEntry(listSize, itemCount);
+		GuiMenuItemEntry *itemEntry = new GuiMenuItemEntry(listSize, itemCount);
 
-		beginPos = curPos;
+		int beginPos = curPos;
 
 		// Now go through the content till we find end-marker and collect data about it.
 		// ':' is an end-marker for each item.
-		tagPos = 0; rightAlignedPos = 0;
-		controlPos = 0; altPos = 0; functionPos = 0;
+		int tagPos = 0;
+		int rightAlignedPos = 0;
+		int controlPos = 0;
+		int altPos = 0;
+		int functionPos = 0;
 		while ((curPos < contentSize) && (content[curPos] != ':')) {
 			switch (content[curPos]) {
 			case '=': // Set tag
@@ -142,13 +139,13 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t
 			}
 			curPos++;
 		}
-		endPos = curPos;
+		int endPos = curPos;
 
 		// Control/Alt/Function key mapping...
 		if (controlPos) {
 			content.setChar(SCI_MENU_REPLACE_ONCONTROL, controlPos);
 			itemEntry->keyModifier = kSciKeyModCtrl;
-			tempPos = controlPos + 1;
+			int tempPos = controlPos + 1;
 			if (tempPos >= contentSize)
 				error("control marker at end of item");
 			itemEntry->keyPress = tolower(content[tempPos]);
@@ -157,7 +154,7 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t
 		if (altPos) {
 			content.setChar(SCI_MENU_REPLACE_ONALT, altPos);
 			itemEntry->keyModifier = kSciKeyModAlt;
-			tempPos = altPos + 1;
+			int tempPos = altPos + 1;
 			if (tempPos >= contentSize)
 				error("alt marker at end of item");
 			itemEntry->keyPress = tolower(content[tempPos]);
@@ -165,7 +162,7 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t
 		}
 		if (functionPos) {
 			content.setChar(SCI_MENU_REPLACE_ONFUNCTION, functionPos);
-			tempPos = functionPos + 1;
+			int tempPos = functionPos + 1;
 			if (tempPos >= contentSize)
 				error("function marker at end of item");
 			itemEntry->keyPress = content[tempPos];
@@ -186,14 +183,14 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t
 		}
 
 		// Now get all strings
-		tempPos = endPos;
+		int tempPos = endPos;
 		if (rightAlignedPos) {
 			tempPos = rightAlignedPos;
 		} else if (tagPos) {
 			tempPos = tagPos;
 		}
 		curPos = beginPos;
-		separatorCount = 0;
+		int separatorCount = 0;
 		while (curPos < tempPos) {
 			switch (content[curPos]) {
 			case '!':
@@ -221,7 +218,7 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t
 			itemEntry->text = Common::String(content.c_str() + beginPos, tempPos - beginPos);
 
 			// LSL6 uses "Ctrl-" prefix string instead of ^ like all the other games do
-			tempPtr = itemEntry->text.c_str();
+			const char *tempPtr = itemEntry->text.c_str();
 			tempPtr = strstr(tempPtr, "Ctrl-");
 			if (tempPtr) {
 				itemEntry->keyModifier = kSciKeyModCtrl;
@@ -270,11 +267,10 @@ void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t
 GuiMenuItemEntry *GfxMenu::findItem(uint16 menuId, uint16 itemId) {
 	GuiMenuItemList::iterator listIterator;
 	GuiMenuItemList::iterator listEnd = _itemList.end();
-	GuiMenuItemEntry *listEntry;
 
 	listIterator = _itemList.begin();
 	while (listIterator != listEnd) {
-		listEntry = *listIterator;
+		GuiMenuItemEntry *listEntry = *listIterator;
 		if ((listEntry->menuId == menuId) && (listEntry->id == itemId))
 			return listEntry;
 
@@ -346,7 +342,6 @@ reg_t GfxMenu::kernelGetAttribute(uint16 menuId, uint16 itemId, uint16 attribute
 }
 
 void GfxMenu::drawBar() {
-	GuiMenuEntry *listEntry;
 	GuiMenuList::iterator listIterator;
 	GuiMenuList::iterator listEnd = _list.end();
 
@@ -361,10 +356,10 @@ void GfxMenu::drawBar() {
 
 	listIterator = _list.begin();
 	while (listIterator != listEnd) {
-		listEntry = *listIterator;
-		int16 textWidth;
-		int16 textHeight;
+		GuiMenuEntry *listEntry = *listIterator;
 		if (g_sci->isLanguageRTL()) {
+			int16 textWidth;
+			int16 textHeight;
 			_text16->StringWidth(listEntry->textSplit.c_str(), _text16->GetFontId(), textWidth, textHeight);
 			_ports->_curPort->curLeft -= textWidth;
 		}
@@ -381,12 +376,11 @@ void GfxMenu::drawBar() {
 void GfxMenu::calculateMenuWidth() {
 	GuiMenuList::iterator menuIterator;
 	GuiMenuList::iterator menuEnd = _list.end();
-	GuiMenuEntry *menuEntry;
 	int16 dummyHeight;
 
 	menuIterator = _list.begin();
 	while (menuIterator != menuEnd) {
-		menuEntry = *menuIterator;
+		GuiMenuEntry *menuEntry = *menuIterator;
 		menuEntry->textSplit = g_sci->strSplit(menuEntry->text.c_str(), nullptr);
 		_text16->StringWidth(menuEntry->textSplit.c_str(), 0, menuEntry->textWidth, dummyHeight);
 
@@ -398,14 +392,13 @@ void GfxMenu::calculateMenuWidth() {
 void GfxMenu::calculateMenuAndItemWidth() {
 	GuiMenuItemList::iterator itemIterator;
 	GuiMenuItemList::iterator itemEnd = _itemList.end();
-	GuiMenuItemEntry *itemEntry;
 	int16 dummyHeight;
 
 	calculateMenuWidth();
 
 	itemIterator = _itemList.begin();
 	while (itemIterator != itemEnd) {
-		itemEntry = *itemIterator;
+		GuiMenuItemEntry *itemEntry = *itemIterator;
 		// Split the text now for multilingual SCI01 games
 		itemEntry->textSplit = g_sci->strSplit(itemEntry->text.c_str(), nullptr);
 		_text16->StringWidth(itemEntry->textSplit.c_str(), 0, itemEntry->textWidth, dummyHeight);
@@ -569,7 +562,6 @@ GuiMenuItemEntry *GfxMenu::interactiveGetItem(uint16 menuId, uint16 itemId, bool
 }
 
 void GfxMenu::drawMenu(uint16 oldMenuId, uint16 newMenuId) {
-	GuiMenuEntry *listEntry;
 	GuiMenuList::iterator listIterator;
 	GuiMenuList::iterator listEnd = _list.end();
 	GuiMenuItemEntry *listItemEntry;
@@ -601,7 +593,7 @@ void GfxMenu::drawMenu(uint16 oldMenuId, uint16 newMenuId) {
 		menuTextRect.left = menuTextRect.right = _ports->_menuBarRect.right - 7;
 	listIterator = _list.begin();
 	while (listIterator != listEnd) {
-		listEntry = *listIterator;
+		GuiMenuEntry *listEntry = *listIterator;
 		listNr++;
 		if (!g_sci->isLanguageRTL()) {
 			menuTextRect.left = menuTextRect.right;
@@ -748,7 +740,6 @@ void GfxMenu::interactiveEnd(bool pauseSound) {
 }
 
 uint16 GfxMenu::mouseFindMenuSelection(Common::Point mousePosition) {
-	GuiMenuEntry *listEntry;
 	GuiMenuList::iterator listIterator;
 	GuiMenuList::iterator listEnd = _list.end();
 	uint16 curXstart;
@@ -759,7 +750,7 @@ uint16 GfxMenu::mouseFindMenuSelection(Common::Point mousePosition) {
 
 	listIterator = _list.begin();
 	while (listIterator != listEnd) {
-		listEntry = *listIterator;
+		GuiMenuEntry *listEntry = *listIterator;
 		if (!g_sci->isLanguageRTL()) {
 			if (mousePosition.x >= curXstart && mousePosition.x < curXstart + listEntry->textWidth) {
 				return listEntry->id;
diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp
index 40852d7f5b8..98f321708e6 100644
--- a/engines/sci/graphics/palette.cpp
+++ b/engines/sci/graphics/palette.cpp
@@ -274,9 +274,6 @@ static byte blendColors(byte c1, byte c2) {
 }
 
 void GfxPalette::setEGA() {
-	int curColor;
-	byte color1, color2;
-
 	_sysPalette.colors[1].r  = 0x000; _sysPalette.colors[1].g  = 0x000; _sysPalette.colors[1].b  = 0x0AA;
 	_sysPalette.colors[2].r  = 0x000; _sysPalette.colors[2].g  = 0x0AA; _sysPalette.colors[2].b  = 0x000;
 	_sysPalette.colors[3].r  = 0x000; _sysPalette.colors[3].g  = 0x0AA; _sysPalette.colors[3].b  = 0x0AA;
@@ -292,14 +289,15 @@ void GfxPalette::setEGA() {
 	_sysPalette.colors[13].r = 0x0FF; _sysPalette.colors[13].g = 0x055; _sysPalette.colors[13].b = 0x0FF;
 	_sysPalette.colors[14].r = 0x0FF; _sysPalette.colors[14].g = 0x0FF; _sysPalette.colors[14].b = 0x055;
 	_sysPalette.colors[15].r = 0x0FF; _sysPalette.colors[15].g = 0x0FF; _sysPalette.colors[15].b = 0x0FF;
-	for (curColor = 0; curColor <= 15; curColor++) {
+	for (int curColor = 0; curColor <= 15; curColor++) {
 		_sysPalette.colors[curColor].used = 1;
 	}
 	// Now setting colors 16-254 to the correct mix colors that occur when not doing a dithering run on
 	//  finished pictures
-	for (curColor = 0x10; curColor <= 0xFE; curColor++) {
+	for (int curColor = 0x10; curColor <= 0xFE; curColor++) {
 		_sysPalette.colors[curColor].used = 1;
-		color1 = curColor & 0x0F; color2 = curColor >> 4;
+		byte color1 = curColor & 0x0F;
+		byte color2 = curColor >> 4;
 
 		_sysPalette.colors[curColor].r = blendColors(_sysPalette.colors[color1].r, _sysPalette.colors[color2].r);
 		_sysPalette.colors[curColor].g = blendColors(_sysPalette.colors[color1].g, _sysPalette.colors[color2].g);
diff --git a/engines/sci/graphics/picture.cpp b/engines/sci/graphics/picture.cpp
index 56f999bdef1..fd50ae8d7cf 100644
--- a/engines/sci/graphics/picture.cpp
+++ b/engines/sci/graphics/picture.cpp
@@ -142,37 +142,31 @@ extern void unpackCelData(const SciSpan<const byte> &inBuffer, SciSpan<byte> &ce
 void GfxPicture::drawCelData(const SciSpan<const byte> &inbuffer, int headerPos, int rlePos, int literalPos, int16 drawX, int16 drawY, int16 pictureX, int16 pictureY, bool isEGA) {
 	const SciSpan<const byte> headerPtr = inbuffer.subspan(headerPos);
 	const SciSpan<const byte> rlePtr = inbuffer.subspan(rlePos);
-	// displaceX, displaceY fields are ignored, and may contain garbage
-	// (e.g. pic 261 in Dr. Brain 1 Spanish - bug #6388)
-	//int16 displaceX, displaceY;
-	byte priority = _priority;
-	byte clearColor;
-	byte curByte;
-	int16 y, lastY, x, leftX, rightX;
-	int pixelCount;
-	uint16 width, height;
 
 	// if the picture is not an overlay and we are also not in EGA mode, use priority 0
-	if (!isEGA && !_addToFlag)
-		priority = 0;
+	const byte priority = (!isEGA && !_addToFlag) ? 0 : _priority;
 
 	// Width/height here are always LE, even in Mac versions
-	width = headerPtr.getUint16LEAt(0);
-	height = headerPtr.getUint16LEAt(2);
-	//displaceX = (signed char)headerPtr[4];
-	//displaceY = (unsigned char)headerPtr[5];
+	uint16 width = headerPtr.getUint16LEAt(0);
+	uint16 height = headerPtr.getUint16LEAt(2);
+
+	// displaceX, displaceY fields are ignored, and may contain garbage
+	// (e.g. pic 261 in Dr. Brain 1 Spanish - bug #6388)
+	//int16 displaceX = (signed char)headerPtr[4];
+	//int16 displaceY = (unsigned char)headerPtr[5];
+	//if (displaceX || displaceY)
+	//	error("unsupported embedded cel-data in picture");
+
+	byte clearColor;
 	if (_resourceType == SCI_PICTURE_TYPE_SCI11)
 		// SCI1.1 uses hardcoded clearcolor for pictures, even if cel header specifies otherwise
 		clearColor = _screen->getColorWhite();
 	else
 		clearColor = headerPtr[6];
 
-	//if (displaceX || displaceY)
-	//	error("unsupported embedded cel-data in picture");
-
 	// We will unpack cel-data into a temporary buffer and then plot it to screen
 	//  That needs to be done cause a mirrored picture may be requested
-	pixelCount = width * height;
+	int pixelCount = width * height;
 	Common::SpanOwner<SciSpan<byte> > celBitmap;
 	celBitmap->allocate(pixelCount, _resource->name());
 	unpackCelData(inbuffer, *celBitmap, clearColor, rlePos, literalPos, _resMan->getViewType(), width, false);
@@ -207,10 +201,10 @@ void GfxPicture::drawCelData(const SciSpan<const byte> &inbuffer, int headerPos,
 	}
 
 	if (displayWidth > 0 && displayHeight > 0) {
-		y = displayArea.top + drawY;
-		lastY = MIN<int16>(height + y, displayArea.bottom);
-		leftX = displayArea.left + drawX;
-		rightX = MIN<int16>(displayWidth + leftX, displayArea.right);
+		int16 y = displayArea.top + drawY;
+		int16 lastY = MIN<int16>(height + y, displayArea.bottom);
+		int16 leftX = displayArea.left + drawX;
+		int16 rightX = MIN<int16>(displayWidth + leftX, displayArea.right);
 
 		uint16 sourcePixelSkipPerRow = 0;
 		if (width > rightX - leftX)
@@ -233,9 +227,9 @@ void GfxPicture::drawCelData(const SciSpan<const byte> &inbuffer, int headerPos,
 			// VGA + EGA, EGA only checks priority, when given priority is below 16
 			if (!_mirroredFlag) {
 				// Draw bitmap to screen
-				x = leftX;
+				int16 x = leftX;
 				while (y < lastY) {
-					curByte = *ptr++;
+					byte curByte = *ptr++;
 					if ((curByte != clearColor) && (priority >= _screen->getPriority(x, y)))
 						_screen->putPixel(x, y, drawMask, curByte, priority, 0);
 
@@ -249,9 +243,9 @@ void GfxPicture::drawCelData(const SciSpan<const byte> &inbuffer, int headerPos,
 				}
 			} else {
 				// Draw bitmap to screen (mirrored)
-				x = rightX - 1;
+				int16 x = rightX - 1;
 				while (y < lastY) {
-					curByte = *ptr++;
+					byte curByte = *ptr++;
 					if ((curByte != clearColor) && (priority >= _screen->getPriority(x, y)))
 						_screen->putPixel(x, y, drawMask, curByte, priority, 0);
 
@@ -270,9 +264,9 @@ void GfxPicture::drawCelData(const SciSpan<const byte> &inbuffer, int headerPos,
 			//  fixes picture 48 of kq5 (island overview). Bug #5182
 			if (!_mirroredFlag) {
 				// EGA+priority>15: Draw bitmap to screen
-				x = leftX;
+				int16 x = leftX;
 				while (y < lastY) {
-					curByte = *ptr++;
+					byte curByte = *ptr++;
 					if (curByte != clearColor)
 						_screen->putPixel(x, y, GFX_SCREEN_MASK_VISUAL, curByte, 0, 0);
 
@@ -286,9 +280,9 @@ void GfxPicture::drawCelData(const SciSpan<const byte> &inbuffer, int headerPos,
 				}
 			} else {
 				// EGA+priority>15: Draw bitmap to screen (mirrored)
-				x = rightX - 1;
+				int16 x = rightX - 1;
 				while (y < lastY) {
-					curByte = *ptr++;
+					byte curByte = *ptr++;
 					if (curByte != clearColor)
 						_screen->putPixel(x, y, GFX_SCREEN_MASK_VISUAL, curByte, 0, 0);
 
diff --git a/engines/sci/graphics/portrait.cpp b/engines/sci/graphics/portrait.cpp
index dc10b06b471..cbed86f31fe 100644
--- a/engines/sci/graphics/portrait.cpp
+++ b/engines/sci/graphics/portrait.cpp
@@ -119,13 +119,11 @@ void Portrait::init() {
 
 	// Read all bitmaps
 	uint16 bitmapNr;
-	uint16 bytesPerLine;
-
 	for (bitmapNr = 0; bitmapNr < _bitmaps.size(); bitmapNr++) {
 		PortraitBitmap &curBitmap = _bitmaps[bitmapNr];
 		curBitmap.width = data.getUint16LEAt(2);
 		curBitmap.height = data.getUint16LEAt(4);
-		bytesPerLine = data.getUint16LEAt(6);
+		uint16 bytesPerLine = data.getUint16LEAt(6);
 		if (bytesPerLine < curBitmap.width)
 			error("kPortrait: bytesPerLine larger than actual width");
 		curBitmap.extraBytesPerLine = bytesPerLine - curBitmap.width;
@@ -158,7 +156,6 @@ void Portrait::init() {
 	// raw lip-sync frame table follows
 	uint32 lipSyncDataTableSize;
 	uint32 lipSyncDataTableLastOffset;
-	byte   lipSyncData;
 	uint16 lipSyncDataNr;
 	uint16 lipSyncCurOffset;
 
@@ -177,7 +174,7 @@ void Portrait::init() {
 		_lipSyncDataOffsetTable[lipSyncDataNr] = lipSyncCurOffset;
 
 		// Look for end of ID-frame data
-		lipSyncData = *data++; lipSyncCurOffset++;
+		byte lipSyncData = *data++; lipSyncCurOffset++;
 		while (lipSyncData != 0xFF && lipSyncCurOffset < lipSyncDataTableLastOffset) {
 			// Either terminator (0xFF) or frame-data (1 byte tick count and 1 byte bitmap ID)
 			data++;
@@ -268,7 +265,6 @@ void Portrait::doit(Common::Point position, uint16 resourceId, uint16 noun, uint
 	byte raveLipSyncTicks;
 	byte raveLipSyncBitmapNr;
 	int timerPosition = 0;
-	int timerPositionWithin = 0;
 	int curPosition;
 	SciEvent curEvent;
 	bool userAbort = false;
@@ -315,7 +311,7 @@ void Portrait::doit(Common::Point position, uint16 resourceId, uint16 noun, uint
 			// lip sync data is
 			//  Tick:Byte, Bitmap-Nr:BYTE
 			//  Tick = 0xFF is the terminator for the data
-			timerPositionWithin = timerPosition;
+			int timerPositionWithin = timerPosition;
 			raveLipSyncTicks = *raveLipSyncData++;
 			while (raveLipSyncData.size() && raveLipSyncTicks != 0xFF) {
 				if (raveLipSyncTicks)
@@ -423,14 +419,13 @@ void Portrait::doit(Common::Point position, uint16 resourceId, uint16 noun, uint
 int16 Portrait::raveGetTicks(Resource *resource, uint *offset) {
 	uint curOffset = *offset;
 	SciSpan<const byte> curData = resource->subspan(curOffset);
-	byte curByte;
 	uint16 curValue = 0;
 
 	if (curOffset >= resource->size())
 		return -1;
 
 	while (curOffset < resource->size()) {
-		curByte = *curData++; curOffset++;
+		byte curByte = *curData++; curOffset++;
 		if ( curByte == ' ' )
 			break;
 		if ( (curByte >= '0') && (curByte <= '9') ) {
@@ -448,11 +443,10 @@ int16 Portrait::raveGetTicks(Resource *resource, uint *offset) {
 uint16 Portrait::raveGetID(Resource *resource, uint *offset) {
 	uint curOffset = *offset;
 	SciSpan<const byte> curData = resource->subspan(curOffset);
-	byte curByte = 0;
 	uint16 curValue = 0;
 
 	while (curOffset < resource->size()) {
-		curByte = *curData++; curOffset++;
+		byte curByte = *curData++; curOffset++;
 		if ( curByte == ' ' )
 			break;
 		if (!curValue) {
@@ -468,22 +462,18 @@ uint16 Portrait::raveGetID(Resource *resource, uint *offset) {
 
 // Searches for a specific lip sync ID and returns pointer to lip sync data or NULL in case ID was not found
 SciSpan<const byte> Portrait::raveGetLipSyncData(const uint16 raveID) {
-	uint lipSyncIDNr = 0;
 	SciSpan<const byte> lipSyncIDPtr = _lipSyncIDTable;
-	byte lipSyncIDByte1, lipSyncIDByte2;
-	uint16 lipSyncID;
 
 	lipSyncIDPtr++; // skip over first byte
-	while (lipSyncIDNr < _lipSyncIDCount) {
-		lipSyncIDByte1 = *lipSyncIDPtr++;
-		lipSyncIDByte2 = *lipSyncIDPtr++;
-		lipSyncID = (lipSyncIDByte1 << 8) | lipSyncIDByte2;
+	for (uint lipSyncIDNr = 0; lipSyncIDNr < _lipSyncIDCount; lipSyncIDNr++) {
+		byte lipSyncIDByte1 = *lipSyncIDPtr++;
+		byte lipSyncIDByte2 = *lipSyncIDPtr++;
+		uint16 lipSyncID = (lipSyncIDByte1 << 8) | lipSyncIDByte2;
 
 		if (lipSyncID == raveID) {
 			return _lipSyncData.subspan(_lipSyncDataOffsetTable[lipSyncIDNr]);
 		}
 
-		lipSyncIDNr++;
 		lipSyncIDPtr += 2; // ID is every 4 bytes
 	}
 	return SciSpan<const byte>();
diff --git a/engines/sci/graphics/ports.cpp b/engines/sci/graphics/ports.cpp
index bfcca45c058..53370cf4263 100644
--- a/engines/sci/graphics/ports.cpp
+++ b/engines/sci/graphics/ports.cpp
@@ -691,10 +691,9 @@ void GfxPorts::priorityBandsInit(int16 bandCount, int16 top, int16 bottom) {
 
 void GfxPorts::priorityBandsInit(const SciSpan<const byte> &data) {
 	int i = 0, inx;
-	byte priority = 0;
 
 	for (inx = 0; inx < 14; inx++) {
-		priority = data[inx];
+		byte priority = data[inx];
 		while (i < priority && i < 200)
 			_priorityBands[i++] = inx;
 	}
@@ -742,9 +741,8 @@ byte GfxPorts::kernelCoordinateToPriority(int16 y) {
 }
 
 int16 GfxPorts::kernelPriorityToCoordinate(byte priority) {
-	int16 y;
 	if (priority <= _priorityBandCount) {
-		for (y = 0; y <= _priorityBottom; y++)
+		for (int16 y = 0; y <= _priorityBottom; y++)
 			if (_priorityBands[y] == priority)
 				return y;
 	}
diff --git a/engines/sci/graphics/screen.cpp b/engines/sci/graphics/screen.cpp
index 1c357a7d605..8da7f0a80a1 100644
--- a/engines/sci/graphics/screen.cpp
+++ b/engines/sci/graphics/screen.cpp
@@ -859,7 +859,7 @@ void GfxScreen::kernelShakeScreen(uint16 shakeCount, uint16 directions) {
 
 void GfxScreen::dither(bool addToFlag) {
 	int y, x;
-	byte color, ditheredColor;
+	byte color;
 	byte *visualPtr = _visualScreen;
 	byte *displayPtr = _displayScreen;
 	byte *paletteMapPtr = _paletteMapScreen;
@@ -901,6 +901,7 @@ void GfxScreen::dither(bool addToFlag) {
 					_ditheredPicColors[color]++;
 					// if decoded color wants do dither with black on left side, we turn it around
 					//  otherwise the normal ega color would get used for display
+					byte ditheredColor;
 					if (color & 0xF0) {
 						ditheredColor = color;
 					}	else {
diff --git a/engines/sci/graphics/text16.cpp b/engines/sci/graphics/text16.cpp
index 676be5f8ec4..dffb581459b 100644
--- a/engines/sci/graphics/text16.cpp
+++ b/engines/sci/graphics/text16.cpp
@@ -377,18 +377,18 @@ int16 GfxText16::GetLongest(const char *&textPtr, int16 maxWidth, GuiResourceId
 }
 
 void GfxText16::Width(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight, bool restoreFont) {
-	uint16 curChar;
 	GuiResourceId previousFontId = GetFontId();
 	int16 previousPenColor = _ports->_curPort->penClr;
 
-	textWidth = 0; textHeight = 0;
-	bool escapedNewLine = false;
+	textWidth = 0;
+	textHeight = 0;
 
 	GetFont();
 	if (_font) {
+		bool escapedNewLine = false;
 		text += from;
 		while (len--) {
-			curChar = (*(const byte *)text++);
+			uint16 curChar = (*(const byte *)text++);
 			if (_font->isDoubleByte(curChar)) {
 				curChar |= (*(const byte *)text++) << 8;
 				len--;
@@ -443,9 +443,8 @@ void GfxText16::DrawString(const Common::String &str, GuiResourceId orgFontId, i
 int16 GfxText16::Size(Common::Rect &rect, const char *text, uint16 languageSplitter, GuiResourceId fontId, int16 maxWidth) {
 	GuiResourceId previousFontId = GetFontId();
 	int16 previousPenColor = _ports->_curPort->penClr;
-	int16 charCount;
 	int16 maxTextWidth = 0, textWidth;
-	int16 totalHeight = 0, textHeight;
+	int16 textHeight;
 
 	if (fontId != -1)
 		SetFont(fontId);
@@ -474,12 +473,13 @@ int16 GfxText16::Size(Common::Rect &rect, const char *text, uint16 languageSplit
 		if (g_sci->getLanguage() == Common::KO_KOR)
 			SwitchToFont1001OnKorean(curTextPos, languageSplitter);
 
+		int16 totalHeight = 0;
 		while (*curTextPos) {
 			// We need to check for Shift-JIS every line
 			if (g_sci->getLanguage() == Common::JA_JPN)
 				SwitchToFont900OnSjis(curTextPos, languageSplitter);
 
-			charCount = GetLongest(curTextPos, rect.right, fontId);
+			int16 charCount = GetLongest(curTextPos, rect.right, fontId);
 			if (charCount == 0)
 				break;
 			Width(curTextLine, 0, charCount, fontId, textWidth, textHeight, false);
@@ -497,19 +497,17 @@ int16 GfxText16::Size(Common::Rect &rect, const char *text, uint16 languageSplit
 
 // returns maximum font height used
 void GfxText16::Draw(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 orgPenColor) {
-	uint16 curChar, charWidth;
-	Common::Rect rect;
-
 	GetFont();
 	if (!_font)
 		return;
 
+	Common::Rect rect;
 	rect.top = _ports->_curPort->curTop;
 	rect.bottom = rect.top + _ports->_curPort->fontHeight;
 	text += from;
 	bool escapedNewLine = false;
 	while (len--) {
-		curChar = (*(const byte *)text++);
+		uint16 curChar = (*(const byte *)text++);
 		if (_font->isDoubleByte(curChar)) {
 			curChar |= (*(const byte *)text++) << 8;
 			len--;
@@ -534,8 +532,8 @@ void GfxText16::Draw(const char *text, int16 from, int16 len, GuiResourceId orgF
 				break;
 			}
 			// fall through
-		default:
-			charWidth = _font->getCharWidth(curChar);
+		default: {
+			uint16 charWidth = _font->getCharWidth(curChar);
 			// clear char
 			if (_ports->_curPort->penMode == 1) {
 				rect.left = _ports->_curPort->curLeft;
@@ -546,6 +544,7 @@ void GfxText16::Draw(const char *text, int16 from, int16 len, GuiResourceId orgF
 			_font->draw(curChar, _ports->_curPort->top + _ports->_curPort->curTop, _ports->_curPort->left + _ports->_curPort->curLeft, _ports->_curPort->penClr, _ports->_curPort->greyedOutput);
 			_ports->_curPort->curLeft += charWidth;
 		}
+		}
 	}
 }
 
@@ -562,7 +561,7 @@ void GfxText16::Show(const char *text, int16 from, int16 len, GuiResourceId orgF
 
 // Draws a text in rect.
 void GfxText16::Box(const char *text, uint16 languageSplitter, bool show, const Common::Rect &rect, TextAlignment alignment, GuiResourceId fontId) {
-	int16 textWidth, maxTextWidth, textHeight, charCount;
+	int16 textWidth, maxTextWidth, textHeight;
 	int16 offset = 0;
 	int16 hline = 0;
 	GuiResourceId previousFontId = GetFontId();
@@ -597,7 +596,7 @@ void GfxText16::Box(const char *text, uint16 languageSplitter, bool show, const
 				doubleByteMode = true;
 		}
 
-		charCount = GetLongest(curTextPos, rect.width(), fontId);
+		int16 charCount = GetLongest(curTextPos, rect.width(), fontId);
 		if (charCount == 0)
 			break;
 		Width(curTextLine, 0, charCount, fontId, textWidth, textHeight, true);
@@ -693,7 +692,9 @@ void GfxText16::DrawString(const Common::String &textOrig) {
 // we need to have a separate status drawing code
 //  In KQ4 the IV char is actually 0xA, which would otherwise get considered as linebreak and not printed
 void GfxText16::DrawStatus(const Common::String &strOrig) {
-	uint16 curChar, charWidth;
+	GetFont();
+	if (!_font)
+		return;
 
 	Common::String str;
 	if (!g_sci->isLanguageRTL())
@@ -705,22 +706,19 @@ void GfxText16::DrawStatus(const Common::String &strOrig) {
 	uint16 textLen = str.size();
 	Common::Rect rect;
 
-	GetFont();
-	if (!_font)
-		return;
-
 	rect.top = _ports->_curPort->curTop;
 	rect.bottom = rect.top + _ports->_curPort->fontHeight;
 	while (textLen--) {
-		curChar = *text++;
+		uint16 curChar = *text++;
 		switch (curChar) {
 		case 0:
 			break;
-		default:
-			charWidth = _font->getCharWidth(curChar);
+		default: {
+			uint16 charWidth = _font->getCharWidth(curChar);
 			_font->draw(curChar, _ports->_curPort->top + _ports->_curPort->curTop, _ports->_curPort->left + _ports->_curPort->curLeft, _ports->_curPort->penClr, _ports->_curPort->greyedOutput);
 			_ports->_curPort->curLeft += charWidth;
 		}
+		}
 	}
 }
 
diff --git a/engines/sci/graphics/transitions.cpp b/engines/sci/graphics/transitions.cpp
index 654549f3ed3..a684937d456 100644
--- a/engines/sci/graphics/transitions.cpp
+++ b/engines/sci/graphics/transitions.cpp
@@ -163,13 +163,11 @@ const GfxTransitionTranslateEntry *GfxTransitions::translateNumber (int16 number
 }
 
 void GfxTransitions::doit(Common::Rect picRect) {
-	const GfxTransitionTranslateEntry *translationEntry = _translationTable;
-
 	_picRect = picRect;
 
 	if (_translationTable) {
 		// We need to translate the ID
-		translationEntry = translateNumber(_number, _translationTable);
+		const GfxTransitionTranslateEntry *translationEntry = translateNumber(_number, _translationTable);
 		if (translationEntry) {
 			_number = translationEntry->newId;
 			_blackoutFlag = translationEntry->blackoutFlag;
@@ -183,7 +181,7 @@ void GfxTransitions::doit(Common::Rect picRect) {
 	if (_blackoutFlag) {
 		// We need to find out what transition we are supposed to use for
 		// blackout
-		translationEntry = translateNumber(_number, blackoutTransitionIDs);
+		const GfxTransitionTranslateEntry *translationEntry = translateNumber(_number, blackoutTransitionIDs);
 		if (translationEntry) {
 			doTransition(translationEntry->newId, true);
 		} else {
diff --git a/engines/sci/graphics/view.cpp b/engines/sci/graphics/view.cpp
index 74b5133ad77..865c7513b38 100644
--- a/engines/sci/graphics/view.cpp
+++ b/engines/sci/graphics/view.cpp
@@ -110,10 +110,7 @@ void GfxView::initData(GuiResourceId resourceId) {
 	uint16 celCount = 0;
 	uint16 mirrorBits = 0;
 	uint32 palOffset = 0;
-	uint16 headerSize = 0;
-	uint16 loopSize = 0, celSize = 0;
-	uint loopNo, celNo, EGAmapNr;
-	byte seekEntry;
+	uint loopNo, celNo;
 	bool isEGA = false;
 	bool isCompressed = true;
 	ViewType curViewType = _resMan->getViewType();
@@ -171,6 +168,7 @@ void GfxView::initData(GuiResourceId resourceId) {
 				//  with broken mapping tables. I guess those games won't use the mapping, so I rather disable it
 				//  for them
 				if (getSciVersion() == SCI_VERSION_1_EGA_ONLY) {
+					uint EGAmapNr;
 					for (EGAmapNr = 0; EGAmapNr < SCI_VIEW_EGAMAPPING_COUNT; EGAmapNr++) {
 						const SciSpan<const byte> mapping = _resource->subspan(palOffset + EGAmapNr * SCI_VIEW_EGAMAPPING_SIZE, SCI_VIEW_EGAMAPPING_SIZE);
 						if (memcmp(mapping.getUnsafeDataAt(0, SCI_VIEW_EGAMAPPING_SIZE), EGAmappingStraight, SCI_VIEW_EGAMAPPING_SIZE) != 0)
@@ -246,7 +244,7 @@ void GfxView::initData(GuiResourceId resourceId) {
 
 	case kViewVga11: { // View-format SCI1.1+
 		// HeaderSize:WORD LoopCount:BYTE Flags:BYTE Version:WORD Unknown:WORD PaletteOffset:WORD
-		headerSize = _resource->getUint16SEAt(0) + 2; // headerSize is not part of the header, so it's added
+		uint16 headerSize = _resource->getUint16SEAt(0) + 2; // headerSize is not part of the header, so it's added
 		assert(headerSize >= 16);
 		const uint8 loopCount = _resource->getUint8At(2);
 		assert(loopCount);
@@ -271,9 +269,9 @@ void GfxView::initData(GuiResourceId resourceId) {
 		}
 
 		loopData = _resource->subspan(headerSize);
-		loopSize = _resource->getUint8At(12);
+		uint16 loopSize = _resource->getUint8At(12);
 		assert(loopSize >= 16);
-		celSize = _resource->getUint8At(13);
+		uint16 celSize = _resource->getUint8At(13);
 		assert(celSize >= 32);
 
 		if (palOffset) {
@@ -285,7 +283,7 @@ void GfxView::initData(GuiResourceId resourceId) {
 		for (loopNo = 0; loopNo < loopCount; loopNo++) {
 			loopData = _resource->subspan(headerSize + (loopNo * loopSize));
 
-			seekEntry = loopData[0];
+			byte seekEntry = loopData[0];
 			if (seekEntry != 255) {
 				_loop[loopNo].mirrorFlag = true;
 
@@ -713,8 +711,6 @@ void GfxView::unditherBitmap(SciSpan<byte> &bitmapPtr, int16 width, int16 height
 	// Walk through the bitmap and remember all combinations of colors
 	int16 ditheredBitmapColors[DITHERED_BG_COLORS_SIZE];
 	byte color1, color2;
-	byte nextColor1, nextColor2;
-	int16 y, x;
 
 	memset(&ditheredBitmapColors, 0, sizeof(ditheredBitmapColors));
 
@@ -724,12 +720,13 @@ void GfxView::unditherBitmap(SciSpan<byte> &bitmapPtr, int16 width, int16 height
 	int16 checkHeight = height - 1;
 	byte *curPtr = bitmapPtr.getUnsafeDataAt(0, checkHeight * width);
 	const byte *nextPtr = bitmapPtr.getUnsafeDataAt(width, checkHeight * width);
-	for (y = 0; y < checkHeight; y++) {
+	for (int16 y = 0; y < checkHeight; y++) {
 		color1 = curPtr[0]; color2 = (curPtr[1] << 4) | curPtr[2];
-		nextColor1 = nextPtr[0] << 4; nextColor2 = (nextPtr[2] << 4) | nextPtr[1];
+		byte nextColor1 = nextPtr[0] << 4;
+		byte nextColor2 = (nextPtr[2] << 4) | nextPtr[1];
 		curPtr += 3;
 		nextPtr += 3;
-		for (x = 3; x < width; x++) {
+		for (int16 x = 3; x < width; x++) {
 			color1 = (color1 << 4) | (color2 >> 4);
 			color2 = (color2 << 4) | *curPtr++;
 			nextColor1 = (nextColor1 >> 4) | (nextColor2 << 4);
@@ -764,9 +761,9 @@ void GfxView::unditherBitmap(SciSpan<byte> &bitmapPtr, int16 width, int16 height
 
 	// We now need to replace color-combinations
 	curPtr = bitmapPtr.getUnsafeDataAt(0, height * width);
-	for (y = 0; y < height; y++) {
+	for (int16 y = 0; y < height; y++) {
 		color = curPtr[0];
-		for (x = 1; x < width; x++) {
+		for (int16 x = 1; x < width; x++) {
 			color = (color << 4) | curPtr[1];
 			if (unditherTable[color]) {
 				// Some color with black? Turn colors around, otherwise it won't
diff --git a/engines/sci/metaengine.cpp b/engines/sci/metaengine.cpp
index c3fc3bdaddf..367293c740e 100644
--- a/engines/sci/metaengine.cpp
+++ b/engines/sci/metaengine.cpp
@@ -339,10 +339,9 @@ SaveStateList SciMetaEngine::listSaves(const char *target) const {
 
 	SaveStateList saveList;
 	bool hasAutosave = false;
-	int slotNr = 0;
 	for (Common::StringArray::const_iterator file = filenames.begin(); file != filenames.end(); ++file) {
 		// Obtain the last 3 digits of the filename, since they correspond to the save slot
-		slotNr = atoi(file->c_str() + file->size() - 3);
+		int slotNr = atoi(file->c_str() + file->size() - 3);
 
 		if (slotNr >= 0 && slotNr <= 99) {
 			Common::InSaveFile *in = saveFileMan->openForLoading(*file);
diff --git a/engines/sci/resource/resource.cpp b/engines/sci/resource/resource.cpp
index 71f6719b575..1c45463aee3 100644
--- a/engines/sci/resource/resource.cpp
+++ b/engines/sci/resource/resource.cpp
@@ -1346,16 +1346,13 @@ ResVersion ResourceManager::detectMapVersion() {
 
 	// SCI1 and SCI1.1 maps consist of a fixed 3-byte header, a directory list (3-bytes each) that has one entry
 	// of id FFh and points to EOF. The actual entries have 6-bytes on SCI1 and 5-bytes on SCI1.1
-	byte directoryType = 0;
-	uint16 directoryOffset = 0;
 	uint16 lastDirectoryOffset = 0;
-	uint16 directorySize = 0;
 	ResVersion mapDetected = kResVersionUnknown;
 	fileStream->seek(0, SEEK_SET);
 
 	while (!fileStream->eos()) {
-		directoryType = fileStream->readByte();
-		directoryOffset = fileStream->readUint16LE();
+		byte directoryType = fileStream->readByte();
+		uint16 directoryOffset = fileStream->readUint16LE();
 
 		// Only SCI32 has directory type < 0x80
 		if (directoryType < 0x80 && (mapDetected == kResVersionUnknown || mapDetected == kResVersionSci2))
@@ -1368,7 +1365,7 @@ ResVersion ResourceManager::detectMapVersion() {
 			break;
 
 		if (lastDirectoryOffset && mapDetected == kResVersionUnknown) {
-			directorySize = directoryOffset - lastDirectoryOffset;
+			uint16 directorySize = directoryOffset - lastDirectoryOffset;
 			if ((directorySize % 5) && (directorySize % 6 == 0))
 				mapDetected = kResVersionSci1Late;
 			if ((directorySize % 5 == 0) && (directorySize % 6))
@@ -1431,8 +1428,6 @@ ResVersion ResourceManager::detectVolVersion() {
 	// SCI32 volume format:   {bResType wResNumber dwPacked dwUnpacked wCompression} = 13 bytes
 	// Try to parse volume with SCI0 scheme to see if it make sense
 	// Checking 1MB of data should be enough to determine the version
-	uint16 wCompression;
-	uint32 dwPacked, dwUnpacked;
 	ResVersion curVersion = kResVersionSci0Sci1Early;
 	bool failed = false;
 	bool sci11Align = false;
@@ -1442,15 +1437,15 @@ ResVersion ResourceManager::detectVolVersion() {
 		if (curVersion > kResVersionSci0Sci1Early)
 			fileStream->readByte();
 		fileStream->skip(2);	// resId
-		dwPacked = (curVersion < kResVersionSci2) ? fileStream->readUint16LE() : fileStream->readUint32LE();
-		dwUnpacked = (curVersion < kResVersionSci2) ? fileStream->readUint16LE() : fileStream->readUint32LE();
+		uint32 dwPacked = (curVersion < kResVersionSci2) ? fileStream->readUint16LE() : fileStream->readUint32LE();
+		uint32 dwUnpacked = (curVersion < kResVersionSci2) ? fileStream->readUint16LE() : fileStream->readUint32LE();
 
 		// The compression field is present, but bogus when
 		// loading SCI3 volumes, the format is otherwise
 		// identical to SCI2. We therefore get the compression
 		// indicator here, but disregard it in the following
 		// code.
-		wCompression = fileStream->readUint16LE();
+		uint16 wCompression = fileStream->readUint16LE();
 
 		if (fileStream->eos()) {
 			delete fileStream;
@@ -1871,8 +1866,6 @@ void ResourceManager::readResourcePatches() {
 int ResourceManager::readResourceMapSCI0(ResourceSource *map) {
 	Common::SeekableReadStream *fileStream = nullptr;
 	ResourceType type = kResourceTypeInvalid;	// to silence a false positive in MSVC
-	uint16 number, id;
-	uint32 offset;
 
 	if (map->_resourceFile) {
 		fileStream = map->_resourceFile->createReadStream();
@@ -1898,8 +1891,8 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) {
 		if (_mapVersion == kResVersionKQ5FMT)
 			type = convertResType(fileStream->readByte());
 
-		id = fileStream->readUint16LE();
-		offset = fileStream->readUint32LE();
+		uint16 id = fileStream->readUint16LE();
+		uint32 offset = fileStream->readUint32LE();
 
 		if (fileStream->eos() || fileStream->err()) {
 			delete fileStream;
@@ -1910,6 +1903,7 @@ int ResourceManager::readResourceMapSCI0(ResourceSource *map) {
 		if (offset == 0xFFFFFFFF)
 			break;
 
+		uint16 number;
 		if (_mapVersion == kResVersionKQ5FMT) {
 			number = id;
 		} else {
diff --git a/engines/sci/sound/drivers/macmixer.h b/engines/sci/sound/drivers/macmixer.h
index f4aff6db6b1..18a493578f5 100644
--- a/engines/sci/sound/drivers/macmixer.h
+++ b/engines/sci/sound/drivers/macmixer.h
@@ -216,10 +216,9 @@ int Mixer_Mac<T>::readBuffer(int16 *data, const int numSamples) {
 
 	const int stereoFactor = isStereo() ? 2 : 1;
 	int len = numSamples / stereoFactor;
-	int step;
 
 	do {
-		step = len;
+		int step = len;
 		if (step > ufracToUint(_nextTick))
 			step = ufracToUint(_nextTick);
 
diff --git a/engines/sci/sound/drivers/pcjr.cpp b/engines/sci/sound/drivers/pcjr.cpp
index 866bd579ad5..c1fd4c1de56 100644
--- a/engines/sci/sound/drivers/pcjr.cpp
+++ b/engines/sci/sound/drivers/pcjr.cpp
@@ -98,14 +98,13 @@ void MidiDriver_PCJr::send(uint32 b) {
 	byte command = b & 0xff;
 	byte op1 = (b >> 8) & 0xff;
 	byte op2 = (b >> 16) & 0xff;
-	int i;
 	int mapped_chan = -1;
 	int chan_nr = command & 0xf;
 
 	// First, test for channel having been assigned already
 	if (_channels_assigned & (1 << chan_nr)) {
 		// Already assigned this channel number:
-		for (i = 0; i < _channels_nr; i++)
+		for (int i = 0; i < _channels_nr; i++)
 			if (_chan_nrs[i] == chan_nr) {
 				mapped_chan = i;
 				break;
diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp
index 72b544b8179..73e2f535aa7 100644
--- a/engines/sci/sound/music.cpp
+++ b/engines/sci/sound/music.cpp
@@ -424,7 +424,6 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
 		}
 	}
 
-	int channelFilterMask = 0;
 	SoundResource::Track *track = pSnd->soundRes->getTrackByType(_pMidiDrv->getPlayId());
 
 	// If MIDI device is selected but there is no digital track in sound
@@ -493,7 +492,7 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
 			pSnd->pauseCounter = 0;
 
 			// Find out what channels to filter for SCI0
-			channelFilterMask = pSnd->soundRes->getChannelFilterMask(_pMidiDrv->getPlayId(), _pMidiDrv->hasRhythmChannel());
+			int channelFilterMask = pSnd->soundRes->getChannelFilterMask(_pMidiDrv->getPlayId(), _pMidiDrv->hasRhythmChannel());
 
 			for (int i = 0; i < 16; ++i) {
 				pSnd->_usedChannels[i] = 0xFF;


Commit: cd319125efe4135416b008e74c5c63404e656784
    https://github.com/scummvm/scummvm/commit/cd319125efe4135416b008e74c5c63404e656784
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2023-11-03T15:12:41-07:00

Commit Message:
SCI: More const ref parameters

Changed paths:
    engines/sci/console.cpp
    engines/sci/engine/message.cpp
    engines/sci/engine/message.h
    engines/sci/graphics/menu.cpp
    engines/sci/graphics/menu.h
    engines/sci/graphics/portrait.cpp
    engines/sci/graphics/portrait.h
    engines/sci/metaengine.cpp


diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp
index 3e41907fa8a..71473205379 100644
--- a/engines/sci/console.cpp
+++ b/engines/sci/console.cpp
@@ -4172,7 +4172,7 @@ bool Console::cmdBreakpointDelete(int argc, const char **argv) {
 	return true;
 }
 
-static bool stringToBreakpointAction(Common::String str, BreakpointAction &action) {
+static bool stringToBreakpointAction(const Common::String &str, BreakpointAction &action) {
 	if (str == "break")
 		action = BREAK_BREAK;
 	else if (str == "log")
diff --git a/engines/sci/engine/message.cpp b/engines/sci/engine/message.cpp
index b577f2dd3c0..71ca61bef30 100644
--- a/engines/sci/engine/message.cpp
+++ b/engines/sci/engine/message.cpp
@@ -309,7 +309,7 @@ bool MessageState::getRecord(CursorStack &stack, bool recurse, MessageRecord &re
 	}
 }
 
-int MessageState::getMessage(int module, MessageTuple &t, reg_t buf) {
+int MessageState::getMessage(int module, const MessageTuple &t, reg_t buf) {
 	_cursorStack.init(module, t);
 	return nextMessage(buf);
 }
diff --git a/engines/sci/engine/message.h b/engines/sci/engine/message.h
index 9a43e27fc00..5ff454c8313 100644
--- a/engines/sci/engine/message.h
+++ b/engines/sci/engine/message.h
@@ -68,7 +68,7 @@ typedef Common::Stack<CursorStack> CursorStackStack;
 class MessageState {
 public:
 	MessageState(SegManager *segMan) : _segMan(segMan), _lastReturnedModule(0) { }
-	int getMessage(int module, MessageTuple &t, reg_t buf);
+	int getMessage(int module, const MessageTuple &t, reg_t buf);
 	int nextMessage(reg_t buf);
 	int messageSize(int module, MessageTuple &t);
 	bool messageRef(int module, const MessageTuple &t, MessageTuple &ref);
diff --git a/engines/sci/graphics/menu.cpp b/engines/sci/graphics/menu.cpp
index facbe297a26..b5e73d67268 100644
--- a/engines/sci/graphics/menu.cpp
+++ b/engines/sci/graphics/menu.cpp
@@ -73,7 +73,7 @@ void GfxMenu::reset() {
 	_curItemId = 1;
 }
 
-void GfxMenu::kernelAddEntry(Common::String title, Common::String content, reg_t contentVmPtr) {
+void GfxMenu::kernelAddEntry(const Common::String &title, Common::String content, reg_t contentVmPtr) {
 	uint16 itemCount = 0;
 	const int contentSize = content.size();
 
diff --git a/engines/sci/graphics/menu.h b/engines/sci/graphics/menu.h
index a4a5adf9ed7..1e4493ed00a 100644
--- a/engines/sci/graphics/menu.h
+++ b/engines/sci/graphics/menu.h
@@ -83,7 +83,7 @@ public:
 	~GfxMenu();
 
 	void reset();
-	void kernelAddEntry(Common::String title, Common::String content, reg_t contentVmPtr);
+	void kernelAddEntry(const Common::String &title, Common::String content, reg_t contentVmPtr);
 	void kernelSetAttribute(uint16 menuId, uint16 itemId, uint16 attributeId, reg_t value);
 	reg_t kernelGetAttribute(uint16 menuId, uint16 itemId, uint16 attributeId);
 
diff --git a/engines/sci/graphics/portrait.cpp b/engines/sci/graphics/portrait.cpp
index cbed86f31fe..22243b16120 100644
--- a/engines/sci/graphics/portrait.cpp
+++ b/engines/sci/graphics/portrait.cpp
@@ -33,7 +33,7 @@
 
 namespace Sci {
 
-Portrait::Portrait(ResourceManager *resMan, EventManager *event, GfxScreen *screen, GfxPalette *palette, AudioPlayer *audio, Common::String resourceName)
+Portrait::Portrait(ResourceManager *resMan, EventManager *event, GfxScreen *screen, GfxPalette *palette, AudioPlayer *audio, const Common::String &resourceName)
 	: _resMan(resMan), _event(event), _screen(screen), _palette(palette), _audio(audio), _resourceName(resourceName) {
 	init();
 }
diff --git a/engines/sci/graphics/portrait.h b/engines/sci/graphics/portrait.h
index 530e7528d1e..fc0e6bda29c 100644
--- a/engines/sci/graphics/portrait.h
+++ b/engines/sci/graphics/portrait.h
@@ -40,7 +40,7 @@ struct PortraitBitmap {
  */
 class Portrait {
 public:
-	Portrait(ResourceManager *resMan, EventManager *event, GfxScreen *screen, GfxPalette *palette, AudioPlayer *audio, Common::String resourceName);
+	Portrait(ResourceManager *resMan, EventManager *event, GfxScreen *screen, GfxPalette *palette, AudioPlayer *audio, const Common::String &resourceName);
 
 	void setupAudio(uint16 resourceId, uint16 noun, uint16 verb, uint16 cond, uint16 seq);
 	void doit(Common::Point position, uint16 resourceId, uint16 noun, uint16 verb, uint16 cond, uint16 seq);
diff --git a/engines/sci/metaengine.cpp b/engines/sci/metaengine.cpp
index 367293c740e..811f2bead01 100644
--- a/engines/sci/metaengine.cpp
+++ b/engines/sci/metaengine.cpp
@@ -154,7 +154,7 @@ static const DemoIdEntry s_demoIdTable[] = {
 	{ nullptr,      nullptr }
 };
 
-static bool isSierraDemo(Common::String &sierraId, uint32 resourceCount) {
+static bool isSierraDemo(const Common::String &sierraId, uint32 resourceCount) {
 	// If the game has less than the expected scripts, it's a demo
 	uint32 demoThreshold = 100;
 	// ...but there are some exceptions
@@ -591,7 +591,7 @@ bool isSciCDVersion(const AdvancedMetaEngine::FileMap &allFiles) {
 	return false;
 }
 
-void constructFallbackDetectionEntry(Common::String &gameId, Common::Platform platform, SciVersion sciVersion, Common::Language language, bool hasEgaViews, bool isCD, bool isDemo) {
+void constructFallbackDetectionEntry(const Common::String &gameId, Common::Platform platform, SciVersion sciVersion, Common::Language language, bool hasEgaViews, bool isCD, bool isDemo) {
 	Common::strlcpy(s_fallbackGameIdBuf, gameId.c_str(), sizeof(s_fallbackGameIdBuf));
 
 	s_fallbackDesc.extra = "";


Commit: 1f4124b1212f2795da2e4ee43314bea1b30074ff
    https://github.com/scummvm/scummvm/commit/1f4124b1212f2795da2e4ee43314bea1b30074ff
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2023-11-03T15:12:41-07:00

Commit Message:
SCI: Remove or disable unused functions

Changed paths:
    engines/sci/graphics/maciconbar.cpp
    engines/sci/graphics/maciconbar.h
    engines/sci/graphics/palette.cpp
    engines/sci/graphics/palette.h
    engines/sci/graphics/picture.cpp
    engines/sci/graphics/picture.h
    engines/sci/graphics/screen.cpp
    engines/sci/graphics/text16.cpp
    engines/sci/graphics/text16.h
    engines/sci/graphics/transitions32.cpp
    engines/sci/graphics/transitions32.h
    engines/sci/resource/resource.cpp
    engines/sci/resource/resource.h
    engines/sci/resource/resource_audio.cpp


diff --git a/engines/sci/graphics/maciconbar.cpp b/engines/sci/graphics/maciconbar.cpp
index 4c8fcd1b932..383f3c32597 100644
--- a/engines/sci/graphics/maciconbar.cpp
+++ b/engines/sci/graphics/maciconbar.cpp
@@ -211,10 +211,6 @@ void GfxMacIconBar::drawImage(Graphics::Surface *surface, const Common::Rect &re
 	}
 }
 
-void GfxMacIconBar::drawSelectedImage(uint16 iconIndex) {
-	drawImage(_iconBarItems[iconIndex].selectedImage, _iconBarItems[iconIndex].rect, true);
-}
-
 bool GfxMacIconBar::isIconEnabled(uint16 iconIndex) const {
 	if (iconIndex >= _iconBarItems.size())
 		return false;
diff --git a/engines/sci/graphics/maciconbar.h b/engines/sci/graphics/maciconbar.h
index 8df712173d6..386f8fe8445 100644
--- a/engines/sci/graphics/maciconbar.h
+++ b/engines/sci/graphics/maciconbar.h
@@ -68,7 +68,6 @@ private:
 	void freeIcons();
 	void addIcon(reg_t obj);
 	void drawIcon(uint16 index, bool selected);
-	void drawSelectedImage(uint16 index);
 	bool isIconEnabled(uint16 index) const;
 	void drawDisabledPattern(Graphics::Surface &surface, const Common::Rect &rect);
 	void drawImage(Graphics::Surface *surface, const Common::Rect &rect, bool enabled);
diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp
index 98f321708e6..754cb81da50 100644
--- a/engines/sci/graphics/palette.cpp
+++ b/engines/sci/graphics/palette.cpp
@@ -489,11 +489,6 @@ uint16 GfxPalette::matchColor(byte matchRed, byte matchGreen, byte matchBlue, bo
 	return bestColorNr;
 }
 
-void GfxPalette::getSys(Palette *pal) {
-	if (pal != &_sysPalette)
-		memcpy(pal, &_sysPalette,sizeof(Palette));
-}
-
 void GfxPalette::setOnScreen(bool update) {
 	copySysPaletteToScreen(update);
 }
diff --git a/engines/sci/graphics/palette.h b/engines/sci/graphics/palette.h
index b97d373bacd..221c0e7a667 100644
--- a/engines/sci/graphics/palette.h
+++ b/engines/sci/graphics/palette.h
@@ -55,7 +55,6 @@ public:
 	bool insert(Palette *newPalette, Palette *destPalette, bool includeFirstColor = false);
 	bool merge(Palette *pFrom, bool force, bool forceRealMerge);
 	uint16 matchColor(byte r, byte g, byte b, bool force16BitColorMatch = false);
-	void getSys(Palette *pal);
 	uint16 getTotalColorCount() const { return _totalScreenColors; }
 
 	// Set palette on screen. If update is false, try not to change the palette
diff --git a/engines/sci/graphics/picture.cpp b/engines/sci/graphics/picture.cpp
index fd50ae8d7cf..2e87736e1c3 100644
--- a/engines/sci/graphics/picture.cpp
+++ b/engines/sci/graphics/picture.cpp
@@ -80,6 +80,7 @@ void GfxPicture::draw(bool mirroredFlag, bool addToFlag, int16 EGApaletteNo) {
 	}
 }
 
+#if 0
 void GfxPicture::reset() {
 	int16 startY = _ports->getPort()->top;
 	int16 startX = 0;
@@ -91,6 +92,7 @@ void GfxPicture::reset() {
 		}
 	}
 }
+#endif
 
 void GfxPicture::drawSci11Vga() {
 	SciSpan<const byte> inbuffer(*_resource);
diff --git a/engines/sci/graphics/picture.h b/engines/sci/graphics/picture.h
index 261e1d11ccf..c46e7453e33 100644
--- a/engines/sci/graphics/picture.h
+++ b/engines/sci/graphics/picture.h
@@ -57,7 +57,9 @@ public:
 
 private:
 	void initData(GuiResourceId resourceId);
+#if 0
 	void reset();
+#endif
 	void drawSci11Vga();
 	void drawCelData(const SciSpan<const byte> &inbuffer, int headerPos, int rlePos, int literalPos, int16 drawX, int16 drawY, int16 pictureX, int16 pictureY, bool isEGA);
 	void drawVectorData(const SciSpan<const byte> &data);
diff --git a/engines/sci/graphics/screen.cpp b/engines/sci/graphics/screen.cpp
index 8da7f0a80a1..3a897558321 100644
--- a/engines/sci/graphics/screen.cpp
+++ b/engines/sci/graphics/screen.cpp
@@ -1005,12 +1005,6 @@ void GfxScreen::scale2x(const SciSpan<const byte> &src, SciSpan<byte> &dst, int1
 	}
 }
 
-struct UpScaledAdjust {
-	GfxScreenUpscaledMode gameHiresMode;
-	int numerator;
-	int denominator;
-};
-
 void GfxScreen::adjustToUpscaledCoordinates(int16 &y, int16 &x) {
 	x = _upscaledWidthMapping[x];
 	y = _upscaledHeightMapping[y];
diff --git a/engines/sci/graphics/text16.cpp b/engines/sci/graphics/text16.cpp
index dffb581459b..607aa927f27 100644
--- a/engines/sci/graphics/text16.cpp
+++ b/engines/sci/graphics/text16.cpp
@@ -77,6 +77,7 @@ void GfxText16::SetFont(GuiResourceId fontId) {
 	_ports->_curPort->fontHeight = _font->getHeight();
 }
 
+#if 0
 void GfxText16::ClearChar(int16 chr) {
 	if (_ports->_curPort->penMode != 1)
 		return;
@@ -87,6 +88,7 @@ void GfxText16::ClearChar(int16 chr) {
 	rect.right = rect.left + GetFont()->getCharWidth(chr);
 	_paint16->eraseRect(rect);
 }
+#endif
 
 // This internal function gets called as soon as a '|' is found in a text. It
 // will process the encountered code and set new font/set color.
@@ -433,9 +435,12 @@ void GfxText16::StringWidth(const Common::String &str, GuiResourceId orgFontId,
 	Width(str.c_str(), 0, str.size(), orgFontId, textWidth, textHeight, true);
 }
 
+#if 0
 void GfxText16::ShowString(const Common::String &str, GuiResourceId orgFontId, int16 orgPenColor) {
 	Show(str.c_str(), 0, str.size(), orgFontId, orgPenColor);
 }
+#endif
+
 void GfxText16::DrawString(const Common::String &str, GuiResourceId orgFontId, int16 orgPenColor) {
 	Draw(str.c_str(), 0, str.size(), orgFontId, orgPenColor);
 }
diff --git a/engines/sci/graphics/text16.h b/engines/sci/graphics/text16.h
index 833332a3dc7..09ea718e30d 100644
--- a/engines/sci/graphics/text16.h
+++ b/engines/sci/graphics/text16.h
@@ -53,12 +53,16 @@ public:
 
 	int16 CodeProcessing(const char *&text, GuiResourceId orgFontId, int16 orgPenColor, bool doingDrawing);
 
+#if 0
 	void ClearChar(int16 chr);
+#endif
 
 	int16 GetLongest(const char *&text, int16 maxWidth, GuiResourceId orgFontId);
 	void Width(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight, bool restoreFont);
 	void StringWidth(const Common::String &str, GuiResourceId orgFontId, int16 &textWidth, int16 &textHeight);
+#if 0
 	void ShowString(const Common::String &str, GuiResourceId orgFontId, int16 orgPenColor);
+#endif
 	void DrawString(const Common::String &str, GuiResourceId orgFontId, int16 orgPenColor);
 	int16 Size(Common::Rect &rect, const char *text, uint16 textLanguage, GuiResourceId fontId, int16 maxWidth);
 	void Draw(const char *text, int16 from, int16 len, GuiResourceId orgFontId, int16 orgPenColor);
diff --git a/engines/sci/graphics/transitions32.cpp b/engines/sci/graphics/transitions32.cpp
index 9911db989a9..daa1e168949 100644
--- a/engines/sci/graphics/transitions32.cpp
+++ b/engines/sci/graphics/transitions32.cpp
@@ -734,9 +734,11 @@ bool GfxTransitions32::processIrisIn(PlaneShowStyle &showStyle) {
 	return processWipe(1, showStyle);
 }
 
+#if 0
 void GfxTransitions32::processDissolveNoMorph(PlaneShowStyle &showStyle) {
 	error("DissolveNoMorph is not known to be used by any game. Please submit a bug report with details about the game you were playing and what you were doing that triggered this error. Thanks!");
 }
+#endif
 
 inline int bitWidth(int number) {
 	int width = 0;
diff --git a/engines/sci/graphics/transitions32.h b/engines/sci/graphics/transitions32.h
index 817c4215a21..a588b892992 100644
--- a/engines/sci/graphics/transitions32.h
+++ b/engines/sci/graphics/transitions32.h
@@ -392,11 +392,13 @@ private:
 	 */
 	bool processIrisIn(PlaneShowStyle &showStyle);
 
+#if 0
 	/**
 	 * Performs a transition that renders between rooms using a block dissolve
 	 * effect.
 	 */
 	void processDissolveNoMorph(PlaneShowStyle &showStyle);
+#endif
 
 	/**
 	 * Performs a transition that renders between rooms with a pixel dissolve
diff --git a/engines/sci/resource/resource.cpp b/engines/sci/resource/resource.cpp
index 1c45463aee3..59ae2119701 100644
--- a/engines/sci/resource/resource.cpp
+++ b/engines/sci/resource/resource.cpp
@@ -1147,23 +1147,6 @@ void ResourceManager::addToLRU(Resource *res) {
 	res->_status = kResStatusEnqueued;
 }
 
-void ResourceManager::printLRU() {
-	int mem = 0;
-	int entries = 0;
-	Common::List<Resource *>::iterator it = _LRU.begin();
-	Resource *res;
-
-	while (it != _LRU.end()) {
-		res = *it;
-		debug("\t%s: %u bytes", res->_id.toString().c_str(), res->size());
-		mem += res->size();
-		++entries;
-		++it;
-	}
-
-	debug("Total: %d entries, %d bytes (mgr says %d)", entries, mem, _memoryLRU);
-}
-
 void ResourceManager::freeOldResources() {
 	while (_maxMemoryLRU < _memoryLRU) {
 		assert(!_LRU.empty());
diff --git a/engines/sci/resource/resource.h b/engines/sci/resource/resource.h
index 855fe8bec42..4798d704c2f 100644
--- a/engines/sci/resource/resource.h
+++ b/engines/sci/resource/resource.h
@@ -643,7 +643,6 @@ protected:
 	 */
 	bool hasOldScriptHeader();
 
-	void printLRU();
 	void addToLRU(Resource *res);
 	void removeFromLRU(Resource *res);
 
@@ -711,7 +710,9 @@ public:
 	Track *getTrackByType(byte type);
 	Track *getDigitalTrack();
 	int getChannelFilterMask(int hardwareMask, bool wantsRhythm);
+#if 0
 	byte getInitialVoiceCount(byte channel);
+#endif
 	byte getSoundPriority() const { return _soundPriority; }
 	bool exists() const { return _resource != nullptr; }
 
diff --git a/engines/sci/resource/resource_audio.cpp b/engines/sci/resource/resource_audio.cpp
index 6b10af29201..4dde944645f 100644
--- a/engines/sci/resource/resource_audio.cpp
+++ b/engines/sci/resource/resource_audio.cpp
@@ -1080,6 +1080,7 @@ int SoundResource::getChannelFilterMask(int hardwareMask, bool wantsRhythm) {
 	return channelMask;
 }
 
+#if 0
 byte SoundResource::getInitialVoiceCount(byte channel) {
 	if (_soundVersion > SCI_VERSION_0_LATE)
 		return 0; // TODO
@@ -1092,6 +1093,7 @@ byte SoundResource::getInitialVoiceCount(byte channel) {
 	else
 		return data[channel * 2];
 }
+#endif
 
 void WaveResourceSource::loadResource(ResourceManager *resMan, Resource *res) {
 	Common::SeekableReadStream *fileStream = getVolumeFile(resMan, res);


Commit: 7da3c93c14369f035ff8ad7b7a7166e756009d57
    https://github.com/scummvm/scummvm/commit/7da3c93c14369f035ff8ad7b7a7166e756009d57
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2023-11-03T15:12:42-07:00

Commit Message:
SCI: Remove unused variable from kDoBresen

Changed paths:
    engines/sci/engine/kmovement.cpp


diff --git a/engines/sci/engine/kmovement.cpp b/engines/sci/engine/kmovement.cpp
index e56d5199447..8872e4307a4 100644
--- a/engines/sci/engine/kmovement.cpp
+++ b/engines/sci/engine/kmovement.cpp
@@ -344,8 +344,6 @@ reg_t kDoBresen(EngineState *s, int argc, reg_t *argv) {
 
 		// Now call client::canBeHere/client::cantBehere to check for collisions
 		bool collision = false;
-		reg_t cantBeHere = NULL_REG;
-
 		// adding this here for hoyle 3 to get happy. CantBeHere is a dummy in hoyle 3 and acc is != 0 so we would
 		//  get a collision otherwise. Resetting the result was always done in SSCI
 		s->r_acc = NULL_REG;
@@ -353,7 +351,6 @@ reg_t kDoBresen(EngineState *s, int argc, reg_t *argv) {
 			invokeSelector(s, client, SELECTOR(cantBeHere), argc, argv);
 			if (!s->r_acc.isNull())
 				collision = true;
-			cantBeHere = s->r_acc;
 		} else {
 			invokeSelector(s, client, SELECTOR(canBeHere), argc, argv);
 			if (s->r_acc.isNull())




More information about the Scummvm-git-logs mailing list