diff --git a/engines/access/access.cpp b/engines/access/access.cpp index a3cadc10256c..f04a5dec8853 100644 --- a/engines/access/access.cpp +++ b/engines/access/access.cpp @@ -245,8 +245,9 @@ void AccessEngine::speakText(ASurface *s, const Common::String &msg) { _events->waitKeyMouse(); } else { for (;;) { - _sound->_soundTable[0] = _sound->loadSound(_narateFile + 99, _sndSubFile); - _sound->_soundPriority[0] = 1; + _sound->freeSounds(); + Resource *sound = _sound->loadSound(_narateFile + 99, _sndSubFile); + _sound->_soundTable.push_back(SoundEntry(sound, 1)); _sound->playSound(0); _scripts->cmdFreeSound(); @@ -287,8 +288,9 @@ void AccessEngine::speakText(ASurface *s, const Common::String &msg) { } for (;;) { - _sound->_soundTable[0] = _sound->loadSound(_narateFile + 99, _sndSubFile); - _sound->_soundPriority[0] = 1; + _sound->freeSounds(); + Resource *res = _sound->loadSound(_narateFile + 99, _sndSubFile); + _sound->_soundTable.push_back(SoundEntry(res, 1)); _sound->playSound(0); _scripts->cmdFreeSound(); diff --git a/engines/access/amazon/amazon_game.cpp b/engines/access/amazon/amazon_game.cpp index 8270eaee6b61..9801df7f3c88 100644 --- a/engines/access/amazon/amazon_game.cpp +++ b/engines/access/amazon/amazon_game.cpp @@ -132,10 +132,7 @@ void AmazonEngine::doTitle() { _events->hideCursor(); _sound->queueSound(0, 98, 30); - _sound->_soundPriority[0] = 1; - _sound->queueSound(1, 98, 8); - _sound->_soundPriority[1] = 1; _files->_loadPalFlag = false; _files->loadScreen(0, 3); @@ -404,14 +401,13 @@ void AmazonEngine::startChapter(int chapter) { _timers[20]._timer = 500; _timers[20]._initTm = 500; _timers[20]._flag++; + _sound->freeSounds(); - _sound->_soundTable[0] = _sound->loadSound(115, 0); - _sound->_soundPriority[0] = 1; + _sound->_soundTable.push_back(SoundEntry(_sound->loadSound(115, 0), 1)); _sound->playSound(0); _sound->freeSounds(); - _sound->_soundTable[0] = _sound->loadSound(115, 1); - _sound->_soundPriority[0] = 1; + _sound->_soundTable.push_back(SoundEntry(_sound->loadSound(115, 1), 1)); _sound->playSound(0); _sound->freeSounds(); diff --git a/engines/access/amazon/amazon_scripts.cpp b/engines/access/amazon/amazon_scripts.cpp index 5d9f2d9436f9..12902081b707 100644 --- a/engines/access/amazon/amazon_scripts.cpp +++ b/engines/access/amazon/amazon_scripts.cpp @@ -116,7 +116,6 @@ void AmazonScripts::mWhile1() { _sequence = 2200; _vm->_sound->queueSound(0, 14, 15); - _vm->_sound->_soundPriority[0] = 1; do { cLoop(); diff --git a/engines/access/martian/martian_game.cpp b/engines/access/martian/martian_game.cpp index 2f11d8b85853..1c135930f388 100644 --- a/engines/access/martian/martian_game.cpp +++ b/engines/access/martian/martian_game.cpp @@ -96,7 +96,6 @@ void MartianEngine::doTitle() { _events->hideCursor(); _sound->queueSound(0, 98, 30); - _sound->_soundPriority[0] = 1; _files->_loadPalFlag = false; _files->loadScreen(0, 3); diff --git a/engines/access/scripts.cpp b/engines/access/scripts.cpp index 6c4c37491fdd..bf58a20eef3e 100644 --- a/engines/access/scripts.cpp +++ b/engines/access/scripts.cpp @@ -707,15 +707,14 @@ void Scripts::cmdLoadSound() { int idx = _data->readSint16LE(); _vm->_sound->_soundTable.clear(); - _vm->_sound->_soundPriority.clear(); - _vm->_sound->_soundTable.push_back(_vm->_files->loadFile(_vm->_extraCells[idx]._vidSound)); - _vm->_sound->_soundPriority.push_back(1); + Resource *sound = _vm->_files->loadFile(_vm->_extraCells[idx]._vidSound); + _vm->_sound->_soundTable.push_back(SoundEntry(sound, 1)); } void Scripts::cmdFreeSound() { SoundManager &sound = *_vm->_sound; - if (sound._soundTable.size() > 0 && sound._soundTable[0]) { + if (sound._soundTable.size() > 0 && sound._soundTable[0]._res) { // Keep doing char display loop if playing sound for it do { if (_vm->_flags[236] == 1) @@ -725,8 +724,8 @@ void Scripts::cmdFreeSound() { } while (!_vm->shouldQuit() && sound._playingSound); // Free the sound - delete sound._soundTable[0]; - sound._soundTable[0] = nullptr; + delete sound._soundTable[0]._res; + sound._soundTable.remove_at(0); } } @@ -766,8 +765,7 @@ void Scripts::cmdDead() { _vm->_screen->forceFadeOut(); cmdFreeSound(); - _vm->_sound->_soundTable[0] = _vm->_files->loadFile(98, 44); - _vm->_sound->_soundPriority[1] = 1; + _vm->_sound->_soundTable.push_back(SoundEntry(_vm->_files->loadFile(98, 44), 1)); _vm->_screen->clearScreen(); _vm->_screen->setPanel(3); diff --git a/engines/access/sound.cpp b/engines/access/sound.cpp index dd8cf1618941..075bfc005e7c 100644 --- a/engines/access/sound.cpp +++ b/engines/access/sound.cpp @@ -44,14 +44,17 @@ SoundManager::~SoundManager() { void SoundManager::clearSounds() { for (uint i = 0; i < _soundTable.size(); ++i) - delete _soundTable[i]; + delete _soundTable[i]._res; _soundTable.clear(); - _soundPriority.clear(); } void SoundManager::queueSound(int idx, int fileNum, int subfile) { - delete _soundTable[idx]; - _soundTable[idx] = _vm->_files->loadFile(fileNum, subfile); + if (idx >= (int)_soundTable.size()) + _soundTable.resize(idx + 1); + + delete _soundTable[idx]._res; + _soundTable[idx]._res = _vm->_files->loadFile(fileNum, subfile); + _soundTable[idx]._priority = 1; } Resource *SoundManager::loadSound(int fileNum, int subfile) { @@ -59,8 +62,8 @@ Resource *SoundManager::loadSound(int fileNum, int subfile) { } void SoundManager::playSound(int soundIndex) { - int priority = _soundPriority[soundIndex]; - playSound(_soundTable[soundIndex], priority); + int priority = _soundTable[soundIndex]._priority; + playSound(_soundTable[soundIndex]._res, priority); } void SoundManager::playSound(Resource *res, int priority) { @@ -76,8 +79,8 @@ void SoundManager::loadSounds(Common::Array &sounds) { clearSounds(); for (uint i = 0; i < sounds.size(); ++i) { - _soundTable.push_back(loadSound(sounds[i]._fileNum, sounds[i]._subfile)); - _soundPriority.push_back(sounds[i]._priority); + Resource *sound = loadSound(sounds[i]._fileNum, sounds[i]._subfile); + _soundTable.push_back(SoundEntry(sound, sounds[i]._priority)); } } diff --git a/engines/access/sound.h b/engines/access/sound.h index c1b398199795..2456ba7753ff 100644 --- a/engines/access/sound.h +++ b/engines/access/sound.h @@ -33,6 +33,14 @@ namespace Access { class AccessEngine; +struct SoundEntry { + Resource *_res; + int _priority; + + SoundEntry() { _res = nullptr; _priority = 0; } + SoundEntry(Resource *res, int priority) { _res = res; _priority = priority; } +}; + class SoundManager { private: AccessEngine *_vm; @@ -45,8 +53,7 @@ class SoundManager { void stopSound(); public: - Common::Array _soundTable; - Common::Array _soundPriority; + Common::Array _soundTable; Resource *_music; Resource *_tempMusic; bool _musicRepeat;