Skip to content

Commit

Permalink
ACCESS: Merge the sound resource and priority lists
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Dec 13, 2014
1 parent 63bacba commit dc218d5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
10 changes: 6 additions & 4 deletions engines/access/access.cpp
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down
10 changes: 3 additions & 7 deletions engines/access/amazon/amazon_game.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
1 change: 0 additions & 1 deletion engines/access/amazon/amazon_scripts.cpp
Expand Up @@ -116,7 +116,6 @@ void AmazonScripts::mWhile1() {
_sequence = 2200;

_vm->_sound->queueSound(0, 14, 15);
_vm->_sound->_soundPriority[0] = 1;

do {
cLoop();
Expand Down
1 change: 0 additions & 1 deletion engines/access/martian/martian_game.cpp
Expand Up @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions engines/access/scripts.cpp
Expand Up @@ -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)
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
19 changes: 11 additions & 8 deletions engines/access/sound.cpp
Expand Up @@ -44,23 +44,26 @@ 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) {
return _vm->_files->loadFile(fileNum, 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) {
Expand All @@ -76,8 +79,8 @@ void SoundManager::loadSounds(Common::Array<RoomInfo::SoundIdent> &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));
}
}

Expand Down
11 changes: 9 additions & 2 deletions engines/access/sound.h
Expand Up @@ -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;
Expand All @@ -45,8 +53,7 @@ class SoundManager {
void stopSound();

public:
Common::Array<Resource *> _soundTable;
Common::Array<int> _soundPriority;
Common::Array<SoundEntry> _soundTable;
Resource *_music;
Resource *_tempMusic;
bool _musicRepeat;
Expand Down

0 comments on commit dc218d5

Please sign in to comment.