aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/sound
diff options
context:
space:
mode:
authorPaul Gilbert2016-08-03 21:47:11 -0400
committerPaul Gilbert2016-08-03 21:47:11 -0400
commit3fda4f0ef5ec56caad0332e473993f5628ca6e42 (patch)
treef5b279f67335fb0b4cf71a26c70059b6f9138027 /engines/titanic/sound
parent9f316a5b37c2065c960dca88953c988d923d748f (diff)
downloadscummvm-rg350-3fda4f0ef5ec56caad0332e473993f5628ca6e42.tar.gz
scummvm-rg350-3fda4f0ef5ec56caad0332e473993f5628ca6e42.tar.bz2
scummvm-rg350-3fda4f0ef5ec56caad0332e473993f5628ca6e42.zip
TITANIC: Add CSound sound loading methods
Diffstat (limited to 'engines/titanic/sound')
-rw-r--r--engines/titanic/sound/proximity.cpp37
-rw-r--r--engines/titanic/sound/proximity.h69
-rw-r--r--engines/titanic/sound/sound.cpp115
-rw-r--r--engines/titanic/sound/sound.h52
-rw-r--r--engines/titanic/sound/sound_manager.cpp13
-rw-r--r--engines/titanic/sound/sound_manager.h51
-rw-r--r--engines/titanic/sound/sound_resource.cpp32
-rw-r--r--engines/titanic/sound/sound_resource.h35
8 files changed, 343 insertions, 61 deletions
diff --git a/engines/titanic/sound/proximity.cpp b/engines/titanic/sound/proximity.cpp
new file mode 100644
index 0000000000..af23b7bd5f
--- /dev/null
+++ b/engines/titanic/sound/proximity.cpp
@@ -0,0 +1,37 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/sound/proximity.h"
+#include "titanic/true_talk/tt_talker.h"
+
+namespace Titanic {
+
+CProximity::CProximity() : _field4(0), _field8(100), _fieldC(0),
+ _speechHandle(-1), _field14(0), _field18(0), _field1C(1.875),
+ _field20(0), _field24(10), _field28(0), _field2C(0.0),
+ _field30(0.5), _field34(0), _posX(0.0), _posY(0.0), _posZ(0.0),
+ _field44(0), _field48(0), _field4C(0), _field50(0), _field54(0),
+ _field58(0), _field5C(0), _field60(0), _endTalkerFn(nullptr),
+ _talker(nullptr), _field6C(0) {
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/sound/proximity.h b/engines/titanic/sound/proximity.h
new file mode 100644
index 0000000000..4427574f40
--- /dev/null
+++ b/engines/titanic/sound/proximity.h
@@ -0,0 +1,69 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_PROXIMITY_H
+#define TITANIC_PROXIMITY_H
+
+#include "common/scummsys.h"
+
+namespace Titanic {
+
+class TTtalker;
+
+typedef void (*CEndTalkerFn)(TTtalker *talker);
+
+class CProximity {
+public:
+ int _field4;
+ int _field8;
+ int _fieldC;
+ int _speechHandle;
+ int _field14;
+ int _field18;
+ int _field1C;
+ int _field20;
+ int _field24;
+ int _field28;
+ double _field2C;
+ double _field30;
+ int _field34;
+ double _posX;
+ double _posY;
+ double _posZ;
+ int _field44;
+ int _field48;
+ int _field4C;
+ int _field50;
+ int _field54;
+ int _field58;
+ int _field5C;
+ int _field60;
+ CEndTalkerFn _endTalkerFn;
+ TTtalker *_talker;
+ int _field6C;
+public:
+ CProximity();
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_PROXIMITY_H */
diff --git a/engines/titanic/sound/sound.cpp b/engines/titanic/sound/sound.cpp
index 7968a088da..34214f5cd0 100644
--- a/engines/titanic/sound/sound.cpp
+++ b/engines/titanic/sound/sound.cpp
@@ -71,12 +71,40 @@ void CSound::fn3(int handle, int val2, int val3) {
warning("TODO: CSound::fn3");
}
-int CSound::playSpeech(CDialogueFile *dialogueFile, int speechId, const CProximity &prox) {
- warning("TODO: CSound::playSpeech");
- return 0;
+void CSound::fn4(CSoundResource *soundRes, int val) {
+ // TODO
+}
+
+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->_soundResource)) {
+ _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->_soundResource)) {
+ _sounds.remove(soundItem);
+ delete soundItem;
+ break;
+ }
+ }
+}
+
+CSoundItem *CSound::getTrueTalkSound(CDialogueFile *dialogueFile, int index) {
+ warning("TODO: CSound::getTrueTalkSound");
+ return nullptr;
}
-uint CSound::loadSound(const CString &name) {
+CSoundResource *CSound::loadSound(const CString &name) {
checkSounds();
// Check whether an entry for the given name is already active
@@ -86,16 +114,16 @@ uint CSound::loadSound(const CString &name) {
// Found it, so move it to the front of the list and return
_sounds.remove(soundItem);
_sounds.push_front(soundItem);
- return soundItem->_soundHandle;
+ return soundItem->_soundResource;
}
}
// Create new sound item
CSoundItem *soundItem = new CSoundItem(name);
- soundItem->_soundHandle = _soundManager.loadSound(name);
+ soundItem->_soundResource = _soundManager.loadSound(name);
- if (!soundItem->_soundHandle) {
- // Could load sound, so destroy new item and return
+ if (!soundItem->_soundResource) {
+ // Couldn't load sound, so destroy new item and return
delete soundItem;
return 0;
}
@@ -108,36 +136,65 @@ uint CSound::loadSound(const CString &name) {
if (_sounds.size() > 10)
removeOldest();
- return soundItem->_soundHandle;
+ return soundItem->_soundResource;
}
-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;
- }
- }
- }
+int CSound::playSound(const CString &name, CProximity &prox) {
+ CSoundResource *soundRes = loadSound(name);
+ if (!soundRes)
+ return -1;
+
+ prox._field6C = soundRes->fn1();
+ fn4(soundRes, prox._field60);
+
+ return _soundManager.playSound(*soundRes, prox);
}
-void CSound::removeOldest() {
- for (CSoundItemList::iterator i = _sounds.reverse_begin();
- i != _sounds.end(); --i) {
+CSoundResource *CSound::loadSpeech(CDialogueFile *dialogueFile, int speechId) {
+ 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->_field28 && !_soundManager.isActive(soundItem->_soundHandle)) {
+ if (soundItem->_dialogueFileHandle == dialogueFile->getFile()
+ && soundItem->_speechId == speechId) {
+ // Found it, so move it to the front of the list and return
_sounds.remove(soundItem);
- delete soundItem;
- break;
+ _sounds.push_front(soundItem);
+ return soundItem->_soundResource;
}
}
+
+ // Create new sound item
+ CSoundItem *soundItem = new CSoundItem(dialogueFile->getFile(), speechId);
+ soundItem->_soundResource = _soundManager.loadSpeech(dialogueFile, speechId);
+
+ if (!soundItem->_soundResource) {
+ // Couldn't load speech, 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->_soundResource;
}
-CSoundItem *CSound::getTrueTalkSound(CDialogueFile *dialogueFile, int index) {
- warning("TODO: CSound::getTrueTalkSound");
- return nullptr;
+int CSound::playSpeech(CDialogueFile *dialogueFile, int speechId, CProximity &prox) {
+ CSoundResource *soundRes = loadSpeech(dialogueFile, speechId);
+ if (!soundRes)
+ return -1;
+
+ prox._field6C = soundRes->fn1();
+ fn4(soundRes, prox._field60);
+
+ return _soundManager.playSound(*soundRes, prox);
}
-} // End of namespace Titanic z
+} // End of namespace Titanic
diff --git a/engines/titanic/sound/sound.h b/engines/titanic/sound/sound.h
index f550493624..bc61d488ef 100644
--- a/engines/titanic/sound/sound.h
+++ b/engines/titanic/sound/sound.h
@@ -24,8 +24,9 @@
#define TITANIC_SOUND_H
#include "titanic/support/simple_file.h"
-#include "titanic/support/proximity.h"
+#include "titanic/sound/proximity.h"
#include "titanic/sound/sound_manager.h"
+#include "titanic/sound/sound_resource.h"
#include "titanic/core/list.h"
#include "titanic/core/view_item.h"
#include "titanic/true_talk/dialogue_file.h"
@@ -37,16 +38,18 @@ class CGameManager;
class CSoundItem : public ListItem {
public:
CString _name;
- int _soundHandle;
- int _field1C;
- int _field20;
+ CSoundResource *_soundResource;
+ File *_dialogueFileHandle;
+ int _speechId;
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) {}
+ CSoundItem() : ListItem(), _soundResource(nullptr), _dialogueFileHandle(nullptr),
+ _speechId(0), _field24(0), _field28(0) {}
+ CSoundItem(const CString &name) : ListItem(), _name(name), _soundResource(nullptr),
+ _dialogueFileHandle(nullptr), _speechId(0), _field24(0), _field28(0) {}
+ CSoundItem(File *dialogueFile, int speechId) : ListItem(), _soundResource(nullptr),
+ _dialogueFileHandle(dialogueFile), _speechId(speechId), _field24(0), _field28(0) {}
int fn1();
};
@@ -109,25 +112,38 @@ public:
*/
void preEnterView(CViewItem *newView, bool isNewRoom);
+ bool fn1(int val);
+ void fn2(int handle);
+ void fn3(int handle, int val2, int val3);
+ void fn4(CSoundResource *soundRes, int val);
+
+ void managerProc8(int v) { _soundManager.proc8(v); }
+
+ CSoundItem *getTrueTalkSound(CDialogueFile *dialogueFile, int index);
+
/**
* Load a sound
* @param name Name of sound resource
- * @returns Sound handle Id
+ * @returns Sound item record
*/
- uint loadSound(const CString &name);
-
- bool fn1(int val);
- void fn2(int handle);
- void fn3(int handle, int val2, int val3);
+ CSoundResource *loadSpeech(CDialogueFile *dialogueFile, int speechId);
/**
* Play a speech
*/
- int playSpeech(CDialogueFile *dialogueFile, int speechId, const CProximity &prox);
-
- void managerProc8(int v) { _soundManager.proc8(v); }
+ int playSpeech(CDialogueFile *dialogueFile, int speechId, CProximity &prox);
- CSoundItem *getTrueTalkSound(CDialogueFile *dialogueFile, int index);
+ /**
+ * Load a sound
+ * @param name Name of sound resource
+ * @returns Sound item record
+ */
+ CSoundResource *loadSound(const CString &name);
+
+ /**
+ * Play a sound
+ */
+ int playSound(const CString &name, CProximity &prox);
};
} // End of namespace Titanic
diff --git a/engines/titanic/sound/sound_manager.cpp b/engines/titanic/sound/sound_manager.cpp
index 1cafe3bafa..5cc5b597aa 100644
--- a/engines/titanic/sound/sound_manager.cpp
+++ b/engines/titanic/sound/sound_manager.cpp
@@ -34,14 +34,14 @@ QSoundManager::QSoundManager() : _field18(0), _field1C(0) {
Common::fill(&_field4A0[0], &_field4A0[16], 0);
}
-int QSoundManager::loadSound(const CString &name) {
+CSoundResource *QSoundManager::loadSound(const CString &name) {
warning("TODO");
- return 0;
+ return nullptr;
}
-int QSoundManager::proc4() const {
+CSoundResource *QSoundManager::loadSpeech(CDialogueFile *dialogueFile, int speechId) {
warning("TODO");
- return 0;
+ return nullptr;
}
int QSoundManager::proc5() const {
@@ -49,8 +49,9 @@ int QSoundManager::proc5() const {
return 0;
}
-void QSoundManager::proc6() {
+int QSoundManager::playSound(CSoundResource &soundRes, CProximity &prox) {
warning("TODO");
+ return 0;
}
void QSoundManager::proc7() {
@@ -86,7 +87,7 @@ bool QSoundManager::proc14() {
return false;
}
-bool QSoundManager::isActive(int handle) const {
+bool QSoundManager::isActive(const CSoundResource *soundRes) const {
warning("TODO");
return false;
}
diff --git a/engines/titanic/sound/sound_manager.h b/engines/titanic/sound/sound_manager.h
index a65162d779..5a3aa2f01d 100644
--- a/engines/titanic/sound/sound_manager.h
+++ b/engines/titanic/sound/sound_manager.h
@@ -24,6 +24,9 @@
#define TITANIC_SOUND_MANAGER_H
#include "titanic/support/simple_file.h"
+#include "titanic/sound/proximity.h"
+#include "titanic/sound/sound_resource.h"
+#include "titanic/true_talk/dialogue_file.h"
namespace Titanic {
@@ -43,11 +46,22 @@ public:
* @param name Name of sound resource
* @returns Loaded sound handle
*/
- virtual int loadSound(const CString &name) { return 0; }
+ virtual CSoundResource *loadSound(const CString &name) { return nullptr; }
+
+ /**
+ * Loads a speech resource from a dialogue file
+ * @param name Name of sound resource
+ * @returns Loaded sound handle
+ */
+ virtual CSoundResource *loadSpeech(CDialogueFile *dialogueFile, int speechId) { return 0; }
- virtual int proc4() const { return 0; }
virtual int proc5() const { return 0; }
- virtual void proc6() = 0;
+
+ /**
+ * Start playing a previously loaded sound resource
+ */
+ virtual int playSound(CSoundResource &soundRes, CProximity &prox) = 0;
+
virtual void proc7() = 0;
virtual void proc8(int v) = 0;
virtual void proc9() {}
@@ -56,7 +70,12 @@ public:
virtual void proc12() {}
virtual void proc13() {}
virtual bool proc14() = 0;
- virtual bool isActive(int handle) const { return false; }
+
+ /**
+ * Returns true if the given sound is currently active
+ */
+ virtual bool isActive(const CSoundResource *soundRes) const { return false; }
+
virtual int proc16() const { return 0; }
virtual void WaveMixPump() {}
@@ -117,11 +136,22 @@ public:
* @param name Name of sound resource
* @returns Loaded sound handle
*/
- virtual int loadSound(const CString &name);
+ virtual CSoundResource *loadSound(const CString &name);
+
+ /**
+ * Loads a speech resource from a dialogue file
+ * @param name Name of sound resource
+ * @returns Loaded sound handle
+ */
+ virtual CSoundResource *loadSpeech(CDialogueFile *dialogueFile, int speechId);
- virtual int proc4() const;
virtual int proc5() const;
- virtual void proc6();
+
+ /**
+ * Start playing a previously loaded sound resource
+ */
+ virtual int playSound(CSoundResource &soundRes, CProximity &prox);
+
virtual void proc7();
virtual void proc8(int v);
virtual void proc9();
@@ -130,7 +160,12 @@ public:
virtual void proc12();
virtual void proc13();
virtual bool proc14();
- virtual bool isActive(int handle) const;
+
+ /**
+ * Returns true if the given sound is currently active
+ */
+ virtual bool isActive(const CSoundResource *soundRes) const;
+
virtual int proc16() const;
virtual void WaveMixPump();
diff --git a/engines/titanic/sound/sound_resource.cpp b/engines/titanic/sound/sound_resource.cpp
new file mode 100644
index 0000000000..2184a25f52
--- /dev/null
+++ b/engines/titanic/sound/sound_resource.cpp
@@ -0,0 +1,32 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "titanic/sound/sound_resource.h"
+
+namespace Titanic {
+
+int CSoundResource::fn1() {
+ // TODO
+ return 0;
+}
+
+} // End of namespace Titanic z
diff --git a/engines/titanic/sound/sound_resource.h b/engines/titanic/sound/sound_resource.h
new file mode 100644
index 0000000000..b88988ed21
--- /dev/null
+++ b/engines/titanic/sound/sound_resource.h
@@ -0,0 +1,35 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef TITANIC_SOUND_RESOURCE_H
+#define TITANIC_SOUND_RESOURCE_H
+
+namespace Titanic {
+
+class CSoundResource {
+public:
+ int fn1();
+};
+
+} // End of namespace Titanic
+
+#endif /* TITANIC_SOUND_RESOURCE_H */