From e48d6aecae1c442b9a9f7afd4def8ff04e28dde3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Jun 2015 11:37:00 -0400 Subject: SHERLOCK: Implement setupBGArea --- engines/sherlock/scene.cpp | 4 +- engines/sherlock/scene.h | 5 ++ engines/sherlock/screen.cpp | 7 --- engines/sherlock/screen.h | 5 +- engines/sherlock/tattoo/tattoo_scene.cpp | 70 +++++++++++++++++++++++++ engines/sherlock/tattoo/tattoo_scene.h | 12 +++++ engines/sherlock/tattoo/tattoo_user_interface.h | 10 ++-- engines/sherlock/user_interface.h | 5 -- 8 files changed, 95 insertions(+), 23 deletions(-) diff --git a/engines/sherlock/scene.cpp b/engines/sherlock/scene.cpp index ec189ee270..35cdacebb1 100644 --- a/engines/sherlock/scene.cpp +++ b/engines/sherlock/scene.cpp @@ -27,6 +27,7 @@ #include "sherlock/screen.h" #include "sherlock/tattoo/tattoo.h" #include "sherlock/tattoo/tattoo_scene.h" +#include "sherlock/tattoo/tattoo_user_interface.h" namespace Sherlock { @@ -340,9 +341,8 @@ bool Scene::loadScene(const Common::String &filename) { screen.initPaletteFade(bgHeader._bytesWritten); rrmStream->read(screen._cMap, PALETTE_SIZE); screen.translatePalette(screen._cMap); - screen.setupBGArea(screen._cMap); - ui.initScrollVars(); + paletteLoaded(); // Read in background if (_lzwMode) { diff --git a/engines/sherlock/scene.h b/engines/sherlock/scene.h index e13c3a5504..70531a7173 100644 --- a/engines/sherlock/scene.h +++ b/engines/sherlock/scene.h @@ -197,6 +197,11 @@ protected: */ virtual void drawAllShapes() = 0; + /** + * Called by loadScene when the palette is loaded for Rose Tattoo + */ + virtual void paletteLoaded() {} + Scene(SherlockEngine *vm); public: int _currentScene; diff --git a/engines/sherlock/screen.cpp b/engines/sherlock/screen.cpp index b5f731948a..adf3129169 100644 --- a/engines/sherlock/screen.cpp +++ b/engines/sherlock/screen.cpp @@ -508,13 +508,6 @@ int Screen::fadeRead(Common::SeekableReadStream &stream, byte *buf, int totalSiz return totalSize; } -/** - * Creates a grey-scale version of the passed palette - */ -void Screen::setupBGArea(const byte cMap[PALETTE_SIZE]) { - warning("TODO"); -} - void Screen::translatePalette(byte palette[PALETTE_SIZE]) { for (int idx = 0; idx < PALETTE_SIZE; ++idx) palette[idx] = VGA_COLOR_TRANS(palette[idx]); diff --git a/engines/sherlock/screen.h b/engines/sherlock/screen.h index 7d49c52def..ba46876e64 100644 --- a/engines/sherlock/screen.h +++ b/engines/sherlock/screen.h @@ -34,6 +34,7 @@ namespace Sherlock { #define PALETTE_SIZE 768 #define PALETTE_COUNT 256 #define VGA_COLOR_TRANS(x) ((x) * 255 / 63) +#define BG_GREYSCALE_RANGE_END 229 enum { INFO_BLACK = 1, @@ -69,8 +70,6 @@ private: // Rose Tattoo fields int _fadeBytesRead, _fadeBytesToRead; int _oldFadePercent; - byte _lookupTable[PALETTE_COUNT]; - byte _lookupTable1[PALETTE_COUNT]; private: /** * Merges together overlapping dirty areas of the screen @@ -268,8 +267,6 @@ public: int fadeRead(Common::SeekableReadStream &stream, byte *buf, int totalSize); - void setupBGArea(const byte cMap[PALETTE_SIZE]); - /** * Translate a palette from 6-bit RGB values to full 8-bit values suitable for passing * to the underlying palette manager diff --git a/engines/sherlock/tattoo/tattoo_scene.cpp b/engines/sherlock/tattoo/tattoo_scene.cpp index 904d87c515..f902c06b5d 100644 --- a/engines/sherlock/tattoo/tattoo_scene.cpp +++ b/engines/sherlock/tattoo/tattoo_scene.cpp @@ -50,6 +50,8 @@ static bool sortImagesY(const ShapeEntry &s1, const ShapeEntry &s2) { /*----------------------------------------------------------------*/ TattooScene::TattooScene(SherlockEngine *vm) : Scene(vm) { + Common::fill(&_lookupTable[0], &_lookupTable[PALETTE_COUNT], 0); + Common::fill(&_lookupTable1[0], &_lookupTable1[PALETTE_COUNT], 0); _arrowZone = -1; _mask = _mask1 = nullptr; _maskCounter = 0; @@ -218,6 +220,14 @@ void TattooScene::drawAllShapes() { } } +void TattooScene::paletteLoaded() { + Screen &screen = *_vm->_screen; + TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui; + + setupBGArea(screen._cMap); + ui.initScrollVars(); +} + void TattooScene::checkBgShapes() { People &people = *_vm->_people; Person &holmes = people._player; @@ -703,6 +713,66 @@ int TattooScene::getScaleVal(const Common::Point &pt) { return result; } +void TattooScene::setupBGArea(const byte cMap[PALETTE_SIZE]) { + int r, g, b; + byte c; + int cd, d; + + // This requires that there is a 16 grayscale palette sequence in the palette that goes from lighter + // to darker as the palette numbers go up. The last palette entry in that run is specified by _bgColor + byte *p = &_lookupTable[0]; + for (int idx = 0; idx < PALETTE_COUNT; ++idx) + *p++ = BG_GREYSCALE_RANGE_END - (cMap[idx * 3] * 30 + cMap[idx * 3 + 1] * 59 + cMap[idx * 3 + 2] * 11) / 480; + + // If we're going to a scene with a haze special effect, initialize the translate table to lighten the colors + if (_mask != nullptr) { + p = &_lookupTable1[0]; + + for (int idx = 0; idx < PALETTE_COUNT; ++idx) { + switch (_currentScene) { + case 8: + r = cMap[idx * 3] * 4 / 5; + g = cMap[idx * 3 + 1] * 3 / 4; + b = cMap[idx * 3 + 2] * 3 / 4; + break; + + case 18: + case 68: + r = cMap[idx * 3] * 4 / 3; + g = cMap[idx * 3 + 1] * 4 / 3; + b = cMap[idx * 3 + 2] * 4 / 3; + break; + + case 7: + case 53: + r = cMap[idx * 3] * 4 / 3; + g = cMap[idx * 3 + 1] * 4 / 3; + b = cMap[idx * 3 + 2] * 4 / 3; + break; + + default: + r = g = b = 0; + break; + } + + c = 0; + cd = (r - cMap[0]) * (r - cMap[0]) + (g - cMap[1]) * (g - cMap[1]) + (b - cMap[2]) * (b - cMap[2]); + + for (int pal = 0; pal < PALETTE_COUNT; ++pal) { + d = (r - cMap[pal * 3]) * (r - cMap[pal * 3]) + (g - cMap[pal * 3 + 1]) * (g - cMap[pal * 3 + 1]) + + (b - cMap[pal * 3 + 2])*(b - cMap[pal * 3 + 2]); + + if (d < cd) { + c = pal; + cd = d; + if (!d) + break; + } + } + *p++ = c; + } + } +} } // End of namespace Tattoo diff --git a/engines/sherlock/tattoo/tattoo_scene.h b/engines/sherlock/tattoo/tattoo_scene.h index 963f7e928f..fc979846ce 100644 --- a/engines/sherlock/tattoo/tattoo_scene.h +++ b/engines/sherlock/tattoo/tattoo_scene.h @@ -40,6 +40,8 @@ private: int _maskCounter; Common::Point _maskOffset; bool _labTableScene; + byte _lookupTable[PALETTE_COUNT]; + byte _lookupTable1[PALETTE_COUNT]; private: void doBgAnimCheckCursor(); @@ -57,6 +59,11 @@ private: * scale zones, interpolating inbetween the top and bottom values of the zones as needed */ int getScaleVal(const Common::Point &pt); + + /** + * Makes a greyscale translation table for each palette entry in the table + */ + void setupBGArea(const byte cMap[PALETTE_SIZE]); protected: /** * Loads the data associated for a given scene. The room resource file's format is: @@ -80,6 +87,11 @@ protected: * Draw all the shapes, people and NPCs in the correct order */ virtual void drawAllShapes(); + + /** + * Called by loadScene when the palette is loaded for Rose Tattoo + */ + virtual void paletteLoaded(); public: ImageFile *_mask, *_mask1; CAnimStream _activeCAnim; diff --git a/engines/sherlock/tattoo/tattoo_user_interface.h b/engines/sherlock/tattoo/tattoo_user_interface.h index db6a04f75c..a04239b39b 100644 --- a/engines/sherlock/tattoo/tattoo_user_interface.h +++ b/engines/sherlock/tattoo/tattoo_user_interface.h @@ -66,6 +66,11 @@ public: * Checks to see if the screen needs to be scrolled. If so, scrolls it towards the target position */ void doScroll(); + + /** + * Initializes scroll variables + */ + void initScrollVars(); public: virtual ~TattooUserInterface() {} @@ -78,11 +83,6 @@ public: * Draw the user interface onto the screen's back buffers */ virtual void drawInterface(int bufferNum = 3); - - /** - * Initializes scroll variables - */ - virtual void initScrollVars(); }; } // End of namespace Tattoo diff --git a/engines/sherlock/user_interface.h b/engines/sherlock/user_interface.h index 7ae014dad1..ff50884e47 100644 --- a/engines/sherlock/user_interface.h +++ b/engines/sherlock/user_interface.h @@ -126,11 +126,6 @@ public: * Print the previously selected object's decription */ virtual void printObjectDesc() {} - - /** - * Initializes scroll variables - */ - virtual void initScrollVars() {} }; } // End of namespace Sherlock -- cgit v1.2.3