diff options
author | Paul Gilbert | 2012-02-14 21:07:12 +1100 |
---|---|---|
committer | Paul Gilbert | 2012-02-14 21:07:12 +1100 |
commit | fc1d93ee1b8281e7af308ebc17707b3c6cb2e6d7 (patch) | |
tree | b6f03802da56d0349434690deb5dccfddf941970 /engines | |
parent | 5cf932198e289b8e8d2fe0ee3e57d7cfbf3b65eb (diff) | |
download | scummvm-rg350-fc1d93ee1b8281e7af308ebc17707b3c6cb2e6d7.tar.gz scummvm-rg350-fc1d93ee1b8281e7af308ebc17707b3c6cb2e6d7.tar.bz2 scummvm-rg350-fc1d93ee1b8281e7af308ebc17707b3c6cb2e6d7.zip |
TSAGE: Implemented missing R2R method SceneHandler::setupPaletteMaps
Diffstat (limited to 'engines')
-rw-r--r-- | engines/tsage/globals.cpp | 2 | ||||
-rw-r--r-- | engines/tsage/globals.h | 3 | ||||
-rw-r--r-- | engines/tsage/ringworld2/ringworld2_logic.cpp | 103 | ||||
-rw-r--r-- | engines/tsage/ringworld2/ringworld2_logic.h | 2 |
4 files changed, 110 insertions, 0 deletions
diff --git a/engines/tsage/globals.cpp b/engines/tsage/globals.cpp index d3843aa174..afd029d035 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 6e3a2eb19d..88b0a8146a 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 83ca51faf5..d146e4cbee 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 22bea5c216..925a3d6522 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(); }; |