Skip to content

Commit

Permalink
TITANIC: Add sounds list to QSoundManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Aug 6, 2016
1 parent dbee762 commit c691449
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
45 changes: 45 additions & 0 deletions engines/titanic/sound/sound_manager.cpp
Expand Up @@ -32,6 +32,51 @@ CSoundManager::CSoundManager() : _musicPercent(75.0), _speechPercent(75.0),
_masterPercent(75.0), _parrotPercent(75.0), _field14(1) {
}

/*------------------------------------------------------------------------*/

void QSoundManagerSounds::add(CWaveFile *waveFile, int iChannel, CEndTalkerFn endFn, TTtalker *talker) {
push_back(new QSoundManagerSound(waveFile, iChannel, endFn, talker));
}

void QSoundManagerSounds::flushChannel(int iChannel) {
for (iterator i = begin(); i != end(); ++i) {
QSoundManagerSound *item = *i;
if (item->_iChannel == iChannel) {
if (item->_endFn)
item->_endFn(item->_talker);

remove(item);
delete item;
break;
}
}
}

void QSoundManagerSounds::flushChannel(int v1, int iChannel) {
for (iterator i = begin(); i != end(); ++i) {
QSoundManagerSound *item = *i;
if (item->_waveFile->isLoaded() && item->_iChannel == iChannel) {
if (item->_endFn)
item->_endFn(item->_talker);

remove(item);
delete item;
break;
}
}
}

bool QSoundManagerSounds::contains(const CWaveFile *waveFile) const {
for (const_iterator i = begin(); i != end(); ++i) {
const QSoundManagerSound *item = *i;
if (item->_waveFile == waveFile)
return true;
}

return false;
}


/*------------------------------------------------------------------------*/

QSoundManager::QSoundManager(Audio::Mixer *mixer) : CSoundManager(), QMixer(mixer),
Expand Down
39 changes: 39 additions & 0 deletions engines/titanic/sound/sound_manager.h
Expand Up @@ -23,6 +23,7 @@
#ifndef TITANIC_SOUND_MANAGER_H
#define TITANIC_SOUND_MANAGER_H

#include "titanic/core/list.h"
#include "titanic/support/simple_file.h"
#include "titanic/sound/proximity.h"
#include "titanic/sound/qmixer.h"
Expand Down Expand Up @@ -125,11 +126,49 @@ class CSoundManager {
virtual void proc29() {}
};

class QSoundManagerSound : public ListItem {
public:
CWaveFile *_waveFile;
int _iChannel;
CEndTalkerFn _endFn;
TTtalker *_talker;
public:
QSoundManagerSound() : ListItem(), _waveFile(nullptr),
_iChannel(0), _endFn(nullptr), _talker(nullptr) {}
QSoundManagerSound(CWaveFile *waveFile, int iChannel, CEndTalkerFn endFn, TTtalker *talker) :
ListItem(), _waveFile(waveFile), _iChannel(iChannel), _endFn(endFn), _talker(talker) {}
};

class QSoundManagerSounds : public List<QSoundManagerSound> {
public:
/**
* Adds a new sound entry to the list
*/
void add(CWaveFile *waveFile, int iChannel, CEndTalkerFn endFn, TTtalker *talker);

/**
* Flushes a wave file attached to the specified channel
*/
void flushChannel(int iChannel);

/**
* Flushes a wave file attached to the specified channel
*/
void flushChannel(int v1, int iChannel);

/**
* Returns true if the list contains the specified wave file
*/
bool contains(const CWaveFile *waveFile) const;
};

/**
* Concrete sound manager class that handles interfacing with
* the QMixer sound mixer class
*/
class QSoundManager : public CSoundManager, public QMixer {
private:
QSoundManagerSounds _sounds;
public:
int _field18;
int _field1C;
Expand Down
1 change: 1 addition & 0 deletions engines/titanic/sound/wave_file.cpp
Expand Up @@ -48,6 +48,7 @@ bool CWaveFile::loadSound(const CString &name) {

Common::SeekableReadStream *stream = file.readStream();
_stream = Audio::makeWAVStream(stream->readStream(stream->size()), DisposeAfterUse::YES);
return true;
}


Expand Down

0 comments on commit c691449

Please sign in to comment.