Skip to content

Commit

Permalink
TITANIC: Add CSound sound loading methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Aug 4, 2016
1 parent 9f316a5 commit 3fda4f0
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 67 deletions.
12 changes: 11 additions & 1 deletion engines/titanic/core/game_object.cpp
Expand Up @@ -644,7 +644,17 @@ int CGameObject::playSound(const CString &name, int val2, int val3, int val4) {

int CGameObject::playSound(const CString &name, CProximity &prox) {
if (prox._field28 == 2) {
// TODO
// If the proximity doesn't have a position defined, default it to
// the position of the view to which the game object belongs
if (prox._posX == 0.0 && prox._posY == 0.0 && prox._posZ == 0.0)
findView()->getPosition(prox._posX, prox._posY, prox._posZ);
}

CGameManager *gameManager = getGameManager();
if (gameManager) {
g_vm->_filesManager->preload(name);

gameManager->_sound.playSound(name, prox);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion engines/titanic/core/game_object.h
Expand Up @@ -26,7 +26,7 @@
#include "titanic/support/mouse_cursor.h"
#include "titanic/support/credit_text.h"
#include "titanic/support/movie_range_info.h"
#include "titanic/support/proximity.h"
#include "titanic/sound/proximity.h"
#include "titanic/support/rect.h"
#include "titanic/support/movie_clip.h"
#include "titanic/core/named_item.h"
Expand Down
3 changes: 2 additions & 1 deletion engines/titanic/module.mk
Expand Up @@ -402,13 +402,15 @@ MODULE_OBJS := \
sound/music_room.o \
sound/music_player.o \
sound/node_auto_sound_player.o \
sound/proximity.o \
sound/restricted_auto_music_player.o \
sound/room_auto_sound_player.o \
sound/room_trigger_auto_music_player.o \
sound/season_noises.o \
sound/seasonal_music_player.o \
sound/sound.o \
sound/sound_manager.o \
sound/sound_resource.o \
sound/titania_speech.o \
sound/trigger_auto_music_player.o \
sound/view_auto_sound_player.o \
Expand Down Expand Up @@ -460,7 +462,6 @@ MODULE_OBJS := \
support/movie_range_info.o \
support/movie_manager.o \
support/credit_text.o \
support/proximity.o \
support/rect.o \
support/screen_manager.o \
support/simple_file.o \
Expand Down
Expand Up @@ -20,7 +20,7 @@
*
*/

#include "titanic/support/proximity.h"
#include "titanic/sound/proximity.h"
#include "titanic/true_talk/tt_talker.h"

namespace Titanic {
Expand Down
File renamed without changes.
115 changes: 86 additions & 29 deletions engines/titanic/sound/sound.cpp
Expand Up @@ -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
Expand All @@ -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;
}
Expand All @@ -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
52 changes: 34 additions & 18 deletions engines/titanic/sound/sound.h
Expand Up @@ -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"
Expand All @@ -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();
};
Expand Down Expand Up @@ -109,25 +112,38 @@ class CSound {
*/
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
Expand Down
13 changes: 7 additions & 6 deletions engines/titanic/sound/sound_manager.cpp
Expand Up @@ -34,23 +34,24 @@ 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 {
warning("TODO");
return 0;
}

void QSoundManager::proc6() {
int QSoundManager::playSound(CSoundResource &soundRes, CProximity &prox) {
warning("TODO");
return 0;
}

void QSoundManager::proc7() {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3fda4f0

Please sign in to comment.