[Scummvm-git-logs] scummvm master -> 8bb49c1acff2013c564eb9654008ab7ff34c2f18

sdelamarre noreply at scummvm.org
Thu Jan 12 22:36:29 UTC 2023


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:
8bb49c1acf GOB: fix cursor still visible in breakout game of some Adibou2 versions


Commit: 8bb49c1acff2013c564eb9654008ab7ff34c2f18
    https://github.com/scummvm/scummvm/commit/8bb49c1acff2013c564eb9654008ab7ff34c2f18
Author: Simon Delamarre (simon.delamarre14 at gmail.com)
Date: 2023-01-12T23:26:40+01:00

Commit Message:
GOB: fix cursor still visible in breakout game of some Adibou2 versions

Only cursors drawn from scripts must be copied in _cursorSprites, not the ones loaded from executable.
This simplifies a lot of globals from the Draw object, that were needed only in the cursor-from-exec case.

Note: other GOB games are not impacted even if shared code from draw_v2.cpp, inter_v1.cpp is modified (_cursorHotspotsX and _doCursorPalettes are non-null only in Adibou 2).

Changed paths:
    engines/gob/draw.cpp
    engines/gob/draw.h
    engines/gob/draw_v2.cpp
    engines/gob/draw_v7.cpp
    engines/gob/inter_v1.cpp


diff --git a/engines/gob/draw.cpp b/engines/gob/draw.cpp
index ecf18f925b6..a9819e3f25d 100644
--- a/engines/gob/draw.cpp
+++ b/engines/gob/draw.cpp
@@ -112,13 +112,6 @@ Draw::Draw(GobEngine *vm) : _vm(vm) {
 	}
 
 	_cursorCount         = 0;
-	_doCursorPalettes    = nullptr;
-	_cursorPalettes      = nullptr;
-	_cursorKeyColors     = nullptr;
-	_cursorPaletteStarts = nullptr;
-	_cursorPaletteCounts = nullptr;
-	_cursorHotspotsX     = nullptr;
-	_cursorHotspotsY     = nullptr;
 
 	_palLoadData1[0] = 0;
 	_palLoadData1[1] = 17;
@@ -137,14 +130,6 @@ Draw::Draw(GobEngine *vm) : _vm(vm) {
 }
 
 Draw::~Draw() {
-	delete[] _cursorPalettes;
-	delete[] _doCursorPalettes;
-	delete[] _cursorKeyColors;
-	delete[] _cursorPaletteStarts;
-	delete[] _cursorPaletteCounts;
-	delete[] _cursorHotspotsX;
-	delete[] _cursorHotspotsY;
-
 	for (int i = 0; i < kFontCount; i++)
 		delete _fonts[i];
 }
@@ -398,8 +383,7 @@ void Draw::resizeCursors(int16 width, int16 height, int16 count, bool transparen
 
 	// Cursors sprite already big enough
 	if (sameCursorDimensions &&
-		_vm->_draw->_cursorCount >= count &&
-		_vm->_draw->_doCursorPalettes != nullptr)
+		_vm->_draw->_cursorCount >= count)
 		return;
 
 	debugC(5, kDebugGraphics, "Resizing cursors: size %dx%d -> %dx%d, cursor count %d -> %d)",
@@ -418,7 +402,6 @@ void Draw::resizeCursors(int16 width, int16 height, int16 count, bool transparen
 	_vm->_draw->freeSprite(Draw::kCursorSurface);
 	_vm->_draw->_cursorSprites.reset();
 	_vm->_draw->_cursorSpritesBack.reset();
-	_vm->_draw->_scummvmCursor.reset();
 
 	_vm->_draw->initSpriteSurf(Draw::kCursorSurface, width * count, height, 2);
 
@@ -428,59 +411,6 @@ void Draw::resizeCursors(int16 width, int16 height, int16 count, bool transparen
 	if (sameCursorDimensions && oldCursorCount < count)
 		_vm->_draw->_cursorSprites->blit(*oldCursorsSprites);
 	oldCursorsSprites.reset();
-
-	_vm->_draw->_scummvmCursor = _vm->_video->initSurfDesc(width, height, SCUMMVM_CURSOR);
-
-	if (oldCursorCount < count || _vm->_draw->_doCursorPalettes == nullptr) {
-		bool *oldDoCursorPalettes = _vm->_draw->_doCursorPalettes;
-		byte *oldCursorPalettes = _vm->_draw->_cursorPalettes;
-		byte *oldCursorKeyColors = _vm->_draw->_cursorKeyColors;
-		uint16 *oldCursorPaletteStarts = _vm->_draw->_cursorPaletteStarts;
-		uint16 *oldCursorPaletteCounts = _vm->_draw->_cursorPaletteCounts;
-		int32 *oldCursorHotspotsX = _vm->_draw->_cursorHotspotsX;
-		int32 *oldCursorHotspotsY = _vm->_draw->_cursorHotspotsY;
-
-		_vm->_draw->_cursorPalettes      = new byte[256 * 3 * count];
-		_vm->_draw->_doCursorPalettes    = new bool[count];
-		_vm->_draw->_cursorKeyColors     = new byte[count];
-		_vm->_draw->_cursorPaletteStarts = new uint16[count];
-		_vm->_draw->_cursorPaletteCounts = new uint16[count];
-		_vm->_draw->_cursorHotspotsX     = new int32[count];
-		_vm->_draw->_cursorHotspotsY     = new int32[count];
-
-		memset(_vm->_draw->_cursorPalettes     , 0, count * 256 * 3);
-		memset(_vm->_draw->_doCursorPalettes   , 0, count * sizeof(bool));
-		memset(_vm->_draw->_cursorKeyColors    , 0, count * sizeof(byte));
-		memset(_vm->_draw->_cursorPaletteStarts, 0, count * sizeof(uint16));
-		memset(_vm->_draw->_cursorPaletteCounts, 0, count * sizeof(uint16));
-		memset(_vm->_draw->_cursorHotspotsX    , 0, count * sizeof(int32));
-		memset(_vm->_draw->_cursorHotspotsY    , 0, count * sizeof(int32));
-
-		if (sameCursorDimensions && oldCursorCount < count) {
-			if (oldCursorPalettes != nullptr)
-				memcpy(_vm->_draw->_cursorPalettes, oldCursorPalettes, oldCursorCount * 256 * 3);
-			if (oldDoCursorPalettes != nullptr)
-				memcpy(_vm->_draw->_doCursorPalettes, oldDoCursorPalettes, oldCursorCount * sizeof(bool));
-			if (oldCursorKeyColors != nullptr)
-				memcpy(_vm->_draw->_cursorKeyColors, oldCursorKeyColors, oldCursorCount * sizeof(byte));
-			if (oldCursorPaletteStarts != nullptr)
-				memcpy(_vm->_draw->_cursorPaletteStarts, oldCursorPaletteStarts, oldCursorCount * sizeof(uint16));
-			if (oldCursorPaletteCounts != nullptr)
-				memcpy(_vm->_draw->_cursorPaletteCounts, oldCursorPaletteCounts, oldCursorCount * sizeof(uint16));
-			if (oldCursorHotspotsX != nullptr)
-				memcpy(_vm->_draw->_cursorHotspotsX, oldCursorHotspotsX, oldCursorCount * sizeof(int32));
-			if (oldCursorHotspotsY != nullptr)
-				memcpy(_vm->_draw->_cursorHotspotsY, oldCursorHotspotsY, oldCursorCount * sizeof(int32));
-		}
-
-		delete[] oldDoCursorPalettes;
-		delete[] oldCursorPalettes;
-		delete[] oldCursorKeyColors;
-		delete[] oldCursorPaletteStarts;
-		delete[] oldCursorPaletteCounts;
-		delete[] oldCursorHotspotsX;
-		delete[] oldCursorHotspotsY;
-	}
 }
 
 int Draw::stringLength(const char *str, uint16 fontIndex) {
diff --git a/engines/gob/draw.h b/engines/gob/draw.h
index d2f7aa4baa6..6297f183502 100644
--- a/engines/gob/draw.h
+++ b/engines/gob/draw.h
@@ -149,16 +149,9 @@ public:
 	int8 _cursorAnimDelays[40];
 	Common::String _cursorNames[40];
 	Common::String _cursorName;
-	bool _isCursorFromExe;
+	bool _cursorDrawnFromScripts;
 
 	int32 _cursorCount;
-	bool *_doCursorPalettes;
-	byte *_cursorPalettes;
-	byte *_cursorKeyColors;
-	uint16 *_cursorPaletteStarts;
-	uint16 *_cursorPaletteCounts;
-	int32 *_cursorHotspotsX;
-	int32 *_cursorHotspotsY;
 
 	int16 _palLoadData1[4];
 	int16 _palLoadData2[4];
@@ -321,7 +314,7 @@ private:
 	Common::WinResources *_cursors;
 
 	bool loadCursorFile();
-	bool loadCursorFromFile(int cursorIndex);
+	bool loadCursorFromFile(Common::String filename);
 };
 
 // Draw operations
diff --git a/engines/gob/draw_v2.cpp b/engines/gob/draw_v2.cpp
index de25fbd8ee4..0537f4a044d 100644
--- a/engines/gob/draw_v2.cpp
+++ b/engines/gob/draw_v2.cpp
@@ -144,9 +144,6 @@ void Draw_v2::animateCursor(int16 cursor) {
 		} else if (_cursorHotspotX != -1) {
 			hotspotX = _cursorHotspotX;
 			hotspotY = _cursorHotspotY;
-		} else if (_cursorHotspotsX != nullptr) {
-			hotspotX = _cursorHotspotsX[_cursorIndex];
-			hotspotY = _cursorHotspotsY[_cursorIndex];
 		}
 
 		newX = _vm->_global->_inter_mouseX - hotspotX;
@@ -158,19 +155,9 @@ void Draw_v2::animateCursor(int16 cursor) {
 				(cursorIndex + 1) * _cursorWidth - 1,
 				_cursorHeight - 1, 0, 0);
 
-		uint32 keyColor = 0;
-		if (_doCursorPalettes && _cursorKeyColors && _doCursorPalettes[cursorIndex])
-			keyColor = _cursorKeyColors[cursorIndex];
-
 		CursorMan.replaceCursor(_scummvmCursor->getData(),
-				_cursorWidth, _cursorHeight, hotspotX, hotspotY, keyColor, false, &_vm->getPixelFormat());
-
-		if (_doCursorPalettes && _doCursorPalettes[cursorIndex]) {
-			CursorMan.replaceCursorPalette(_cursorPalettes + (cursorIndex * 256 * 3),
-					_cursorPaletteStarts[cursorIndex], _cursorPaletteCounts[cursorIndex]);
-			CursorMan.disableCursorPalette(false);
-		} else
-			CursorMan.disableCursorPalette(true);
+				_cursorWidth, _cursorHeight, hotspotX, hotspotY, 0, false, &_vm->getPixelFormat());
+		CursorMan.disableCursorPalette(true);
 
 		if (_frontSurface != _backSurface) {
 			if (!_noInvalidated) {
diff --git a/engines/gob/draw_v7.cpp b/engines/gob/draw_v7.cpp
index c4f51bbf851..d15b04f8d97 100644
--- a/engines/gob/draw_v7.cpp
+++ b/engines/gob/draw_v7.cpp
@@ -63,12 +63,7 @@ bool Draw_v7::loadCursorFile() {
 	return false;
 }
 
-bool Draw_v7::loadCursorFromFile(int cursorIndex) {
-	if (cursorIndex < 0 || cursorIndex >= 40)
-		return false;
-
-	Common::String cursorName = _cursorNames[cursorIndex];
-
+bool Draw_v7::loadCursorFromFile(Common::String cursorName) {
 	Graphics::WinCursorGroup *cursorGroup = nullptr;
 	Graphics::Cursor *defaultCursor = nullptr;
 
@@ -85,21 +80,29 @@ bool Draw_v7::loadCursorFromFile(int cursorIndex) {
 	} else
 		cursor = cursorGroup->cursors[0].cursor;
 
-	// Make sure the cursors sprite it big enough
-	resizeCursors(cursor->getWidth(), cursor->getHeight(), cursorIndex + 1, true);
-
-	Surface cursorSurf(cursor->getWidth(), cursor->getHeight(), 1, cursor->getSurface());
-
-	_vm->_draw->_cursorSprites->blit(cursorSurf, cursorIndex * _vm->_draw->_cursorWidth, 0);
+	// Make sure the cursor sprite is big enough
+	if (_scummvmCursor->getWidth() != cursor->getWidth() || _scummvmCursor->getHeight() != cursor->getHeight()) {
+		_vm->_draw->_scummvmCursor.reset();
+		_vm->_draw->_scummvmCursor = _vm->_video->initSurfDesc(cursor->getWidth(), cursor->getHeight(), SCUMMVM_CURSOR);
+	}
 
-	memcpy(_vm->_draw->_cursorPalettes + cursorIndex * 256 * 3, cursor->getPalette(), cursor->getPaletteCount() * 3);
+	_scummvmCursor->clear();
 
-	_vm->_draw->_doCursorPalettes   [cursorIndex] = true;
-	_vm->_draw->_cursorKeyColors    [cursorIndex] = cursor->getKeyColor();
-	_vm->_draw->_cursorPaletteStarts[cursorIndex] = cursor->getPaletteStartIndex();
-	_vm->_draw->_cursorPaletteCounts[cursorIndex] = cursor->getPaletteCount();
-	_vm->_draw->_cursorHotspotsX    [cursorIndex] = cursor->getHotspotX();
-	_vm->_draw->_cursorHotspotsY    [cursorIndex] = cursor->getHotspotY();
+	Surface cursorSurf(cursor->getWidth(), cursor->getHeight(), 1, cursor->getSurface());
+	_scummvmCursor->blit(cursorSurf, 0, 0);
+
+	CursorMan.replaceCursor(_scummvmCursor->getData(),
+							cursor->getWidth(),
+							cursor->getHeight(),
+							cursor->getHotspotX(),
+							cursor->getHotspotY(),
+							cursor->getKeyColor(),
+							false,
+							&_vm->getPixelFormat());
+	CursorMan.replaceCursorPalette(cursor->getPalette(),
+								   cursor->getPaletteStartIndex(),
+								   cursor->getPaletteCount());
+	CursorMan.disableCursorPalette(false);
 
 	delete cursorGroup;
 	delete defaultCursor;
@@ -154,7 +157,8 @@ void Draw_v7::animateCursor(int16 cursor) {
 	// '------
 
 	if (_cursorAnimLow[cursorIndex] != -1) {
-		// .-- _draw_animateCursorSUB2 ---
+		// --- Advance cursor animation
+		// TODO: Not sure if this is still valid in Adibou2/Adi4
 		if (cursorIndex == _cursorIndex) {
 			if ((_cursorAnimDelays[_cursorIndex] != 0) &&
 				((_cursorTimeKey + (_cursorAnimDelays[_cursorIndex] * 10)) <=
@@ -164,13 +168,13 @@ void Draw_v7::animateCursor(int16 cursor) {
 					(_cursorAnimLow[_cursorIndex] > _cursorAnim))
 					_cursorAnim = _cursorAnimLow[_cursorIndex];
 				_cursorTimeKey = _vm->_util->getTimeKey();
-			} else {
+			} /* else { // Not found in Adibou 2 ASM
 				if (_noInvalidated && (_vm->_global->_inter_mouseX == _cursorX) &&
 					(_vm->_global->_inter_mouseY == _cursorY)) {
 					_vm->_video->waitRetrace();
 					return;
 				}
-			}
+			}*/
 		} else {
 			_cursorIndex = cursorIndex;
 			if (_cursorAnimDelays[cursorIndex] != 0) {
@@ -188,46 +192,33 @@ void Draw_v7::animateCursor(int16 cursor) {
 		}
 		// '------
 
-		bool cursorChanged = _cursorNames[cursorIndex] != _cursorName;
+		if (cursorIndex == -1)
+			return;
 
-		if (((!_cursorNames[cursorIndex].empty() || _isCursorFromExe)) && cursorChanged) {
+		bool cursorChanged = _cursorNames[cursorIndex] != _cursorName;
+		if ((!_cursorDrawnFromScripts || !_cursorNames[cursorIndex].empty()) && cursorChanged) {
 			_cursorName = _cursorNames[cursorIndex];
-
 			// If the cursor name is empty, that cursor will be drawn by the scripts
 			if (_cursorNames[cursorIndex].empty() || _cursorNames[cursorIndex] == "VIDE") { // "VIDE" is "empty" in french
 				for (int i = 0; i < 40; i++) {
 					_cursorNames[i].clear();
 				}
 
-				_isCursorFromExe = false;
-
-				// Make sure the cursors sprite is big enough and set to non-extern palette
-				resizeCursors(-1, -1, cursorIndex + 1, true);
-				for (int i = 0; i < _vm->_draw->_cursorCount; i++) {
-					_vm->_draw->_doCursorPalettes[i] = false;
-				}
+				_cursorDrawnFromScripts = true;
 
 				_cursorX =  _vm->_global->_inter_mouseX;
 				_cursorY =  _vm->_global->_inter_mouseY;
 				_showCursor &= ~1;
 				return;
 			} else {
-				// Clear the cursor sprite at that index
-				_vm->_draw->_cursorSprites->fillRect(cursorIndex * _vm->_draw->_cursorWidth, 0,
-													 cursorIndex * _vm->_draw->_cursorWidth + _vm->_draw->_cursorWidth - 1,
-													 _vm->_draw->_cursorHeight - 1, 0);
-
-				if (!loadCursorFromFile(cursorIndex)) {
-					_cursorX =  _vm->_global->_inter_mouseX;
-					_cursorY =  _vm->_global->_inter_mouseY;
-					return;
-				}
-
-				_isCursorFromExe = true;
+				_cursorDrawnFromScripts = false;
+				loadCursorFromFile(_cursorName);
+				_cursorX =  _vm->_global->_inter_mouseX;
+				_cursorY =  _vm->_global->_inter_mouseY;
 			}
 		}
 
-		if (cursorChanged || !_isCursorFromExe) {
+		if (_cursorDrawnFromScripts) {
 			hotspotX = 0;
 			hotspotY = 0;
 
@@ -237,33 +228,25 @@ void Draw_v7::animateCursor(int16 cursor) {
 			} else if (_cursorHotspotX != -1) {
 				hotspotX = _cursorHotspotX;
 				hotspotY = _cursorHotspotY;
-			} else if (_cursorHotspotsX != nullptr) {
-				hotspotX = _cursorHotspotsX[_cursorIndex];
-				hotspotY = _cursorHotspotsY[_cursorIndex];
 			}
 
 			newX = _vm->_global->_inter_mouseX - hotspotX;
 			newY = _vm->_global->_inter_mouseY - hotspotY;
 
+			if (_scummvmCursor->getWidth() != _cursorWidth || _scummvmCursor->getHeight() != _cursorHeight) {
+				_vm->_draw->_scummvmCursor.reset();
+				_vm->_draw->_scummvmCursor = _vm->_video->initSurfDesc(_cursorWidth, _cursorHeight, SCUMMVM_CURSOR);
+			}
+
 			_scummvmCursor->clear();
 			_scummvmCursor->blit(*_cursorSprites,
 								 cursorIndex * _cursorWidth, 0,
 								 (cursorIndex + 1) * _cursorWidth - 1,
 								 _cursorHeight - 1, 0, 0);
 
-			uint32 keyColor = 0;
-			if (_doCursorPalettes && _cursorKeyColors && _doCursorPalettes[cursorIndex])
-				keyColor = _cursorKeyColors[cursorIndex];
-
 			CursorMan.replaceCursor(_scummvmCursor->getData(),
-									_cursorWidth, _cursorHeight, hotspotX, hotspotY, keyColor, false, &_vm->getPixelFormat());
-
-			if (_doCursorPalettes && _doCursorPalettes[cursorIndex]) {
-				CursorMan.replaceCursorPalette(_cursorPalettes + (cursorIndex * 256 * 3),
-											   _cursorPaletteStarts[cursorIndex], _cursorPaletteCounts[cursorIndex]);
-				CursorMan.disableCursorPalette(false);
-			} else
-				CursorMan.disableCursorPalette(true);
+									_cursorWidth, _cursorHeight, hotspotX, hotspotY, 0, false, &_vm->getPixelFormat());
+			CursorMan.disableCursorPalette(true);
 		}
 
 		if (_frontSurface != _backSurface) {
@@ -278,10 +261,11 @@ void Draw_v7::animateCursor(int16 cursor) {
 				if (MIN(newY, _cursorY) < 50)
 					_vm->_util->delay(5);
 			}
-
-			if (!cursorChanged)
-				return;
 		}
+
+		if (!cursorChanged && !_cursorDrawnFromScripts)
+			return;
+
 	} else {
 		blitCursor();
 		_cursorX = newX;
diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp
index 5151581e709..63066c67468 100644
--- a/engines/gob/inter_v1.cpp
+++ b/engines/gob/inter_v1.cpp
@@ -358,11 +358,6 @@ void Inter_v1::o1_initCursor() {
 		_vm->_draw->_cursorSpritesBack.reset();
 		_vm->_draw->_scummvmCursor.reset();
 
-		if (_vm->_draw->_doCursorPalettes != nullptr) {
-			delete _vm->_draw->_doCursorPalettes;
-			_vm->_draw->_doCursorPalettes = nullptr;
-		}
-
 		_vm->_draw->_cursorWidth = width;
 		_vm->_draw->_cursorHeight = height;
 




More information about the Scummvm-git-logs mailing list