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

Strangerke noreply at scummvm.org
Sun May 12 11:55:59 UTC 2024


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

Summary:
cd5c19bcb5 BAGEL: More cleanup related to assignments in if statements and useless null checks, add more details in several calls t


Commit: cd5c19bcb5a2484e5120d43f5063c789ea6cc59e
    https://github.com/scummvm/scummvm/commit/cd5c19bcb5a2484e5120d43f5063c789ea6cc59e
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-12T12:55:50+01:00

Commit Message:
BAGEL: More cleanup related to assignments in if statements and useless null checks, add more details in several calls to reportError()

Changed paths:
    engines/bagel/boflib/gui/text_box.cpp
    engines/bagel/dialogs/restore_dialog.cpp
    engines/bagel/dialogs/save_dialog.cpp
    engines/bagel/dialogs/start_dialog.cpp
    engines/bagel/spacebar/bibble_window.cpp
    engines/bagel/spacebar/slot_wnd.cpp
    engines/bagel/spacebar/vid_wnd.cpp


diff --git a/engines/bagel/boflib/gui/text_box.cpp b/engines/bagel/boflib/gui/text_box.cpp
index 3d340c43a3d..92580df00a2 100644
--- a/engines/bagel/boflib/gui/text_box.cpp
+++ b/engines/bagel/boflib/gui/text_box.cpp
@@ -106,15 +106,12 @@ ErrorCode CBofTextBox::setBox(const CBofRect *pRect) {
 	assert(pRect != nullptr);
 
 	// Remove previous text field (if any)
-	if (_pTextField != nullptr) {
-		delete _pTextField;
-		_pTextField = nullptr;
-	}
+	delete _pTextField;
+	_pTextField = nullptr;
 
 	// Create a new text field the size of the box we want
-	if ((_pTextField = new CBofText(pRect, JUSTIFY_WRAP)) != nullptr) {
-
-	} else {
+	_pTextField = new CBofText(pRect, JUSTIFY_WRAP);
+	if (_pTextField == nullptr) {
 		reportError(ERR_MEMORY, "Could not allocate a CBofText");
 	}
 
diff --git a/engines/bagel/dialogs/restore_dialog.cpp b/engines/bagel/dialogs/restore_dialog.cpp
index 59fed8314e0..c839d8ee1da 100644
--- a/engines/bagel/dialogs/restore_dialog.cpp
+++ b/engines/bagel/dialogs/restore_dialog.cpp
@@ -115,20 +115,19 @@ ErrorCode CBagRestoreDialog::attach() {
 	for (int i = 0; i < NUM_RESTORE_BTNS; i++) {
 		assert(_pButtons[i] == nullptr);
 
-		if ((_pButtons[i] = new CBofBmpButton) != nullptr) {
-			CBofBitmap *pUp, *pDown, *pFocus, *pDis;
-
-			pUp = loadBitmap(buildSysDir(g_stButtons[i]._pszUp), pPal);
-			pDown = loadBitmap(buildSysDir(g_stButtons[i]._pszDown), pPal);
-			pFocus = loadBitmap(buildSysDir(g_stButtons[i]._pszFocus), pPal);
-			pDis = loadBitmap(buildSysDir(g_stButtons[i]._pszDisabled), pPal);
+		_pButtons[i] = new CBofBmpButton;
+		if (_pButtons[i] != nullptr) {
+			CBofBitmap *pUp = loadBitmap(buildSysDir(g_stButtons[i]._pszUp), pPal);
+			CBofBitmap *pDown = loadBitmap(buildSysDir(g_stButtons[i]._pszDown), pPal);
+			CBofBitmap *pFocus = loadBitmap(buildSysDir(g_stButtons[i]._pszFocus), pPal);
+			CBofBitmap *pDis = loadBitmap(buildSysDir(g_stButtons[i]._pszDisabled), pPal);
 
 			_pButtons[i]->loadBitmaps(pUp, pDown, pFocus, pDis);
 
 			_pButtons[i]->create(g_stButtons[i]._pszName, g_stButtons[i]._nLeft, g_stButtons[i]._nTop, g_stButtons[i]._nWidth, g_stButtons[i]._nHeight, this, g_stButtons[i]._nID);
 			_pButtons[i]->show();
 		} else {
-			reportError(ERR_MEMORY);
+			reportError(ERR_MEMORY, "Unable to allocate a CBofBmpButton");
 			break;
 		}
 	}
@@ -155,7 +154,9 @@ ErrorCode CBagRestoreDialog::attach() {
 
 	// Create a list box for the user to choose the slot to save into
 	CBofRect cRect(LIST_X, LIST_Y, LIST_X + LIST_DX - 1, LIST_Y + LIST_DY - 1);
-	if ((_pListBox = new CBofListBox()) != nullptr) {
+
+	_pListBox = new CBofListBox();
+	if (_pListBox != nullptr) {
 		_pListBox->create("SaveGameList", &cRect, this);
 
 		_pListBox->setPointSize(LIST_FONT_SIZE);
@@ -163,10 +164,7 @@ ErrorCode CBagRestoreDialog::attach() {
 
 		// Set a color for selection highlighting
 		if (_pBackdrop != nullptr) {
-			CBofPalette *pPal2;
-
-			pPal2 = _pBackdrop->getPalette();
-
+			CBofPalette *pPal2 = _pBackdrop->getPalette();
 			byte iPalIdx = pPal2->getNearestIndex(RGB(255, 0, 0));
 
 			_pListBox->setHighlightColor(pPal2->getColor(iPalIdx));
@@ -195,14 +193,15 @@ ErrorCode CBagRestoreDialog::attach() {
 		_pListBox->updateWindow();
 
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofListBox");
 	}
 
 	if (!errorOccurred()) {
 		// There could not already be a text field
 		assert(_pText == nullptr);
 
-		if ((_pText = new CBofText) != nullptr) {
+		_pText = new CBofText;
+		if (_pText != nullptr) {
 			cRect.setRect(170, 405, 470, 435);
 			_pText->setupText(&cRect, JUSTIFY_LEFT, FORMAT_CENTER_LEFT);
 			_pText->SetSize(16);
@@ -231,28 +230,19 @@ ErrorCode CBagRestoreDialog::detach() {
 
 	CBagCursor::hideSystemCursor();
 
-	if (_pText != nullptr) {
-		delete _pText;
-		_pText = nullptr;
-	}
+	delete _pText;
+	_pText = nullptr;
 
-	if (_pScrollBar != nullptr) {
-		delete _pScrollBar;
-		_pScrollBar = nullptr;
-	}
+	delete _pScrollBar;
+	_pScrollBar = nullptr;
 
-	if (_pListBox != nullptr) {
-		delete _pListBox;
-		_pListBox = nullptr;
-	}
+	delete _pListBox;
+	_pListBox = nullptr;
 
 	// Destroy all buttons
 	for (int i = 0; i < NUM_RESTORE_BTNS; i++) {
-
-		if (_pButtons[i] != nullptr) {
-			delete _pButtons[i];
-			_pButtons[i] = nullptr;
-		}
+		delete _pButtons[i];
+		_pButtons[i] = nullptr;
 	}
 
 	_nSelectedItem = -1;
diff --git a/engines/bagel/dialogs/save_dialog.cpp b/engines/bagel/dialogs/save_dialog.cpp
index ef26171a880..2c07ed1e8bf 100644
--- a/engines/bagel/dialogs/save_dialog.cpp
+++ b/engines/bagel/dialogs/save_dialog.cpp
@@ -120,20 +120,19 @@ ErrorCode CBagSaveDialog::attach() {
 	for (int i = 0; i < NUM_BUTTONS; i++) {
 		assert(_pButtons[i] == nullptr);
 
-		if ((_pButtons[i] = new CBofBmpButton) != nullptr) {
-			CBofBitmap *pUp, *pDown, *pFocus, *pDis;
-
-			pUp = loadBitmap(buildSysDir(g_stButtons[i]._up), pPal);
-			pDown = loadBitmap(buildSysDir(g_stButtons[i]._down), pPal);
-			pFocus = loadBitmap(buildSysDir(g_stButtons[i]._focus), pPal);
-			pDis = loadBitmap(buildSysDir(g_stButtons[i]._disabled), pPal);
+		_pButtons[i] = new CBofBmpButton;
+		if (_pButtons[i] != nullptr) {
+			CBofBitmap *pUp = loadBitmap(buildSysDir(g_stButtons[i]._up), pPal);
+			CBofBitmap *pDown = loadBitmap(buildSysDir(g_stButtons[i]._down), pPal);
+			CBofBitmap *pFocus = loadBitmap(buildSysDir(g_stButtons[i]._focus), pPal);
+			CBofBitmap *pDis = loadBitmap(buildSysDir(g_stButtons[i]._disabled), pPal);
 
 			_pButtons[i]->loadBitmaps(pUp, pDown, pFocus, pDis);
 
 			_pButtons[i]->create(g_stButtons[i]._name, g_stButtons[i]._left, g_stButtons[i]._top, g_stButtons[i]._width, g_stButtons[i]._height, this, g_stButtons[i]._id);
 			_pButtons[i]->show();
 		} else {
-			reportError(ERR_MEMORY);
+			reportError(ERR_MEMORY, "Unable to allocate a CBofBmpButton");
 			break;
 		}
 	}
@@ -160,7 +159,8 @@ ErrorCode CBagSaveDialog::attach() {
 	assert(_pListBox == nullptr);
 
 	// Create a list box for the user to choose the slot to save into
-	if ((_pListBox = new CBofListBox()) != nullptr) {
+	_pListBox = new CBofListBox();
+	if (_pListBox != nullptr) {
 		CBofRect cRect(LIST_X, LIST_Y, LIST_X + LIST_DX - 1, LIST_Y + LIST_DY - 1);
 
 		_pListBox->create("SaveGameList", &cRect, this);
@@ -201,7 +201,7 @@ ErrorCode CBagSaveDialog::attach() {
 		_pListBox->updateWindow();
 
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofListBox");
 	}
 
 	if (_nSelectedItem != -1) {
@@ -231,27 +231,19 @@ ErrorCode CBagSaveDialog::detach() {
 
 	CBagCursor::hideSystemCursor();
 
-	if (_pScrollBar != nullptr) {
-		delete _pScrollBar;
-		_pScrollBar = nullptr;
-	}
+	delete _pScrollBar;
+	_pScrollBar = nullptr;
 
-	if (_pEditText != nullptr) {
-		delete _pEditText;
-		_pEditText = nullptr;
-	}
+	delete _pEditText;
+	_pEditText = nullptr;
 
-	if (_pListBox != nullptr) {
-		delete _pListBox;
-		_pListBox = nullptr;
-	}
+	delete _pListBox;
+	_pListBox = nullptr;
 
 	// Destroy all buttons
 	for (int i = 0; i < NUM_BUTTONS; i++) {
-		if (_pButtons[i] != nullptr) {
-			delete _pButtons[i];
-			_pButtons[i] = nullptr;
-		}
+		delete _pButtons[i];
+		_pButtons[i] = nullptr;
 	}
 
 	_nSelectedItem = -1;
diff --git a/engines/bagel/dialogs/start_dialog.cpp b/engines/bagel/dialogs/start_dialog.cpp
index 19c8f536a67..0f6ab85daef 100644
--- a/engines/bagel/dialogs/start_dialog.cpp
+++ b/engines/bagel/dialogs/start_dialog.cpp
@@ -87,7 +87,7 @@ void CBagStartDialog::onInitDialog() {
 			_buttons[i]->show();
 
 		} else {
-			reportError(ERR_MEMORY);
+			reportError(ERR_MEMORY, "Unable to allocate a CBofBmpButton");
 			break;
 		}
 	}
diff --git a/engines/bagel/spacebar/bibble_window.cpp b/engines/bagel/spacebar/bibble_window.cpp
index 0e187acab9d..4913591c481 100644
--- a/engines/bagel/spacebar/bibble_window.cpp
+++ b/engines/bagel/spacebar/bibble_window.cpp
@@ -308,14 +308,14 @@ ErrorCode CBibbleWindow::attach() {
 		_pCreditsText->setWeight(TEXT_BOLD);
 		_pCreditsText->setText(buildString("%d", _nNumCredits));
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofText");
 	}
 
 	// Pre-load the "One", "Two", "Three", and "Four" shouts
 	for (int i = 0; i < BIBBLE_NUM_SHOUTS; i++) {
 		_pShouts[i] = new CBofSound(this, BuildDir(pszShouts[i]), SOUND_MIX);
 		if (_pShouts[i] == nullptr) {
-			reportError(ERR_MEMORY);
+			reportError(ERR_MEMORY, "Unable to allocate a CBofSound");
 			break;
 		}
 	}
@@ -330,7 +330,7 @@ ErrorCode CBibbleWindow::attach() {
 		_pBall->linkSprite();
 
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofSprite");
 	}
 
 	// Pre-load the bibbles
@@ -342,7 +342,7 @@ ErrorCode CBibbleWindow::attach() {
 		_pMasterBibble->setAnimated(false);
 
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofSprite");
 	}
 
 	// Dup the bibbles
@@ -353,7 +353,7 @@ ErrorCode CBibbleWindow::attach() {
 			_pBibble[i]->linkSprite();
 
 		} else {
-			reportError(ERR_MEMORY);
+			reportError(ERR_MEMORY, "Unable to duplicate a CBofSprite");
 		}
 	}
 
@@ -365,7 +365,7 @@ ErrorCode CBibbleWindow::attach() {
 		_pArch1->setZOrder(SPRITE_MIDDLE);
 		_pArch1->linkSprite();
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofSprite");
 	}
 
 	_pArch2 = new CBofSprite;
@@ -376,7 +376,7 @@ ErrorCode CBibbleWindow::attach() {
 		_pArch2->linkSprite();
 
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofSprite");
 	}
 
 	_pArch3 = new CBofSprite;
@@ -387,7 +387,7 @@ ErrorCode CBibbleWindow::attach() {
 		_pArch3->linkSprite();
 
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofSprite");
 	}
 
 
@@ -406,7 +406,7 @@ ErrorCode CBibbleWindow::attach() {
 			_pButtons[i]->show();
 
 		} else {
-			reportError(ERR_MEMORY);
+			reportError(ERR_MEMORY, "Unable to allocate a CBofBmpButton");
 			break;
 		}
 	}
@@ -415,7 +415,7 @@ ErrorCode CBibbleWindow::attach() {
 	if (_pBkgSnd != nullptr) {
 		_pBkgSnd->play();
 	} else {
-		reportError(ERR_MEMORY);
+		reportError(ERR_MEMORY, "Unable to allocate a CBofSound");
 	}
 
 	// No bet area currently selected
diff --git a/engines/bagel/spacebar/slot_wnd.cpp b/engines/bagel/spacebar/slot_wnd.cpp
index 065eca27128..4f5a2af6503 100644
--- a/engines/bagel/spacebar/slot_wnd.cpp
+++ b/engines/bagel/spacebar/slot_wnd.cpp
@@ -176,7 +176,7 @@ ErrorCode  SBarSlotWnd::attach() {
 
 	_pSlotSound = new CBofSound(this, BuildSlotDir(SLOT_AUDIO), SOUND_MIX, 1);
 	if (_pSlotSound == nullptr) {
-		reportError(ERR_MEMORY, "Could not allocate a CBofSound");
+		reportError(ERR_MEMORY, "Unable to allocate a CBofSound");
 	}
 
 
diff --git a/engines/bagel/spacebar/vid_wnd.cpp b/engines/bagel/spacebar/vid_wnd.cpp
index 24e76a0e06a..a0b95d9f981 100644
--- a/engines/bagel/spacebar/vid_wnd.cpp
+++ b/engines/bagel/spacebar/vid_wnd.cpp
@@ -79,7 +79,7 @@ SBarVidWnd::SBarVidWnd() {
 SBarVidWnd::~SBarVidWnd() {
 	assert(isValidObject(this));
 
-	detach();
+	SBarVidWnd::detach();
 }
 
 ErrorCode SBarVidWnd::attach() {
@@ -113,7 +113,7 @@ ErrorCode SBarVidWnd::attach() {
 			_pMovie->attach();
 
 		} else {
-			reportError(ERR_MEMORY);
+			reportError(ERR_MEMORY, "Unable to allocate a CBagCharacterObject");
 		}
 
 		_fTimerDiff = 0;
@@ -179,12 +179,10 @@ void SBarVidWnd::setPlayMode(int nMode) {
 
 	// If user is playing the disk with the death scene on it, then
 	// reflect that in the script.
-	if (nMode != 0 && _pDiscVar != nullptr) {
-		if (_pDiscVar->getNumValue() == 2) {
-			CBagVar *pVar = g_VarManager->getVariable("VIDDISC_SEEN");
-			if (pVar != nullptr) {
-				pVar->setValue(1);
-			}
+	if (nMode != 0 && _pDiscVar != nullptr && _pDiscVar->getNumValue() == 2) {
+		CBagVar *pVar = g_VarManager->getVariable("VIDDISC_SEEN");
+		if (pVar != nullptr) {
+			pVar->setValue(1);
 		}
 	}
 }
@@ -211,9 +209,7 @@ int SBarVidWnd::getFrame(double fTime, int nUseDisc) {
 		if (g_stFrames[i]._nUseDisc == nUseDisc || (g_stFrames[i]._nUseDisc == 0)) {
 
 			if ((fTime >= g_stFrames[i]._fStart) && (fTime < g_stFrames[i]._fEnd)) {
-
 				nFrame = g_stFrames[i]._nFrame;
-
 				if (nFrame == -1) {
 					nFrame = int(8 + (fTime - 180) * 10);
 				}




More information about the Scummvm-git-logs mailing list