[Scummvm-cvs-logs] scummvm master -> fc1d93ee1b8281e7af308ebc17707b3c6cb2e6d7

dreammaster dreammaster at scummvm.org
Tue Feb 14 11:08:00 CET 2012


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:
fc1d93ee1b TSAGE: Implemented missing R2R method SceneHandler::setupPaletteMaps


Commit: fc1d93ee1b8281e7af308ebc17707b3c6cb2e6d7
    https://github.com/scummvm/scummvm/commit/fc1d93ee1b8281e7af308ebc17707b3c6cb2e6d7
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2012-02-14T02:07:12-08:00

Commit Message:
TSAGE: Implemented missing R2R method SceneHandler::setupPaletteMaps

Changed paths:
    engines/tsage/globals.cpp
    engines/tsage/globals.h
    engines/tsage/ringworld2/ringworld2_logic.cpp
    engines/tsage/ringworld2/ringworld2_logic.h



diff --git a/engines/tsage/globals.cpp b/engines/tsage/globals.cpp
index d3843aa..afd029d 100644
--- a/engines/tsage/globals.cpp
+++ b/engines/tsage/globals.cpp
@@ -375,6 +375,8 @@ void Ringworld2Globals::reset() {
 	T2_GLOBALS._uiElements._active = false;
 
 	// Reset fields
+	Common::fill(&_v1000[0], &_v1000[0x1000], 0);
+	_v1000Flag = false;
 	_v5589E.set(0, 0, 0, 0);
 	_v558B6.set(0, 0, 0, 0);
 	_v558C2 = 0;
diff --git a/engines/tsage/globals.h b/engines/tsage/globals.h
index 6e3a2eb..88b0a81 100644
--- a/engines/tsage/globals.h
+++ b/engines/tsage/globals.h
@@ -252,6 +252,9 @@ public:
 	ASoundExt _sound1, _sound2, _sound3, _sound4;
 	PlayStream _playStream;
 	StripProxy _stripProxy;
+	bool _v1000Flag;
+	byte _v1000[0x1000];
+	byte _palIndexList[10][256];
 	int _insetUp;
 	int _frameEdgeColour;	// _v421e
 	Rect _v5589E;
diff --git a/engines/tsage/ringworld2/ringworld2_logic.cpp b/engines/tsage/ringworld2/ringworld2_logic.cpp
index 83ca51f..d146e4c 100644
--- a/engines/tsage/ringworld2/ringworld2_logic.cpp
+++ b/engines/tsage/ringworld2/ringworld2_logic.cpp
@@ -323,6 +323,19 @@ void SceneExt::postInit(SceneObjectList *OwnerList) {
 	_action = NULL;
 	_field12 = 0;
 	_sceneMode = 0;
+
+	int prevScene = R2_GLOBALS._sceneManager._previousScene;
+	int sceneNumber = R2_GLOBALS._sceneManager._sceneNumber;
+	if (((prevScene == -1) && (sceneNumber != 180) && (sceneNumber != 205) && (sceneNumber != 50)) 
+			|| (sceneNumber == 50)
+			|| ((prevScene == 205) && (sceneNumber == 100))
+			|| ((prevScene == 180) && (sceneNumber == 100))) {
+		static_cast<SceneHandlerExt *>(R2_GLOBALS._sceneHandler)->setupPaletteMaps();
+		R2_GLOBALS._v58CE2 = 1;
+		R2_GLOBALS._uiElements.show();
+	} else {
+		R2_GLOBALS._uiElements.updateInventory();
+	}
 }
 
 void SceneExt::remove() {
@@ -570,6 +583,96 @@ void SceneHandlerExt::process(Event &event) {
 		SceneHandler::process(event);
 }
 
+void SceneHandlerExt::setupPaletteMaps() {
+	byte *palP = &R2_GLOBALS._scenePalette._palette[0];
+
+	if (!R2_GLOBALS._v1000Flag) {
+		R2_GLOBALS._v1000Flag = true;
+
+		for (int idx = 0; idx < 10; ++idx) {
+			for (int palIndex = 0; palIndex < 224; ++palIndex) {
+				int r, g, b;
+
+				// Get adjusted RGB values
+				switch (idx) {
+				case 7:
+					r = palP[palIndex * 3] * 85 / 100;
+					g = palP[palIndex * 3 + 1] * 7 / 10;
+					b = palP[palIndex * 3 + 2] * 7 / 10;
+					break;
+				case 8:
+					r = palP[palIndex * 3] * 7 / 10;
+					g = palP[palIndex * 3 + 1] * 85 / 100;
+					b = palP[palIndex * 3 + 2] * 7 / 10;
+					break;
+				case 9:
+					r = palP[palIndex * 3] * 8 / 10;
+					g = palP[palIndex * 3 + 1] * 5 / 10;
+					b = palP[palIndex * 3 + 2] * 9 / 10;
+					break;
+				default:
+					r = palP[palIndex * 3] * (10 - idx) / 10;
+					g = palP[palIndex * 3 + 1] * (10 - idx) / 12;
+					b = palP[palIndex * 3 + 2] * (10 - idx) / 10;
+					break;
+				}
+
+				// Scan for the palette index with the closest matching colour
+				int threshold = 769;
+				int foundIndex = -1;
+				for (int pIndex2 = 223; pIndex2 >= 0; --pIndex2) {
+					int diffSum = ABS(palP[pIndex2 * 3] - r);
+					if (diffSum >= threshold)
+						continue;
+
+					diffSum += ABS(palP[pIndex2 * 3 + 1] - g);
+					if (diffSum >= threshold)
+						continue;
+					
+					diffSum += ABS(palP[pIndex2 * 3 + 2] - b);
+					if (diffSum >= threshold)
+						continue;
+					
+					threshold = diffSum;
+					foundIndex = pIndex2;
+				}
+
+				R2_GLOBALS._palIndexList[idx][palIndex] = foundIndex;
+			}
+		}
+	}
+
+	for (int palIndex = 0; palIndex < 224; ++palIndex) {
+		int r = palP[palIndex * 3] >> 2;
+		int g = palP[palIndex * 3 + 1] >> 2;
+		int b = palP[palIndex * 3 + 2] >> 2;
+
+		int idx = (((r << 4) | g) << 4) | b;
+		R2_GLOBALS._v1000[idx] = palIndex;
+	}
+
+	int vdx = 0;
+	int idx = 0;
+	int palIndex = 224;
+
+	for (int vIndex = 0; vIndex < 4096; ++vIndex) {
+		int v = R2_GLOBALS._v1000[vIndex];
+		if (!v) {
+			R2_GLOBALS._v1000[vIndex] = idx;
+		} else {
+			idx = v;
+		}
+
+		if (!palIndex) {
+			vdx = palIndex;
+		} else {
+			int idxTemp = palIndex;
+			palIndex = (palIndex + vdx) / 2;
+			vdx = idxTemp;
+		}
+	}
+}
+
 /*--------------------------------------------------------------------------*/
 
 DisplayHotspot::DisplayHotspot(int regionId, ...) {
diff --git a/engines/tsage/ringworld2/ringworld2_logic.h b/engines/tsage/ringworld2/ringworld2_logic.h
index 22bea5c..925a3d6 100644
--- a/engines/tsage/ringworld2/ringworld2_logic.h
+++ b/engines/tsage/ringworld2/ringworld2_logic.h
@@ -114,6 +114,8 @@ class SceneHandlerExt: public SceneHandler {
 public:
 	virtual void postInit(SceneObjectList *OwnerList = NULL);
 	virtual void process(Event &event);
+
+	void setupPaletteMaps();
 };
 
 






More information about the Scummvm-git-logs mailing list