diff options
author | johndoe123 | 2016-03-26 21:36:27 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-07-20 06:43:33 +0000 |
commit | 2bd13865285058d72e13150ab64462dbbe23163c (patch) | |
tree | d22f04f4985d51ec8554004b9f9d789db80ebadb | |
parent | 9447d42fd71ce092d70fad416caf2babacf00dcd (diff) | |
download | scummvm-rg350-2bd13865285058d72e13150ab64462dbbe23163c.tar.gz scummvm-rg350-2bd13865285058d72e13150ab64462dbbe23163c.tar.bz2 scummvm-rg350-2bd13865285058d72e13150ab64462dbbe23163c.zip |
ILLUSIONS: Move palette code from Screen to new ScreenPalette class
-rw-r--r-- | engines/illusions/bbdou/illusions_bbdou.cpp | 1 | ||||
-rw-r--r-- | engines/illusions/duckman/illusions_duckman.cpp | 39 | ||||
-rw-r--r-- | engines/illusions/duckman/illusions_duckman.h | 5 | ||||
-rw-r--r-- | engines/illusions/illusions.cpp | 43 | ||||
-rw-r--r-- | engines/illusions/illusions.h | 10 | ||||
-rw-r--r-- | engines/illusions/resources/backgroundresource.cpp | 6 | ||||
-rw-r--r-- | engines/illusions/screen.cpp | 278 | ||||
-rw-r--r-- | engines/illusions/screen.h | 60 | ||||
-rw-r--r-- | engines/illusions/screentext.cpp | 4 | ||||
-rw-r--r-- | engines/illusions/sequenceopcodes.cpp | 4 |
10 files changed, 241 insertions, 209 deletions
diff --git a/engines/illusions/bbdou/illusions_bbdou.cpp b/engines/illusions/bbdou/illusions_bbdou.cpp index bacd53ed62..15b103108d 100644 --- a/engines/illusions/bbdou/illusions_bbdou.cpp +++ b/engines/illusions/bbdou/illusions_bbdou.cpp @@ -152,6 +152,7 @@ Common::Error IllusionsEngine_BBDOU::run() { _resSys->addResourceLoader(0x00170000, new SpecialCodeLoader(this)); _screen = new Screen(this, 640, 480, 16); + _screenPalette = new NullScreenPalette(); _screenText = new ScreenText(this); _input = new Input(); _actorInstances = new ActorInstanceList(this); diff --git a/engines/illusions/duckman/illusions_duckman.cpp b/engines/illusions/duckman/illusions_duckman.cpp index 8f28a99c56..a9f6b6e2af 100644 --- a/engines/illusions/duckman/illusions_duckman.cpp +++ b/engines/illusions/duckman/illusions_duckman.cpp @@ -104,6 +104,7 @@ Common::Error IllusionsEngine_Duckman::run() { _resSys->addResourceLoader(0x00190000, new GenericResourceLoader(this)); _screen = new Screen(this, 320, 200, 8); + _screenPalette = new ScreenPalette(this); _screenText = new ScreenText(this); _input = new Input(); _actorInstances = new ActorInstanceList(this); @@ -221,6 +222,7 @@ Common::Error IllusionsEngine_Duckman::run() { delete _actorInstances; delete _input; delete _screenText; + delete _screenPalette; delete _screen; delete _resSys; delete _resReader; @@ -283,7 +285,7 @@ void IllusionsEngine_Duckman::initUpdateFunctions() { int IllusionsEngine_Duckman::updateScript(uint flags) { // TODO Some more stuff - if (_screen->isDisplayOn() && !_screen->isFaderActive() && _pauseCtr == 0) { + if (_screen->isDisplayOn() && !_screenPalette->isFaderActive() && _pauseCtr == 0) { if (_input->pollEvent(kEventAbort)) { startScriptThread(0x00020342, 0); } else if (_input->pollEvent(kEventF1)) { @@ -362,6 +364,39 @@ void IllusionsEngine_Duckman::startFader(int duration, int minValue, int maxValu _fader->_notifyThreadId = threadId; } +void IllusionsEngine_Duckman::updateFader() { + if (_fader && !_fader->_paused && _fader->_active) { + int32 currTime = getCurrentTime(); + int32 currDuration = currTime - _fader->_startTime; + if (currDuration) { + int newValue; + if (currDuration >= _fader->_duration) { + newValue = _fader->_maxValue; + } else { + newValue = (currDuration * (_fader->_maxValue - _fader->_minValue) / _fader->_duration) + _fader->_minValue; + } + if (_fader->_currValue != newValue) { + _fader->_currValue = newValue; + _screenPalette->setFader(newValue, _fader->_firstIndex, _fader->_lastIndex); + } + if (_fader->_currValue == _fader->_maxValue) { + _fader->_active = false; + notifyThreadId(_fader->_notifyThreadId); + } + } + } +} + +void IllusionsEngine_Duckman::pauseFader() { + _fader->_paused = true; + _fader->_startTime = getCurrentTime() - _fader->_startTime; +} + +void IllusionsEngine_Duckman::unpauseFader() { + _fader->_startTime = getCurrentTime() - _fader->_startTime; + _fader->_paused = false; +} + void IllusionsEngine_Duckman::setDefaultTextCoords() { WidthHeight dimensions; dimensions._width = 300; @@ -1145,7 +1180,7 @@ bool IllusionsEngine_Duckman::loadSavegameFromScript(int16 slotNum, uint32 calli bool IllusionsEngine_Duckman::saveSavegameFromScript(int16 slotNum, uint32 callingThreadId) { // TODO - const char *fileName = getSavegameFilename(slotNum); + // const char *fileName = getSavegameFilename(slotNum); bool success = false;//savegame(fileName, _savegameDescription.c_str()); return success; } diff --git a/engines/illusions/duckman/illusions_duckman.h b/engines/illusions/duckman/illusions_duckman.h index f19a659ac3..daa1b06c0c 100644 --- a/engines/illusions/duckman/illusions_duckman.h +++ b/engines/illusions/duckman/illusions_duckman.h @@ -81,7 +81,7 @@ public: protected: virtual Common::Error run(); virtual bool hasFeature(EngineFeature f) const; -public: +public: // TODO ActiveScenes _activeScenes; uint32 _prevSceneId; @@ -112,6 +112,9 @@ public: int updateScreenShaker(uint flags); void startFader(int duration, int minValue, int maxValue, int firstIndex, int lastIndex, uint32 threadId); + void updateFader(); + void pauseFader(); + void unpauseFader(); void setDefaultTextCoords(); diff --git a/engines/illusions/illusions.cpp b/engines/illusions/illusions.cpp index e22ef0c316..9bb40c344c 100644 --- a/engines/illusions/illusions.cpp +++ b/engines/illusions/illusions.cpp @@ -206,14 +206,14 @@ int IllusionsEngine::updateGraphics(uint flags) { return kUFNext; } -int IllusionsEngine::updateSprites(uint flags) { - _screen->updateSprites(); - _screen->updatePalette(); +int IllusionsEngine::updateSoundMan(uint flags) { + _soundMan->update(); return kUFNext; } -int IllusionsEngine::updateSoundMan(uint flags) { - _soundMan->update(); +int IllusionsEngine::updateSprites(uint flags) { + _screen->updateSprites(); + _screenPalette->updatePalette(); return kUFNext; } @@ -267,39 +267,6 @@ bool IllusionsEngine::isSoundActive() { return true; } -void IllusionsEngine::updateFader() { - if (_fader && !_fader->_paused && _fader->_active) { - int32 currTime = getCurrentTime(); - int32 currDuration = currTime - _fader->_startTime; - if (currDuration) { - int newValue; - if (currDuration >= _fader->_duration) { - newValue = _fader->_maxValue; - } else { - newValue = (currDuration * (_fader->_maxValue - _fader->_minValue) / _fader->_duration) + _fader->_minValue; - } - if (_fader->_currValue != newValue) { - _fader->_currValue = newValue; - _screen->setFader(newValue, _fader->_firstIndex, _fader->_lastIndex); - } - if (_fader->_currValue == _fader->_maxValue) { - _fader->_active = false; - notifyThreadId(_fader->_notifyThreadId); - } - } - } -} - -void IllusionsEngine::pauseFader() { - _fader->_paused = true; - _fader->_startTime = getCurrentTime() - _fader->_startTime; -} - -void IllusionsEngine::unpauseFader() { - _fader->_startTime = getCurrentTime() - _fader->_startTime; - _fader->_paused = false; -} - void IllusionsEngine::setCurrFontId(uint32 fontId) { _fontId = fontId; } diff --git a/engines/illusions/illusions.h b/engines/illusions/illusions.h index 836282d8e3..40ed32702c 100644 --- a/engines/illusions/illusions.h +++ b/engines/illusions/illusions.h @@ -77,6 +77,7 @@ class TalkInstanceList; class ThreadList; class UpdateFunctions; class GameState; +class ScreenPaletteBase; enum { kGameIdBBDOU = 1, @@ -108,6 +109,7 @@ public: void updateEvents(); Screen *_screen; + ScreenPaletteBase *_screenPalette; ScreenText *_screenText; Input *_input; ActorInstanceList *_actorInstances; @@ -157,8 +159,8 @@ public: int updateActors(uint flags); int updateSequences(uint flags); int updateGraphics(uint flags); - int updateSprites(uint flags); int updateSoundMan(uint flags); + int updateSprites(uint flags); uint32 getElapsedUpdateTime(); Common::Point *getObjectActorPositionPtr(uint32 objectId); @@ -168,9 +170,9 @@ public: void playVideo(uint32 videoId, uint32 objectId, uint32 value, uint32 threadId); bool isSoundActive(); - void updateFader(); - void pauseFader(); - void unpauseFader(); + virtual void updateFader() {}; + virtual void pauseFader() {}; + virtual void unpauseFader() {}; void setCurrFontId(uint32 fontId); bool checkActiveTalkThreads(); diff --git a/engines/illusions/resources/backgroundresource.cpp b/engines/illusions/resources/backgroundresource.cpp index a95919635b..4df66e10f4 100644 --- a/engines/illusions/resources/backgroundresource.cpp +++ b/engines/illusions/resources/backgroundresource.cpp @@ -404,7 +404,7 @@ void BackgroundInstance::load(Resource *resource) { if (_bgRes->_palettesCount > 0) { Palette *palette = _bgRes->getPalette(_bgRes->_paletteIndex - 1); - _vm->_screen->setPalette(palette->_palette, 1, palette->_count); + _vm->_screenPalette->setPalette(palette->_palette, 1, palette->_count); } } @@ -425,7 +425,7 @@ void BackgroundInstance::pause() { _vm->setDefaultTextCoords(); _vm->_camera->getActiveState(_savedCameraState); _savedPalette = new byte[1024]; - _vm->_screen->getPalette(_savedPalette); + _vm->_screenPalette->getPalette(_savedPalette); freeSurface(); } } @@ -435,7 +435,7 @@ void BackgroundInstance::unpause() { if (_pauseCtr <= 0) { registerResources(); initSurface(); - _vm->_screen->setPalette(_savedPalette, 1, 256); + _vm->_screenPalette->setPalette(_savedPalette, 1, 256); delete[] _savedPalette; _savedPalette = 0; // TODO _vm->_screen->_fadeClear(); diff --git a/engines/illusions/screen.cpp b/engines/illusions/screen.cpp index 8add55ef2e..3cbdd9158a 100644 --- a/engines/illusions/screen.cpp +++ b/engines/illusions/screen.cpp @@ -214,137 +214,27 @@ bool SpriteDrawQueue::calcItemRect(SpriteDrawQueueItem *item, Common::Rect &srcR return true; } -// Screen +// Palette -Screen::Screen(IllusionsEngine *vm, int16 width, int16 height, int bpp) - : _vm(vm), _colorKey1(0), _colorKey2(0) { - _displayOn = true; - _decompressQueue = new SpriteDecompressQueue(this); - _drawQueue = new SpriteDrawQueue(this); - if (bpp == 8) { - initGraphics(width, height, false); - } else { - Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0); - initGraphics(width, height, true, &pixelFormat16); - } +ScreenPalette::ScreenPalette(IllusionsEngine *vm) + : _vm(vm), _needRefreshPalette(false), _isFaderActive(false) { - _backSurface = allocSurface(width, height); - - _needRefreshPalette = false; memset(_mainPalette, 0, sizeof(_mainPalette)); - - _isFaderActive = false; - _isScreenOffsetActive = false; - -} - -Screen::~Screen() { - delete _drawQueue; - delete _decompressQueue; - _backSurface->free(); - delete _backSurface; -} - -Graphics::Surface *Screen::allocSurface(int16 width, int16 height) { - Graphics::Surface *surface = new Graphics::Surface(); - surface->create(width, height, _vm->_system->getScreenFormat()); - return surface; -} - -Graphics::Surface *Screen::allocSurface(SurfInfo &surfInfo) { - return allocSurface(surfInfo._dimensions._width, surfInfo._dimensions._height); -} - -bool Screen::isDisplayOn() { - return _displayOn; -} - -void Screen::setDisplayOn(bool isOn) { - _displayOn = isOn; - // TODO Clear screen when off -} - -void Screen::setScreenOffset(Common::Point offsPt) { - if (offsPt.x != 0 || offsPt.y != 0) { - _isScreenOffsetActive = true; - _screenOffsetPt = offsPt; - } else { - _isScreenOffsetActive = false; - } -} - -void Screen::updateSprites() { - _decompressQueue->decompressAll(); - // NOTE Skipped doShiftBrightness and related as it seems to be unused - _drawQueue->drawAll(); - if (_isScreenOffsetActive) - clearScreenOffsetAreas(); - if (!_displayOn) // TODO Check if a video is playing then don't do it - _backSurface->fillRect(Common::Rect(_backSurface->w, _backSurface->h), 0); - g_system->copyRectToScreen((byte*)_backSurface->getBasePtr(0, 0), _backSurface->pitch, 0, 0, _backSurface->w, _backSurface->h); -} - -void Screen::clearScreenOffsetAreas() { - int16 x1 = 0, y1 = 0, x2 = 0, y2 = 0; - if (_screenOffsetPt.x < 0) { - x1 = _backSurface->w + _screenOffsetPt.x; - x2 = _backSurface->w; - } else if (_screenOffsetPt.x > 0) { - x1 = 0; - x2 = _screenOffsetPt.x; - } - if (_screenOffsetPt.y < 0) { - y1 = _backSurface->h + _screenOffsetPt.y; - y2 = _backSurface->h; - } else if (_screenOffsetPt.y > 0) { - y1 = 0; - y2 = _screenOffsetPt.y; - } - _backSurface->fillRect(Common::Rect(0, y1, _backSurface->w, y2), 0); - _backSurface->fillRect(Common::Rect(x1, 0, x2, _backSurface->h), 0); -} - -void Screen::decompressSprite(SpriteDecompressQueueItem *item) { - switch (_backSurface->format.bytesPerPixel) { - case 1: - decompressSprite8(item); - break; - case 2: - decompressSprite16(item); - break; - default: - break; - } } -void Screen::drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags) { - switch (_backSurface->format.bytesPerPixel) { - case 1: - drawSurface8(dstRect, surface, srcRect, scale, flags); - break; - case 2: - drawSurface16(dstRect, surface, srcRect, scale, flags); - break; - default: - break; - } -} - -void Screen::setPalette(byte *colors, uint start, uint count) { - if (_backSurface->format.bytesPerPixel == 1) { - byte *dstPal = &_mainPalette[3 * (start - 1)]; - for (uint i = 0; i < count; ++i) { - *dstPal++ = *colors++; - *dstPal++ = *colors++; - *dstPal++ = *colors++; - ++colors; - } - buildColorTransTbl(); - _needRefreshPalette = true; +void ScreenPalette::setPalette(byte *colors, uint start, uint count) { + byte *dstPal = &_mainPalette[3 * (start - 1)]; + for (uint i = 0; i < count; ++i) { + *dstPal++ = *colors++; + *dstPal++ = *colors++; + *dstPal++ = *colors++; + ++colors; } + buildColorTransTbl(); + _needRefreshPalette = true; } -void Screen::setPaletteEntry(int16 index, byte r, byte g, byte b) { +void ScreenPalette::setPaletteEntry(int16 index, byte r, byte g, byte b) { byte colors[4]; colors[0] = r; colors[1] = g; @@ -352,7 +242,7 @@ void Screen::setPaletteEntry(int16 index, byte r, byte g, byte b) { setPalette(colors, index, 1); } -void Screen::getPalette(byte *colors) { +void ScreenPalette::getPalette(byte *colors) { byte *srcPal = _mainPalette; for (uint i = 0; i < 256; ++i) { *colors++ = *srcPal++; @@ -362,7 +252,7 @@ void Screen::getPalette(byte *colors) { } } -void Screen::shiftPalette(int16 fromIndex, int16 toIndex) { +void ScreenPalette::shiftPalette(int16 fromIndex, int16 toIndex) { byte r, g, b; if (toIndex > fromIndex) { r = _mainPalette[3 * toIndex + 0]; @@ -397,7 +287,7 @@ void Screen::shiftPalette(int16 fromIndex, int16 toIndex) { _needRefreshPalette = true; } -void Screen::updatePalette() { +void ScreenPalette::updatePalette() { if (_needRefreshPalette) { if (_isFaderActive) { updateFaderPalette(); @@ -409,7 +299,7 @@ void Screen::updatePalette() { } } -void Screen::updateFaderPalette() { +void ScreenPalette::updateFaderPalette() { if (_newFaderValue >= 255) { _newFaderValue -= 256; for (int i = _firstFaderIndex; i <= _lastFaderIndex; ++i) { @@ -432,7 +322,7 @@ void Screen::updateFaderPalette() { } } -void Screen::setFader(int newValue, int firstIndex, int lastIndex) { +void ScreenPalette::setFader(int newValue, int firstIndex, int lastIndex) { if (newValue == 255) { _isFaderActive = false; _needRefreshPalette = true; @@ -445,7 +335,11 @@ void Screen::setFader(int newValue, int firstIndex, int lastIndex) { } } -void Screen::buildColorTransTbl() { +void ScreenPalette::setSystemPalette(byte *palette) { + g_system->getPaletteManager()->setPalette(palette, 0, 256); +} + +void ScreenPalette::buildColorTransTbl() { const int cr = _mainPalette[3 * 1 + 0]; const int cg = _mainPalette[3 * 1 + 1]; const int cb = _mainPalette[3 * 1 + 2]; @@ -469,6 +363,118 @@ void Screen::buildColorTransTbl() { } } +// Screen + +Screen::Screen(IllusionsEngine *vm, int16 width, int16 height, int bpp) + : _vm(vm), _colorKey1(0), _colorKey2(0) { + _displayOn = true; + _decompressQueue = new SpriteDecompressQueue(this); + _drawQueue = new SpriteDrawQueue(this); + if (bpp == 8) { + initGraphics(width, height, false); + } else { + Graphics::PixelFormat pixelFormat16(2, 5, 6, 5, 0, 11, 5, 0, 0); + initGraphics(width, height, true, &pixelFormat16); + } + + _backSurface = allocSurface(width, height); + + _isScreenOffsetActive = false; + +} + +Screen::~Screen() { + delete _drawQueue; + delete _decompressQueue; + _backSurface->free(); + delete _backSurface; +} + +Graphics::Surface *Screen::allocSurface(int16 width, int16 height) { + Graphics::Surface *surface = new Graphics::Surface(); + surface->create(width, height, _vm->_system->getScreenFormat()); + return surface; +} + +Graphics::Surface *Screen::allocSurface(SurfInfo &surfInfo) { + return allocSurface(surfInfo._dimensions._width, surfInfo._dimensions._height); +} + +bool Screen::isDisplayOn() { + return _displayOn; +} + +void Screen::setDisplayOn(bool isOn) { + _displayOn = isOn; + // TODO Clear screen when off +} + +void Screen::setScreenOffset(Common::Point offsPt) { + if (offsPt.x != 0 || offsPt.y != 0) { + _isScreenOffsetActive = true; + _screenOffsetPt = offsPt; + } else { + _isScreenOffsetActive = false; + } +} + +void Screen::updateSprites() { + _decompressQueue->decompressAll(); + // NOTE Skipped doShiftBrightness and related as it seems to be unused + _drawQueue->drawAll(); + if (_isScreenOffsetActive) + clearScreenOffsetAreas(); + if (!_displayOn) // TODO Check if a video is playing then don't do it + _backSurface->fillRect(Common::Rect(_backSurface->w, _backSurface->h), 0); + g_system->copyRectToScreen((byte*)_backSurface->getBasePtr(0, 0), _backSurface->pitch, 0, 0, _backSurface->w, _backSurface->h); +} + +void Screen::clearScreenOffsetAreas() { + int16 x1 = 0, y1 = 0, x2 = 0, y2 = 0; + if (_screenOffsetPt.x < 0) { + x1 = _backSurface->w + _screenOffsetPt.x; + x2 = _backSurface->w; + } else if (_screenOffsetPt.x > 0) { + x1 = 0; + x2 = _screenOffsetPt.x; + } + if (_screenOffsetPt.y < 0) { + y1 = _backSurface->h + _screenOffsetPt.y; + y2 = _backSurface->h; + } else if (_screenOffsetPt.y > 0) { + y1 = 0; + y2 = _screenOffsetPt.y; + } + _backSurface->fillRect(Common::Rect(0, y1, _backSurface->w, y2), 0); + _backSurface->fillRect(Common::Rect(x1, 0, x2, _backSurface->h), 0); +} + +void Screen::decompressSprite(SpriteDecompressQueueItem *item) { + switch (_backSurface->format.bytesPerPixel) { + case 1: + decompressSprite8(item); + break; + case 2: + decompressSprite16(item); + break; + default: + break; + } +} + +void Screen::drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags) { + switch (_backSurface->format.bytesPerPixel) { + case 1: + drawSurface8(dstRect, surface, srcRect, scale, flags); + break; + case 2: + drawSurface16(dstRect, surface, srcRect, scale, flags); + break; + default: + break; + } +} + void Screen::drawText(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count) { switch (_backSurface->format.bytesPerPixel) { case 1: @@ -547,10 +553,6 @@ int16 Screen::drawChar16(FontResource *font, Graphics::Surface *surface, int16 x return charWidth; } -void Screen::setSystemPalette(byte *palette) { - g_system->getPaletteManager()->setPalette(palette, 0, 256); -} - void Screen::decompressSprite8(SpriteDecompressQueueItem *item) { byte *src = item->_compressedPixels; Graphics::Surface *dstSurface = item->_surface; @@ -637,6 +639,7 @@ void Screen::drawSurface81(int16 destX, int16 destY, Graphics::Surface *surface, // Unscaled const int16 w = srcRect.width(); const int16 h = srcRect.height(); + const byte* colorTransTbl = _vm->_screenPalette->getColorTransTbl(); for (int16 yc = 0; yc < h; ++yc) { byte *src = (byte*)surface->getBasePtr(srcRect.left, srcRect.top + yc); byte *dst = (byte*)_backSurface->getBasePtr(destX, destY + yc); @@ -644,7 +647,7 @@ void Screen::drawSurface81(int16 destX, int16 destY, Graphics::Surface *surface, const byte pixel = *src++; if (pixel != 0) { if (pixel == 1) - *dst = _colorTransTbl[*dst]; + *dst = colorTransTbl[*dst]; else *dst = pixel; } @@ -659,10 +662,9 @@ void Screen::drawSurface82(Common::Rect &dstRect, Graphics::Surface *surface, Co const int srcWidth = srcRect.width(), srcHeight = srcRect.height(); const int errYStart = srcHeight / dstHeight; const int errYIncr = srcHeight % dstHeight; -// const int midY = dstHeight / 2; const int errXStart = srcWidth / dstWidth; const int errXIncr = srcWidth % dstWidth; -// const int midX = dstWidth / 2; + const byte* colorTransTbl = _vm->_screenPalette->getColorTransTbl(); int h = dstHeight, errY = 0, skipY, srcY = srcRect.top; byte *dst = (byte*)_backSurface->getBasePtr(dstRect.left, dstRect.top); skipY = (dstHeight < srcHeight) ? 0 : dstHeight / (2*srcHeight) + 1; @@ -677,7 +679,7 @@ void Screen::drawSurface82(Common::Rect &dstRect, Graphics::Surface *surface, Co const byte pixel = *src; if (pixel != 0) { if (pixel == 1) - *dstRow = _colorTransTbl[*dstRow]; + *dstRow = colorTransTbl[*dstRow]; else *dstRow = pixel; } @@ -693,7 +695,7 @@ void Screen::drawSurface82(Common::Rect &dstRect, Graphics::Surface *surface, Co const byte pixel = *src; if (pixel != 0) { if (pixel == 1) - *dstRow = _colorTransTbl[*dstRow]; + *dstRow = colorTransTbl[*dstRow]; else *dstRow = pixel; } diff --git a/engines/illusions/screen.h b/engines/illusions/screen.h index b801458d82..7715058597 100644 --- a/engines/illusions/screen.h +++ b/engines/illusions/screen.h @@ -111,6 +111,47 @@ struct Fader { Fader() : _active(false), _paused(false) {} }; +class ScreenPaletteBase { +public: + virtual ~ScreenPaletteBase() {}; + virtual void setPalette(byte *colors, uint start, uint count) {}; + virtual void setPaletteEntry(int16 index, byte r, byte g, byte b) {}; + virtual void getPalette(byte *colors) {}; + virtual void shiftPalette(int16 fromIndex, int16 toIndex) {}; + virtual void updatePalette() {}; + virtual void updateFaderPalette() {}; + virtual void setFader(int newValue, int firstIndex, int lastIndex) {}; + virtual bool isFaderActive() const { return false; } + virtual const byte* getColorTransTbl() const { return 0; } +}; + +class ScreenPalette : public ScreenPaletteBase { +public: + ScreenPalette(IllusionsEngine *vm); + void setPalette(byte *colors, uint start, uint count); + void setPaletteEntry(int16 index, byte r, byte g, byte b); + void getPalette(byte *colors); + void shiftPalette(int16 fromIndex, int16 toIndex); + void updatePalette(); + void updateFaderPalette(); + void setFader(int newValue, int firstIndex, int lastIndex); + bool isFaderActive() const { return _isFaderActive; } + const byte* getColorTransTbl() const { return _colorTransTbl; } +protected: + IllusionsEngine *_vm; + bool _needRefreshPalette; + byte _mainPalette[768]; + byte _colorTransTbl[256]; + bool _isFaderActive; + byte _faderPalette[768]; + int _newFaderValue, _firstFaderIndex, _lastFaderIndex; + void setSystemPalette(byte *palette); + void buildColorTransTbl(); +}; + +class NullScreenPalette : public ScreenPaletteBase { +}; + // TODO Split into two classes (8bit and 16bit)? class Screen { @@ -126,13 +167,6 @@ public: void clearScreenOffsetAreas(); void decompressSprite(SpriteDecompressQueueItem *item); void drawSurface(Common::Rect &dstRect, Graphics::Surface *surface, Common::Rect &srcRect, int16 scale, uint32 flags); - void setPalette(byte *colors, uint start, uint count); - void setPaletteEntry(int16 index, byte r, byte g, byte b); - void getPalette(byte *colors); - void shiftPalette(int16 fromIndex, int16 toIndex); - void updatePalette(); - void updateFaderPalette(); - void setFader(int newValue, int firstIndex, int lastIndex); void drawText(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count); void fillSurface(Graphics::Surface *surface, byte color); uint16 convertColor(byte color); @@ -141,7 +175,6 @@ public: uint16 getColorKey2() const { return _colorKey2; } int16 getScreenWidth() const { return _backSurface->w; } int16 getScreenHeight() const { return _backSurface->h; } - bool isFaderActive() const { return _isFaderActive; } public: IllusionsEngine *_vm; bool _displayOn; @@ -151,20 +184,9 @@ public: SpriteDrawQueue *_drawQueue; Graphics::Surface *_backSurface; - bool _needRefreshPalette; - byte _mainPalette[768]; - byte _colorTransTbl[256]; - - bool _isFaderActive; - byte _faderPalette[768]; - int _newFaderValue, _firstFaderIndex, _lastFaderIndex; - bool _isScreenOffsetActive; Common::Point _screenOffsetPt; - void setSystemPalette(byte *palette); - void buildColorTransTbl(); - void drawText8(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 *text, uint count); int16 drawChar8(FontResource *font, Graphics::Surface *surface, int16 x, int16 y, uint16 c); diff --git a/engines/illusions/screentext.cpp b/engines/illusions/screentext.cpp index 9fa3d4000d..0a91570859 100644 --- a/engines/illusions/screentext.cpp +++ b/engines/illusions/screentext.cpp @@ -128,7 +128,7 @@ bool ScreenText::insertText(uint16 *text, uint32 fontId, WidthHeight dimensions, bool done = refreshScreenText(font, screenText->_info._dimensions, screenText->_info._offsPt, text, screenText->_info._flags, screenText->_info._color2, screenText->_info._color1, outTextPtr); - _vm->_screen->setPaletteEntry(font->getColorIndex(), screenText->_info._colorR, screenText->_info._colorG, screenText->_info._colorB); + _vm->_screenPalette->setPaletteEntry(font->getColorIndex(), screenText->_info._colorR, screenText->_info._colorG, screenText->_info._colorB); uint16 *textPart = screenText->_text; while (text != outTextPtr) @@ -157,7 +157,7 @@ void ScreenText::removeText() { refreshScreenText(font, screenText->_info._dimensions, screenText->_info._offsPt, screenText->_text, screenText->_info._flags, screenText->_info._color2, screenText->_info._color1, outTextPtr); - _vm->_screen->setPaletteEntry(font->getColorIndex(), screenText->_info._colorR, screenText->_info._colorG, screenText->_info._colorB); + _vm->_screenPalette->setPaletteEntry(font->getColorIndex(), screenText->_info._colorR, screenText->_info._colorG, screenText->_info._colorB); setTextInfoPosition(screenText->_info._position); } } diff --git a/engines/illusions/sequenceopcodes.cpp b/engines/illusions/sequenceopcodes.cpp index 5ce25ca1fb..81f881be46 100644 --- a/engines/illusions/sequenceopcodes.cpp +++ b/engines/illusions/sequenceopcodes.cpp @@ -361,13 +361,13 @@ void SequenceOpcodes::opSetPalette(Control *control, OpCall &opCall) { ARG_BYTE(fromIndex); BackgroundResource *bgRes = _vm->_backgroundInstances->getActiveBgResource(); Palette *palette = bgRes->getPalette(paletteIndex - 1); - _vm->_screen->setPalette(palette->_palette, fromIndex, palette->_count); + _vm->_screenPalette->setPalette(palette->_palette, fromIndex, palette->_count); } void SequenceOpcodes::opShiftPalette(Control *control, OpCall &opCall) { ARG_INT16(fromIndex); ARG_INT16(toIndex); - _vm->_screen->shiftPalette(fromIndex, toIndex); + _vm->_screenPalette->shiftPalette(fromIndex, toIndex); } void SequenceOpcodes::opPlaySound(Control *control, OpCall &opCall) { |