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

neuromancer noreply at scummvm.org
Sun Nov 28 13:22:12 UTC 2021


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

Summary:
0578120fb4 PRIVATE: fix and refactor palette remapping
3d247f33e1 PRIVATE: fixed save game bug
c8849911f8 HYPNO: spider movement in arcade sequences


Commit: 0578120fb429a49edad65dac5f33dff3220bb4c9
    https://github.com/scummvm/scummvm/commit/0578120fb429a49edad65dac5f33dff3220bb4c9
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2021-11-28T14:21:59+01:00

Commit Message:
PRIVATE: fix and refactor palette remapping

Changed paths:
    engines/private/metaengine.cpp
    engines/private/private.cpp
    engines/private/private.h


diff --git a/engines/private/metaengine.cpp b/engines/private/metaengine.cpp
index a7547c6fdb..33ade05c5b 100644
--- a/engines/private/metaengine.cpp
+++ b/engines/private/metaengine.cpp
@@ -41,7 +41,7 @@ Common::Error PrivateMetaEngine::createInstance(OSystem *syst, Engine **engine,
 }
 
 void PrivateMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
-	Graphics::Surface *vs = Private::g_private->decodeImage(Private::g_private->_nextVS);
+	Graphics::Surface *vs = Private::g_private->decodeImage(Private::g_private->_nextVS, nullptr);
 	Graphics::Surface *svs = vs->scale(kThumbnailWidth, kThumbnailHeight2);
 	thumb.copyFrom(*svs);
 
diff --git a/engines/private/private.cpp b/engines/private/private.cpp
index f91d713de6..c831ea6884 100644
--- a/engines/private/private.cpp
+++ b/engines/private/private.cpp
@@ -217,10 +217,10 @@ Common::Error PrivateEngine::run() {
 	_compositeSurface->setTransparentColor(_transparentColor);
 
 	// Load the game frame once
-	_frameImage = decodeImage(_framePath);
-	_mframeImage = decodeImage(_framePath); 
+	byte *palette;
+	_frameImage = decodeImage(_framePath, nullptr);
+	_mframeImage = decodeImage(_framePath, &palette); 
 
-	const byte *palette = decodePalette(_framePath);
 	_framePalette = (byte *) malloc(3*256);
 	memcpy(_framePalette, palette, 3*256);
 
@@ -1232,7 +1232,7 @@ void PrivateEngine::stopSound(bool all) {
 	}
 }
 
-Graphics::Surface *PrivateEngine::decodeImage(const Common::String &name) {
+Graphics::Surface *PrivateEngine::decodeImage(const Common::String &name, byte **palette) {
 	debugC(1, kPrivateDebugFunction, "%s(%s)", __FUNCTION__, name.c_str());
 	Common::File file;
 	Common::String path = convertPath(name);
@@ -1240,59 +1240,51 @@ Graphics::Surface *PrivateEngine::decodeImage(const Common::String &name) {
 		error("unable to load image %s", path.c_str());
 
 	_image->loadStream(file);
-	return _image->getSurface()->convertTo(_pixelFormat, _image->getPalette());
-}
-
-const byte *PrivateEngine::decodePalette(const Common::String &name) {
-	debugC(1, kPrivateDebugFunction, "%s(%s)", __FUNCTION__, name.c_str());
-	Common::File file;
-	Common::String path = convertPath(name);
-	if (!file.open(path))
-		error("unable to load image %s", path.c_str());
-
-	_image->loadStream(file);
-	return _image->getPalette();
-}
+	const Graphics::Surface *oldImage = _image->getSurface();
+	Graphics::Surface *newImage;
+
+	const byte *oldPalette = _image->getPalette();
+	byte *currentPalette;
+
+	uint16 ncolors = _image->getPaletteColorCount();
+	if (ncolors < 256) { // For some reason, requires color remapping
+		currentPalette = (byte *) malloc(3*256);
+		drawScreen();
+		g_system->getPaletteManager()->grabPalette(currentPalette, 0, 256);
+		newImage = oldImage->convertTo(_pixelFormat, currentPalette);
+		remapImage(ncolors, oldImage, oldPalette, newImage, currentPalette);
+	} else {
+		currentPalette = (byte *) oldPalette;
+		newImage = oldImage->convertTo(_pixelFormat, currentPalette);
+	}
 
-void PrivateEngine::loadImage(const Common::String &name, int x, int y) {
-	debugC(1, kPrivateDebugFunction, "%s(%s,%d,%d)", __FUNCTION__, name.c_str(), x, y);
-	Graphics::Surface *surf = decodeImage(name);
-	const byte *palette = decodePalette(name);
-	_compositeSurface->setPalette(palette, 0, 256);
-	_compositeSurface->setTransparentColor(_transparentColor);
-	_compositeSurface->transBlitFrom(*surf, _origin + Common::Point(x, y), _transparentColor);
-	surf->free();
-	delete surf;
-	_image->destroy();
-}
+	if (palette != nullptr) {
+		*palette = currentPalette;
+	}
 
-void PrivateEngine::fillRect(uint32 color, Common::Rect rect) {
-	debugC(1, kPrivateDebugFunction, "%s(%d,..)", __FUNCTION__, color);
-	rect.translate(_origin.x, _origin.y);
-	_compositeSurface->fillRect(rect, color);
+	return newImage;
 }
 
-void PrivateEngine::drawScreenFrame(const byte *newPalette) {
+void PrivateEngine::remapImage(uint16 ncolors, const Graphics::Surface *oldImage, const byte *oldPalette, Graphics::Surface *newImage, const byte *currentPalette) {
 	debugC(1, kPrivateDebugFunction, "%s(..)", __FUNCTION__);
 	byte paletteMap[256];
+	// Run through every color in old palette
+	for (int i = 0; i != ncolors; ++i) {
+		byte r0 = oldPalette[3 * i + 0];
+		byte g0 = oldPalette[3 * i + 1];
+		byte b0 = oldPalette[3 * i + 2];
 
-	// Run through every color in frame palette
-	for (int i = 0; i != 256; ++i) {
-		byte r0 = _framePalette[3 * i + 0];
-		byte g0 = _framePalette[3 * i + 1];
-		byte b0 = _framePalette[3 * i + 2];
-
-		// Find the closest color in video palette
+		// Find the closest color in current palette
 		int closest_distance = 10000;
 		int closest_j = 0;
 		for (int j = 0; j != 256; ++j) {
-			byte r1 = newPalette[3 * j + 0];
-			byte g1 = newPalette[3 * j + 1];
-			byte b1 = newPalette[3 * j + 2];
+			byte r1 = currentPalette[3 * j + 0];
+			byte g1 = currentPalette[3 * j + 1];
+			byte b1 = currentPalette[3 * j + 2];
 
 			int distance = (MAX(r0, r1) - MIN(r0, r1))
-			             + (MAX(g0, g1) - MIN(g0, g1))
-			             + (MAX(b0, b1) - MIN(b0, b1));
+						+ (MAX(g0, g1) - MIN(g0, g1))
+						+ (MAX(b0, b1) - MIN(b0, b1));
 
 			if (distance < closest_distance) {
 				closest_distance = distance;
@@ -1302,16 +1294,38 @@ void PrivateEngine::drawScreenFrame(const byte *newPalette) {
 		paletteMap[i] = closest_j;
 	}
 
-	byte *src = (byte*)_frameImage->getPixels();
-	byte *dst = (byte*)_mframeImage->getPixels();
+	const byte *src = (const byte*) oldImage->getPixels();
+	byte *dst = (byte *) newImage->getPixels();
 
-	int pitch = _frameImage->pitch;
-	for (int y = 0; y != _frameImage->h; ++y) {
-		for (int x = 0; x != _frameImage->w; ++x) {
+	int pitch = oldImage->pitch;
+	for (int y = 0; y != oldImage->h; ++y) {
+		for (int x = 0; x != oldImage->w; ++x) {
 			dst[y * pitch + x] = paletteMap[src[y * pitch + x]];
 		}
 	}
+}
+
+void PrivateEngine::loadImage(const Common::String &name, int x, int y) {
+	debugC(1, kPrivateDebugFunction, "%s(%s,%d,%d)", __FUNCTION__, name.c_str(), x, y);
+	byte *palette;
+	Graphics::Surface *surf = decodeImage(name, &palette);
+	_compositeSurface->setPalette(palette, 0, 256);
+	_compositeSurface->setTransparentColor(_transparentColor);
+	_compositeSurface->transBlitFrom(*surf, _origin + Common::Point(x, y), _transparentColor);
+	surf->free();
+	delete surf;
+	_image->destroy();
+}
 
+void PrivateEngine::fillRect(uint32 color, Common::Rect rect) {
+	debugC(1, kPrivateDebugFunction, "%s(%d,..)", __FUNCTION__, color);
+	rect.translate(_origin.x, _origin.y);
+	_compositeSurface->fillRect(rect, color);
+}
+
+void PrivateEngine::drawScreenFrame(const byte *newPalette) {
+	debugC(1, kPrivateDebugFunction, "%s(..)", __FUNCTION__);
+	remapImage(256, _frameImage, _framePalette, _mframeImage, newPalette);
 	g_system->copyRectToScreen(_mframeImage->getPixels(), _mframeImage->pitch, 0, 0, _screenW, _screenH);
 }
 
@@ -1320,7 +1334,8 @@ Graphics::Surface *PrivateEngine::loadMask(const Common::String &name, int x, in
 	Graphics::Surface *surf = new Graphics::Surface();
 	surf->create(_screenW, _screenH, _pixelFormat);
 	surf->fillRect(_screenRect, _transparentColor);
-	Graphics::Surface *csurf = decodeImage(name);
+	byte *palette;
+	Graphics::Surface *csurf = decodeImage(name, &palette);
 
 	uint32 hdiff = 0;
 	uint32 wdiff = 0;
@@ -1332,17 +1347,17 @@ Graphics::Surface *PrivateEngine::loadMask(const Common::String &name, int x, in
 
 	Common::Rect crect(csurf->w - wdiff, csurf->h - hdiff);
 	surf->copyRectToSurface(*csurf, x, y, crect);
-	csurf->free();
-	delete csurf;
-	_image->destroy();
 
 	if (drawn) {
-		const byte *palette = decodePalette(name);
 		_compositeSurface->setPalette(palette, 0, 256);
 		_compositeSurface->setTransparentColor(_transparentColor);
 		drawMask(surf);
 	}
 
+	csurf->free();
+	delete csurf;
+	_image->destroy();
+
 	return surf;
 }
 
diff --git a/engines/private/private.h b/engines/private/private.h
index cce5422c41..6c4e65fa62 100644
--- a/engines/private/private.h
+++ b/engines/private/private.h
@@ -200,8 +200,9 @@ public:
 	void playVideo(const Common::String &);
 	void skipVideo();
 
-	Graphics::Surface *decodeImage(const Common::String &file);
-	const byte *decodePalette(const Common::String &name);
+	Graphics::Surface *decodeImage(const Common::String &file, byte **palette);
+	//byte *decodePalette(const Common::String &name);
+	void remapImage(uint16 ncolors, const Graphics::Surface *oldImage, const byte *oldPalette, Graphics::Surface *newImage, const byte *currentPalette);
 	void loadImage(const Common::String &file, int x, int y);
 	void drawScreenFrame(const byte *videoPalette);
 


Commit: 3d247f33e10753a23cc6e65c7a127e0109647ee7
    https://github.com/scummvm/scummvm/commit/3d247f33e10753a23cc6e65c7a127e0109647ee7
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2021-11-28T14:21:59+01:00

Commit Message:
PRIVATE: fixed save game bug

Changed paths:
    engines/private/metaengine.cpp


diff --git a/engines/private/metaengine.cpp b/engines/private/metaengine.cpp
index 33ade05c5b..eaeee16061 100644
--- a/engines/private/metaengine.cpp
+++ b/engines/private/metaengine.cpp
@@ -41,13 +41,9 @@ Common::Error PrivateMetaEngine::createInstance(OSystem *syst, Engine **engine,
 }
 
 void PrivateMetaEngine::getSavegameThumbnail(Graphics::Surface &thumb) {
-	Graphics::Surface *vs = Private::g_private->decodeImage(Private::g_private->_nextVS, nullptr);
-	Graphics::Surface *svs = vs->scale(kThumbnailWidth, kThumbnailHeight2);
-	thumb.copyFrom(*svs);
-
-	svs->free();
-	delete svs;
-
+	byte *palette; 
+	Graphics::Surface *vs = Private::g_private->decodeImage(Private::g_private->_nextVS, &palette);
+	::createThumbnail(&thumb, (const uint8 *)vs->getPixels(), vs->w, vs->h, palette);
 	vs->free();
 	delete vs;
 }


Commit: c8849911f8007f08708ccbc2a232177d5bf848ed
    https://github.com/scummvm/scummvm/commit/c8849911f8007f08708ccbc2a232177d5bf848ed
Author: neuromancer (gustavo.grieco at gmail.com)
Date: 2021-11-28T14:21:59+01:00

Commit Message:
HYPNO: spider movement in arcade sequences

Changed paths:
    engines/hypno/arcade.cpp
    engines/hypno/hypno.h
    engines/hypno/spider/arcade.cpp


diff --git a/engines/hypno/arcade.cpp b/engines/hypno/arcade.cpp
index 1da9dc0d90..18f41fcf66 100644
--- a/engines/hypno/arcade.cpp
+++ b/engines/hypno/arcade.cpp
@@ -126,7 +126,9 @@ void HypnoEngine::runArcade(ArcadeShooting *arc) {
 	_shoots.clear();
 	_playerFrames = decodeFrames(arc->player);
 	_playerFrameSep = 0;
-	_playerPosition = 0;
+	// Only used in spider
+	_currentPlayerPosition = PlayerLeft;
+	_lastPlayerPosition = PlayerLeft;
 
 	for (Frames::iterator it =_playerFrames.begin(); it != _playerFrames.end(); ++it) {
 		if ((*it)->getPixel(0, 0) == _pixelFormat.RGBToColor(0, 255, 255))
@@ -172,13 +174,17 @@ void HypnoEngine::runArcade(ArcadeShooting *arc) {
 					showCredits();
 					background.decoder->pauseVideo(false);
 				} else if (event.kbd.keycode == Common::KEYCODE_LEFT) {
-					_playerPosition = 0;
+					_lastPlayerPosition = _currentPlayerPosition; 
+					_currentPlayerPosition = PlayerLeft;
 				} else if (event.kbd.keycode == Common::KEYCODE_DOWN) {
-					_playerPosition = 3;
+					_lastPlayerPosition = _currentPlayerPosition;
+					_currentPlayerPosition = PlayerDown;
 				} else if (event.kbd.keycode == Common::KEYCODE_RIGHT) {
-					_playerPosition = 7;
+					_lastPlayerPosition = _currentPlayerPosition;
+					_currentPlayerPosition = PlayerRight;
 				} else if (event.kbd.keycode == Common::KEYCODE_UP) {
-					_playerPosition = 11;
+					_lastPlayerPosition = _currentPlayerPosition;
+					_currentPlayerPosition = PlayerUp;
 				}
 				break;
 
diff --git a/engines/hypno/hypno.h b/engines/hypno/hypno.h
index 244dd31ed9..e2b1675c27 100644
--- a/engines/hypno/hypno.h
+++ b/engines/hypno/hypno.h
@@ -59,6 +59,15 @@ enum {
 
 typedef Common::Array<Graphics::Surface *> Frames;
 
+// Player positions
+
+enum PlayerPosition {
+	PlayerUp,
+	PlayerDown,
+	PlayerLeft,
+	PlayerRight
+};
+
 class HypnoEngine : public Engine {
 private:
 	Common::RandomSource *_rnd;
@@ -197,7 +206,8 @@ public:
 
 	// Arcade
 	Common::String _arcadeMode;
-	uint32 _playerPosition;
+	uint32 _currentPlayerPosition;
+	uint32 _lastPlayerPosition;
 	int detectTarget(const Common::Point &mousePos);
 	virtual bool clickedPrimaryShoot(const Common::Point &mousePos);
 	virtual bool clickedSecondaryShoot(const Common::Point &mousePos);
diff --git a/engines/hypno/spider/arcade.cpp b/engines/hypno/spider/arcade.cpp
index 7b389ec06e..af7fc5f12d 100644
--- a/engines/hypno/spider/arcade.cpp
+++ b/engines/hypno/spider/arcade.cpp
@@ -64,7 +64,79 @@ void SpiderEngine::drawPlayer() {
 	if (_arcadeMode == "YC") {
 		ox = 0;
 		oy = 0;
-		_playerFrameIdx = _playerPosition;
+
+		if (_playerFrameIdx < 0)
+			_playerFrameIdx = 0;
+		else if (_lastPlayerPosition != _currentPlayerPosition && (_playerFrameIdx % 4 == 0 || _playerFrameIdx % 4 == 3)) {
+
+			switch(_lastPlayerPosition) {
+				case PlayerLeft:
+					switch(_currentPlayerPosition) {
+						case PlayerUp:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 1;
+						break;
+						case PlayerDown:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 13;
+						break;
+						case PlayerRight:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 45;
+						break;
+					}
+				break;
+				case PlayerRight:
+					switch(_currentPlayerPosition) {
+						case PlayerUp:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 5;
+						break;
+						case PlayerDown:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 17;
+						break;
+						case PlayerLeft:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 33;
+						break;
+					}
+				break;
+				case PlayerDown:
+					switch(_currentPlayerPosition) {
+						case PlayerUp:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 9;
+						break;
+						case PlayerLeft:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 29;
+						break;
+						case PlayerRight:
+							_lastPlayerPosition = _currentPlayerPosition;
+							_playerFrameIdx = 41;
+						break;
+					}
+				break;
+				case PlayerUp:
+					switch(_currentPlayerPosition) {
+						case PlayerDown:
+							_playerFrameIdx = 21;
+						break;
+						case PlayerLeft:
+							_playerFrameIdx = 25;
+						break;
+						case PlayerRight:
+							_playerFrameIdx = 37;
+						break;
+					}
+				break;
+			}
+			_lastPlayerPosition = _currentPlayerPosition;
+		} else if (_playerFrameIdx % 4 != 0 && _playerFrameIdx % 4 != 3) {
+			_playerFrameIdx++;
+			_lastPlayerPosition = _currentPlayerPosition;
+		}
 	} else if (_arcadeMode == "YE") {
 		Common::Point mousePos = g_system->getEventManager()->getMousePos();
 		uint32 idx = mousePos.x / (_screenW / 5);




More information about the Scummvm-git-logs mailing list