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

Strangerke noreply at scummvm.org
Sat Jun 21 05:29:50 UTC 2025


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

Summary:
cb23480344 M4: Reduce some variable scopes, some cleanup and constification in the gui
ea6d26eb89 M4: Remove useless code in mouse_set_sprite(), cleanup


Commit: cb23480344d3c3cd65aa37a68d2b2bf9aa66143e
    https://github.com/scummvm/scummvm/commit/cb23480344d3c3cd65aa37a68d2b2bf9aa66143e
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-06-21T06:27:36+01:00

Commit Message:
M4: Reduce some variable scopes, some cleanup and constification in the gui

Changed paths:
    engines/m4/gui/gui_menu_items.h
    engines/m4/gui/gui_mouse.cpp
    engines/m4/gui/gui_sys.cpp
    engines/m4/gui/gui_univ.h
    engines/m4/gui/gui_vmng_core.cpp
    engines/m4/gui/gui_vmng_rectangles.cpp
    engines/m4/gui/gui_vmng_screen.cpp
    engines/m4/gui/hotkeys.cpp


diff --git a/engines/m4/gui/gui_menu_items.h b/engines/m4/gui/gui_menu_items.h
index 603a9efeef4..ce7ae97191e 100644
--- a/engines/m4/gui/gui_menu_items.h
+++ b/engines/m4/gui/gui_menu_items.h
@@ -27,6 +27,7 @@
 #include "m4/m4_types.h"
 #include "m4/graphics/gr_buff.h"
 #include "m4/gui/gui_univ.h"
+#include "m4/graphics/gr_font.h"
 
 namespace M4 {
 
diff --git a/engines/m4/gui/gui_mouse.cpp b/engines/m4/gui/gui_mouse.cpp
index c5837b152b8..24c1300962c 100644
--- a/engines/m4/gui/gui_mouse.cpp
+++ b/engines/m4/gui/gui_mouse.cpp
@@ -96,31 +96,25 @@ void transShow(void *s, void *r, void *b, int32 destX, int32 destY) {
 	ScreenContext *myScreen = (ScreenContext *)s;
 	matte *myRectList = (matte *)r;
 	Buffer *destBuffer = (Buffer *)b;
-	ScreenContext *tempScreen;
-	transSprite *mySource;
-	M4sprite *mySprite;
-	Buffer *myBuff;
 	Buffer drawSpriteBuff;
 	DrawRequest spriteDrawReq;
 	matte *myMatte, tempMatte;
 	RectList *updateList, *updateRect;
 	RectList *newUpdateList;
-	uint8 *rowPtr, *destPtr;
-	int32 i, j;
 
 	// Parameter verification
 	if (!myScreen)
 		return;
 
-	mySource = (transSprite *)(myScreen->scrnContent);
+	transSprite *mySource = (transSprite *)(myScreen->scrnContent);
 	if (!mySource)
 		return;
 
-	myBuff = (Buffer *)(mySource->scrnBuffer);
+	Buffer *myBuff = (Buffer *)(mySource->scrnBuffer);
 	if (!myBuff)
 		return;
 
-	mySprite = mySource->srcSprite;
+	M4sprite *mySprite = mySource->srcSprite;
 	if (!mySprite)
 		return;
 
@@ -138,7 +132,7 @@ void transShow(void *s, void *r, void *b, int32 destX, int32 destY) {
 			updateList->next = nullptr;
 
 			// Now loop through all the screens behind myScreen
-			tempScreen = myScreen->behind;
+			ScreenContext *tempScreen = myScreen->behind;
 			while (tempScreen && updateList) {
 				// Duplicate the updateList
 				newUpdateList = vmng_DuplicateRectList(updateList);
@@ -165,7 +159,7 @@ void transShow(void *s, void *r, void *b, int32 destX, int32 destY) {
 				}
 
 				// The newUpdateList now contains all the pieces not covered by tempScreen;
-				// turf the update list, and replace it with the newupdateList
+				// turf the update list, and replace it with the newUpdateList
 				vmng_DisposeRectList(&updateList);
 				updateList = newUpdateList;
 
@@ -220,13 +214,13 @@ void transShow(void *s, void *r, void *b, int32 destX, int32 destY) {
 			// Else the data for the transparent sprite is stored directly in mySprite->data
 
 			// Loop through the rows
-			for (j = 0; (j < mySprite->h) && (j < myBuff->h); j++) {
+			for (int32 j = 0; (j < mySprite->h) && (j < myBuff->h); j++) {
 				// Set the rowPtr and the destPtr
-				rowPtr = mySprite->data + (j * mySprite->w);
-				destPtr = myBuff->data + (j * myBuff->stride);
+				uint8 *rowPtr = mySprite->data + (j * mySprite->w);
+				uint8 *destPtr = myBuff->data + (j * myBuff->stride);
 
 				// Loop through the columns
-				for (i = 0; (i < mySprite->w) && (i < myBuff->w); i++) {
+				for (int32 i = 0; (i < mySprite->w) && (i < myBuff->w); i++) {
 					if (*rowPtr) {
 						*destPtr = *rowPtr;
 					}
@@ -257,7 +251,6 @@ void transShow(void *s, void *r, void *b, int32 destX, int32 destY) {
 
 bool mouse_set_sprite(int32 spriteNum) {
 	M4sprite *tempSprite;
-	int32 minX, minY, maxX, maxY;
 
 	if (_G(mouseIsLocked)) {
 		_G(newMouseNum) = spriteNum;
@@ -271,10 +264,10 @@ bool mouse_set_sprite(int32 spriteNum) {
 	if (!_G(mouseSeriesHandle) || !*_G(mouseSeriesHandle))
 		return false;
 
-	minX = _G(oldX) - _G(mouseX1offset);
-	minY = _G(oldY) - _G(mouseY1offset);
-	maxX = _G(oldX) + _G(mouseX2offset);
-	maxY = _G(oldY) + _G(mouseY2offset);
+	int32 minX = _G(oldX) - _G(mouseX1offset);
+	int32 minY = _G(oldY) - _G(mouseY1offset);
+	int32 maxX = _G(oldX) + _G(mouseX2offset);
+	int32 maxY = _G(oldY) + _G(mouseY2offset);
 
 	if ((tempSprite = CreateSprite(_G(mouseSeriesHandle), _G(mouseSeriesOffset), spriteNum,
 			_G(mouseSprite), nullptr)) == nullptr)
diff --git a/engines/m4/gui/gui_sys.cpp b/engines/m4/gui/gui_sys.cpp
index 61c755dc8d3..62be33ada4f 100644
--- a/engines/m4/gui/gui_sys.cpp
+++ b/engines/m4/gui/gui_sys.cpp
@@ -23,7 +23,6 @@
 #include "m4/gui/gui_dialog.h"
 #include "m4/gui/gui_event.h"
 #include "m4/gui/gui_vmng.h"
-#include "m4/core/mouse.h"
 #include "m4/mem/memman.h"
 #include "m4/vars.h"
 
@@ -37,10 +36,8 @@ bool gui_system_init() {
 }
 
 void gui_system_shutdown() {
-	Hotkey *myHotkeys, *tempHotkey;
-
-	myHotkeys = _G(systemHotkeys);
-	tempHotkey = myHotkeys;
+	Hotkey *myHotkeys = _G(systemHotkeys);
+	Hotkey *tempHotkey = myHotkeys;
 
 	while (tempHotkey) {
 		myHotkeys = myHotkeys->next;
@@ -50,12 +47,9 @@ void gui_system_shutdown() {
 }
 
 void gui_system_event_handler() {
-	MouseEvent newMouseEvent;
-
 	ScreenContext *myScreen;
 	Hotkey *myHotkey;
 	int32 parm1 = 0;
-	bool handled;
 	bool blocked;
 	bool found;
 
@@ -76,7 +70,7 @@ void gui_system_event_handler() {
 	_G(mouseX) = _G(MouseState).CursorColumn;
 	_G(mouseY) = _G(MouseState).CursorRow;
 
-	newMouseEvent = mouse_get_event();
+	const MouseEvent newMouseEvent = mouse_get_event();
 
 	if (newMouseEvent != _ME_no_event) {	// We have a mouse event
 		gui_mouse_refresh();
@@ -125,7 +119,7 @@ void gui_system_event_handler() {
 		// a window which handles or blocks key events. The event is passed to the handler
 		// if found.
 		//
-		handled = false;
+		bool handled = false;
 		myScreen = _G(frontScreen);
 		found = false;
 		blocked = false;
@@ -183,13 +177,11 @@ void gui_system_event_handler() {
 }
 
 void AddSystemHotkey(int32 myKey, HotkeyCB callback) {
-	Hotkey *myHotkey;
-
 	if (!_G(vmng_Initted)) {
 		return;
 	}
 
-	myHotkey = _G(systemHotkeys);
+	Hotkey *myHotkey = _G(systemHotkeys);
 	while (myHotkey && (myHotkey->myKey != myKey)) {
 		myHotkey = myHotkey->next;
 	}
@@ -209,13 +201,11 @@ void AddSystemHotkey(int32 myKey, HotkeyCB callback) {
 }
 
 void RemoveSystemHotkey(int32 myKey) {
-	Hotkey *myHotkey, *tempHotkey;
-
 	if (!_G(vmng_Initted))
 		return;
 
-	myHotkey = _G(systemHotkeys);
-	tempHotkey = myHotkey;
+	Hotkey *myHotkey = _G(systemHotkeys);
+	Hotkey *tempHotkey = myHotkey;
 
 	while (myHotkey && (myHotkey->myKey != myKey)) {
 		if (tempHotkey != myHotkey) tempHotkey = tempHotkey->next;
@@ -233,12 +223,11 @@ void RemoveSystemHotkey(int32 myKey) {
 }
 
 HotkeyCB GetSystemHotkey(int32 myKey) {
-	Hotkey *myHotkey, *tempHotkey;
 	if (!_G(vmng_Initted))
 		return (nullptr);
 
-	myHotkey = _G(systemHotkeys);
-	tempHotkey = myHotkey;
+	Hotkey *myHotkey = _G(systemHotkeys);
+	Hotkey *tempHotkey = myHotkey;
 
 	while (myHotkey && (myHotkey->myKey != myKey)) {
 		if (tempHotkey != myHotkey)
diff --git a/engines/m4/gui/gui_univ.h b/engines/m4/gui/gui_univ.h
index a69f6b0e7ff..66dc4df3b79 100644
--- a/engines/m4/gui/gui_univ.h
+++ b/engines/m4/gui/gui_univ.h
@@ -25,8 +25,7 @@
 
 #include "m4/m4_types.h"
 #include "m4/gui/gui.h"
-#include "m4/graphics/gr_font.h"
-#include "m4/graphics/gr_buff.h"
+
 
 namespace M4 {
 
diff --git a/engines/m4/gui/gui_vmng_core.cpp b/engines/m4/gui/gui_vmng_core.cpp
index 35002dd5695..8869ac4988c 100644
--- a/engines/m4/gui/gui_vmng_core.cpp
+++ b/engines/m4/gui/gui_vmng_core.cpp
@@ -58,7 +58,6 @@
 #include "graphics/surface.h"
 #include "m4/gui/gui_vmng.h"
 #include "m4/gui/gui_dialog.h"
-#include "m4/core/errors.h"
 #include "m4/core/imath.h"
 #include "m4/mem/memman.h"
 #include "m4/mem/mem.h"
@@ -89,7 +88,6 @@ bool vmng_init() {
 }
 
 void vmng_shutdown() {
-	ScreenContext *myScreen;
 	Hotkey *myHotkeys, *tempHotkey;
 
 	if (!_G(vmng_Initted))
@@ -97,7 +95,7 @@ void vmng_shutdown() {
 	_G(vmng_Initted) = false;
 
 	// First, destroy all active windows
-	myScreen = _G(frontScreen);
+	ScreenContext *myScreen = _G(frontScreen);
 	while (myScreen) {
 		_G(frontScreen) = _G(frontScreen)->behind;
 		if (myScreen->scrnType == SCRN_DLG) {
@@ -132,7 +130,6 @@ void vmng_shutdown() {
 		while (tempHotkey) {
 			myHotkeys = myHotkeys->next;
 			mem_free(tempHotkey);
-			//mem_free_to_stash((void*)tempHotkey, memtypeHOTKEY);
 			tempHotkey = myHotkeys;
 		}
 
@@ -172,12 +169,12 @@ ScreenContext *vmng_screen_create(int32 x1, int32 y1, int32 x2, int32 y2, int32
 }
 
 void vmng_screen_dispose(void *scrnContent) {
-	ScreenContext *myScreen;
-	Hotkey *myHotkeys, *tempHotkey;
-	if ((myScreen = ExtractScreen(scrnContent, SCRN_ANY)) == nullptr) return;
+	ScreenContext *myScreen = ExtractScreen(scrnContent, SCRN_ANY);
+	if (myScreen == nullptr)
+		return;
 	RestoreScreens(myScreen->x1, myScreen->y1, myScreen->x2, myScreen->y2);
-	myHotkeys = myScreen->scrnHotkeys;
-	tempHotkey = myHotkeys;
+	Hotkey *myHotkeys = myScreen->scrnHotkeys;
+	Hotkey *tempHotkey = myHotkeys;
 	while (tempHotkey) {
 		myHotkeys = myHotkeys->next;
 		mem_free(tempHotkey);
@@ -198,8 +195,8 @@ void vmng_screen_hide(void *scrnContent) {
 }
 
 void vmng_screen_show(void *scrnContent) {
-	ScreenContext *myScreen, *tempScreen;
-	if ((myScreen = ExtractScreen(scrnContent, SCRN_ANY)) == nullptr)
+	ScreenContext *myScreen = ExtractScreen(scrnContent, SCRN_ANY);
+	if (myScreen == nullptr)
 		return;
 
 	if (!_G(frontScreen)) {
@@ -209,7 +206,7 @@ void vmng_screen_show(void *scrnContent) {
 		_G(backScreen) = myScreen;
 
 	} else {
-		tempScreen = _G(frontScreen);
+		ScreenContext *tempScreen = _G(frontScreen);
 		while (tempScreen &&
 			((tempScreen->scrnFlags & SF_LAYER) > (myScreen->scrnFlags & SF_LAYER))) {
 			tempScreen = tempScreen->behind;
@@ -236,13 +233,12 @@ void vmng_screen_show(void *scrnContent) {
 }
 
 ScreenContext *vmng_screen_find(void *scrnContent, int32 *status) {
-	ScreenContext *myScreen;
 	int32 myStatus = SCRN_ACTIVE;
 
 	if (!_G(vmng_Initted))
 		return nullptr;
 
-	myScreen = _G(frontScreen);
+	ScreenContext *myScreen = _G(frontScreen);
 
 	while (myScreen && (myScreen->scrnContent != scrnContent))
 		myScreen = myScreen->behind;
diff --git a/engines/m4/gui/gui_vmng_rectangles.cpp b/engines/m4/gui/gui_vmng_rectangles.cpp
index 28dc71655f0..69dc36bb32f 100644
--- a/engines/m4/gui/gui_vmng_rectangles.cpp
+++ b/engines/m4/gui/gui_vmng_rectangles.cpp
@@ -49,38 +49,32 @@ RectList *vmng_CreateNewRect(int32 x1, int32 y1, int32 x2, int32 y2) {
 }
 
 void vmng_AddRectToRectList(RectList **theRectList, int32 rectX1, int32 rectY1, int32 rectX2, int32 rectY2) {
-	RectList *dirtyRect, *dirtyRectList;
-	RectList *endCleanRectList, *cleanRectList;
-	RectList *myRect, *myRectList;
-	RectList *newRect;
-	bool intersected;
-
 	// First make sure we have a valid rectangle
 	if ((rectX1 > rectX2) || (rectY1 > rectY2)) {
 		return;
 	}
 
-	// Intialize the dirty rect list
-	dirtyRectList = vmng_CreateNewRect(rectX1, rectY1, rectX2, rectY2);
+	// Initialize the dirty rect list
+	RectList *dirtyRectList = vmng_CreateNewRect(rectX1, rectY1, rectX2, rectY2);
 
-	// Intialize the clean rectList
-	cleanRectList = nullptr;
-	endCleanRectList = nullptr;
+	// Initialize the clean rectList
+	RectList *cleanRectList = nullptr;
+	RectList *endCleanRectList = nullptr;
 
 	// Use a local var for theRectlist
-	myRectList = *theRectList;
+	RectList *myRectList = *theRectList;
 
 	// Loop through all the dirtyRects
-	dirtyRect = dirtyRectList;
+	RectList *dirtyRect = dirtyRectList;
 	while (dirtyRect) {
 		// Remove dirtyRect from the head of the dirtyRectList
 		dirtyRectList = dirtyRectList->next;
 
 		// Set the intersected flag
-		intersected = false;
+		bool intersected = false;
 
 		// Loop on through
-		myRect = myRectList;
+		RectList *myRect = myRectList;
 		while (myRect) {
 
 			// If the two rectangles intersect
@@ -101,6 +95,7 @@ void vmng_AddRectToRectList(RectList **theRectList, int32 rectX1, int32 rectY1,
 						myRect->next->prev = myRect->prev;
 					}
 
+					RectList *newRect;
 					// So now there is an intersection.
 					// If myRect sticks out above dirtyRect, chop it off and put it in the main rect list, to be recheck by other dirty rects
 					if (myRect->y1 < dirtyRect->y1) {
@@ -219,15 +214,14 @@ void vmng_AddRectToRectList(RectList **theRectList, int32 rectX1, int32 rectY1,
 }
 
 RectList *vmng_DuplicateRectList(RectList *myRectList) {
-	RectList *newRectList, *tempRect, *myRect, *prevRect;
-
-	newRectList = nullptr;
-	prevRect = nullptr;
-	myRect = myRectList;
+	RectList *newRectList = nullptr;
+	RectList *prevRect = nullptr;
+	RectList *myRect = myRectList;
 	while (myRect) {
 
 		// Duplicate myRect and stick it on the newRectList
-		if ((tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectList")) == nullptr) {
+		RectList *tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectList");
+		if (tempRect == nullptr) {
 			error_show(FL, 'OOS!', "vmng_DuplicateRectList()");
 		}
 		tempRect->x1 = myRect->x1;
@@ -251,22 +245,19 @@ RectList *vmng_DuplicateRectList(RectList *myRectList) {
 }
 
 bool vmng_RectIntersectsRectList(RectList *myRectList, int32 x1, int32 y1, int32 x2, int32 y2) {
-	RectList *myRect;
-	int32 intrX1, intrY1, intrX2, intrY2;
-
 	// Parameter verification
 	if ((!myRectList) || (x1 > x2) || (y1 > y2)) {
 		return false;
 	}
 
 	// Loop through the list, and break as soon as there is an intersection
-	myRect = myRectList;
+	RectList *myRect = myRectList;
 	while (myRect) {
 		// Calculate the intersection
-		intrX1 = imath_max(myRect->x1, x1);
-		intrY1 = imath_max(myRect->y1, y1);
-		intrX2 = imath_min(myRect->x2, x2);
-		intrY2 = imath_min(myRect->y2, y2);
+		const int32 intrX1 = imath_max(myRect->x1, x1);
+		const int32 intrY1 = imath_max(myRect->y1, y1);
+		const int32 intrX2 = imath_min(myRect->x2, x2);
+		const int32 intrY2 = imath_min(myRect->y2, y2);
 
 		// If we intersected, return true
 		if ((intrX1 <= intrX2) && (intrY1 <= intrY2)) {
@@ -282,21 +273,18 @@ bool vmng_RectIntersectsRectList(RectList *myRectList, int32 x1, int32 y1, int32
 }
 
 bool vmng_ClipRectList(RectList **myRectList, int32 clipX1, int32 clipY1, int32 clipX2, int32 clipY2) {
-	RectList *nextRect, *myRect;
-	int32 x1, y1, x2, y2;
-
 	// Loop through myRect list
-	myRect = *myRectList;
+	RectList *myRect = *myRectList;
 	while (myRect) {
 
 		// Set the next rect
-		nextRect = myRect->next;
+		RectList *nextRect = myRect->next;
 
 		// Clip myRect
-		x1 = imath_max(myRect->x1, clipX1);
-		y1 = imath_max(myRect->y1, clipY1);
-		x2 = imath_min(myRect->x2, clipX2);
-		y2 = imath_min(myRect->y2, clipY2);
+		const int32 x1 = imath_max(myRect->x1, clipX1);
+		const int32 y1 = imath_max(myRect->y1, clipY1);
+		const int32 x2 = imath_min(myRect->x2, clipX2);
+		const int32 y2 = imath_min(myRect->y2, clipY2);
 
 		// If we have a valid rectangle
 		if ((x1 <= x2) && (y1 <= y2)) {
@@ -327,11 +315,9 @@ bool vmng_ClipRectList(RectList **myRectList, int32 clipX1, int32 clipY1, int32
 }
 
 bool vmng_RectListValid(RectList *myRectList) {
-	RectList *myRect, *tempRectList;
-
-	myRect = myRectList;
+	RectList *myRect = myRectList;
 	while (myRect) {
-		tempRectList = myRect->next;
+		RectList *tempRectList = myRect->next;
 		if (vmng_RectIntersectsRectList(tempRectList, myRect->x1, myRect->y1, myRect->x2, myRect->y2)) {
 			return false;
 		}
@@ -342,10 +328,8 @@ bool vmng_RectListValid(RectList *myRectList) {
 }
 
 void vmng_DisposeRectList(RectList **rectList) {
-	RectList *myRect;
-
 	// Loop through the rect list
-	myRect = *rectList;
+	RectList *myRect = *rectList;
 	while (myRect) {
 		// Remove myRect from the head of the list
 		*rectList = myRect->next;
@@ -359,26 +343,22 @@ void vmng_DisposeRectList(RectList **rectList) {
 }
 
 void vmng_RemoveRectFromRectList(RectList **scrnRectList, int32 x1, int32 y1, int32 x2, int32 y2) {
-	RectList *myRect, *prevRect, *nextRect, *tempRect;
-	RectList *rectList, *unsortedRectList;
-	int32 tempX1, tempY1, tempX2, tempY2;
-	bool finished;
-
-	rectList = *scrnRectList;
+	RectList *tempRect;
+	RectList *rectList = *scrnRectList;
 
 	// Go through the rectList list breaking down any rects which intersect the given coords
-	unsortedRectList = nullptr;
-	myRect = rectList;
+	RectList *unsortedRectList = nullptr;
+	RectList *myRect = rectList;
 
 	while (myRect) {
 		// Set the nextRect pointer
-		nextRect = myRect->next;
+		RectList *nextRect = myRect->next;
 
 		// Check for an intersection
-		tempX1 = imath_max(x1, myRect->x1);
-		tempY1 = imath_max(y1, myRect->y1);
-		tempX2 = imath_min(x2, myRect->x2);
-		tempY2 = imath_min(y2, myRect->y2);
+		const int32 tempX1 = imath_max(x1, myRect->x1);
+		const int32 tempY1 = imath_max(y1, myRect->y1);
+		const int32 tempX2 = imath_min(x2, myRect->x2);
+		const int32 tempY2 = imath_min(y2, myRect->y2);
 
 		// If we have an intersection
 		if ((tempX1 <= tempX2) && (tempY1 <= tempY2)) {
@@ -386,7 +366,8 @@ void vmng_RemoveRectFromRectList(RectList **scrnRectList, int32 x1, int32 y1, in
 			// Top edge
 			if (myRect->y1 < y1) {
 				// Create a new rect of just the part that extends beyond the top of myRect
-				if ((tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectangle")) == nullptr) {
+				tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectangle");
+				if (tempRect == nullptr) {
 					error_show(FL, 'OOS!', "vmng_AddRectToRectList");
 				}
 				tempRect->x1 = myRect->x1;
@@ -405,7 +386,8 @@ void vmng_RemoveRectFromRectList(RectList **scrnRectList, int32 x1, int32 y1, in
 			// Bottom edge
 			if (myRect->y2 > y2) {
 				// Create a new rect of just the part that extends beyond the top of myRect
-				if ((tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectangle")) == nullptr) {
+				tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectangle");
+				if (tempRect == nullptr) {
 					error_show(FL, 'OOS!', "vmng_AddRectToRectList");
 				}
 				tempRect->x1 = myRect->x1;
@@ -424,7 +406,8 @@ void vmng_RemoveRectFromRectList(RectList **scrnRectList, int32 x1, int32 y1, in
 			// Left edge
 			if (myRect->x1 < x1) {
 				// Create a new rect of just the part that extends beyond the top of myRect
-				if ((tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectangle")) == nullptr) {
+				tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectangle");
+				if (tempRect == nullptr) {
 					error_show(FL, 'OOS!', "vmng_AddRectToRectList");
 				}
 				tempRect->x1 = myRect->x1;
@@ -440,7 +423,8 @@ void vmng_RemoveRectFromRectList(RectList **scrnRectList, int32 x1, int32 y1, in
 			// Right edge
 			if (myRect->x2 > x2) {
 				// Create a new rect of just the part that extends beyond the top of myRect
-				if ((tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectangle")) == nullptr) {
+				tempRect = (RectList *)mem_get_from_stash(_G(memtypeRECT), "+guiRectangle");
+				if (tempRect == nullptr) {
 					error_show(FL, 'OOS!', "vmng_AddRectToRectList");
 				}
 
@@ -476,8 +460,8 @@ void vmng_RemoveRectFromRectList(RectList **scrnRectList, int32 x1, int32 y1, in
 	while (tempRect) {
 		unsortedRectList = unsortedRectList->next;
 		// For each unsorted rect, loop through the rect list until its place is found
-		finished = false;
-		prevRect = nullptr;
+		bool finished = false;
+		RectList *prevRect = nullptr;
 		myRect = rectList;
 
 		while (myRect && (!finished)) {
diff --git a/engines/m4/gui/gui_vmng_screen.cpp b/engines/m4/gui/gui_vmng_screen.cpp
index 55f3c1b8711..6617490b9d3 100644
--- a/engines/m4/gui/gui_vmng_screen.cpp
+++ b/engines/m4/gui/gui_vmng_screen.cpp
@@ -32,8 +32,8 @@ static void vmng_black_out_video(int32 x1, int32 y1, int32 x2, int32 y2);
 static bool MoveScreen(ScreenContext *myScreen, int32 parmX, int32 parmY, bool deltaMove);
 
 bool GetScreenCoords(void *scrnContent, int32 *x1, int32 *y1, int32 *x2, int32 *y2) {
-	ScreenContext *myScreen;
-	if ((myScreen = vmng_screen_find(scrnContent, nullptr)) == nullptr)
+	ScreenContext *myScreen = vmng_screen_find(scrnContent, nullptr);
+	if (myScreen == nullptr)
 		return false;
 
 	if (x1)
@@ -49,7 +49,6 @@ bool GetScreenCoords(void *scrnContent, int32 *x1, int32 *y1, int32 *x2, int32 *
 }
 
 void RestoreScreens(int32 updateX1, int32 updateY1, int32 updateX2, int32 updateY2) {
-	ScreenContext *myScreen, *tempScreen;
 	RectList *updateRectList, *scrnUpdateList, *tempRect;
 
 	if (!_G(vmng_Initted) || _G(system_shutting_down)) {
@@ -75,7 +74,7 @@ void RestoreScreens(int32 updateX1, int32 updateY1, int32 updateX2, int32 update
 	updateRectList = vmng_CreateNewRect(updateX1, updateY1, updateX2, updateY2);
 
 	// First loop through the screens back to front, drawing only the transparent screens
-	myScreen = _G(backScreen);
+	ScreenContext *myScreen = _G(backScreen);
 
 	while (myScreen && updateRectList) {
 		// We only draw transparent screens on the first pass
@@ -87,7 +86,7 @@ void RestoreScreens(int32 updateX1, int32 updateY1, int32 updateX2, int32 update
 			vmng_ClipRectList(&scrnUpdateList, myScreen->x1, myScreen->y1, myScreen->x2, myScreen->y2);
 
 			// Now remove the rects of all screens blocking the scrnUpdateList
-			tempScreen = myScreen->infront;
+			ScreenContext *tempScreen = myScreen->infront;
 
 			while (scrnUpdateList && tempScreen) {
 				vmng_RemoveRectFromRectList(&scrnUpdateList, tempScreen->x1, tempScreen->y1, tempScreen->x2, tempScreen->y2);
@@ -159,15 +158,13 @@ void RestoreScreens(int32 updateX1, int32 updateY1, int32 updateX2, int32 update
 }
 
 void RestoreScreensInContext(int32 x1, int32 y1, int32 x2, int32 y2, ScreenContext *myScreen) {
-	ScreenContext *tempScreen;
-
 	//verify the gui has been initted
 	if (!_G(vmng_Initted)) {
 		return;
 	}
 
 	//verify parameters
-	tempScreen = _G(frontScreen);
+	ScreenContext *tempScreen = _G(frontScreen);
 	while (tempScreen && (tempScreen != myScreen)) {
 		tempScreen = tempScreen->behind;
 	}
@@ -186,22 +183,22 @@ void RestoreScreensInContext(int32 x1, int32 y1, int32 x2, int32 y2, ScreenConte
 }
 
 bool ResizeScreen(void *scrnContent, int32 newW, int32 newH) {
-	ScreenContext *myScreen;
-	int32 status, oldX2, oldY2;
-
 	if ((newW <= 0) || (newH <= 0))
 		return false;
-	if ((myScreen = vmng_screen_find(scrnContent, &status)) == nullptr)
+
+	int32 status;
+	ScreenContext *myScreen = vmng_screen_find(scrnContent, &status);
+	if (myScreen == nullptr)
 		return false;
 
-	oldX2 = myScreen->x2;
+	const int32 oldX2 = myScreen->x2;
 	myScreen->x2 = myScreen->x1 + newW - 1;
 
 	if (myScreen->x2 < oldX2) {
 		RestoreScreens(myScreen->x2 + 1, myScreen->y1, oldX2, myScreen->y2);
 	}
 
-	oldY2 = myScreen->y2;
+	const int32 oldY2 = myScreen->y2;
 	myScreen->y2 = myScreen->y1 + newH - 1;
 
 	if (myScreen->y2 < oldY2) {
@@ -217,13 +214,12 @@ static void vmng_black_out_video(int32 x1, int32 y1, int32 x2, int32 y2) {
 }
 
 bool AddScreenHotkey(void *scrnContent, int32 myKey, HotkeyCB callback) {
-	ScreenContext *myScreen;
-	Hotkey *myHotkey;
-
-	if ((myScreen = vmng_screen_find(scrnContent, nullptr)) == nullptr)
+	ScreenContext *myScreen = vmng_screen_find(scrnContent, nullptr);
+	if (myScreen == nullptr)
 		return false;
 
-	if ((myHotkey = (Hotkey *)mem_alloc(sizeof(Hotkey), "hotkey")) == nullptr)
+	Hotkey *myHotkey = (Hotkey *)mem_alloc(sizeof(Hotkey), "hotkey");
+	if (myHotkey == nullptr)
 		return false;
 
 	myHotkey->myKey = myKey;
@@ -234,12 +230,11 @@ bool AddScreenHotkey(void *scrnContent, int32 myKey, HotkeyCB callback) {
 }
 
 bool RemoveScreenHotkey(void *scrnContent, int32 myKey) {
-	ScreenContext *myScreen;
-	Hotkey *myHotkey, *tempHotkey;
-	if ((myScreen = vmng_screen_find(scrnContent, nullptr)) == nullptr)
+	ScreenContext *myScreen = vmng_screen_find(scrnContent, nullptr);
+	if (myScreen == nullptr)
 		return false;
 
-	myHotkey = myScreen->scrnHotkeys;
+	Hotkey *myHotkey = myScreen->scrnHotkeys;
 
 	if (myHotkey->myKey == myKey) {
 		myScreen->scrnHotkeys = myHotkey->next;
@@ -250,7 +245,7 @@ bool RemoveScreenHotkey(void *scrnContent, int32 myKey) {
 			myHotkey = myHotkey->next;
 		}
 		if (myHotkey->next) {
-			tempHotkey = myHotkey->next;
+			Hotkey *tempHotkey = myHotkey->next;
 			myHotkey->next = tempHotkey->next;
 			mem_free(tempHotkey);
 		} else {
@@ -274,15 +269,15 @@ bool MoveScreenDelta(int32 parmX, int32 parmY) {
 }
 
 void vmng_screen_to_back(void *scrnContent) {
-	ScreenContext *myScreen, *tempScreen;
-	if ((myScreen = ExtractScreen(scrnContent, SCRN_ANY)) == nullptr) return;
+	ScreenContext *myScreen = ExtractScreen(scrnContent, SCRN_ANY);
+	if (myScreen == nullptr) return;
 	if (!_G(backScreen)) {
 		myScreen->infront = nullptr;
 		myScreen->behind = nullptr;
 		_G(frontScreen) = myScreen;
 		_G(backScreen) = myScreen;
 	} else {
-		tempScreen = _G(backScreen);
+		ScreenContext *tempScreen = _G(backScreen);
 		while (tempScreen &&
 			((tempScreen->scrnFlags & SF_LAYER) < (myScreen->scrnFlags & SF_LAYER))) {
 			tempScreen = tempScreen->infront;
@@ -309,14 +304,13 @@ void vmng_screen_to_back(void *scrnContent) {
 }
 
 static bool MoveScreen(ScreenContext *myScreen, int32 parmX, int32 parmY, bool deltaMove) {
-	int32 origX1, origY1, origX2, origY2;
 	if (!_G(vmng_Initted))
 		return false;
 
-	origX1 = myScreen->x1;
-	origY1 = myScreen->y1;
-	origX2 = myScreen->x2;
-	origY2 = myScreen->y2;
+	const int32 origX1 = myScreen->x1;
+	const int32 origY1 = myScreen->y1;
+	const int32 origX2 = myScreen->x2;
+	const int32 origY2 = myScreen->y2;
 
 	if (!deltaMove) {
 		parmX -= origX1;
diff --git a/engines/m4/gui/hotkeys.cpp b/engines/m4/gui/hotkeys.cpp
index d65c2b1e3fe..c90f19fcea6 100644
--- a/engines/m4/gui/hotkeys.cpp
+++ b/engines/m4/gui/hotkeys.cpp
@@ -285,9 +285,9 @@ void Hotkeys::changeGlobalChange(void *, void *) {
 	_changeGlobalDialog->destroy();
 
 	// Create secondary dialog to get value to set global to
-	int globalVal = (g_engine->getGameType() == GType_Burger) ?
-		Burger::g_vars->_flags[(Burger::Flag)_globalToChange] :
-		Riddle::g_vars->_flags[(Riddle::Flag)_globalToChange];
+	const int globalVal = (g_engine->getGameType() == GType_Burger) ?
+		                      Burger::g_vars->_flags[(Burger::Flag)_globalToChange] :
+		                      Riddle::g_vars->_flags[(Riddle::Flag)_globalToChange];
 
 	_changeGlobalDialog = DialogCreateAbsolute(250, 120, 450, 220, 242);
 	_changeGlobalDialog->addButton(60, 40,
@@ -305,7 +305,7 @@ void Hotkeys::changeGlobalChange(void *, void *) {
 
 void Hotkeys::changeGlobalDoChange(void *, void *) {
 	Item *textField = _changeGlobalDialog->getItem(3);
-	int globalVal = atoi(textField->prompt);
+	const int globalVal = atoi(textField->prompt);
 
 	if (g_engine->getGameType() == GType_Burger)
 		Burger::g_vars->_flags[(Burger::Flag)_globalToChange] = globalVal;


Commit: ea6d26eb89fd13d2bef087645f5b7b8d029b7d54
    https://github.com/scummvm/scummvm/commit/ea6d26eb89fd13d2bef087645f5b7b8d029b7d54
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2025-06-21T06:29:44+01:00

Commit Message:
M4: Remove useless code in mouse_set_sprite(), cleanup

Changed paths:
    engines/m4/gui/gui_mouse.cpp


diff --git a/engines/m4/gui/gui_mouse.cpp b/engines/m4/gui/gui_mouse.cpp
index 24c1300962c..06f58eadc37 100644
--- a/engines/m4/gui/gui_mouse.cpp
+++ b/engines/m4/gui/gui_mouse.cpp
@@ -250,8 +250,6 @@ void transShow(void *s, void *r, void *b, int32 destX, int32 destY) {
 }
 
 bool mouse_set_sprite(int32 spriteNum) {
-	M4sprite *tempSprite;
-
 	if (_G(mouseIsLocked)) {
 		_G(newMouseNum) = spriteNum;
 		return true;
@@ -264,13 +262,9 @@ bool mouse_set_sprite(int32 spriteNum) {
 	if (!_G(mouseSeriesHandle) || !*_G(mouseSeriesHandle))
 		return false;
 
-	int32 minX = _G(oldX) - _G(mouseX1offset);
-	int32 minY = _G(oldY) - _G(mouseY1offset);
-	int32 maxX = _G(oldX) + _G(mouseX2offset);
-	int32 maxY = _G(oldY) + _G(mouseY2offset);
-
-	if ((tempSprite = CreateSprite(_G(mouseSeriesHandle), _G(mouseSeriesOffset), spriteNum,
-			_G(mouseSprite), nullptr)) == nullptr)
+	M4sprite *tempSprite = CreateSprite(_G(mouseSeriesHandle), _G(mouseSeriesOffset), spriteNum,
+	                                    _G(mouseSprite), nullptr);
+	if (tempSprite == nullptr)
 		return false;
 
 	_G(mouseSprite) = tempSprite;
@@ -278,14 +272,6 @@ bool mouse_set_sprite(int32 spriteNum) {
 	_G(mouseY1offset) = _G(mouseSprite)->yOffset;
 	_G(mouseX2offset) = _G(mouseSprite)->w - _G(mouseX1offset) - 1;
 	_G(mouseY2offset) = _G(mouseSprite)->h - _G(mouseY1offset) - 1;
-	if (_G(mouseX) - _G(mouseX1offset) < minX)
-		minX = _G(mouseX) - _G(mouseX1offset);
-	if (_G(mouseY) - _G(mouseY1offset) < minY)
-		minY = _G(mouseY) - _G(mouseY1offset);
-	if (_G(mouseX) + _G(mouseX2offset) > maxX)
-		maxX = _G(mouseX) + _G(mouseX2offset);
-	if (_G(mouseY) + _G(mouseY2offset) > maxY)
-		maxY = _G(mouseY) + _G(mouseY2offset);
 
 	gui_mouse_refresh();
 	_G(currMouseNum) = spriteNum;




More information about the Scummvm-git-logs mailing list