aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/core
diff options
context:
space:
mode:
authorPaul Gilbert2016-08-07 09:49:10 -0400
committerPaul Gilbert2016-08-07 09:49:10 -0400
commit3c9d72486633fab34694e00ae67dfdccd3c357d4 (patch)
tree678c0cfe51dd87c3c1d6a3c5896bcdd7504f293a /engines/titanic/core
parent3864f316e0df25b82348b6443e2d1774567bc290 (diff)
downloadscummvm-rg350-3c9d72486633fab34694e00ae67dfdccd3c357d4.tar.gz
scummvm-rg350-3c9d72486633fab34694e00ae67dfdccd3c357d4.tar.bz2
scummvm-rg350-3c9d72486633fab34694e00ae67dfdccd3c357d4.zip
TITANIC: Added sound methods to CGameObject
Diffstat (limited to 'engines/titanic/core')
-rw-r--r--engines/titanic/core/game_object.cpp90
-rw-r--r--engines/titanic/core/game_object.h31
2 files changed, 112 insertions, 9 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp
index 6cd9db7056..73e3511319 100644
--- a/engines/titanic/core/game_object.cpp
+++ b/engines/titanic/core/game_object.cpp
@@ -437,8 +437,53 @@ bool CGameObject::isSoundActive(int handle) const {
return false;
}
-void CGameObject::soundFn2(const CString &resName, int v1, int v2, int v3, int handleIndex) {
- warning("TODO: CGameObject::soundFn2");
+void CGameObject::playGlobalSound(const CString &resName, int mode, bool initialMute, bool repeated, int handleIndex) {
+ if (handleIndex < 0 || handleIndex > 3)
+ return;
+ CGameManager *gameManager = getGameManager();
+ if (!gameManager)
+ return;
+
+ // Preload the file, and stop any existing sound using the given slot
+ CSound &sound = gameManager->_sound;
+ g_vm->_filesManager->preload(resName);
+ if (_soundHandles[handleIndex] != -1) {
+ sound.stopSound(_soundHandles[handleIndex]);
+ _soundHandles[handleIndex] = -1;
+ }
+
+ // If no new name specified, then exit
+ if (resName.empty())
+ return;
+
+ uint newVolume = sound._soundManager.getModeVolume(mode);
+ uint volume = initialMute ? 0 : newVolume;
+
+ CProximity prox;
+ prox._channelVolume = newVolume;
+ prox._repeated = repeated;
+
+ switch (handleIndex) {
+ case 0:
+ prox._channel = 6;
+ break;
+ case 1:
+ prox._channel = 7;
+ break;
+ case 2:
+ prox._channel = 8;
+ break;
+ case 3:
+ prox._channel = 9;
+ break;
+ default:
+ break;
+ }
+
+ _soundHandles[handleIndex] = sound.playSound(resName, prox);
+
+ if (_soundHandles[handleIndex])
+ sound.setVolume(_soundHandles[handleIndex], newVolume, 2);
}
void CGameObject::setSoundVolume(uint handle, uint percent, uint seconds) {
@@ -449,12 +494,47 @@ void CGameObject::setSoundVolume(uint handle, uint percent, uint seconds) {
}
}
-void CGameObject::soundFn4(int v1, int v2, int v3) {
+void CGameObject::stopGlobalSound(bool transition, int handleIndex) {
+ CGameManager *gameManager = getGameManager();
+ if (!gameManager)
+ return;
+ CSound &sound = gameManager->_sound;
+
+ if (handleIndex == -1) {
+ for (int idx = 0; idx < 3; ++idx) {
+ if (_soundHandles[idx] != -1) {
+ sound.setVolume(_soundHandles[idx], 0, transition ? 1 : 0);
+ sound.setCanFree(_soundHandles[idx]);
+ _soundHandles[idx] = -1;
+ }
+ }
+ } else if (handleIndex >= 0 && handleIndex <= 2 && _soundHandles[handleIndex] != -1) {
+ if (transition) {
+ // Transitioning to silent over 1 second
+ sound.setVolume(_soundHandles[handleIndex], 0, 1);
+ sleep(1000);
+ }
+
+ sound.stopSound(_soundHandles[handleIndex]);
+ _soundHandles[handleIndex] = -1;
+ }
warning("CGameObject::soundFn4");
}
-void CGameObject::soundFn5(int v1, int v2, int v3) {
- warning("CGameObject::soundFn5");
+void CGameObject::setGlobalSoundVolume(int mode, uint seconds, int handleIndex) {
+ CGameManager *gameManager = getGameManager();
+ if (!gameManager)
+ return;
+ CSound &sound = gameManager->_sound;
+
+ if (handleIndex == -1) {
+ // Iterate through calling the method for each handle
+ for (int idx = 0; idx < 3; ++idx)
+ setGlobalSoundVolume(mode, seconds, idx);
+ } else if (handleIndex >= 0 && handleIndex <= 2 && _soundHandles[handleIndex] != -1) {
+ uint newVolume = sound._soundManager.getModeVolume(mode);
+ sound.setVolume(_soundHandles[handleIndex], newVolume, seconds);
+ }
}
void CGameObject::sound8(bool flag) const {
diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h
index 7bc5d156fc..fdbbcd6959 100644
--- a/engines/titanic/core/game_object.h
+++ b/engines/titanic/core/game_object.h
@@ -183,11 +183,15 @@ protected:
/**
* Plays a sound
+ * @param resName Filename of sound to play
+ * @param volume Volume level
*/
int playSound(const CString &name, uint volume = 100, int val3 = 0, bool repeated = false);
/**
* Plays a sound
+ * @param resName Filename of sound to play
+ * @param prox Proximity object with the sound data
*/
int playSound(const CString &name, CProximity &prox);
@@ -203,8 +207,6 @@ protected:
*/
bool isSoundActive(int handle) const;
- void soundFn2(const CString &resName, int v1, int v2, int v3, int handleIndex);
-
/**
* Sets the volume for a sound
* @param handle Sound handle
@@ -213,9 +215,30 @@ protected:
*/
void setSoundVolume(uint handle, uint percent, uint seconds);
- void soundFn4(int v1, int v2, int v3);
+ /**
+ * Plays a sound, and saves it's handle in the global sound handles list
+ * @param resName Filename of sound to play
+ * @param mode Volume mode level
+ * @param initialMute If set, sound transitions in from mute over 2 seconds
+ * @param repeated Flag for repeating sounds
+ * @param handleIndex Slot 0 to 3 in the shared sound handle list to store the sound's handle
+ */
+ void playGlobalSound(const CString &resName, int mode, bool initialMute, bool repeated, int handleIndex);
+
+ /**
+ * Stops a sound saved in the global sound handle list
+ * @param transition If set, the sound transitions to silent before stopping
+ * @param handleIndex Index of sound to stop. If -1, all global sounds are stopped
+ */
+ void stopGlobalSound(bool transition, int handleIndex);
- void soundFn5(int v1, int v2, int v3);
+ /**
+ * Updates the volume for a global sound based on the specified mode's volume
+ * @param mode Volume level mode
+ * @param seconds Number of seconds to transition to new volume
+ * @param handleIndex Index of global sound to update. If -1, all global sounds are updated
+ */
+ void setGlobalSoundVolume(int mode, uint seconds, int handleIndex);
void sound8(bool flag) const;