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

Strangerke noreply at scummvm.org
Sun May 19 19:27:43 UTC 2024


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

Summary:
23a8fccd85 BAGEL: Remove some more useless checks, turn some functions into void functions
c7229574ef BAGEL: Remove an unused function in CBofSprite


Commit: 23a8fccd8500f9de567bf336cd9770e167a3d8c0
    https://github.com/scummvm/scummvm/commit/23a8fccd8500f9de567bf336cd9770e167a3d8c0
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-19T20:27:29+01:00

Commit Message:
BAGEL: Remove some more useless checks, turn some functions into void functions

Changed paths:
    engines/bagel/boflib/gfx/bitmap.cpp
    engines/bagel/boflib/gfx/sprite.cpp
    engines/bagel/boflib/gfx/sprite.h


diff --git a/engines/bagel/boflib/gfx/bitmap.cpp b/engines/bagel/boflib/gfx/bitmap.cpp
index 7838b82ce02..656155a41c5 100644
--- a/engines/bagel/boflib/gfx/bitmap.cpp
+++ b/engines/bagel/boflib/gfx/bitmap.cpp
@@ -87,9 +87,7 @@ CBofBitmap::CBofBitmap(const char *pszFileName, CBofPalette *pPalette, bool bOwn
 
 	if (pPalette == nullptr) {
 		pPalette = new CBofPalette(pszFileName);
-		if (pPalette != nullptr) {
-			_bOwnPalette = true;
-		}
+		_bOwnPalette = true;
 	}
 
 	// Init the info needed to load a bitmap from disk
@@ -166,35 +164,31 @@ ErrorCode CBofBitmap::loadBitmap(const char *pszFileName, CBofPalette *pPalette)
 		CBofFile *pFile = new CBofFile(pszFileName, CBOFFILE_READONLY);
 
 		// Open bitmap
-		if (pFile == nullptr)
-			reportError(ERR_MEMORY, "Could not allocate a CBofFile for %s", pszFileName);
-		else {
-			// filename must fit into our buffer
-			assert(strlen(pszFileName) < MAX_FNAME);
-
-			// Keep track of this filename
-			Common::strcpy_s(_szFileName, pszFileName);
-
-			// Decode the bitmap
-			Image::BitmapDecoder decoder;
-			Common::SeekableReadStream *rs = *pFile;
-			if (!rs || !decoder.loadStream(*rs))
-				error("Could not load bitmap");
-
-			// Load up the decoded bitmap
-			_bitmap.copyFrom(*decoder.getSurface());
-
-			// Load the bitmap palette
-			_bitmap.setPalette(decoder.getPalette(), 0, PALETTE_COUNT);
-
-			_nDX = _bitmap.w;
-			_nDY = _bitmap.h;
-			_nScanDX = _bitmap.pitch;
-			_pBits = (byte*)_bitmap.getBasePtr(0, 0);
-
-			// Close bitmap file
-			delete pFile;
-		}
+		// filename must fit into our buffer
+		assert(strlen(pszFileName) < MAX_FNAME);
+
+		// Keep track of this filename
+		Common::strcpy_s(_szFileName, pszFileName);
+
+		// Decode the bitmap
+		Image::BitmapDecoder decoder;
+		Common::SeekableReadStream *rs = *pFile;
+		if (!rs || !decoder.loadStream(*rs))
+			error("Could not load bitmap");
+
+		// Load up the decoded bitmap
+		_bitmap.copyFrom(*decoder.getSurface());
+
+		// Load the bitmap palette
+		_bitmap.setPalette(decoder.getPalette(), 0, PALETTE_COUNT);
+
+		_nDX = _bitmap.w;
+		_nDY = _bitmap.h;
+		_nScanDX = _bitmap.pitch;
+		_pBits = (byte*)_bitmap.getBasePtr(0, 0);
+
+		// Close bitmap file
+		delete pFile;
 	}
 
 	return _errCode;
@@ -1120,22 +1114,17 @@ ErrorCode paintBitmap(CBofWindow *pWindow, const char *pszFileName, CBofRect *pD
 	ErrorCode errorCode;
 	CBofBitmap *pBmp = new CBofBitmap(pszFileName, pPalette);
 
-	if (pBmp != nullptr) {
-		CBofRect cRect = pBmp->getRect();
-
-		if (pSrcRect == nullptr)
-			pSrcRect = &cRect;
+	CBofRect cRect = pBmp->getRect();
 
-		if (pDstRect == nullptr)
-			pDstRect = &cRect;
+	if (pSrcRect == nullptr)
+		pSrcRect = &cRect;
 
-		errorCode = pBmp->paint(pWindow, pDstRect, pSrcRect, nMaskColor);
+	if (pDstRect == nullptr)
+		pDstRect = &cRect;
 
-		delete pBmp;
+	errorCode = pBmp->paint(pWindow, pDstRect, pSrcRect, nMaskColor);
 
-	} else {
-		errorCode = ERR_MEMORY;
-	}
+	delete pBmp;
 
 	return errorCode;
 }
diff --git a/engines/bagel/boflib/gfx/sprite.cpp b/engines/bagel/boflib/gfx/sprite.cpp
index 82791ecd854..d1d2c892161 100644
--- a/engines/bagel/boflib/gfx/sprite.cpp
+++ b/engines/bagel/boflib/gfx/sprite.cpp
@@ -164,10 +164,7 @@ void CBofSprite::flushSpriteChain() {
 }
 
 
-bool CBofSprite::setupWorkArea(int dx, int dy) {
-	// Assume failure
-	bool bSuccess = false;
-
+void CBofSprite::setupWorkArea(int dx, int dy) {
 	// Do we already have a work area?
 	if (_pWorkBmp != nullptr) {
 		// Yes, so lets tear it down before we start a new one
@@ -176,13 +173,8 @@ bool CBofSprite::setupWorkArea(int dx, int dy) {
 
 	// Create an offscreen bitmap where we do all the work;
 	_pWorkBmp = new CBofBitmap(dx, dy, _pSharedPalette);
-	if (_pWorkBmp != nullptr) {
-		_nWorkDX = dx;
-		_nWorkDY = dy;
-		bSuccess = true;
-	}
-
-	return bSuccess;
+	_nWorkDX = dx;
+	_nWorkDY = dy;
 }
 
 
@@ -197,40 +189,28 @@ CBofSprite *CBofSprite::duplicateSprite() {
 
 	// Create an object for the sprite
 	CBofSprite *pSprite = new CBofSprite;
-
-	if (pSprite != nullptr) {
-		duplicateSprite(pSprite);
-	}
+	duplicateSprite(pSprite);
 
 	return pSprite;
 }
 
 
-bool CBofSprite::duplicateSprite(CBofSprite *pSprite) {
-	assert(isValidObject(this));
-
-	// We require a valid sprite to copy
-	assert(pSprite != nullptr);
-
-	if (pSprite != nullptr) {
-		pSprite->_pImage = _pImage;
-
-		pSprite->_cRect = _cRect;
-		pSprite->_cImageRect = _cImageRect;
-		pSprite->_cSize = _cSize;
-		pSprite->_cPosition = _cPosition;
-		pSprite->_nZOrder = _nZOrder;
-		pSprite->_nCelID = _nCelID;
-		pSprite->_nCelCount = _nCelCount;
-		pSprite->_bAnimated = _bAnimated;
-		pSprite->_nMaskColor = _nMaskColor;
-
-		pSprite->_bDuplicated = true;		// Mark it as a sprite with shared resources
+void CBofSprite::duplicateSprite(CBofSprite *pSprite) {
+	if (!isValidObject(this) || (pSprite == nullptr))
+		error("duplicateSprite - Invalid source or destination sprite");
 
-		return true;
-	}
+	pSprite->_pImage = _pImage;
+	pSprite->_cRect = _cRect;
+	pSprite->_cImageRect = _cImageRect;
+	pSprite->_cSize = _cSize;
+	pSprite->_cPosition = _cPosition;
+	pSprite->_nZOrder = _nZOrder;
+	pSprite->_nCelID = _nCelID;
+	pSprite->_nCelCount = _nCelCount;
+	pSprite->_bAnimated = _bAnimated;
+	pSprite->_nMaskColor = _nMaskColor;
 
-	return false;
+	pSprite->_bDuplicated = true;		// Mark it as a sprite with shared resources
 }
 
 
@@ -241,11 +221,7 @@ bool CBofSprite::loadSprite(const char *pszPathName, int nCels) {
 
 	// Create an object for the sprite's image
 	CBofBitmap *pBitmap = new CBofBitmap(pszPathName, _pSharedPalette);
-	if (pBitmap != nullptr) {
-		return loadSprite(pBitmap, nCels);
-	}
-
-	return false;	// Return failure
+	return loadSprite(pBitmap, nCels);
 }
 
 
@@ -331,7 +307,7 @@ void CBofSprite::prevCel() {
 bool CBofSprite::paintSprite(CBofWindow *pWnd, const int x, const int y) {
 	assert(isValidObject(this));
 
-	// Can't paint to a non-existant window
+	// Can't paint to a non-existent window
 	assert(pWnd != nullptr);
 
 	// The window MUST have a backdrop
diff --git a/engines/bagel/boflib/gfx/sprite.h b/engines/bagel/boflib/gfx/sprite.h
index 8083198351c..61933f0b357 100644
--- a/engines/bagel/boflib/gfx/sprite.h
+++ b/engines/bagel/boflib/gfx/sprite.h
@@ -50,7 +50,7 @@ public:
 
 	// Implementation
 	CBofSprite *duplicateSprite();
-	bool duplicateSprite(CBofSprite *pSprite);
+	void duplicateSprite(CBofSprite *pSprite);
 
 	bool loadSprite(const char *pszPathName, int nCels = 1);
 	bool loadSprite(CBofBitmap *pBitmap, int nCels = 1);
@@ -185,7 +185,7 @@ public:
 
 	static void flushSpriteChain();
 
-	static bool setupWorkArea(int dx, int dy);
+	static void setupWorkArea(int dx, int dy);
 	static void tearDownWorkArea();
 
 	// Add a method for allowing callers of this object to block


Commit: c7229574efc92f7937d011cdf2b1381a852beb97
    https://github.com/scummvm/scummvm/commit/c7229574efc92f7937d011cdf2b1381a852beb97
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-05-19T20:27:29+01:00

Commit Message:
BAGEL: Remove an unused function in CBofSprite

Changed paths:
    engines/bagel/boflib/gfx/sprite.cpp
    engines/bagel/boflib/gfx/sprite.h


diff --git a/engines/bagel/boflib/gfx/sprite.cpp b/engines/bagel/boflib/gfx/sprite.cpp
index d1d2c892161..f77882e889b 100644
--- a/engines/bagel/boflib/gfx/sprite.cpp
+++ b/engines/bagel/boflib/gfx/sprite.cpp
@@ -693,33 +693,6 @@ void CBofSprite::setPosition(int x, int y) {
 }
 
 
-bool CBofSprite::cropImage(CBofWindow *pWnd, CBofRect *pRect, bool bUpdateNow) {
-	assert(isValidObject(this));
-	assert(pWnd != nullptr);
-	assert(pRect != nullptr);
-	assert(_pImage != nullptr);
-
-	if (_nMaskColor != NOT_TRANSPARENT) {
-
-		CBofRect myRect = *pRect; // Offset crop area by image rect
-		myRect.left += _cImageRect.left;
-		myRect.right += _cImageRect.left;
-		CBofRect cDestRect = myRect + _cPosition;
-
-		_pImage->fillRect(&myRect, (byte)_nMaskColor);
-
-		if (bUpdateNow) {
-			CBofBitmap *pBackdrop = pWnd->getBackdrop();
-			if (pBackdrop != nullptr) {
-				pBackdrop->paint(pWnd, &cDestRect, &myRect);
-			}
-		}
-	}
-
-	return true;
-}
-
-
 void CBofSprite::clearImage() {
 	assert(isValidObject(this));
 
diff --git a/engines/bagel/boflib/gfx/sprite.h b/engines/bagel/boflib/gfx/sprite.h
index 61933f0b357..6702ae3ba18 100644
--- a/engines/bagel/boflib/gfx/sprite.h
+++ b/engines/bagel/boflib/gfx/sprite.h
@@ -77,8 +77,6 @@ public:
 	void nextCel();
 	void prevCel();
 
-	bool cropImage(CBofWindow *pWnd, CBofRect *pRect, bool bUpdateNow = true);
-
 	bool refreshSprite(CBofBitmap *pBmp) {
 		return paintSprite(pBmp, _cPosition.x, _cPosition.y);
 	}




More information about the Scummvm-git-logs mailing list