diff options
Diffstat (limited to 'engines/sword2')
-rw-r--r-- | engines/sword2/animation.cpp | 78 | ||||
-rw-r--r-- | engines/sword2/animation.h | 11 |
2 files changed, 59 insertions, 30 deletions
diff --git a/engines/sword2/animation.cpp b/engines/sword2/animation.cpp index 1c5c2e5f8c..c3f3e796b2 100644 --- a/engines/sword2/animation.cpp +++ b/engines/sword2/animation.cpp @@ -47,9 +47,10 @@ namespace Sword2 { /////////////////////////////////////////////////////////////////////////////// MoviePlayer::MoviePlayer(Sword2Engine *vm, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType) - : _vm(vm), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system), VideoPlayer(decoder) { + : _vm(vm), _snd(snd), _bgSoundHandle(bgSoundHandle), _system(system) { _bgSoundStream = NULL; _decoderType = decoderType; + _decoder = decoder; } MoviePlayer:: ~MoviePlayer() { @@ -62,11 +63,10 @@ MoviePlayer:: ~MoviePlayer() { * @param id the id of the file */ bool MoviePlayer::load(const char *name) { - if (_decoderType == kVideoDecoderDXA) { + if (_decoderType == kVideoDecoderDXA) _bgSoundStream = Audio::SeekableAudioStream::openStreamFile(name); - } else { + else _bgSoundStream = NULL; - } _textSurface = NULL; @@ -97,13 +97,11 @@ void MoviePlayer::play(MovieText *movieTexts, uint32 numMovieTexts, uint32 leadI _currentMovieText = 0; _leadOut = leadOut; - if (leadIn) { + if (leadIn) _vm->_sound->playMovieSound(leadIn, kLeadInSound); - } - if (_bgSoundStream) { + if (_bgSoundStream) _snd->playStream(Audio::Mixer::kSFXSoundType, _bgSoundHandle, _bgSoundStream); - } bool terminated = false; @@ -186,12 +184,12 @@ void MoviePlayer::closeTextObject(uint32 index, byte *screen) { for (int y = 0; y < text->_textSprite.h; y++) { if (_textY + y < frameY || _textY + y >= frameY + frameHeight) { - memset(dst + _textX, _decoder->getBlack(), text->_textSprite.w); + memset(dst + _textX, findBlackPalIndex(), text->_textSprite.w); } else { if (frameX > _textX) - memset(dst + _textX, _decoder->getBlack(), frameX - _textX); + memset(dst + _textX, findBlackPalIndex(), frameX - _textX); if (frameX + frameWidth < _textX + text->_textSprite.w) - memset(dst + frameX + frameWidth, _decoder->getBlack(), _textX + text->_textSprite.w - (frameX + frameWidth)); + memset(dst + frameX + frameWidth, findBlackPalIndex(), _textX + text->_textSprite.w - (frameX + frameWidth)); } dst += _system->getWidth(); @@ -207,8 +205,8 @@ void MoviePlayer::closeTextObject(uint32 index, byte *screen) { void MoviePlayer::drawTextObject(uint32 index, byte *screen) { MovieText *text = &_movieTexts[index]; - byte white = _decoder->getWhite(); - byte black = _decoder->getBlack(); + byte white = findWhitePalIndex(); + byte black = findBlackPalIndex(); if (text->_textMem && _textSurface) { byte *src = text->_textSprite.data; @@ -240,7 +238,7 @@ void MoviePlayer::drawTextObject(uint32 index, byte *screen) { void MoviePlayer::performPostProcessing(byte *screen) { MovieText *text; - int frame = _decoder->getCurFrame() + 1; + int frame = _decoder->getCurFrame(); if (_currentMovieText < _numMovieTexts) { text = &_movieTexts[_currentMovieText]; @@ -272,25 +270,51 @@ void MoviePlayer::performPostProcessing(byte *screen) { } } -DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle) - : _mixer(mixer), _bgSoundHandle(bgSoundHandle) { +bool MoviePlayer::playVideo() { + uint16 x = (g_system->getWidth() - _decoder->getWidth()) / 2; + uint16 y = (g_system->getHeight() - _decoder->getHeight()) / 2; + + while (!_vm->shouldQuit() && !_decoder->endOfVideo()) { + if (_decoder->needsUpdate()) { + Graphics::Surface *frame = _decoder->decodeNextFrame(); + if (frame) + _vm->_system->copyRectToScreen((byte *)frame->pixels, frame->pitch, x, y, frame->w, frame->h); + + if (_decoder->hasDirtyPalette()) + _decoder->setSystemPalette(); + + Graphics::Surface *screen = _vm->_system->lockScreen(); + performPostProcessing((byte *)screen->pixels); + _vm->_system->unlockScreen(); + _vm->_system->updateScreen(); + } + + Common::Event event; + while (_vm->_system->getEventManager()->pollEvent(event)) + if ((event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) || event.type == Common::EVENT_LBUTTONUP) + return false; + } + + return !_vm->shouldQuit(); } -int32 DXADecoderWithSound::getAudioLag() { - if (!_fileStream) - return 0; +byte MoviePlayer::findBlackPalIndex() { + return 0; +} - if (!_mixer->isSoundHandleActive(*_bgSoundHandle)) - return 0; +byte MoviePlayer::findWhitePalIndex() { + return 0xff; +} - int32 frameDelay = getFrameDelay(); - int32 videoTime = _videoInfo.currentFrame * frameDelay; - int32 audioTime; +DXADecoderWithSound::DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle) + : _mixer(mixer), _bgSoundHandle(bgSoundHandle) { +} - const Audio::Timestamp ts = _mixer->getElapsedTime(*_bgSoundHandle); - audioTime = ts.convertToFramerate(100000).totalNumberOfFrames(); +uint32 DXADecoderWithSound::getElapsedTime() const { + if (_mixer->isSoundHandleActive(*_bgSoundHandle)) + return _mixer->getSoundElapsedTime(*_bgSoundHandle); - return videoTime - audioTime; + return VideoDecoder::getElapsedTime(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/engines/sword2/animation.h b/engines/sword2/animation.h index 7f9ae0ff2d..bbf83e264c 100644 --- a/engines/sword2/animation.h +++ b/engines/sword2/animation.h @@ -30,7 +30,7 @@ #include "graphics/video/dxa_decoder.h" #include "graphics/video/smk_decoder.h" -#include "graphics/video/video_player.h" +#include "graphics/video/video_decoder.h" #include "sound/mixer.h" #include "sword2/screen.h" @@ -63,13 +63,13 @@ public: DXADecoderWithSound(Audio::Mixer *mixer, Audio::SoundHandle *bgSoundHandle); ~DXADecoderWithSound() {} - int32 getAudioLag(); + uint32 getElapsedTime() const; private: Audio::Mixer *_mixer; Audio::SoundHandle *_bgSoundHandle; }; -class MoviePlayer : public Graphics::VideoPlayer { +class MoviePlayer { public: MoviePlayer(Sword2Engine *vm, Audio::Mixer *snd, OSystem *system, Audio::SoundHandle *bgSoundHandle, Graphics::VideoDecoder *decoder, DecoderType decoderType); virtual ~MoviePlayer(); @@ -89,6 +89,7 @@ protected: int _textX, _textY; DecoderType _decoderType; + Graphics::VideoDecoder *_decoder; Audio::SoundHandle *_bgSoundHandle; Audio::AudioStream *_bgSoundStream; @@ -96,10 +97,14 @@ protected: int _leadOutFrame; void performPostProcessing(byte *screen); + bool playVideo(); void openTextObject(uint32 index); void closeTextObject(uint32 index, byte *screen); void drawTextObject(uint32 index, byte *screen); + + byte findBlackPalIndex(); + byte findWhitePalIndex(); }; MoviePlayer *makeMoviePlayer(const char *name, Sword2Engine *vm, Audio::Mixer *snd, OSystem *system); |