From c691449958790019650829233a616c64ba726f71 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 5 Aug 2016 23:08:34 -0400 Subject: TITANIC: Add sounds list to QSoundManager --- engines/titanic/sound/sound_manager.cpp | 45 +++++++++++++++++++++++++++++++++ engines/titanic/sound/sound_manager.h | 39 ++++++++++++++++++++++++++++ engines/titanic/sound/wave_file.cpp | 1 + 3 files changed, 85 insertions(+) (limited to 'engines/titanic') diff --git a/engines/titanic/sound/sound_manager.cpp b/engines/titanic/sound/sound_manager.cpp index 0d133c37e6..ec26b170a6 100644 --- a/engines/titanic/sound/sound_manager.cpp +++ b/engines/titanic/sound/sound_manager.cpp @@ -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), diff --git a/engines/titanic/sound/sound_manager.h b/engines/titanic/sound/sound_manager.h index f703e4f022..e69cfffd78 100644 --- a/engines/titanic/sound/sound_manager.h +++ b/engines/titanic/sound/sound_manager.h @@ -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" @@ -125,11 +126,49 @@ public: 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 { +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; diff --git a/engines/titanic/sound/wave_file.cpp b/engines/titanic/sound/wave_file.cpp index 56e12e3e61..6f0007f511 100644 --- a/engines/titanic/sound/wave_file.cpp +++ b/engines/titanic/sound/wave_file.cpp @@ -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; } -- cgit v1.2.3