aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/sound
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
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')
-rw-r--r--engines/titanic/sound/sound.cpp59
-rw-r--r--engines/titanic/sound/sound.h38
-rw-r--r--engines/titanic/sound/sound_manager.cpp6
-rw-r--r--engines/titanic/sound/sound_manager.h20
4 files changed, 116 insertions, 7 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
diff --git a/engines/titanic/sound/sound.h b/engines/titanic/sound/sound.h
index 488d4deb5e..19a8edfc21 100644
--- a/engines/titanic/sound/sound.h
+++ b/engines/titanic/sound/sound.h
@@ -25,15 +25,46 @@
#include "titanic/support/simple_file.h"
#include "titanic/sound/sound_manager.h"
+#include "titanic/core/list.h"
#include "titanic/core/view_item.h"
namespace Titanic {
class CGameManager;
+class CSoundItem : public ListItem {
+public:
+ CString _name;
+ uint _soundHandle;
+ int _field1C;
+ int _field20;
+ int _field24;
+ int _field28;
+public:
+ CSoundItem() : ListItem(), _soundHandle(0), _field1C(0),
+ _field20(0), _field24(0), _field28(0) {}
+ CSoundItem(const CString &name) : ListItem(), _name(name),
+ _soundHandle(0), _field1C(0), _field20(0), _field24(0), _field28(0) {}
+};
+
+class CSoundItemList : public List<CSoundItem> {
+};
+
class CSound {
private:
CGameManager *_gameManager;
+ CSoundItemList _sounds;
+private:
+ /**
+ * Check whether any sounds are done and can be be removed
+ */
+ void checkSounds();
+
+ /**
+ * Removes the oldest sound from the sounds list that isn't
+ * currently playing
+ */
+ void removeOldest();
public:
QSoundManager _soundManager;
public:
@@ -74,6 +105,13 @@ public:
*/
void preEnterView(CViewItem *newView, bool isNewRoom);
+ /**
+ * Load a sound
+ * @param name Name of sound resource
+ * @returns Sound handle Id
+ */
+ uint loadSound(const CString &name);
+
bool fn1(int val);
void fn2(int val);
void fn3(int val, int val2, int val3);
diff --git a/engines/titanic/sound/sound_manager.cpp b/engines/titanic/sound/sound_manager.cpp
index 53e5a3dfe0..5c26527e09 100644
--- a/engines/titanic/sound/sound_manager.cpp
+++ b/engines/titanic/sound/sound_manager.cpp
@@ -34,7 +34,7 @@ QSoundManager::QSoundManager() : _field18(0), _field1C(0) {
Common::fill(&_field4A0[0], &_field4A0[16], 0);
}
-int QSoundManager::proc3() {
+uint QSoundManager::loadSound(const CString &name) {
warning("TODO");
return 0;
}
@@ -86,9 +86,9 @@ bool QSoundManager::proc14() {
return false;
}
-int QSoundManager::proc15() {
+bool QSoundManager::isActive(uint handle) const {
warning("TODO");
- return 0;
+ return false;
}
int QSoundManager::proc16() {
diff --git a/engines/titanic/sound/sound_manager.h b/engines/titanic/sound/sound_manager.h
index 68843dd1f2..84d9aeb5bd 100644
--- a/engines/titanic/sound/sound_manager.h
+++ b/engines/titanic/sound/sound_manager.h
@@ -37,7 +37,13 @@ protected:
public:
SoundManager();
- virtual int proc3() const { return 0; }
+ /**
+ * Loads a sound
+ * @param name Name of sound resource
+ * @returns Loaded sound handle
+ */
+ virtual uint loadSound(const CString &name) { return 0; }
+
virtual int proc4() const { return 0; }
virtual int proc5() const { return 0; }
virtual void proc6() = 0;
@@ -49,7 +55,7 @@ public:
virtual void proc12() {}
virtual void proc13() {}
virtual bool proc14() = 0;
- virtual int proc15() const { return 0; }
+ virtual bool isActive(uint handle) const { return false; }
virtual int proc16() const { return 0; }
virtual void WaveMixPump() {}
virtual int proc18() const { return 0; }
@@ -100,7 +106,13 @@ public:
public:
QSoundManager();
- virtual int proc3();
+ /**
+ * Loads a sound
+ * @param name Name of sound resource
+ * @returns Loaded sound handle
+ */
+ virtual uint loadSound(const CString &name);
+
virtual int proc4();
virtual int proc5();
virtual void proc6();
@@ -112,7 +124,7 @@ public:
virtual void proc12();
virtual void proc13();
virtual bool proc14();
- virtual int proc15();
+ virtual bool isActive(uint handle) const;
virtual int proc16();
virtual void WaveMixPump();
virtual int proc18() const;