diff options
-rw-r--r-- | graphics/animation.cpp | 76 | ||||
-rw-r--r-- | graphics/animation.h | 4 | ||||
-rw-r--r-- | sword1/animation.cpp | 74 | ||||
-rw-r--r-- | sword1/animation.h | 3 | ||||
-rw-r--r-- | sword2/driver/animation.cpp | 82 | ||||
-rw-r--r-- | sword2/driver/animation.h | 3 |
6 files changed, 96 insertions, 146 deletions
diff --git a/graphics/animation.cpp b/graphics/animation.cpp index 4808402a46..63bf92f42d 100644 --- a/graphics/animation.cpp +++ b/graphics/animation.cpp @@ -151,6 +151,82 @@ bool BaseAnimationState::init(const char *name) { #endif } +bool BaseAnimationState::decodeFrame() { +#ifdef USE_MPEG2 + mpeg2_state_t state; + const mpeg2_sequence_t *sequence_i; + size_t size = (size_t) -1; + + do { + state = mpeg2_parse(decoder); + sequence_i = info->sequence; + + switch (state) { + case STATE_BUFFER: + size = mpgfile->read(buffer, BUFFER_SIZE); + mpeg2_buffer(decoder, buffer, buffer + size); + break; + + case STATE_SLICE: + case STATE_END: + if (info->display_fbuf) { + /* simple audio video sync code: + * we calculate the actual frame by taking the elapsed audio time and try + * to stay inside +- 1 frame of this calculated frame number by dropping + * frames if we run behind and delaying if we are too fast + */ + + /* Avoid deadlock is sound was too far ahead */ + if (bgSoundStream && !bgSound.isActive()) + return false; + + if (checkPaletteSwitch() || (bgSoundStream == NULL) || + ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum + 1) || + frameskipped > 10) { + if (frameskipped > 10) { + warning("force frame %i redraw", framenum); + frameskipped = 0; + } + drawYUV(sequence_i->width, sequence_i->height, info->display_fbuf->buf); + + if (bgSoundStream) { + while ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum) + _sys->delay_msecs(10); + } else { + ticks += 83; + while (_sys->get_msecs() < ticks) + _sys->delay_msecs(10); + // FIXME: This used to be used for the Sword2 version of this + // method. I do not see any compelling reason why it should be + // used, but maybe I am wrong; so if you know more, either + // remove this comment, or change the implementation of the + // method to use "sleepUntil" for BS2. + //_vm->sleepUntil(ticks); + } + + } else { + warning("dropped frame %i", framenum); + frameskipped++; + } + +#ifdef BACKEND_8BIT + buildLookup(palnum + 1, lutcalcnum); +#endif + + framenum++; + return true; + + } + break; + + default: + break; + } + } while (size); +#endif + return false; +} + bool BaseAnimationState::checkPaletteSwitch() { #ifdef BACKEND_8BIT // if we have reached the last image with this palette, switch to new one diff --git a/graphics/animation.h b/graphics/animation.h index e532036929..e4a92a66fa 100644 --- a/graphics/animation.h +++ b/graphics/animation.h @@ -123,8 +123,12 @@ public: virtual ~BaseAnimationState(); bool init(const char *name); + bool decodeFrame(); + protected: bool checkPaletteSwitch(); + virtual void drawYUV(int width, int height, byte *const *dat) = 0; + #ifdef BACKEND_8BIT void buildLookup(int p, int lines); virtual void setPalette(byte *pal) = 0; diff --git a/sword1/animation.cpp b/sword1/animation.cpp index 0f2164c08b..0b79d91a07 100644 --- a/sword1/animation.cpp +++ b/sword1/animation.cpp @@ -43,79 +43,13 @@ void AnimationState::setPalette(byte *pal) { #endif -bool AnimationState::decodeFrame() { -#ifdef USE_MPEG2 - mpeg2_state_t state; - const mpeg2_sequence_t *sequence_i; - size_t size = (size_t) -1; - - do { - state = mpeg2_parse(decoder); - sequence_i = info->sequence; - - switch (state) { - case STATE_BUFFER: - size = mpgfile->read(buffer, BUFFER_SIZE); - mpeg2_buffer(decoder, buffer, buffer + size); - break; - - case STATE_SLICE: - case STATE_END: - if (info->display_fbuf) { - /* simple audio video sync code: - * we calculate the actual frame by taking the elapsed audio time and try - * to stay inside +- 1 frame of this calculated frame number by dropping - * frames if we run behind and delaying if we are too fast - */ - - /* Avoid deadlock is sound was too far ahead */ - if (bgSoundStream && !bgSound.isActive()) - return false; - - if (checkPaletteSwitch() || (bgSoundStream == NULL) || - ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum + 1) || - frameskipped > 10) { - if (frameskipped > 10) { - warning("force frame %i redraw", framenum); - frameskipped = 0; - } +void AnimationState::drawYUV(int width, int height, byte *const *dat) { #ifdef BACKEND_8BIT - _scr->plotYUV(lut, sequence_i->width, sequence_i->height, info->display_fbuf->buf); + _scr->plotYUV(lut, width, height, dat); #else - plotYUV(lookup, sequence_i->width, sequence_i->height, info->display_fbuf->buf); - _sys->copy_rect_overlay(overlay, MOVIE_WIDTH, 0, 40, MOVIE_WIDTH, MOVIE_HEIGHT); -#endif - - if (bgSoundStream) { - while ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum) - _sys->delay_msecs(10); - } else { - ticks += 83; - while (_sys->get_msecs() < ticks) - _sys->delay_msecs(10); - } - - } else { - warning("dropped frame %i", framenum); - frameskipped++; - } - -#ifdef BACKEND_8BIT - buildLookup(palnum + 1, lutcalcnum); -#endif - - framenum++; - return true; - - } - break; - - default: - break; - } - } while (size); + plotYUV(lookup, width, height, dat); + _sys->copy_rect_overlay(overlay, MOVIE_WIDTH, 0, 40, MOVIE_WIDTH, MOVIE_HEIGHT); #endif - return false; } MoviePlayer::MoviePlayer(Screen *scr, SoundMixer *snd, OSystem *sys) diff --git a/sword1/animation.h b/sword1/animation.h index 567bb7ebf0..b1a0ecc6a0 100644 --- a/sword1/animation.h +++ b/sword1/animation.h @@ -39,9 +39,8 @@ public: AnimationState(Screen *scr, SoundMixer *snd, OSystem *sys); ~AnimationState(); - bool decodeFrame(); - private: + void drawYUV(int width, int height, byte *const *dat); #ifdef BACKEND_8BIT void setPalette(byte *pal); diff --git a/sword2/driver/animation.cpp b/sword2/driver/animation.cpp index 297d745ec1..0f6436727f 100644 --- a/sword2/driver/animation.cpp +++ b/sword2/driver/animation.cpp @@ -89,81 +89,19 @@ void AnimationState::updateDisplay(void) { #endif -bool AnimationState::decodeFrame() { -#ifdef USE_MPEG2 - mpeg2_state_t state; - const mpeg2_sequence_t *sequence_i; - size_t size = (size_t) -1; - - do { - state = mpeg2_parse(decoder); - sequence_i = info->sequence; - - switch (state) { - case STATE_BUFFER: - size = mpgfile->read(buffer, BUFFER_SIZE); - mpeg2_buffer(decoder, buffer, buffer + size); - break; - - case STATE_SLICE: - case STATE_END: - if (info->display_fbuf) { - /* simple audio video sync code: - * we calculate the actual frame by taking the elapsed audio time and try - * to stay inside +- 1 frame of this calculated frame number by dropping - * frames if we run behind and delaying if we are too fast - */ - - /* Avoid deadlock is sound was too far ahead */ - if (bgSoundStream && !bgSound.isActive()) - return false; - - if (checkPaletteSwitch() || (bgSoundStream == NULL) || - ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum + 1) || - frameskipped > 10) { - if (frameskipped > 10) { - warning("force frame %i redraw", framenum); - frameskipped = 0; - } +void AnimationState::drawYUV(int width, int height, byte *const *dat) { #ifdef BACKEND_8BIT - _vm->_graphics->plotYUV(lut, sequence_i->width, sequence_i->height, info->display_fbuf->buf); + _vm->_graphics->plotYUV(lut, width, height, dat); + // FIXME: We used to call setNeedFullRedraw() a bit later (that is, + // it was called by decodeFrame(), after the 'delay_msecs' calls, so + // after the syncing code. Not sure if moving it here causes any + // problems, and I have no way to test it. However I do not see why + // it should cause problems... of course that doesn't mean anything, + // only that I can't see that far :-) + _vm->_graphics->setNeedFullRedraw(); #else - plotYUV(lookup, sequence_i->width, sequence_i->height, info->display_fbuf->buf); -#endif - - if (bgSoundStream) { - while ((_snd->getChannelElapsedTime(bgSound) * 12) / 1000 < framenum) - _sys->delay_msecs(10); - } else { - ticks += 83; - _vm->sleepUntil(ticks); - } - -#ifdef BACKEND_8BIT - _vm->_graphics->setNeedFullRedraw(); -#endif - - } else { - warning("dropped frame %i", framenum); - frameskipped++; - } - -#ifdef BACKEND_8BIT - buildLookup(palnum + 1, lutcalcnum); -#endif - - framenum++; - return true; - - } - break; - - default: - break; - } - } while (size); + plotYUV(lookup, width, height, dat); #endif - return false; } MovieInfo MoviePlayer::_movies[] = { diff --git a/sword2/driver/animation.h b/sword2/driver/animation.h index c71d263546..00fea9fa67 100644 --- a/sword2/driver/animation.h +++ b/sword2/driver/animation.h @@ -37,8 +37,6 @@ public: AnimationState(Sword2Engine *vm); ~AnimationState(); - bool decodeFrame(); - #ifndef BACKEND_8BIT void drawTextObject(SpriteInfo *s, uint8 *src); void clearDisplay(); @@ -46,6 +44,7 @@ public: #endif private: + void drawYUV(int width, int height, byte *const *dat); #ifdef BACKEND_8BIT void setPalette(byte *pal); |