diff options
author | Filippos Karapetis | 2015-12-27 21:12:41 +0200 |
---|---|---|
committer | Filippos Karapetis | 2015-12-27 21:16:43 +0200 |
commit | c5f5fbc208d473d87d42edd64113728bf26153b1 (patch) | |
tree | 3c8adca326cb484297b5a0901b5b23e3b5df0b5e /engines | |
parent | 29342b1331533b2e85057e4cf0a2d2acffd3d56d (diff) | |
download | scummvm-rg350-c5f5fbc208d473d87d42edd64113728bf26153b1.tar.gz scummvm-rg350-c5f5fbc208d473d87d42edd64113728bf26153b1.tar.bz2 scummvm-rg350-c5f5fbc208d473d87d42edd64113728bf26153b1.zip |
LAB: Refactor the music code
Diffstat (limited to 'engines')
-rw-r--r-- | engines/lab/anim.cpp | 8 | ||||
-rw-r--r-- | engines/lab/dispman.cpp | 26 | ||||
-rw-r--r-- | engines/lab/engine.cpp | 12 | ||||
-rw-r--r-- | engines/lab/intro.cpp | 30 | ||||
-rw-r--r-- | engines/lab/lab.cpp | 3 | ||||
-rw-r--r-- | engines/lab/lab.h | 2 | ||||
-rw-r--r-- | engines/lab/map.cpp | 10 | ||||
-rw-r--r-- | engines/lab/music.cpp | 185 | ||||
-rw-r--r-- | engines/lab/music.h | 47 | ||||
-rw-r--r-- | engines/lab/processroom.cpp | 27 | ||||
-rw-r--r-- | engines/lab/resource.cpp | 6 | ||||
-rw-r--r-- | engines/lab/savegame.cpp | 2 | ||||
-rw-r--r-- | engines/lab/special.cpp | 24 |
13 files changed, 115 insertions, 267 deletions
diff --git a/engines/lab/anim.cpp b/engines/lab/anim.cpp index 0c01b072c4..ef6694490a 100644 --- a/engines/lab/anim.cpp +++ b/engines/lab/anim.cpp @@ -143,7 +143,7 @@ void Anim::diffNextFrame(bool onlyDiffData) { return; } - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _lastBlockHeader = _diffFile->readUint32LE(); _size = _diffFile->readUint32LE(); @@ -207,7 +207,7 @@ void Anim::diffNextFrame(bool onlyDiffData) { case 31: if (_waitForEffect) { while (_vm->_music->isSoundEffectActive()) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); } } @@ -229,7 +229,7 @@ void Anim::diffNextFrame(bool onlyDiffData) { if (_waitForEffect) { while (_vm->_music->isSoundEffectActive()) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); if (drawOnScreen) @@ -269,7 +269,7 @@ void Anim::stopDiffEnd() { _stopPlayingEnd = true; while (_isPlaying) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); diffNextFrame(); } } diff --git a/engines/lab/dispman.cpp b/engines/lab/dispman.cpp index 5dba424018..4b256f0c23 100644 --- a/engines/lab/dispman.cpp +++ b/engines/lab/dispman.cpp @@ -87,7 +87,7 @@ void DisplayMan::loadBackPict(const Common::String fileName, uint16 *highPal) { void DisplayMan::readPict(const Common::String filename, bool playOnce, bool onlyDiffData, byte *memoryBuffer) { _vm->_anim->stopDiff(); loadPict(filename); - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->_anim->setOutputBuffer(memoryBuffer); _vm->_anim->readDiff(_curBitmap, playOnce, onlyDiffData); } @@ -480,7 +480,7 @@ void DisplayMan::checkerBoardEffect(uint16 penColor, uint16 x1, uint16 y1, uint1 h = _screenHeight - y1; if ((w > 0) && (h > 0)) { - byte *d = (byte *)getCurrentDrawingBuffer() + y1 * _screenWidth + x1; + byte *d = getCurrentDrawingBuffer() + y1 * _screenWidth + x1; while (h-- > 0) { byte *dd = d; @@ -570,7 +570,7 @@ void DisplayMan::drawText(TextFont *tf, uint16 x, uint16 y, uint16 color, const for (int counterb = 0; counterb < 8; counterb++) { if (templeft <= 0) { curPage++; - vgaTemp = (byte *)(vgaTop - templeft); + vgaTemp = vgaTop - templeft; // Set up VGATempLine for next line vgaTempLine -= _screenBytesPerPage; // Set up LeftInSegment for next line @@ -621,7 +621,7 @@ void DisplayMan::doScrollBlack() { scrollDisplayY(-by, 0, 0, width - 1, height - 1, mem); verticalScroll -= by; - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); } @@ -660,7 +660,7 @@ void DisplayMan::doScrollWipe(const Common::String filename) { uint16 height = _vm->_utils->vgaScaleY(149) + _vm->_utils->svgaCord(2); while (_vm->_music->isSoundEffectActive()) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); } @@ -668,13 +668,13 @@ void DisplayMan::doScrollWipe(const Common::String filename) { setPalette(_vm->_anim->_diffPalette, 256); byte *mem = _vm->_anim->_scrollScreenBuffer; - _vm->updateMusicAndEvents(); + _vm->updateEvents(); uint16 by = _vm->_utils->vgaScaleX(3); uint16 nheight = height; uint16 startLine = 0, onRow = 0; while (onRow < _vm->_anim->getDIFFHeight()) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); if ((by > nheight) && nheight) by = nheight; @@ -713,18 +713,18 @@ void DisplayMan::doScrollBounce() { int height = _vm->_utils->vgaScaleY(149) + _vm->_utils->svgaCord(2); byte *mem = _vm->_anim->_scrollScreenBuffer; - _vm->updateMusicAndEvents(); + _vm->updateEvents(); int startLine = _vm->_anim->getDIFFHeight() - height - 1; for (int i = 0; i < 5; i++) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); startLine -= (5 - i) * multiplier; copyPage(width, height, 0, startLine, mem); _vm->waitTOF(); } for (int i = 8; i > 0; i--) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); startLine += offsets[i - 1] * multiplier; copyPage(width, height, 0, startLine, mem); _vm->waitTOF(); @@ -752,7 +752,7 @@ void DisplayMan::doTransWipe(const Common::String filename) { while (curY < lastY) { if (linesDone >= linesLast) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); linesDone = 0; } @@ -795,7 +795,7 @@ void DisplayMan::doTransWipe(const Common::String filename) { while (curY < lastY) { if (linesDone >= linesLast) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); linesDone = 0; } @@ -950,7 +950,7 @@ void DisplayMan::fade(bool fadeIn) { setAmigaPal(newPal); _vm->waitTOF(); - _vm->updateMusicAndEvents(); + _vm->updateEvents(); } } diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp index 95dcc71923..4d24fb359c 100644 --- a/engines/lab/engine.cpp +++ b/engines/lab/engine.cpp @@ -478,7 +478,7 @@ void LabEngine::mainGameLoop() { } // Make sure we check the music at least after every message - updateMusicAndEvents(); + updateEvents(); interfaceOn(); IntuiMessage *curMsg = _event->getMsg(); if (shouldQuit()) { @@ -490,7 +490,7 @@ void LabEngine::mainGameLoop() { // Does music load and next animation frame when you've run out of messages gotMessage = false; _music->checkRoomMusic(); - updateMusicAndEvents(); + updateEvents(); _anim->diffNextFrame(); if (_followingCrumbs) { @@ -521,7 +521,7 @@ void LabEngine::showLab2Teaser() { _graphics->readPict("P:End/L2In.1"); for (int i = 0; i < 120; i++) { - updateMusicAndEvents(); + updateEvents(); waitTOF(); } @@ -529,7 +529,7 @@ void LabEngine::showLab2Teaser() { _graphics->readPict("P:End/Lost"); while (!_event->getMsg() && !shouldQuit()) { - updateMusicAndEvents(); + updateEvents(); _anim->diffNextFrame(); waitTOF(); } @@ -652,7 +652,7 @@ bool LabEngine::processKey(IntuiMessage *curMsg, uint32 msgClass, uint16 &qualif while (1) { // Make sure we check the music at least after every message - updateMusicAndEvents(); + updateEvents(); curMsg = _event->getMsg(); if (shouldQuit()) @@ -660,7 +660,7 @@ bool LabEngine::processKey(IntuiMessage *curMsg, uint32 msgClass, uint16 &qualif if (!curMsg) { // Does music load and next animation frame when you've run out of messages - updateMusicAndEvents(); + updateEvents(); _anim->diffNextFrame(); } else if (curMsg->_msgClass == kMessageRawKey) { if ((curMsg->_code == Common::KEYCODE_y) || (curMsg->_code == Common::KEYCODE_q)) { diff --git a/engines/lab/intro.cpp b/engines/lab/intro.cpp index f258acc880..2d6457b83f 100644 --- a/engines/lab/intro.cpp +++ b/engines/lab/intro.cpp @@ -72,7 +72,7 @@ void Intro::doPictText(const Common::String filename, bool isScreen) { Common::String path = Common::String("Lab:rooms/Intro/") + filename; uint timeDelay = (isScreen) ? 35 : 7; - _vm->updateMusicAndEvents(); + _vm->updateEvents(); if (_quitIntro) return; @@ -126,7 +126,7 @@ void Intro::doPictText(const Common::String filename, bool isScreen) { } if (!msg) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->_anim->diffNextFrame(); uint32 elapsedSeconds = (_vm->_system->getMillis() - lastMillis) / 1000; @@ -192,13 +192,13 @@ void Intro::doPictText(const Common::String filename, bool isScreen) { } void Intro::musicDelay() { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); if (_quitIntro) return; for (int i = 0; i < 20; i++) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); _vm->waitTOF(); _vm->waitTOF(); @@ -208,7 +208,7 @@ void Intro::musicDelay() { void Intro::nReadPict(const Common::String filename, bool playOnce) { Common::String finalFileName = Common::String("P:Intro/") + filename; - _vm->updateMusicAndEvents(); + _vm->updateEvents(); introEatMessages(); if (_quitIntro) @@ -247,10 +247,10 @@ void Intro::play() { _vm->_graphics->blackAllScreen(); - if (_vm->getPlatform() == Common::kPlatformAmiga) - _vm->_music->initMusic("Music:BackGround"); + if (_vm->getPlatform() != Common::kPlatformAmiga) + _vm->_music->changeMusic("Music:BackGrou", false, false); else - _vm->_music->initMusic("Music:BackGrou"); + _vm->_music->changeMusic("Music:BackGround", false, false); _vm->_anim->_noPalChange = true; if (_vm->getPlatform() == Common::kPlatformDOS) @@ -266,7 +266,7 @@ void Intro::play() { ((_vm->_anim->_diffPalette[i * 3 + 1] >> 2) << 4) + (_vm->_anim->_diffPalette[i * 3 + 2] >> 2); } - _vm->updateMusicAndEvents(); + _vm->updateEvents(); if (!_quitIntro) _vm->_graphics->fade(true); @@ -275,7 +275,7 @@ void Intro::play() { if (_quitIntro) break; - _vm->updateMusicAndEvents(); + _vm->updateEvents(); uint16 temp = palette[2]; for (int i = 2; i < 15; i++) @@ -290,7 +290,7 @@ void Intro::play() { if (!_quitIntro) { _vm->_graphics->fade(false); _vm->_graphics->blackAllScreen(); - _vm->updateMusicAndEvents(); + _vm->updateEvents(); } nReadPict("Title.A"); @@ -313,9 +313,9 @@ void Intro::play() { nReadPict("DA"); musicDelay(); - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->_graphics->blackAllScreen(); - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->_anim->_noPalChange = true; nReadPict("Intro.1"); @@ -334,7 +334,7 @@ void Intro::play() { } _vm->_graphics->blackAllScreen(); - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _introDoBlack = true; nReadPict("Station1"); @@ -369,7 +369,7 @@ void Intro::play() { for (int idx = (8 * 3); idx < (255 * 3); idx++) _vm->_anim->_diffPalette[idx] = 255 - _vm->_anim->_diffPalette[idx]; - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); _vm->_graphics->setPalette(_vm->_anim->_diffPalette, 256); _vm->waitTOF(); diff --git a/engines/lab/lab.cpp b/engines/lab/lab.cpp index be299a8236..e439aa15a7 100644 --- a/engines/lab/lab.cpp +++ b/engines/lab/lab.cpp @@ -243,10 +243,9 @@ void LabEngine::waitTOF() { _lastWaitTOFTicks = now; } -void LabEngine::updateMusicAndEvents() { +void LabEngine::updateEvents() { _event->processInput(); _event->updateMouse(); - _music->updateMusic(); } } // End of namespace Lab diff --git a/engines/lab/lab.h b/engines/lab/lab.h index fd09db0a37..1933f3aec5 100644 --- a/engines/lab/lab.h +++ b/engines/lab/lab.h @@ -222,7 +222,7 @@ public: uint16 getQuarters(); void setDirection(uint16 direction) { _direction = direction; }; void setQuarters(uint16 quarters); - void updateMusicAndEvents(); + void updateEvents(); void waitTOF(); private: diff --git a/engines/lab/map.cpp b/engines/lab/map.cpp index f7b2cfe9ea..ee47c2b14b 100644 --- a/engines/lab/map.cpp +++ b/engines/lab/map.cpp @@ -82,7 +82,7 @@ void LabEngine::loadMapData() { delete mapImages; Common::File *mapFile = _resource->openDataFile("Lab:Maps", MKTAG('M', 'A', 'P', '0')); - updateMusicAndEvents(); + updateEvents(); _maxRooms = mapFile->readUint16LE(); _maps = new MapData[_maxRooms + 1]; // will be freed when the user exits the map @@ -340,7 +340,7 @@ void LabEngine::drawMap(uint16 curRoom, uint16 curMsg, uint16 floorNum, bool fad } } - updateMusicAndEvents(); + updateEvents(); // Makes sure the X is drawn in corridors // NOTE: this here on purpose just in case there's some weird @@ -391,7 +391,7 @@ void LabEngine::processMap(uint16 curRoom) { while (1) { // Make sure we check the music at least after every message - updateMusicAndEvents(); + updateEvents(); IntuiMessage *msg = _event->getMsg(); if (shouldQuit()) { _quitLab = true; @@ -399,7 +399,7 @@ void LabEngine::processMap(uint16 curRoom) { } if (!msg) { - updateMusicAndEvents(); + updateEvents(); byte newcolor[3]; @@ -541,7 +541,7 @@ void LabEngine::doMap(uint16 curRoom) { _graphics->_fadePalette = amigaMapPalette; - updateMusicAndEvents(); + updateEvents(); loadMapData(); _graphics->blackAllScreen(); _event->attachButtonList(&_mapButtonList); diff --git a/engines/lab/music.cpp b/engines/lab/music.cpp index bdd9d8973f..e6ad392029 100644 --- a/engines/lab/music.cpp +++ b/engines/lab/music.cpp @@ -46,18 +46,10 @@ namespace Lab { #define DIMROOM 80 Music::Music(LabEngine *vm) : _vm(vm) { - _file = 0; - _tFile = 0; + _musicFile = nullptr; _musicPaused = false; - - _oldMusicOn = false; - _tLeftInFile = 0; - - _leftInFile = 0; - - _musicOn = false; - _queuingAudioStream = nullptr; _curRoomMusic = 1; + _storedPos = 0; } byte Music::getSoundFlags() { @@ -70,28 +62,6 @@ byte Music::getSoundFlags() { return soundFlags; } -void Music::updateMusic() { - if (!_musicOn || (getPlayingBufferCount() >= MAXBUFFERS)) - return; - - // Queue a music block, and start the music, if needed - bool startMusicFlag = false; - - if (!_queuingAudioStream) { - _queuingAudioStream = Audio::makeQueuingAudioStream(SAMPLESPEED, false); - startMusicFlag = true; - } - - _queuingAudioStream->queueBuffer(fillBuffer(), MUSICBUFSIZE, DisposeAfterUse::YES, getSoundFlags()); - - if (startMusicFlag) - _vm->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, _queuingAudioStream); -} - -uint16 Music::getPlayingBufferCount() { - return (_queuingAudioStream) ? _queuingAudioStream->numQueuedStreams() : 0; -} - void Music::playSoundEffect(uint16 sampleSpeed, uint32 length, bool loop, Common::File *dataFile) { pauseBackMusic(); stopSoundEffect(); @@ -104,7 +74,7 @@ void Music::playSoundEffect(uint16 sampleSpeed, uint32 length, bool loop, Common byte *soundData = (byte *)malloc(length); dataFile->read(soundData, length); - Audio::SeekableAudioStream *audioStream = Audio::makeRawStream(soundData, length, sampleSpeed, getSoundFlags()); + Audio::SeekableAudioStream *audioStream = Audio::makeRawStream((const byte *)soundData, length, sampleSpeed, getSoundFlags()); uint loops = (loop) ? 0 : 1; Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, loops); _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_sfxHandle, loopingAudioStream); @@ -119,68 +89,17 @@ bool Music::isSoundEffectActive() const { return _vm->_mixer->isSoundHandleActive(_sfxHandle); } -byte *Music::fillBuffer() { - // NOTE: We need to use malloc(), cause this will be freed with free() - // by the music code - byte *musicBuffer = (byte *)malloc(MUSICBUFSIZE); - - if (MUSICBUFSIZE < _leftInFile) { - _file->read(musicBuffer, MUSICBUFSIZE); - _leftInFile -= MUSICBUFSIZE; - } else { - _file->read(musicBuffer, _leftInFile); - - memset(musicBuffer + _leftInFile, 0, MUSICBUFSIZE - _leftInFile); - - _file->seek(0); - _leftInFile = _file->size(); - } - - return musicBuffer; -} - -void Music::startMusic(bool restartFl) { - if (!_musicOn) - return; - - stopSoundEffect(); - - if (restartFl) { - _file->seek(0); - _leftInFile = _file->size(); - } - - _musicOn = true; - _vm->updateMusicAndEvents(); -} - -bool Music::initMusic(const Common::String filename) { - _musicOn = true; - _musicPaused = false; - _file = _vm->_resource->openDataFile(filename); - startMusic(true); - return true; -} - void Music::freeMusic() { - _musicOn = false; - _vm->_mixer->stopHandle(_musicHandle); - _queuingAudioStream = nullptr; _vm->_mixer->stopHandle(_sfxHandle); - - delete _file; - _file = nullptr; + _musicPaused = false; + _musicFile = nullptr; } void Music::pauseBackMusic() { - if (!_musicPaused && _musicOn) { - _vm->updateMusicAndEvents(); - _musicOn = false; + if (!_musicPaused) { stopSoundEffect(); - _vm->_mixer->pauseHandle(_musicHandle, true); - _musicPaused = true; } } @@ -188,85 +107,47 @@ void Music::pauseBackMusic() { void Music::resumeBackMusic() { if (_musicPaused) { stopSoundEffect(); - _musicOn = true; - _vm->_mixer->pauseHandle(_musicHandle, false); - - _vm->updateMusicAndEvents(); _musicPaused = false; } } -void Music::setMusic(bool on) { - stopSoundEffect(); - - if (on && !_musicOn) { - _musicOn = true; - startMusic(true); - } else if (!on && _musicOn) { - _musicOn = false; - _vm->updateMusicAndEvents(); - } else - _musicOn = on; -} - void Music::checkRoomMusic() { - if ((_curRoomMusic == _vm->_roomNum) || !_musicOn) + if ((_curRoomMusic == _vm->_roomNum) || !_musicFile) return; - if (_vm->_roomNum == CLOWNROOM) - changeMusic("Music:Laugh"); - else if (_vm->_roomNum == DIMROOM) - changeMusic("Music:Rm81"); - - _curRoomMusic = _vm->_roomNum; -} - -void Music::changeMusic(const Common::String filename) { - if (!_tFile) { - _tFile = _file; - _oldMusicOn = _musicOn; - _tLeftInFile = _leftInFile + 65536; - - if (_tLeftInFile > (uint32)_tFile->size()) - _tLeftInFile = _leftInFile; + if (_vm->_roomNum == CLOWNROOM) { + changeMusic("Music:Laugh", true, false); + } else if (_vm->_roomNum == DIMROOM) { + changeMusic("Music:Rm81", true, false); + } else if (_curRoomMusic == CLOWNROOM || _curRoomMusic == DIMROOM) { + if (_vm->getPlatform() != Common::kPlatformAmiga) + changeMusic("Music:Backgrou", false, true); + else + changeMusic("Music:Background", false, true); } - _file = _vm->_resource->openDataFile(filename); - // turn music off - _musicOn = true; - setMusic(false); - - // turn it back on - _musicOn = false; - setMusic(true); + _curRoomMusic = _vm->_roomNum; } -void Music::resetMusic() { - if (!_tFile) - return; - - if (_file->isOpen()) - _file->close(); - - _file = _tFile; - _leftInFile = _tLeftInFile; - - _file->seek(_file->size() - _leftInFile); +void Music::changeMusic(const Common::String filename, bool storeCurPos, bool seektoStoredPos) { + if (storeCurPos) + _storedPos = _musicFile->pos(); - _musicOn = true; - setMusic(false); - _vm->updateMusicAndEvents(); - - if (_oldMusicOn) - startMusic(false); + _musicPaused = false; + stopSoundEffect(); + freeMusic(); + _musicFile = _vm->_resource->openDataFile(filename); + if (seektoStoredPos) + _musicFile->seek(_storedPos); - _tFile = 0; + Audio::SeekableAudioStream *audioStream = Audio::makeRawStream(_musicFile, SAMPLESPEED, getSoundFlags()); + Audio::LoopingAudioStream *loopingAudioStream = new Audio::LoopingAudioStream(audioStream, 0); + _vm->_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, loopingAudioStream); } -bool Music::readMusic(const Common::String filename, bool loop, bool waitTillFinished) { +bool Music::loadSoundEffect(const Common::String filename, bool loop, bool waitTillFinished) { Common::File *file = _vm->_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F')); - _vm->updateMusicAndEvents(); stopSoundEffect(); if (!file) @@ -293,14 +174,14 @@ void Music::readSound(bool waitTillFinished, bool loop, Common::File *file) { return; while (soundTag != 65535) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); soundTag = file->readUint32LE(); soundSize = file->readUint32LE() - 8; if ((soundTag == 30) || (soundTag == 31)) { if (waitTillFinished) { while (isSoundEffectActive()) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); } } @@ -313,7 +194,7 @@ void Music::readSound(bool waitTillFinished, bool loop, Common::File *file) { } else if (soundTag == 65535) { if (waitTillFinished) { while (isSoundEffectActive()) { - _vm->updateMusicAndEvents(); + _vm->updateEvents(); _vm->waitTOF(); } } diff --git a/engines/lab/music.h b/engines/lab/music.h index 47c538ee25..a06bfca306 100644 --- a/engines/lab/music.h +++ b/engines/lab/music.h @@ -49,37 +49,21 @@ class Music { private: LabEngine *_vm; - Common::File *_file; - Common::File *_tFile; - - bool _musicOn; + Common::File *_musicFile; bool _musicPaused; - bool _oldMusicOn; - - uint16 _curRoomMusic ; - - uint32 _tLeftInFile; - uint32 _leftInFile; + uint16 _curRoomMusic; + uint32 _storedPos; Audio::SoundHandle _musicHandle; Audio::SoundHandle _sfxHandle; - Audio::QueuingAudioStream *_queuingAudioStream; private: - byte *fillBuffer(); - uint16 getPlayingBufferCount(); - /** * Pauses the background music. */ void pauseBackMusic(); void readSound(bool waitTillFinished, bool loop, Common::File *file); - /** - * Starts up the music initially. - */ - void startMusic(bool restartFl); - byte getSoundFlags(); public: @@ -88,7 +72,7 @@ public: /** * Changes the background music to something else. */ - void changeMusic(const Common::String filename); + void changeMusic(const Common::String filename, bool storeCurPos, bool seektoStoredPos); /** * Checks the music that should be playing in a particular room. @@ -100,39 +84,20 @@ public: */ void freeMusic(); - /** - * Initializes the music buffers. - */ - bool initMusic(const Common::String filename); bool isSoundEffectActive() const; void playSoundEffect(uint16 sampleSpeed, uint32 length, bool loop, Common::File *dataFile); /** - * Reads in a music file. Ignores any graphics. + * Reads in a sound effect file. Ignores any graphics. */ - bool readMusic(const Common::String filename, bool loop, bool waitTillFinished); - - /** - * Changes the background music to the original piece playing. - */ - void resetMusic(); + bool loadSoundEffect(const Common::String filename, bool loop, bool waitTillFinished); /** * Resumes the paused background music. */ void resumeBackMusic(); - /** - * Turns the music on and off. - */ - void setMusic(bool on); void stopSoundEffect(); - - /** - * Figures out which buffer is currently playing based on messages sent to - * it from the Audio device. - */ - void updateMusic(); }; } // End of namespace Lab diff --git a/engines/lab/processroom.cpp b/engines/lab/processroom.cpp index 66619af967..491cdf39da 100644 --- a/engines/lab/processroom.cpp +++ b/engines/lab/processroom.cpp @@ -235,19 +235,19 @@ bool LabEngine::takeItem(Common::Point pos) { void LabEngine::doActions(const ActionList &actionList) { ActionList::const_iterator action; for (action = actionList.begin(); action != actionList.end(); ++action) { - updateMusicAndEvents(); + updateEvents(); switch (action->_actionType) { case kActionPlaySound: - _music->readMusic(action->_messages[0], false, true); + _music->loadSoundEffect(action->_messages[0], false, true); break; case kActionPlaySoundNoWait: // only used in scene 7 (street, when teleporting to the surreal maze) - _music->readMusic(action->_messages[0], false, false); + _music->loadSoundEffect(action->_messages[0], false, false); break; case kActionPlaySoundLooping: - _music->readMusic(action->_messages[0], true, false); + _music->loadSoundEffect(action->_messages[0], true, false); break; case kActionShowDiff: @@ -370,26 +370,29 @@ void LabEngine::doActions(const ActionList &actionList) { _graphics->screenUpdate(); while (_system->getMillis() < targetMillis) { - updateMusicAndEvents(); + updateEvents(); _anim->diffNextFrame(); } } break; case kActionStopMusic: // used in scene 44 (heart of the labyrinth, minotaur) - _music->setMusic(false); + _music->freeMusic(); break; - case kActionStartMusic: + case kActionStartMusic: // unused error("Unused opcode kActionStartMusic has been called"); break; case kActionChangeMusic: // used in scene 46 (museum exhibit, for the alarm) - _music->changeMusic(action->_messages[0]); + _music->changeMusic(action->_messages[0], true, false); break; - case kActionResetMusic: // used in scene 45 - _music->resetMusic(); + case kActionResetMusic: // used in scene 45 (sheriff's office, after museum) + if (getPlatform() != Common::kPlatformAmiga) + _music->changeMusic("Music:BackGrou", false, true); + else + _music->changeMusic("Music:BackGround", false, true); break; case kActionFillMusic: @@ -398,7 +401,7 @@ void LabEngine::doActions(const ActionList &actionList) { case kActionWaitSound: // used in scene 44 (heart of the labyrinth / ending) while (_music->isSoundEffectActive()) { - updateMusicAndEvents(); + updateEvents(); _anim->diffNextFrame(); waitTOF(); } @@ -410,7 +413,7 @@ void LabEngine::doActions(const ActionList &actionList) { case kActionWinMusic: // used in scene 44 (heart of the labyrinth / ending) _music->freeMusic(); - _music->initMusic("Music:WinGame"); + _music->changeMusic("Music:WinGame", false, false); break; case kActionWinGame: // used in scene 44 (heart of the labyrinth / ending) diff --git a/engines/lab/resource.cpp b/engines/lab/resource.cpp index 17535a7659..ba42e9a0ac 100644 --- a/engines/lab/resource.cpp +++ b/engines/lab/resource.cpp @@ -59,7 +59,7 @@ TextFont *Resource::getFont(const Common::String fileName) { if (fileSize <= headerSize) return nullptr; - _vm->updateMusicAndEvents(); + _vm->updateEvents(); TextFont *textfont = new TextFont(); textfont->_dataLength = fileSize - headerSize; @@ -76,7 +76,7 @@ TextFont *Resource::getFont(const Common::String fileName) { Common::String Resource::getText(const Common::String fileName) { Common::File *dataFile = openDataFile(fileName); - _vm->updateMusicAndEvents(); + _vm->updateEvents(); uint32 count = dataFile->size(); byte *buffer = new byte[count]; @@ -142,7 +142,7 @@ void Resource::readViews(uint16 roomNum) { readView(dataFile, curRoom->_view[kDirectionWest]); readRule(dataFile, curRoom->_rules); - _vm->updateMusicAndEvents(); + _vm->updateEvents(); delete dataFile; } diff --git a/engines/lab/savegame.cpp b/engines/lab/savegame.cpp index 1564babfc8..8d8b42f3fc 100644 --- a/engines/lab/savegame.cpp +++ b/engines/lab/savegame.cpp @@ -233,7 +233,7 @@ bool LabEngine::saveRestoreGame() { if (slot >= 0) { isOK = loadGame(slot); if (isOK) - _music->resetMusic(); + _music->checkRoomMusic(); } delete dialog; } diff --git a/engines/lab/special.cpp b/engines/lab/special.cpp index 8e503665c7..76b6cbbd1e 100644 --- a/engines/lab/special.cpp +++ b/engines/lab/special.cpp @@ -94,7 +94,7 @@ void LabEngine::loadJournalData() { _graphics->freeFont(&_journalFont); _journalFont = _resource->getFont("F:Journal.fon"); - updateMusicAndEvents(); + updateEvents(); Common::String filename = "Lab:Rooms/j"; @@ -150,7 +150,7 @@ void LabEngine::drawJournalText() { assert((_journalPage & 1) == 0); while (drawingToPage < _journalPage) { - updateMusicAndEvents(); + updateEvents(); // flowText without output curText += _graphics->flowText(_journalFont, -2, 2, 0, false, false, false, false, _utils->vgaRectScale(52, 32, 152, 148), curText); @@ -173,7 +173,7 @@ void LabEngine::drawJournalText() { curText += _graphics->flowText(_journalFont, -2, 2, 0, false, false, false, true, _utils->vgaRectScale(52, 32, 152, 148), curText, _journalBackImage); } - updateMusicAndEvents(); + updateEvents(); curText += _graphics->flowText(_journalFont, -2, 2, 0, false, false, false, true, _utils->vgaRectScale(171, 32, 271, 148), curText, _journalBackImage); _lastPage = (*curText == 0); @@ -182,13 +182,13 @@ void LabEngine::drawJournalText() { void LabEngine::turnPage(bool fromLeft) { if (fromLeft) { for (int i = 0; i < _graphics->_screenWidth; i += 8) { - updateMusicAndEvents(); + updateEvents(); waitTOF(); _journalBackImage->blitBitmap(i, 0, nullptr, i, 0, 8, _graphics->_screenHeight, false); } } else { for (int i = (_graphics->_screenWidth - 8); i > 0; i -= 8) { - updateMusicAndEvents(); + updateEvents(); waitTOF(); _journalBackImage->blitBitmap(i, 0, nullptr, i, 0, 8, _graphics->_screenHeight, false); } @@ -197,7 +197,7 @@ void LabEngine::turnPage(bool fromLeft) { void LabEngine::drawJournal(uint16 wipenum, bool needFade) { _event->mouseHide(); - updateMusicAndEvents(); + updateEvents(); drawJournalText(); _graphics->loadBackPict("P:Journal.pic", _highPalette); @@ -222,7 +222,7 @@ void LabEngine::drawJournal(uint16 wipenum, bool needFade) { void LabEngine::processJournal() { while (1) { // Make sure we check the music at least after every message - updateMusicAndEvents(); + updateEvents(); IntuiMessage *msg = _event->getMsg(); if (shouldQuit()) { _quitLab = true; @@ -230,7 +230,7 @@ void LabEngine::processJournal() { } if (!msg) - updateMusicAndEvents(); + updateEvents(); else { MessageClass msgClass = msg->_msgClass; @@ -265,7 +265,7 @@ void LabEngine::doJournal() { _journalBackImage->_height = _graphics->_screenHeight; _journalBackImage->setData(nullptr, true); - updateMusicAndEvents(); + updateEvents(); loadJournalData(); _event->attachButtonList(&_journalButtonList); drawJournal(0, true); @@ -320,7 +320,7 @@ void LabEngine::drawMonText(const char *text, TextFont *monitorFont, Common::Rec } while (drawingToPage < _monitorPage) { - updateMusicAndEvents(); + updateEvents(); curText = text + charsDrawn; charsDrawn += _graphics->flowText(monitorFont, yspacing, 0, 0, false, false, false, false, textRect, curText); _lastPage = (*curText == 0); @@ -367,7 +367,7 @@ void LabEngine::processMonitor(const char *ntext, TextFont *monitorFont, bool is } // Make sure we check the music at least after every message - updateMusicAndEvents(); + updateEvents(); IntuiMessage *msg = _event->getMsg(); if (shouldQuit()) { _quitLab = true; @@ -375,7 +375,7 @@ void LabEngine::processMonitor(const char *ntext, TextFont *monitorFont, bool is } if (!msg) - updateMusicAndEvents(); + updateEvents(); else { MessageClass msgClass = msg->_msgClass; |