diff options
author | Paul Gilbert | 2007-11-18 05:10:56 +0000 |
---|---|---|
committer | Paul Gilbert | 2007-11-18 05:10:56 +0000 |
commit | 4d214711550eb51114c70b06a96d725c671ed204 (patch) | |
tree | c5ddd9d7184d9cf652520cb99825e2d9139d14cc | |
parent | 2670862c3311793865400b392664704da61fab4e (diff) | |
download | scummvm-rg350-4d214711550eb51114c70b06a96d725c671ed204.tar.gz scummvm-rg350-4d214711550eb51114c70b06a96d725c671ed204.tar.bz2 scummvm-rg350-4d214711550eb51114c70b06a96d725c671ed204.zip |
Cleaned up animation player and added support for a set of sounds to be played during an animation
svn-id: r29547
-rw-r--r-- | engines/lure/animseq.cpp | 54 | ||||
-rw-r--r-- | engines/lure/animseq.h | 14 | ||||
-rw-r--r-- | engines/lure/game.cpp | 19 | ||||
-rw-r--r-- | engines/lure/intro.cpp | 4 |
4 files changed, 52 insertions, 39 deletions
diff --git a/engines/lure/animseq.cpp b/engines/lure/animseq.cpp index 1dc2abe341..83640d6ef8 100644 --- a/engines/lure/animseq.cpp +++ b/engines/lure/animseq.cpp @@ -24,9 +24,10 @@ */ #include "lure/animseq.h" -#include "lure/palette.h" #include "lure/decode.h" #include "lure/events.h" +#include "lure/palette.h" +#include "lure/sound.h" #include "common/endian.h" namespace Lure { @@ -36,10 +37,10 @@ namespace Lure { // Escape has been pressed, and the introduction should be aborted. AnimAbortType AnimationSequence::delay(uint32 milliseconds) { - uint32 delayCtr = _system.getMillis() + milliseconds; Events &events = Events::getReference(); + uint32 delayCtr = g_system->getMillis() + milliseconds; - while (_system.getMillis() < delayCtr) { + while (g_system->getMillis() < delayCtr) { while (events.pollEvent()) { if (events.type() == Common::EVENT_KEYDOWN) { if (events.event().kbd.keycode == Common::KEYCODE_ESCAPE) return ABORT_END_INTRO; @@ -50,9 +51,9 @@ AnimAbortType AnimationSequence::delay(uint32 milliseconds) { return ABORT_END_INTRO; } - uint32 delayAmount = delayCtr - _system.getMillis(); + uint32 delayAmount = delayCtr - g_system->getMillis(); if (delayAmount > 10) delayAmount = 10; - _system.delayMillis(delayAmount); + g_system->delayMillis(delayAmount); } return ABORT_NONE; } @@ -61,7 +62,8 @@ AnimAbortType AnimationSequence::delay(uint32 milliseconds) { // Decodes a single frame of the animation sequence void AnimationSequence::decodeFrame(byte *&pPixels, byte *&pLines) { - byte *screen = _screen.screen_raw(); + Screen &screen = Screen::getReference(); + byte *screenData = screen.screen_raw(); uint16 screenPos = 0; uint16 len; @@ -74,8 +76,8 @@ void AnimationSequence::decodeFrame(byte *&pPixels, byte *&pLines) { } // Move the splice over - memcpy(screen, pPixels, len); - screen += len; + memcpy(screenData, pPixels, len); + screenData += len; screenPos += len; pPixels += len; @@ -86,16 +88,18 @@ void AnimationSequence::decodeFrame(byte *&pPixels, byte *&pLines) { pLines += 2; } - screen += len; + screenData += len; screenPos += len; } // Make the decoded frame visible - _screen.update(); + screen.update(); } -AnimationSequence::AnimationSequence(Screen &screen, OSystem &system, uint16 screenId, Palette &palette, - bool fadeIn): _screen(screen), _system(system), _screenId(screenId), _palette(palette) { +AnimationSequence::AnimationSequence(uint16 screenId, Palette &palette, bool fadeIn, int frameDelay, + const AnimSoundSequence *soundList): _screenId(screenId), _palette(palette), + _frameDelay(frameDelay), _soundList(soundList) { + Screen &screen = Screen::getReference(); PictureDecoder decoder; Disk &d = Disk::getReference(); MemoryBlock *data = d.getEntry(_screenId); @@ -105,13 +109,13 @@ AnimationSequence::AnimationSequence(Screen &screen, OSystem &system, uint16 scr _lineRefs = d.getEntry(_screenId + 1); // Reset the palette and set the initial starting screen - _screen.setPaletteEmpty(RES_PALETTE_ENTRIES); - _screen.screen().data().copyFrom(_decodedData, 0, 0, FULL_SCREEN_HEIGHT * FULL_SCREEN_WIDTH); - _screen.update(); + screen.setPaletteEmpty(RES_PALETTE_ENTRIES); + screen.screen().data().copyFrom(_decodedData, 0, 0, FULL_SCREEN_HEIGHT * FULL_SCREEN_WIDTH); + screen.update(); // Set the palette - if (fadeIn) _screen.paletteFadeIn(&_palette); - else _screen.setPalette(&_palette, 0, _palette.numEntries()); + if (fadeIn) screen.paletteFadeIn(&_palette); + else screen.setPalette(&_palette, 0, _palette.numEntries()); // Set up frame poitners _pPixels = _decodedData->data() + SCREEN_SIZE; @@ -130,22 +134,34 @@ AnimationSequence::~AnimationSequence() { AnimAbortType AnimationSequence::show() { AnimAbortType result; + const AnimSoundSequence *soundFrame = _soundList; + int frameCtr = 0; // Loop through displaying the animations while ((_pPixels < _pPixelsEnd) && (_pLines < _pLinesEnd)) { + if ((soundFrame != NULL) && (frameCtr == 0)) + Sound.musicInterface_Play(soundFrame->soundId, soundFrame->channelNum); + decodeFrame(_pPixels, _pLines); - result = delay(7 * 1000 / 50); + result = delay(_frameDelay * 1000 / 50); if (result != ABORT_NONE) return result; + + if ((soundFrame != NULL) && (++frameCtr == soundFrame->numFrames)) { + frameCtr = 0; + ++soundFrame; + if (soundFrame->numFrames == 0) soundFrame = NULL; + } } return ABORT_NONE; } bool AnimationSequence::step() { + Screen &screen = Screen::getReference(); if ((_pPixels >= _pPixelsEnd) || (_pLines >= _pLinesEnd)) return false; decodeFrame(_pPixels, _pLines); - _screen.setPalette(&_palette); + screen.setPalette(&_palette); return true; } diff --git a/engines/lure/animseq.h b/engines/lure/animseq.h index 665d638e48..e60de55edd 100644 --- a/engines/lure/animseq.h +++ b/engines/lure/animseq.h @@ -32,22 +32,28 @@ namespace Lure { enum AnimAbortType {ABORT_NONE, ABORT_END_INTRO, ABORT_NEXT_SCENE}; +struct AnimSoundSequence { + uint16 numFrames; + uint8 soundId; + uint8 channelNum; +}; + class AnimationSequence { private: - Screen &_screen; - OSystem &_system; uint16 _screenId; Palette &_palette; MemoryBlock *_decodedData; MemoryBlock *_lineRefs; byte *_pPixels, *_pLines; byte *_pPixelsEnd, *_pLinesEnd; + const AnimSoundSequence *_soundList; + int _frameDelay; AnimAbortType delay(uint32 milliseconds); void decodeFrame(byte *&pPixels, byte *&pLines); public: - AnimationSequence(Screen &screen, OSystem &system, uint16 screenId, Palette &palette, - bool fadeIn); + AnimationSequence(uint16 screenId, Palette &palette, bool fadeIn, int frameDelay = 7, + const AnimSoundSequence *soundList = NULL); ~AnimationSequence(); AnimAbortType show(); diff --git a/engines/lure/game.cpp b/engines/lure/game.cpp index 2c25a016e9..5a3a65f7ad 100644 --- a/engines/lure/game.cpp +++ b/engines/lure/game.cpp @@ -267,8 +267,7 @@ void Game::execute() { // If Skorl catches player, show the catching animation if ((_state & GS_CAUGHT) != 0) { Palette palette(SKORL_CATCH_PALETTE_ID); - AnimationSequence *anim = new AnimationSequence(screen, system, - SKORL_CATCH_ANIM_ID, palette, false); + AnimationSequence *anim = new AnimationSequence(SKORL_CATCH_ANIM_ID, palette, false); mouse.cursorOff(); Sound.addSound(0x33); anim->show(); @@ -371,9 +370,7 @@ void Game::playerChangeRoom() { } void Game::displayChuteAnimation() { - OSystem &system = *g_system; Resources &res = Resources::getReference(); - Screen &screen = Screen::getReference(); Mouse &mouse = Mouse::getReference(); ValueTableData &fields = res.fieldList(); @@ -385,18 +382,15 @@ void Game::displayChuteAnimation() { Sound.killSounds(); Sound.musicInterface_Play(0x40, 0); - AnimationSequence *anim = new AnimationSequence(screen, system, - CHUTE_ANIM_ID, palette, false); + AnimationSequence *anim = new AnimationSequence(CHUTE_ANIM_ID, palette, false); anim->show(); delete anim; - anim = new AnimationSequence(screen, system, CHUTE2_ANIM_ID, - palette, false); + anim = new AnimationSequence(CHUTE2_ANIM_ID, palette, false); anim->show(); delete anim; - anim = new AnimationSequence(screen, system, CHUTE3_ANIM_ID, - palette, false); + anim = new AnimationSequence(CHUTE3_ANIM_ID, palette, false); anim->show(); delete anim; @@ -406,14 +400,11 @@ void Game::displayChuteAnimation() { } void Game::displayBarrelAnimation() { - OSystem &system = *g_system; - Screen &screen = Screen::getReference(); Mouse &mouse = Mouse::getReference(); debugC(ERROR_INTERMEDIATE, kLureDebugAnimations, "Starting barrel animation"); Palette palette(BARREL_PALETTE_ID); - AnimationSequence *anim = new AnimationSequence(screen, system, - BARREL_ANIM_ID, palette, false); + AnimationSequence *anim = new AnimationSequence(BARREL_ANIM_ID, palette, false); mouse.cursorOff(); Sound.killSounds(); diff --git a/engines/lure/intro.cpp b/engines/lure/intro.cpp index e59f21d3ad..538cca9673 100644 --- a/engines/lure/intro.cpp +++ b/engines/lure/intro.cpp @@ -117,7 +117,7 @@ bool Introduction::show() { } bool fadeIn = curr_anim == anim_screens; - anim = new AnimationSequence(_screen, _system, curr_anim->resourceId, + anim = new AnimationSequence(curr_anim->resourceId, coll.getPalette(curr_anim->paletteIndex), fadeIn); if (curr_anim->initialPause != 0) if (interruptableDelay(curr_anim->initialPause * 1000 / 50)) return true; @@ -148,7 +148,7 @@ bool Introduction::show() { // Show battle pictures one frame at a time result = false; - anim = new AnimationSequence(_screen, _system, 0x48, coll.getPalette(4), false); + anim = new AnimationSequence(0x48, coll.getPalette(4), false); do { result = interruptableDelay(2000); _screen.paletteFadeOut(); |