diff options
author | Paul Gilbert | 2016-05-04 20:30:52 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-10 16:38:19 -0400 |
commit | b79ed60a8eca775613ec0b36d345dd8fcb4e5f08 (patch) | |
tree | 9f53258bb5aeae1a1daf030202c259b4b745c8c7 /engines | |
parent | 4963c9f50b53cbd663c18387d8606ad4623cca34 (diff) | |
download | scummvm-rg350-b79ed60a8eca775613ec0b36d345dd8fcb4e5f08.tar.gz scummvm-rg350-b79ed60a8eca775613ec0b36d345dd8fcb4e5f08.tar.bz2 scummvm-rg350-b79ed60a8eca775613ec0b36d345dd8fcb4e5f08.zip |
TITANIC: Added loadSound, support methods, and CSoundItem class
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/core/game_object.cpp | 13 | ||||
-rw-r--r-- | engines/titanic/core/game_object.h | 5 | ||||
-rw-r--r-- | engines/titanic/sound/sound.cpp | 59 | ||||
-rw-r--r-- | engines/titanic/sound/sound.h | 38 | ||||
-rw-r--r-- | engines/titanic/sound/sound_manager.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/sound/sound_manager.h | 20 | ||||
-rw-r--r-- | engines/titanic/support/files_manager.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/support/files_manager.h | 5 |
8 files changed, 138 insertions, 12 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index e6b51f7c12..d1991a4baa 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -239,7 +239,7 @@ void CGameObject::loadResource(const CString &name) { } void CGameObject::loadMovie(const CString &name, bool pendingFlag) { - g_vm->_filesManager.fn5(name); + g_vm->_filesManager.preload(name); // Create the surface if it doesn't already exist if (!_surface) { @@ -272,7 +272,7 @@ void CGameObject::loadImage(const CString &name, bool pendingFlag) { _surface = nullptr; } - g_vm->_filesManager.fn5(name); + g_vm->_filesManager.preload(name); if (!name.empty()) { _surface = new OSVideoSurface(screenManager, CResourceKey(name), pendingFlag); @@ -749,4 +749,13 @@ void CGameObject::checkPlayMovie(const CString &name, int flags) { } } +void CGameObject::loadSound(const CString &name) { + CGameManager *gameManager = getGameManager(); + if (gameManager) { + g_vm->_filesManager.preload(name); + if (!name.empty()) + gameManager->_sound.loadSound(name); + } +} + } // End of namespace Titanic diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 7c40c5f027..5bcba778f4 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -220,6 +220,11 @@ protected: * Support function for drag moving */ void dragMove(const Point &pt); + + /** + * Load a sound + */ + void loadSound(const CString &name); public: int _field60; CursorId _cursorId; diff --git a/engines/titanic/sound/sound.cpp b/engines/titanic/sound/sound.cpp index b3b783d4c6..68fb3aeeb6 100644 --- a/engines/titanic/sound/sound.cpp +++ b/engines/titanic/sound/sound.cpp @@ -64,4 +64,63 @@ void CSound::fn3(int val, int val2, int val3) { warning("TODO: CSound::fn3"); } +uint CSound::loadSound(const CString &name) { + 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->_name == name) { + // Found it, so move it to the front of the list and return + _sounds.remove(soundItem); + _sounds.push_front(soundItem); + return soundItem->_soundHandle; + } + } + + // Create new sound item + CSoundItem *soundItem = new CSoundItem(name); + soundItem->_soundHandle = _soundManager.loadSound(name); + + if (!soundItem->_soundHandle) { + // Could load sound, 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->_soundHandle; +} + +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; + } + } + } +} + +void CSound::removeOldest() { + for (CSoundItemList::iterator i = _sounds.reverse_begin(); + i != _sounds.end(); --i) { + CSoundItem *soundItem = *i; + if (soundItem->_field28 && !_soundManager.isActive(soundItem->_soundHandle)) { + _sounds.remove(soundItem); + delete soundItem; + break; + } + } +} + } // End of namespace Titanic z diff --git a/engines/titanic/sound/sound.h b/engines/titanic/sound/sound.h index 488d4deb5e..19a8edfc21 100644 --- a/engines/titanic/sound/sound.h +++ b/engines/titanic/sound/sound.h @@ -25,15 +25,46 @@ #include "titanic/support/simple_file.h" #include "titanic/sound/sound_manager.h" +#include "titanic/core/list.h" #include "titanic/core/view_item.h" namespace Titanic { class CGameManager; +class CSoundItem : public ListItem { +public: + CString _name; + uint _soundHandle; + int _field1C; + int _field20; + 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) {} +}; + +class CSoundItemList : public List<CSoundItem> { +}; + class CSound { private: CGameManager *_gameManager; + CSoundItemList _sounds; +private: + /** + * Check whether any sounds are done and can be be removed + */ + void checkSounds(); + + /** + * Removes the oldest sound from the sounds list that isn't + * currently playing + */ + void removeOldest(); public: QSoundManager _soundManager; public: @@ -74,6 +105,13 @@ public: */ void preEnterView(CViewItem *newView, bool isNewRoom); + /** + * Load a sound + * @param name Name of sound resource + * @returns Sound handle Id + */ + uint loadSound(const CString &name); + bool fn1(int val); void fn2(int val); void fn3(int val, int val2, int val3); diff --git a/engines/titanic/sound/sound_manager.cpp b/engines/titanic/sound/sound_manager.cpp index 53e5a3dfe0..5c26527e09 100644 --- a/engines/titanic/sound/sound_manager.cpp +++ b/engines/titanic/sound/sound_manager.cpp @@ -34,7 +34,7 @@ QSoundManager::QSoundManager() : _field18(0), _field1C(0) { Common::fill(&_field4A0[0], &_field4A0[16], 0); } -int QSoundManager::proc3() { +uint QSoundManager::loadSound(const CString &name) { warning("TODO"); return 0; } @@ -86,9 +86,9 @@ bool QSoundManager::proc14() { return false; } -int QSoundManager::proc15() { +bool QSoundManager::isActive(uint handle) const { warning("TODO"); - return 0; + return false; } int QSoundManager::proc16() { diff --git a/engines/titanic/sound/sound_manager.h b/engines/titanic/sound/sound_manager.h index 68843dd1f2..84d9aeb5bd 100644 --- a/engines/titanic/sound/sound_manager.h +++ b/engines/titanic/sound/sound_manager.h @@ -37,7 +37,13 @@ protected: public: SoundManager(); - virtual int proc3() const { return 0; } + /** + * Loads a sound + * @param name Name of sound resource + * @returns Loaded sound handle + */ + virtual uint loadSound(const CString &name) { return 0; } + virtual int proc4() const { return 0; } virtual int proc5() const { return 0; } virtual void proc6() = 0; @@ -49,7 +55,7 @@ public: virtual void proc12() {} virtual void proc13() {} virtual bool proc14() = 0; - virtual int proc15() const { return 0; } + virtual bool isActive(uint handle) const { return false; } virtual int proc16() const { return 0; } virtual void WaveMixPump() {} virtual int proc18() const { return 0; } @@ -100,7 +106,13 @@ public: public: QSoundManager(); - virtual int proc3(); + /** + * Loads a sound + * @param name Name of sound resource + * @returns Loaded sound handle + */ + virtual uint loadSound(const CString &name); + virtual int proc4(); virtual int proc5(); virtual void proc6(); @@ -112,7 +124,7 @@ public: virtual void proc12(); virtual void proc13(); virtual bool proc14(); - virtual int proc15(); + virtual bool isActive(uint handle) const; virtual int proc16(); virtual void WaveMixPump(); virtual int proc18() const; diff --git a/engines/titanic/support/files_manager.cpp b/engines/titanic/support/files_manager.cpp index 6cd6bfb5f2..8e70387a5f 100644 --- a/engines/titanic/support/files_manager.cpp +++ b/engines/titanic/support/files_manager.cpp @@ -89,8 +89,8 @@ void CFilesManager::fn4(const CString &name) { warning("TODO: CFilesManager::fn4"); } -void CFilesManager::fn5(const CString &name) { - warning("TODO: CFilesManager::fn5"); +void CFilesManager::preload(const CString &name) { + // We don't currently do any preloading of resources } Common::SeekableReadStream *CFilesManager::getResource( diff --git a/engines/titanic/support/files_manager.h b/engines/titanic/support/files_manager.h index ae664698ac..185670c764 100644 --- a/engines/titanic/support/files_manager.h +++ b/engines/titanic/support/files_manager.h @@ -82,7 +82,10 @@ public: void fn4(const CString &name); - void fn5(const CString &name); + /** + * Preloads and caches a file for access shortly + */ + void preload(const CString &name); /** * Get a resource from the executable |