aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/sound/sound.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2016-05-04 20:30:52 -0400
committerPaul Gilbert2016-07-10 16:38:19 -0400
commitb79ed60a8eca775613ec0b36d345dd8fcb4e5f08 (patch)
tree9f53258bb5aeae1a1daf030202c259b4b745c8c7 /engines/titanic/sound/sound.cpp
parent4963c9f50b53cbd663c18387d8606ad4623cca34 (diff)
downloadscummvm-rg350-b79ed60a8eca775613ec0b36d345dd8fcb4e5f08.tar.gz
scummvm-rg350-b79ed60a8eca775613ec0b36d345dd8fcb4e5f08.tar.bz2
scummvm-rg350-b79ed60a8eca775613ec0b36d345dd8fcb4e5f08.zip
TITANIC: Added loadSound, support methods, and CSoundItem class
Diffstat (limited to 'engines/titanic/sound/sound.cpp')
-rw-r--r--engines/titanic/sound/sound.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/engines/titanic/sound/sound.cpp b/engines/titanic/sound/sound.cpp
index b3b783d4c6..68fb3aeeb6 100644
--- a/engines/titanic/sound/sound.cpp
+++ b/engines/titanic/sound/sound.cpp
@@ -64,4 +64,63 @@ void CSound::fn3(int val, int val2, int val3) {
warning("TODO: CSound::fn3");
}
+uint CSound::loadSound(const CString &name) {
+ checkSounds();
+
+ // Check whether an entry for the given name is already active
+ for (CSoundItemList::iterator i = _sounds.begin(); i != _sounds.end(); ++i) {
+ CSoundItem *soundItem = *i;
+ if (soundItem->_name == name) {
+ // Found it, so move it to the front of the list and return
+ _sounds.remove(soundItem);
+ _sounds.push_front(soundItem);
+ return soundItem->_soundHandle;
+ }
+ }
+
+ // Create new sound item
+ CSoundItem *soundItem = new CSoundItem(name);
+ soundItem->_soundHandle = _soundManager.loadSound(name);
+
+ if (!soundItem->_soundHandle) {
+ // Could load sound, so destroy new item and return
+ delete soundItem;
+ return 0;
+ }
+
+ // Add the item to the list of sounds
+ _sounds.push_front(soundItem);
+
+ // If there are more than 10 sounds loaded, remove the last one,
+ // which is the least recently used of all of them
+ if (_sounds.size() > 10)
+ removeOldest();
+
+ return soundItem->_soundHandle;
+}
+
+void CSound::checkSounds() {
+ for (CSoundItemList::iterator i = _sounds.begin(); i != _sounds.end(); ++i) {
+ CSoundItem *soundItem = *i;
+ if (soundItem->_field24 && soundItem->_field28) {
+ if (_soundManager.isActive(soundItem->_soundHandle)) {
+ _sounds.remove(soundItem);
+ delete soundItem;
+ }
+ }
+ }
+}
+
+void CSound::removeOldest() {
+ for (CSoundItemList::iterator i = _sounds.reverse_begin();
+ i != _sounds.end(); --i) {
+ CSoundItem *soundItem = *i;
+ if (soundItem->_field28 && !_soundManager.isActive(soundItem->_soundHandle)) {
+ _sounds.remove(soundItem);
+ delete soundItem;
+ break;
+ }
+ }
+}
+
} // End of namespace Titanic z