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 /engines/illusions/screen.cpp | |
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
Diffstat (limited to 'engines/illusions/screen.cpp')
-rw-r--r-- | engines/illusions/screen.cpp | 278 |
1 files changed, 140 insertions, 138 deletions
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; } |