aboutsummaryrefslogtreecommitdiff
path: root/engines/lastexpress
diff options
context:
space:
mode:
authorLittleboy2011-07-08 22:02:24 -0400
committerLittleboy2011-07-08 22:03:34 -0400
commitbc298a58f53a9ac2f8e3b5b96da8d7541ad99c71 (patch)
tree43c9e4ffc282587f95d466127177958586bccce5 /engines/lastexpress
parente7e689450b942b8328ab25a043a67ae2e392e46e (diff)
downloadscummvm-rg350-bc298a58f53a9ac2f8e3b5b96da8d7541ad99c71.tar.gz
scummvm-rg350-bc298a58f53a9ac2f8e3b5b96da8d7541ad99c71.tar.bz2
scummvm-rg350-bc298a58f53a9ac2f8e3b5b96da8d7541ad99c71.zip
LASTEXPRESS: Simplify SoundQueue::updateQueue()
- Remove useless cache code - Use helper function to get the proper sound entry - Fix crash on using an invalid entry
Diffstat (limited to 'engines/lastexpress')
-rw-r--r--engines/lastexpress/shared.h17
-rw-r--r--engines/lastexpress/sound/entry.cpp6
-rw-r--r--engines/lastexpress/sound/queue.cpp88
-rw-r--r--engines/lastexpress/sound/sound.cpp4
4 files changed, 33 insertions, 82 deletions
diff --git a/engines/lastexpress/shared.h b/engines/lastexpress/shared.h
index 7b640c773a..d60a498447 100644
--- a/engines/lastexpress/shared.h
+++ b/engines/lastexpress/shared.h
@@ -84,29 +84,26 @@ enum SoundFlag {
};
enum SoundState {
- kSoundState0 = 0,
- kSoundState1 = 1,
- kSoundState2 = 2
+ kSoundStateNone = 0,
+ kSoundState1 = 1,
+ kSoundState2 = 2
};
enum SoundStatus {
+ kSoundStatusClear0 = 0x10,
+ kSoundStatusFilter = 0x1F,
kSoundStatus_20 = 0x20,
kSoundStatus_40 = 0x40,
+ kSoundStatusCached = 0x80,
kSoundStatus_180 = 0x180,
kSoundStatusClosed = 0x200,
kSoundStatus_400 = 0x400,
-
+ kSoundStatusClear4 = 0x800,
kSoundStatus_8000 = 0x8000,
kSoundStatus_20000 = 0x20000,
kSoundStatus_100000 = 0x100000,
kSoundStatus_20000000 = 0x20000000,
kSoundStatus_40000000 = 0x40000000,
-
- kSoundStatusClear0 = 0x10,
- kSoundStatusFilter = 0x1F,
- kSoundStatusCached = 0x80,
- kSoundStatusClear3 = 0x200,
- kSoundStatusClear4 = 0x800,
kSoundStatusClearAll = 0xFFFFFFE0
};
diff --git a/engines/lastexpress/sound/entry.cpp b/engines/lastexpress/sound/entry.cpp
index 87d8ccdb30..44cc68a57b 100644
--- a/engines/lastexpress/sound/entry.cpp
+++ b/engines/lastexpress/sound/entry.cpp
@@ -88,8 +88,8 @@ void SoundEntry::close() {
_status.status |= kSoundStatusClosed;
// Loop until ready
- while (!(_status.status1 & 4) && !(getSoundQueue()->getFlag() & 8) && (getSoundQueue()->getFlag() & 1))
- ; // empty loop body
+ //while (!(_status.status1 & 4) && !(getSoundQueue()->getFlag() & 8) && (getSoundQueue()->getFlag() & 1))
+ // ; // empty loop body
// The original game remove the entry from the cache here,
// but since we are called from within an iterator loop
@@ -290,7 +290,7 @@ bool SoundEntry::updateSound() {
}
}
}
- //if (status.status2 & 0x40 && !((uint32)_status.status & 0x180) && v1->soundBuffer)
+ //if (status.status2 & 0x40 && !((uint32)_status.status & 0x180) && v1->soundBuffer)
// Sound_FillSoundBuffer(v1);
}
result = true;
diff --git a/engines/lastexpress/sound/queue.cpp b/engines/lastexpress/sound/queue.cpp
index 0a6442ceed..33b4c06793 100644
--- a/engines/lastexpress/sound/queue.cpp
+++ b/engines/lastexpress/sound/queue.cpp
@@ -102,80 +102,41 @@ void SoundQueue::removeFromQueue(Common::String filename) {
}
void SoundQueue::updateQueue() {
- //Common::StackLock locker(_mutex);
-
- //warning("[Sound::updateQueue] Not implemented");
-
- int maxPriority = 0;
- Common::List<SoundEntry *>::iterator lsnd;
- SoundEntry *msnd;
-
- bool loopedPlaying;
-
- loopedPlaying = 0;
- //++g_sound_flag;
+ Common::StackLock locker(_mutex);
- for (lsnd = _soundList.begin(); lsnd != _soundList.end(); ++lsnd) {
- if ((*lsnd)->getType() == kSoundType1)
- break;
- }
+ ++_flag;
- if (getSoundState() & 1) {
- if (!(*lsnd) || getFlags()->flag_3 || (*lsnd && (*lsnd)->getTime() > getSound()->getLoopingSoundDuration())) {
+ if (getSoundState() & kSoundState1) {
+ SoundEntry *entry = getEntry(kSoundType1);
+ if (!entry || getFlags()->flag_3 || (entry && entry->getTime() > getSound()->getLoopingSoundDuration())) {
getSound()->playLoopingSound(0x45);
} else {
if (getSound()->getData1() && getSound()->getData2() >= getSound()->getData1()) {
- (*lsnd)->update(getSound()->getData0());
+ entry->update(getSound()->getData0());
getSound()->setData1(0);
}
}
}
- msnd = NULL;
-
- for (lsnd = _soundList.begin(); lsnd != _soundList.end(); ++lsnd) {
- if ((*lsnd)->getStatus().status2 & 0x1) { // Sound is stopped
- // original code
- //if ((*lsnd)->soundBuffer)
- // Sound_RemoveSoundDataFromCache(*lsnd);
- //if ((*lsnd)->archive) {
- // Archive_SetStatusNotLoaded((*lsnd)->archive);
- // (*lsnd)->archive = 0;
- // (*lsnd)->field_28 = 3;
- //}
-
- if (_soundList.size() < 6) {
- if ((*lsnd)->getStatus().status1 & 0x1F) {
- int pri = (*lsnd)->getPriority() + ((*lsnd)->getStatus().status1 & 0x1F);
-
- if (pri > maxPriority) {
- msnd = *lsnd;
- maxPriority = pri;
- }
- }
- }
- }
+ for (Common::List<SoundEntry *>::iterator it = _soundList.begin(); it != _soundList.end(); ++it) {
+ SoundEntry *entry = *it;
- if (!(*lsnd)->updateSound() && !((*lsnd)->getStatus().status3 & 0x8)) {
- if (msnd == *lsnd) {
- maxPriority = 0;
- msnd = 0;
- }
- if (*lsnd) {
- (*lsnd)->close();
- SAFE_DELETE(*lsnd);
- lsnd = _soundList.reverse_erase(lsnd);
- }
+ // Original removes the entry data from the cache and sets the archive as not loaded
+ // and if the sound data buffer is not full, loads a new entry to be played based on
+ // its priority and filter id
+
+ if (!entry->updateSound() && !(entry->getStatus().status3 & 0x8)) {
+ entry->close();
+ SAFE_DELETE(entry);
+ it = _soundList.reverse_erase(it);
}
}
-
- // We don't need this
- //if (msnd)
- // msnd->updateEntryInternal();
+ // Original update the current entry, loading another set of samples to be decoded
getFlags()->flag_3 = 0;
- //--g_sound_flag;
+
+ --_flag;
}
void SoundQueue::resetQueue() {
@@ -209,17 +170,10 @@ void SoundQueue::resetQueue(SoundType type1, SoundType type2) {
}
void SoundQueue::clearQueue() {
- _flag |= 4;
-
- // FIXME: Wait a while for a flag to be set
- //for (int i = 0; i < 3000000; i++)
- // if (_flag & 8)
- // break;
+ Common::StackLock locker(_mutex);
_flag |= 8;
- Common::StackLock locker(_mutex);
-
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i) {
SoundEntry *entry = (*i);
@@ -240,7 +194,7 @@ void SoundQueue::clearStatus() {
Common::StackLock locker(_mutex);
for (Common::List<SoundEntry *>::iterator i = _soundList.begin(); i != _soundList.end(); ++i)
- (*i)->setStatus((*i)->getStatus().status | kSoundStatusClear3);
+ (*i)->setStatus((*i)->getStatus().status | kSoundStatusClosed);
}
//////////////////////////////////////////////////////////////////////////
diff --git a/engines/lastexpress/sound/sound.cpp b/engines/lastexpress/sound/sound.cpp
index c04b6d361f..2f7bb4a601 100644
--- a/engines/lastexpress/sound/sound.cpp
+++ b/engines/lastexpress/sound/sound.cpp
@@ -1305,8 +1305,8 @@ void SoundManager::playLoopingSound(int param) {
int partNumber = 1;
int fnameLen = 6;
- if (_queue->getSoundState() & 1 && param >= 0x45 && param <= 0x46) {
- if (_queue->getSoundState() & 2) {
+ if (_queue->getSoundState() & kSoundState1 && param >= 0x45 && param <= 0x46) {
+ if (_queue->getSoundState() & kSoundState2) {
strcpy(tmp, "STEAM.SND");
_loopingSoundDuration = 32767;