[Scummvm-git-logs] scummvm master -> 266efa0025ba028823b1124c1e803f2e5aede6d8

Strangerke noreply at scummvm.org
Sun May 5 20:39:45 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:
266efa0025 BAGEL: Add some missing override, remove useless null checks before delete


Commit: 266efa0025ba028823b1124c1e803f2e5aede6d8
    https://github.com/scummvm/scummvm/commit/266efa0025ba028823b1124c1e803f2e5aede6d8
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-05T21:39:38+01:00

Commit Message:
BAGEL: Add some missing override, remove useless null checks before delete

Changed paths:
    engines/bagel/baglib/sound_object.cpp
    engines/bagel/baglib/sprite_object.cpp
    engines/bagel/baglib/storage_dev_bmp.cpp
    engines/bagel/baglib/storage_dev_bmp.h
    engines/bagel/baglib/text_object.cpp
    engines/bagel/baglib/time_object.cpp
    engines/bagel/baglib/time_object.h
    engines/bagel/baglib/var.cpp
    engines/bagel/baglib/var.h


diff --git a/engines/bagel/baglib/sound_object.cpp b/engines/bagel/baglib/sound_object.cpp
index 7b1fc8c9b2a..d4de5b0af24 100644
--- a/engines/bagel/baglib/sound_object.cpp
+++ b/engines/bagel/baglib/sound_object.cpp
@@ -43,17 +43,17 @@ CBagSoundObject::CBagSoundObject() {
 	_wFlags = SOUND_MIX; //(SOUND_WAVE | SOUND_ASYNCH);
 
 	_nVol = VOLUME_INDEX_DEFAULT;
-	setState(0);
+	CBagObject::setState(0);
 	_bWait = false;
 
 	_nLoops = 1;
 
 	setVisible(false);
-	setOverCursor(3);
+	CBagObject::setOverCursor(3);
 }
 
 CBagSoundObject::~CBagSoundObject() {
-	detach();
+	CBagSoundObject::detach();
 }
 
 ErrorCode CBagSoundObject::attach(CBofWindow *pWnd) {
@@ -280,7 +280,7 @@ ParseCodes CBagSoundObject::setInfo(CBagIfstream &istr) {
 		break;
 
 		//
-		//  No match return from funtion
+		//  No match return from function
 		//
 		default: {
 			ParseCodes rc = CBagObject::setInfo(istr);
diff --git a/engines/bagel/baglib/sprite_object.cpp b/engines/bagel/baglib/sprite_object.cpp
index 7298524dd18..85979131f56 100644
--- a/engines/bagel/baglib/sprite_object.cpp
+++ b/engines/bagel/baglib/sprite_object.cpp
@@ -34,7 +34,7 @@ CBagSpriteObject::CBagSpriteObject() : CBagObject() {
 
 	// Transparent by default
 	setTransparent();
-	setOverCursor(1);
+	CBagObject::setOverCursor(1);
 	setAnimated();
 	setTimeless(true);
 
@@ -44,7 +44,7 @@ CBagSpriteObject::CBagSpriteObject() : CBagObject() {
 }
 
 CBagSpriteObject::~CBagSpriteObject() {
-	detach();
+	CBagSpriteObject::detach();
 }
 
 ErrorCode CBagSpriteObject::attach() {
@@ -92,10 +92,9 @@ ErrorCode CBagSpriteObject::attach() {
 }
 
 ErrorCode CBagSpriteObject::detach() {
-	if (_xSprite != nullptr) {
-		delete _xSprite;
-		_xSprite = nullptr;
-	}
+	delete _xSprite;
+	_xSprite = nullptr;
+
 	return CBagObject::detach();
 }
 
@@ -177,7 +176,7 @@ ParseCodes CBagSpriteObject::setInfo(CBagIfstream &istr) {
 				istr.eatWhite();
 				getIntFromStream(istr, nFrameRate);
 
-				// The framerate is expressed in frames/second, so do some division
+				// The frame rate is expressed in frames/second, so do some division
 				// here to store the number of milliseconds.
 				setFrameRate(1000 / nFrameRate);
 
@@ -188,7 +187,7 @@ ParseCodes CBagSpriteObject::setInfo(CBagIfstream &istr) {
 		}
 		break;
 		//
-		//  no match return from funtion
+		//  no match return from function
 		//
 		default: {
 			ParseCodes rc = CBagObject::setInfo(istr);
diff --git a/engines/bagel/baglib/storage_dev_bmp.cpp b/engines/bagel/baglib/storage_dev_bmp.cpp
index 010a0709eaf..45f847e5a94 100644
--- a/engines/bagel/baglib/storage_dev_bmp.cpp
+++ b/engines/bagel/baglib/storage_dev_bmp.cpp
@@ -32,7 +32,7 @@ CBagStorageDevBmp::CBagStorageDevBmp(CBofWindow *pParent, const CBofRect &xRect,
 	setRect(xRect);
 	_pWorkBmp = nullptr;
 
-	setAssociateWnd(pParent);
+	CBagStorageDev::setAssociateWnd(pParent);
 
 	setVisible();       // This object is visible
 }
@@ -84,10 +84,8 @@ ErrorCode CBagStorageDevBmp::setWorkBmp() {
 }
 
 ErrorCode CBagStorageDevBmp::killWorkBmp() {
-	if (_pWorkBmp != nullptr) {
-		delete _pWorkBmp;
-		_pWorkBmp = nullptr;
-	}
+	delete _pWorkBmp;
+	_pWorkBmp = nullptr;
 
 	return _errCode;
 }
@@ -100,14 +98,9 @@ ErrorCode CBagStorageDevBmp::loadFileFromStream(CBagIfstream &fpInput, const CBo
 }
 
 CBofPoint CBagStorageDevBmp::getScaledPt(CBofPoint xPoint) {
-	CBofRect        SDevDstRect;
-	CBofRect        SDevSrcRect;
-	CBofPoint           pt;
-	CBofRect        rDestRect = getRect();
-
-	SDevDstRect = getRect();                // Get the destination (screen) rect
-	SDevSrcRect = CBagBmpObject::getRect(); // Get the source (origin) rect
+	CBofRect rDestRect = getRect();
 
+	CBofPoint pt;
 	pt.x = _cSrcRect.width() * xPoint.x / rDestRect.width();
 	pt.y = _cSrcRect.height() * xPoint.y / rDestRect.height();
 
@@ -126,12 +119,11 @@ void CBagStorageDevBmp::onLButtonUp(uint32 nFlags, CBofPoint *xPoint, void *info
 }
 
 const CBofPoint CBagStorageDevBmp::devPtToViewPort(const CBofPoint &xPoint) {
-	CBofPoint p;
-
 	// Get the storage device rect
 	CBofRect SDevDstRect = getRect();
 
 	// move point relative to storage device top, left
+	CBofPoint p;
 	p.x = xPoint.x - SDevDstRect.left;
 	p.y = xPoint.y - SDevDstRect.top;
 
diff --git a/engines/bagel/baglib/storage_dev_bmp.h b/engines/bagel/baglib/storage_dev_bmp.h
index 9d2335dbdb6..d375ccb3bf6 100644
--- a/engines/bagel/baglib/storage_dev_bmp.h
+++ b/engines/bagel/baglib/storage_dev_bmp.h
@@ -71,14 +71,14 @@ public:
 	 */
 	CBofPoint getScaledPt(CBofPoint xPoint);
 
-	ErrorCode setBackground(CBofBitmap *pBmp);
-	CBofBitmap *getBackground() {
+	ErrorCode setBackground(CBofBitmap *pBmp) override;
+	CBofBitmap *getBackground() override {
 		return getBitmap();
 	}
 
-	virtual ErrorCode loadFileFromStream(CBagIfstream &fpInput, const CBofString &sWldName, bool bAttach = true);
+	ErrorCode loadFileFromStream(CBagIfstream &fpInput, const CBofString &sWldName, bool bAttach = true) override;
 
-	virtual bool isAttached() {
+	bool isAttached() override {
 		return CBagBmpObject::isAttached();
 	}
 
@@ -86,24 +86,24 @@ public:
 		return true;
 	}
 
-	virtual ErrorCode attach();
-	virtual ErrorCode detach();
+	ErrorCode attach() override;
+	ErrorCode detach() override;
 
-	virtual ErrorCode update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcRect = nullptr, int nMaskColor = -1);
+	ErrorCode update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcRect = nullptr, int nMaskColor = -1) override;
 
 	/**
 	 * Called on the mouse left button up of the bagbmobj
 	 *  and redirected to the lbutton up of the CBagStorageDev
 	 */
-	void onLButtonUp(uint32 nFlags, CBofPoint *xPoint, void *info);
+	void onLButtonUp(uint32 nFlags, CBofPoint *xPoint, void *info) override;
 
 	/**
 	 * Called on the mouse left button down of the bagbmobj
 	 * and redirected to the lbutton down of the CBagStorageDev
 	 */
-	virtual void onLButtonDown(uint32 nFlags, CPoint *xPoint, void *info = nullptr);
+	void onLButtonDown(uint32 nFlags, CPoint *xPoint, void *info = nullptr) override;
 
-	virtual const CBofPoint devPtToViewPort(const CBofPoint &xPoint);
+	const CBofPoint devPtToViewPort(const CBofPoint &xPoint) override;
 };
 
 } // namespace Bagel
diff --git a/engines/bagel/baglib/text_object.cpp b/engines/bagel/baglib/text_object.cpp
index db70ebe6283..5fb68d741ee 100644
--- a/engines/bagel/baglib/text_object.cpp
+++ b/engines/bagel/baglib/text_object.cpp
@@ -40,7 +40,7 @@ CBagTextObject::CBagTextObject() : CBagObject() {
 	_nDX = 80;
 	_nDY = 20;
 	_psText = nullptr;
-	setOverCursor(1); // Switch to cursor 1, 4 doesn't exist.
+	CBagObject::setOverCursor(1); // Switch to cursor 1, 4 doesn't exist.
 
 	_nPointSize = 16;
 	_nFGColor = CTEXT_COLOR;
@@ -58,7 +58,7 @@ CBagTextObject::~CBagTextObject() {
 		delete _psInitInfo;
 		_psInitInfo = nullptr;
 	}
-	detach();
+	CBagTextObject::detach();
 }
 
 CBofRect CBagTextObject::getRect() {
@@ -85,13 +85,10 @@ ErrorCode CBagTextObject::update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcR
 			int nPointSize = _nPointSize;
 			int nFormat = FORMAT_CENTER_LEFT;
 			if (!_bTitle) {
-
-				CBofRect cBevel;
-				int i;
-
 				byte c1 = 3;
 				byte c2 = 9;
 
+				CBofRect cBevel;
 				cBevel.intersectRect(pBmp->getRect(), r);
 
 				int left = cBevel.left;
@@ -104,6 +101,7 @@ ErrorCode CBagTextObject::update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcR
 				r.right -= 5;
 				r.bottom -= 5;
 
+				int i;
 				for (i = 1; i <= 3; i++) {
 					pBmp->line(left + i, bottom - i, right - i, bottom - i, c1);
 					pBmp->line(right - i, bottom - i, right - i, top + i - 1, c1);
@@ -135,10 +133,8 @@ ErrorCode CBagTextObject::attach() {
 
 	if (!getFileName().right(4).find(".TXT") || !getFileName().right(4).find(".txt")) {
 		// Prevent memory leak
-		if (_psText != nullptr) {
-			delete _psText;
-			_psText = nullptr;
-		}
+		delete _psText;
+		_psText = nullptr;
 
 		// Allocate a new string
 		_psText = new CBofString;
@@ -183,13 +179,12 @@ ErrorCode CBagTextObject::attach() {
 	} else {
 		// The Text is in the Bagel script, rather than a .txt file
 		// Prevent memory leak
-		if (_psText != nullptr) {
-			delete _psText;
-			_psText = nullptr;
-		}
+		delete _psText;
+		_psText = nullptr;
 
 		// Allocate a new string
-		if ((_psText = new CBofString) != nullptr) {
+		_psText = new CBofString;
+		if (_psText != nullptr) {
 			*_psText = getFileName();
 
 			// Replace any underscores with spaces
@@ -216,10 +211,8 @@ ErrorCode CBagTextObject::attach() {
 ErrorCode CBagTextObject::detach() {
 	assert(isValidObject(this));
 
-	if (_psText != nullptr) {
-		delete _psText;
-		_psText = nullptr;
-	}
+	delete _psText;
+	_psText = nullptr;
 
 	return CBagObject::detach();
 }
@@ -381,7 +374,7 @@ ParseCodes CBagTextObject::setInfo(CBagIfstream &istr) {
 		}
 
 		//
-		// No match return from funtion
+		// No match return from function
 		//
 		default: {
 			ParseCodes rc;
diff --git a/engines/bagel/baglib/time_object.cpp b/engines/bagel/baglib/time_object.cpp
index 61228a7f74c..d5f90794b0e 100644
--- a/engines/bagel/baglib/time_object.cpp
+++ b/engines/bagel/baglib/time_object.cpp
@@ -35,12 +35,12 @@ CBagTimeObject::CBagTimeObject() : CBagObject() {
 	_xDig4 = nullptr;
 	_nCels = 1;
 
-	setOverCursor(1);
+	CBagObject::setOverCursor(1);
 	setTimeless(true);
 }
 
 CBagTimeObject::~CBagTimeObject() {
-	detach();
+	CBagTimeObject::detach();
 }
 
 ErrorCode CBagTimeObject::attach() {
@@ -60,25 +60,20 @@ ErrorCode CBagTimeObject::attach() {
 	} else {
 		reportError(ERR_MEMORY, "Could not allocate  Dig1 sprite");
 	}
-	if ((_xDig2 = new CBofSprite()) != nullptr) {
 
+	if ((_xDig2 = new CBofSprite()) != nullptr) {
 		if (_xDig2->loadSprite(getFileName(), getCels()) != 0 && (_xDig2->width() != 0) && (_xDig2->height() != 0)) {
-
 			_xDig2->setAnimated(false);
-
 			_xDig2->setPosition(p.x, p.y);
-
 			p.offset(_xDig2->width(), 0);
-
 		} else {
 			reportError(ERR_FOPEN, "Could Not Open Dig2 Sprite: %s", _xDig2->getFileName());
 		}
-
 	} else {
 		reportError(ERR_MEMORY, "Could not allocate  Dig2 sprite");
 	}
-	if ((_xColon = new CBofSprite()) != nullptr) {
 
+	if ((_xColon = new CBofSprite()) != nullptr) {
 		if (_xColon->loadSprite(getFileName(), getCels()) != 0 && (_xColon->width() != 0) && (_xColon->height() != 0)) {
 
 			_xColon->setAnimated(false);
@@ -94,35 +89,27 @@ ErrorCode CBagTimeObject::attach() {
 	} else {
 		reportError(ERR_MEMORY, "Could not allocate  Colon sprite");
 	}
-	if ((_xDig3 = new CBofSprite()) != nullptr) {
 
+	if ((_xDig3 = new CBofSprite()) != nullptr) {
 		if (_xDig3->loadSprite(getFileName(), getCels()) != 0 && (_xDig3->width() != 0) && (_xDig3->height() != 0)) {
-
 			_xDig3->setAnimated(false);
-
 			_xDig3->setPosition(p.x, p.y);
-
 			p.offset(_xDig3->width(), 0);
 		} else {
 			reportError(ERR_FOPEN, "Could Not Open Dig3 Sprite: %s", _xDig3->getFileName());
 		}
-
 	} else {
 		reportError(ERR_MEMORY, "Could not allocate  Dig3 sprite");
 	}
-	if ((_xDig4 = new CBofSprite()) != nullptr) {
 
+	if ((_xDig4 = new CBofSprite()) != nullptr) {
 		if (_xDig4->loadSprite(getFileName(), getCels()) != 0 && (_xDig4->width() != 0) && (_xDig4->height() != 0)) {
-
 			_xDig4->setAnimated(false);
-
 			_xDig4->setPosition(p.x, p.y);
-
 			p.offset(_xDig4->width(), 0);
 		} else {
 			reportError(ERR_FOPEN, "Could Not Open Dig4 Sprite: %s", _xDig4->getFileName());
 		}
-
 	} else {
 		reportError(ERR_MEMORY, "Could not allocate  Dig4 sprite");
 	}
@@ -131,26 +118,20 @@ ErrorCode CBagTimeObject::attach() {
 }
 
 ErrorCode CBagTimeObject::detach() {
-	if (_xDig1) {
-		delete _xDig1;
-		_xDig1 = nullptr;
-	}
-	if (_xDig2) {
-		delete _xDig2;
-		_xDig2 = nullptr;
-	}
-	if (_xColon) {
-		delete _xColon;
-		_xColon = nullptr;
-	}
-	if (_xDig3) {
-		delete _xDig3;
-		_xDig3 = nullptr;
-	}
-	if (_xDig4) {
-		delete _xDig4;
-		_xDig4 = nullptr;
-	}
+	delete _xDig1;
+	_xDig1 = nullptr;
+
+	delete _xDig2;
+	_xDig2 = nullptr;
+
+	delete _xColon;
+	_xColon = nullptr;
+
+	delete _xDig3;
+	_xDig3 = nullptr;
+
+	delete _xDig4;
+	_xDig4 = nullptr;
 
 	return CBagObject::detach();
 }
@@ -181,7 +162,7 @@ CBofRect CBagTimeObject::getRect() {
 	if (_xDig1) {
 		s = _xDig1->getSize();
 
-		// Increase the width to accomadate all 5 sprites
+		// Increase the width to accomodate all 5 sprites
 		s.cx = s.cx * 5;
 	}
 	return CBofRect(p, s);
@@ -304,55 +285,4 @@ ErrorCode CBagTimeObject::update(CBofBitmap *pBmp, CBofPoint pt, CBofRect * /*pS
 	return rc;
 }
 
-ErrorCode CBagTimeObject::update(CBofWindow *pWnd, CBofPoint pt, CBofRect *, int) {
-	char szLocalBuff[256];
-	szLocalBuff[0] = '\0';
-	CBofString sTimeString(szLocalBuff, 256);
-
-	ErrorCode rc = ERR_NONE;
-
-	CBagVar *xVar = g_VarManager->getVariable(_sVariable);
-
-	// If everything looks good
-	if (isAttached() && xVar && !(xVar->getValue().isEmpty())) {
-		int nTimeVal = xVar->getNumValue();
-		sTimeString = buildString("%04d", nTimeVal);
-		char sDigString[2] = "0";
-
-		// Digit 1
-		if (_xDig1) {
-			sDigString[0] = sTimeString[0];
-			_xDig1->setCel(atoi(sDigString));
-			_xDig1->paintSprite(pWnd, pt.x, pt.y);
-			pt.offset(_xDig1->width(), 0);
-		}
-		// Digit 2
-		if (_xDig2) {
-			sDigString[0] = sTimeString[1];
-			_xDig2->setCel(atoi(sDigString));
-			_xDig2->paintSprite(pWnd, pt.x, pt.y);
-			pt.offset(_xDig2->width(), 0);
-		}
-		if (_xColon) {
-			_xColon->paintSprite(pWnd, pt.x, pt.y);
-			pt.offset(_xColon->width(), 0);
-		}
-		// Digit 3
-		if (_xDig3) {
-			sDigString[0] = sTimeString[2];
-			_xDig3->setCel(atoi(sDigString));
-			_xDig3->paintSprite(pWnd, pt.x, pt.y);
-			pt.offset(_xDig3->width(), 0);
-		}
-		// Digit 4
-		if (_xDig4) {
-			sDigString[0] = sTimeString[3];
-			_xDig4->setCel(atoi(sDigString));
-			_xDig4->paintSprite(pWnd, pt.x, pt.y);
-		}
-	}
-
-	return rc;
-}
-
 } // namespace Bagel
diff --git a/engines/bagel/baglib/time_object.h b/engines/bagel/baglib/time_object.h
index fae63952c12..028aef8d2df 100644
--- a/engines/bagel/baglib/time_object.h
+++ b/engines/bagel/baglib/time_object.h
@@ -52,9 +52,9 @@ public:
 	/**
 	 * Create all 5 sprite objects for the clock and set their positions
 	 */
-	ErrorCode attach();
-	ErrorCode detach();
-	bool isAttached() {
+	ErrorCode attach() override;
+	ErrorCode detach() override;
+	bool isAttached() override {
 		return _xDig1 != nullptr;
 	}
 
@@ -62,23 +62,22 @@ public:
 	 * Takes in info and then removes the relative information and returns the info
 	 * without the relevant info.
 	 */
-	ParseCodes setInfo(CBagIfstream &istr);
+	ParseCodes setInfo(CBagIfstream &istr) override;
 
-	CBofRect getRect();
+	CBofRect getRect() override;
 	int getCels() {
 		return _nCels;
 	}
 
 	void setCels(int nCels);
-	virtual void setPosition(const CBofPoint &pos);
+	void setPosition(const CBofPoint &pos) override;
 
 	/**
 	 * Read in the value of the associated variable and set the time equal
 	 * to the first 4 digits of the variable if the variable is less the 4 digits
 	 * the time is padded with 0's if it is greater the 4 we truncate to remaining digits
 	 */
-	virtual ErrorCode update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcRect = nullptr, int /*nMaskColor*/ = -1);
-	virtual ErrorCode update(CBofWindow *pWnd, CBofPoint pt, CBofRect * /*pSrcRect*/ = nullptr, int /*nMaskColor*/ = -1);
+	ErrorCode update(CBofBitmap *pBmp, CBofPoint pt, CBofRect *pSrcRect = nullptr, int /*nMaskColor*/ = -1) override;
 
 	void setVariable(const CBofString &sProp) {
 		_sVariable = sProp;
diff --git a/engines/bagel/baglib/var.cpp b/engines/bagel/baglib/var.cpp
index bdf3317335e..98caaa008ef 100644
--- a/engines/bagel/baglib/var.cpp
+++ b/engines/bagel/baglib/var.cpp
@@ -92,18 +92,13 @@ const CBofString &CBagVar::getValue() {
 
 	// Check if these items should be replaced by the current sdev
 	if (!_sVarName.isEmpty() && !_sVarName.find(CURRSDEV_TOKEN)) {
-		CBofString CurrSDev;
 		if (CBagel::getBagApp()->getMasterWnd()->getCurrentStorageDev()) {
 			_sVarValue = CBagel::getBagApp()->getMasterWnd()->getCurrentStorageDev()->getName();
 		}
-	} else {
-
+	} else if (!_sVarName.isEmpty() && !_sVarName.find(PREVSDEV_TOKEN)) {
 		// Check if these items should be replaced by the previous sdev
-		if (!_sVarName.isEmpty() && !_sVarName.find(PREVSDEV_TOKEN)) {
-			CBofString CurrSDev;
-			if (CBagel::getBagApp()->getMasterWnd()->getCurrentStorageDev()) {
-				_sVarValue = CBagel::getBagApp()->getMasterWnd()->getCurrentStorageDev()->getPrevSDev();
-			}
+		if (CBagel::getBagApp()->getMasterWnd()->getCurrentStorageDev()) {
+			_sVarValue = CBagel::getBagApp()->getMasterWnd()->getCurrentStorageDev()->getPrevSDev();
 		}
 	}
 
@@ -322,10 +317,7 @@ ErrorCode CBagVarManager::releaseVariables(bool bIncludeGlobals) {
 	if (bIncludeGlobals) {
 		while (_xVarList.getCount()) {
 			CBagVar *pVar = _xVarList.removeHead();
-
-			if (pVar) {
-				delete pVar;
-			}
+			delete pVar;
 		}
 	} else { // Do not include globals
 		for (int i = _xVarList.getCount() - 1; i >= 0; i--) {
diff --git a/engines/bagel/baglib/var.h b/engines/bagel/baglib/var.h
index 354743e3e70..55f5f9a6355 100644
--- a/engines/bagel/baglib/var.h
+++ b/engines/bagel/baglib/var.h
@@ -113,7 +113,6 @@ public:
 	void setBoolean() {
 		_xVarType = BOOLEAN;
 	}
-	// void setType(VARTYPE xType)      { _xVarType  = xType; }
 
 	void increment();
 };




More information about the Scummvm-git-logs mailing list