From 7f594fa21d820520f6e19559e5934bd495c96deb Mon Sep 17 00:00:00 2001 From: Gregory Montoir Date: Sun, 25 Jan 2009 12:10:06 +0000 Subject: TUCKER: modified flic playback to make use of dirtyrects svn-id: r36060 --- engines/tucker/sequences.cpp | 59 +++++++++++++++++++++--------------------- engines/tucker/tucker.h | 2 +- graphics/video/flic_player.cpp | 13 ++++++++++ graphics/video/flic_player.h | 2 ++ 4 files changed, 46 insertions(+), 30 deletions(-) diff --git a/engines/tucker/sequences.cpp b/engines/tucker/sequences.cpp index bb064cff9f..abda4a8c10 100644 --- a/engines/tucker/sequences.cpp +++ b/engines/tucker/sequences.cpp @@ -496,7 +496,6 @@ int TuckerEngine::handleSpecialObjectSelectionSequence() { AnimationSequencePlayer::AnimationSequencePlayer(OSystem *system, Audio::Mixer *mixer, Common::EventManager *event, int num) : _system(system), _mixer(mixer), _event(event), _seqNum(num) { memset(_animationPalette, 0, sizeof(_animationPalette)); - memset(_paletteBuffer, 0, sizeof(_paletteBuffer)); _soundSeqDataOffset = 0; _soundSeqDataCount = 0; _soundSeqDataIndex = 0; @@ -559,7 +558,7 @@ void AnimationSequencePlayer::mainLoop() { ++_updateFuncIndex; _seqNum = this->_updateFunc[_updateFuncIndex].num; } - _system->copyRectToScreen(_offscreenBuffer, 320, 0, 0, kScreenWidth, kScreenHeight); + _system->copyRectToScreen(_offscreenBuffer, kScreenWidth, 0, 0, kScreenWidth, kScreenHeight); _system->setPalette(_animationPalette, 0, 256); _system->updateScreen(); syncTime(); @@ -832,19 +831,20 @@ void AnimationSequencePlayer::updateSounds() { } void AnimationSequencePlayer::fadeInPalette() { - memset(_paletteBuffer, 0, sizeof(_paletteBuffer)); + uint8 paletteBuffer[256 * 4]; + memset(paletteBuffer, 0, sizeof(paletteBuffer)); bool fadeColors = true; for (int step = 0; step < 64; ++step) { if (fadeColors) { fadeColors = false; for (int i = 0; i < 1024; ++i) { - if ((i & 3) != 3 && _paletteBuffer[i] < _animationPalette[i]) { - const int color = _paletteBuffer[i] + 4; - _paletteBuffer[i] = MIN(color, _animationPalette[i]); + if ((i & 3) != 3 && paletteBuffer[i] < _animationPalette[i]) { + const int color = paletteBuffer[i] + 4; + paletteBuffer[i] = MIN(color, _animationPalette[i]); fadeColors = true; } } - _system->setPalette(_paletteBuffer, 0, 256); + _system->setPalette(paletteBuffer, 0, 256); _system->updateScreen(); } _system->delayMillis(1000 / 60); @@ -852,19 +852,20 @@ void AnimationSequencePlayer::fadeInPalette() { } void AnimationSequencePlayer::fadeOutPalette() { - memcpy(_paletteBuffer, _animationPalette, 1024); + uint8 paletteBuffer[256 * 4]; + memcpy(paletteBuffer, _animationPalette, 1024); bool fadeColors = true; for (int step = 0; step < 64; ++step) { if (fadeColors) { fadeColors = false; for (int i = 0; i < 1024; ++i) { - if ((i & 3) != 3 && _paletteBuffer[i] > 0) { - const int color = _paletteBuffer[i] - 4; - _paletteBuffer[i] = MAX(0, color); + if ((i & 3) != 3 && paletteBuffer[i] > 0) { + const int color = paletteBuffer[i] - 4; + paletteBuffer[i] = MAX(0, color); fadeColors = true; } } - _system->setPalette(_paletteBuffer, 0, 256); + _system->setPalette(paletteBuffer, 0, 256); _system->updateScreen(); } _system->delayMillis(1000 / 60); @@ -902,13 +903,13 @@ void AnimationSequencePlayer::openAnimation(int index, const char *fileName) { _flicPlayer[index].decodeNextFrame(); if (index == 0) { memcpy(_animationPalette, _flicPlayer[index].getPalette(), 1024); - memcpy(_offscreenBuffer, _flicPlayer[index].getOffscreen(), kScreenWidth * kScreenHeight); + _flicPlayer[index].copyDirtyRectsToBuffer(_offscreenBuffer, kScreenWidth); } } void AnimationSequencePlayer::decodeNextAnimationFrame(int index) { _flicPlayer[index].decodeNextFrame(); - memcpy(_offscreenBuffer, _flicPlayer[index].getOffscreen(), kScreenWidth * kScreenHeight); + _flicPlayer[index].copyDirtyRectsToBuffer(_offscreenBuffer, kScreenWidth); if (index == 0) { if (_flicPlayer[index].isPaletteDirty()) { memcpy(_animationPalette, _flicPlayer[index].getPalette(), 1024); @@ -946,11 +947,11 @@ void AnimationSequencePlayer::playIntroSeq19_20() { _flicPlayer[1].reset(); } } - _flicPlayer[0].decodeNextFrame(); - const uint8 *t = _flicPlayer[1].getOffscreen(); - for (int i = 0; i < 64000; ++i) { - const uint8 color = _flicPlayer[0].getOffscreen()[i]; - _offscreenBuffer[i] = color ? color : t[i]; + decodeNextAnimationFrame(0); + for (int i = 0; i < kScreenWidth * kScreenHeight; ++i) { + if (_offscreenBuffer[i] == 0) { + _offscreenBuffer[i] = _flicPlayer[1].getOffscreen()[i]; + } } updateSounds(); if (_flicPlayer[0].isLastFrame()) { @@ -1049,13 +1050,14 @@ void AnimationSequencePlayer::drawPic2Part10() { } void AnimationSequencePlayer::drawPic1Part10() { - for (int y = 0; y < 200; ++y) { - memcpy(_offscreenBuffer + y * 320, _picBufPtr + 800 + y * 640 + _updateScreenWidth, 320); - } - for (int i = 0; i < 64000; ++i) { - const uint8 color = _flicPlayer[0].getOffscreen()[i]; - if (color) { - _offscreenBuffer[i] = color; + int offset = 0; + for (int y = 0; y < kScreenHeight; ++y) { + for (int x = 0; x < kScreenWidth; ++x) { + uint8 color = _flicPlayer[0].getOffscreen()[offset]; + if (color == 0) { + color = _picBufPtr[800 + y * 640 + _updateScreenWidth + x]; + } + _offscreenBuffer[offset++] = color; } } } @@ -1070,12 +1072,11 @@ void AnimationSequencePlayer::loadIntroSeq9_10() { void AnimationSequencePlayer::playIntroSeq9_10() { decodeNextAnimationFrame(0); - if (_flicPlayer[0].getCurFrame() == 984) { - drawPic2Part10(); - } if (_flicPlayer[0].getCurFrame() >= 264 && _flicPlayer[0].getCurFrame() <= 295) { drawPic1Part10(); _updateScreenWidth += 6; + } else if (_flicPlayer[0].getCurFrame() == 984) { + drawPic2Part10(); } else if (_flicPlayer[0].getCurFrame() >= 988 && _flicPlayer[0].getCurFrame() <= 996) { drawPic1Part10(); _updateScreenWidth -= 25; diff --git a/engines/tucker/tucker.h b/engines/tucker/tucker.h index c9decaa13a..782b5f2e15 100644 --- a/engines/tucker/tucker.h +++ b/engines/tucker/tucker.h @@ -912,7 +912,7 @@ private: const SequenceUpdateFunc *_updateFunc; int _updateFuncIndex; ::Graphics::FlicPlayer _flicPlayer[2]; - uint8 _animationPalette[256 * 4], _paletteBuffer[256 * 4]; + uint8 _animationPalette[256 * 4]; int _soundsList1Offset; int _soundsList1Count; int _soundsList2Offset; diff --git a/graphics/video/flic_player.cpp b/graphics/video/flic_player.cpp index f1c051d480..f5a4fd4e63 100644 --- a/graphics/video/flic_player.cpp +++ b/graphics/video/flic_player.cpp @@ -77,6 +77,7 @@ bool FlicPlayer::loadFile(const char *fileName) { if (_flicInfo.type != 0xAF12) { warning("FlicPlayer::FlicPlayer(): attempted to load non-FLC data (type = 0x%04X)", _flicInfo.type); delete _fileStream; + _fileStream = 0; return false; } @@ -109,6 +110,8 @@ void FlicPlayer::closeFile() { delete[] _offscreen; _offscreen = 0; + + _dirtyRects.clear(); } void FlicPlayer::redraw() { @@ -307,6 +310,16 @@ void FlicPlayer::setPalette(uint8 *mem) { } } +void FlicPlayer::copyDirtyRectsToBuffer(uint8 *dst, uint pitch) { + for (Common::List::const_iterator it = _dirtyRects.begin(); it != _dirtyRects.end(); ++it) { + for (int y = (*it).top; y < (*it).bottom; ++y) { + const int x = (*it).left; + memcpy(dst + y * pitch + x, _offscreen + y * _flicInfo.width + x, (*it).right - x); + } + } + _dirtyRects.clear(); +} + void FlicPlayer::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) { uint h = _flicInfo.height; uint w = _flicInfo.width; diff --git a/graphics/video/flic_player.h b/graphics/video/flic_player.h index 43f3775bdd..40aa0f4fdf 100644 --- a/graphics/video/flic_player.h +++ b/graphics/video/flic_player.h @@ -105,6 +105,8 @@ public: void redraw(); void reset(); + void copyDirtyRectsToBuffer(uint8 *dst, uint pitch); + /** * Copy current frame into the specified position of the destination * buffer. -- cgit v1.2.3