From: <wha...@us...> - 2011-06-07 22:07:59
|
Revision: 7373 http://planeshift.svn.sourceforge.net/planeshift/?rev=7373&view=rev Author: whacko88 Date: 2011-06-07 22:07:52 +0000 (Tue, 07 Jun 2011) Log Message: ----------- Handled the case when ctrlID and queueID has already been defined Reimplemented StopSound in a more safe way Modified Paths: -------------- soc/2011/sound/include/isoundmngr.h soc/2011/sound/src/client/psengine.cpp soc/2011/sound/src/plugins/common/soundmanager/manager.cpp soc/2011/sound/src/plugins/common/soundmanager/manager.h soc/2011/sound/src/plugins/common/soundmanager/queue.cpp soc/2011/sound/src/plugins/common/soundmanager/soundctrl.cpp soc/2011/sound/src/plugins/common/soundmanager/soundctrl.h soc/2011/sound/src/plugins/common/soundmanager/soundmanager.cpp soc/2011/sound/src/plugins/common/soundmanager/soundmanager.h Modified: soc/2011/sound/include/isoundmngr.h =================================================================== --- soc/2011/sound/include/isoundmngr.h 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/include/isoundmngr.h 2011-06-07 22:07:52 UTC (rev 7373) @@ -76,7 +76,7 @@ virtual iSoundControl* GetSndCtrl(int ctrlID)=0; virtual iSoundControl* GetMainSndCtrl()=0; - virtual void AddSndQueue(int queueID, iSoundControl* sndCtrl)=0; + virtual bool AddSndQueue(int queueID, iSoundControl* sndCtrl)=0; virtual void RemoveSndQueue(int queueID)=0; virtual bool PushQueueItem(int queueID, const char* fileName)=0; Modified: soc/2011/sound/src/client/psengine.cpp =================================================================== --- soc/2011/sound/src/client/psengine.cpp 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/src/client/psengine.cpp 2011-06-07 22:07:52 UTC (rev 7373) @@ -407,13 +407,6 @@ // Initialize sound SoundManager->InitializeSectors(); - SoundManager->AddSndCtrl(AMBIENT_SNDCTRL, SNDCTRL_TYPE_AMBIENT); - SoundManager->AddSndCtrl(MUSIC_SNDCTRL, SNDCTRL_TYPE_MUSIC); - SoundManager->AddSndCtrl(ACTION_SNDCTRL, SNDCTRL_TYPE_NORMAL); - SoundManager->AddSndCtrl(EFFECT_SNDCTRL, SNDCTRL_TYPE_NORMAL); - SoundManager->AddSndCtrl(GUI_SNDCTRL, SNDCTRL_TYPE_NORMAL); - iSoundControl* voiceSndCtrl = SoundManager->AddSndCtrl(VOICE_SNDCTRL, SNDCTRL_TYPE_NORMAL); - SoundManager->AddSndQueue(VOICE_QUEUE, voiceSndCtrl); LoadLogSettings(); Modified: soc/2011/sound/src/plugins/common/soundmanager/manager.cpp =================================================================== --- soc/2011/sound/src/plugins/common/soundmanager/manager.cpp 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/src/plugins/common/soundmanager/manager.cpp 2011-06-07 22:07:52 UTC (rev 7373) @@ -40,11 +40,10 @@ // Initialised to false to make sure it is .. Initialised = false; - // Create a new SoundSystem, SoundData Instance and the default SoundControl + // Create a new SoundSystem, SoundData Instance and the main SoundControl soundSystem = new SoundSystem; soundData = new SoundData; mainSndCtrl = new SoundControl(-1); - defaultSndCtrl = new SoundControl(-2); if (soundSystem->Initialize (objectReg) && soundData->Initialize (objectReg)) @@ -84,7 +83,8 @@ delete sc; } - delete defaultSndCtrl; + soundHandles.DeleteAll(); + soundControllers.DeleteAll(); delete soundSystem; delete soundData; @@ -224,8 +224,10 @@ return false; } - soundHandles.Delete(fileName, handle); - delete handle; + // Pause the sound and set autoremove + // The handle will be removed in the next update + handle->sndstream->Pause(); + handle->SetAutoRemove(true); return true; } @@ -249,7 +251,7 @@ * TODO Split into three parts and make it event based */ -void SoundSystemManager::UpdateSound () +void SoundSystemManager::UpdateSound() { float vol; csHash<SoundHandle*, csString>::GlobalIterator handleIter(soundHandles.GetIterator()); @@ -259,10 +261,10 @@ { sh = handleIter.Next(); - if (sh->sndstream->GetPauseState () == CS_SNDSYS_STREAM_PAUSED + if (sh->sndstream->GetPauseState() == CS_SNDSYS_STREAM_PAUSED && sh->GetAutoRemove() == true) { - StopSound(sh->name); + RemoveHandle(sh->name); continue; } @@ -291,7 +293,7 @@ && sh->fade_stop == true) || sh->sndCtrl->GetToggle() == false) { - StopSound(sh->name); + RemoveHandle(sh->name); continue; } else @@ -343,6 +345,11 @@ { SoundControl* newControl; + if(soundControllers.Get(ctrlID, 0) != 0) + { + return 0; + } + newControl = new SoundControl(ctrlID); soundControllers.Put(ctrlID, newControl); @@ -358,4 +365,16 @@ SoundControl* SoundSystemManager::GetSoundControl(int ctrlID) const { return soundControllers.Get(ctrlID, 0); +} + +void SoundSystemManager::RemoveHandle(const char* fileName) +{ + SoundHandle* handle = soundHandles.Get(fileName, 0); + if(handle == 0) + { + return; + } + + soundHandles.Delete(fileName, handle); + delete handle; } \ No newline at end of file Modified: soc/2011/sound/src/plugins/common/soundmanager/manager.h =================================================================== --- soc/2011/sound/src/plugins/common/soundmanager/manager.h 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/src/plugins/common/soundmanager/manager.h 2011-06-07 22:07:52 UTC (rev 7373) @@ -62,9 +62,8 @@ class SoundSystemManager { - public: +public: bool Initialised; ///< is initialized ? - SoundControl* defaultSndCtrl; ///< an always available sound control that can be used when the user hasn't defined one yet SoundControl* mainSndCtrl; ///< sound control for this manager /** @@ -123,13 +122,7 @@ float mindist, float maxdist, float rad, int type3d, SoundHandle * &handle); - /** - * Stops and removes a SoundHandle. - * Use with caution. It doesnt care if its still in use. - * @param fileName - */ bool StopSound(const char* fileName); - bool SetSoundSource(const char* fileName, csVector3 position); /** @@ -159,13 +152,20 @@ SoundSystem* GetSoundSystem() { return soundSystem; } SoundData* GetSoundData() { return soundData; } - private: - SoundSystem *soundSystem; - SoundData *soundData; - csHash<SoundControl*, int> soundControllers; ///< hash which contains all SoundControls by id - csHash<SoundHandle*, csString> soundHandles; ///< hash which contains all SoundHandles by filename - csTicks SndTime; ///< current csticks - csTicks LastUpdateTime; ///< when the last update happened +private: + SoundSystem* soundSystem; + SoundData* soundData; + csHash<SoundControl*, int> soundControllers; ///< hash which contains all SoundControls by id + csHash<SoundHandle*, csString> soundHandles; ///< hash which contains all SoundHandles by filename + csTicks SndTime; ///< current csticks + csTicks LastUpdateTime; ///< when the last update happened + + /** + * Stops and removes a SoundHandle. + * Use with caution. It doesnt care if its still in use. + * @param fileName + */ + void RemoveHandle(const char* fileName); }; #endif /*_SOUND_MANAGER_H_*/ Modified: soc/2011/sound/src/plugins/common/soundmanager/queue.cpp =================================================================== --- soc/2011/sound/src/plugins/common/soundmanager/queue.cpp 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/src/plugins/common/soundmanager/queue.cpp 2011-06-07 22:07:52 UTC (rev 7373) @@ -53,11 +53,11 @@ * name must be a !unique! filename which exists in our vfs */ -void SoundQueue::AddItem (const char *filename) +void SoundQueue::AddItem(const char* filename) { - SoundQueueItem *newItem; + SoundQueueItem* newItem; - newItem = new SoundQueueItem(filename); + newItem = new SoundQueueItem(filename); queue.Push(newItem); } Modified: soc/2011/sound/src/plugins/common/soundmanager/soundctrl.cpp =================================================================== --- soc/2011/sound/src/plugins/common/soundmanager/soundctrl.cpp 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/src/plugins/common/soundmanager/soundctrl.cpp 2011-06-07 22:07:52 UTC (rev 7373) @@ -21,28 +21,14 @@ * */ -//==================================================================================== -// Crystal Space Includes -//==================================================================================== -//TODO: is it needed? //==================================================================================== -// Project Includes -//==================================================================================== -//TODO: is it needed? - -//==================================================================================== // Local Includes //==================================================================================== #include "soundctrl.h" #include "manager.h" -//------------------------------------------------------------------------------------ -// Forward Declarations -//------------------------------------------------------------------------------------ -//TODO: is it needed? - SoundControl::SoundControl(int ID) { id = ID; Modified: soc/2011/sound/src/plugins/common/soundmanager/soundctrl.h =================================================================== --- soc/2011/sound/src/plugins/common/soundmanager/soundctrl.h 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/src/plugins/common/soundmanager/soundctrl.h 2011-06-07 22:07:52 UTC (rev 7373) @@ -26,25 +26,11 @@ #define _SOUND_CONTROL_H_ //==================================================================================== -// Crystal Space Includes -//==================================================================================== -// TODO: is this needed? - -//==================================================================================== // Project Includes //==================================================================================== #include <isoundctrl.h> -//==================================================================================== -// Local Includes -//==================================================================================== -// TODO: is this needed? -//------------------------------------------------------------------------------------ -// Forward Declarations -//------------------------------------------------------------------------------------ -// TODO: is this needed? - /** * A Volume and Sound control class. * With this class you can control the volume and the overall state Modified: soc/2011/sound/src/plugins/common/soundmanager/soundmanager.cpp =================================================================== --- soc/2011/sound/src/plugins/common/soundmanager/soundmanager.cpp 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/src/plugins/common/soundmanager/soundmanager.cpp 2011-06-07 22:07:52 UTC (rev 7373) @@ -71,6 +71,8 @@ sq = queueIter.Next(); delete sq; } + + soundQueues.DeleteAll(); } @@ -79,12 +81,19 @@ sndSysMgr = new SoundSystemManager(objReg); objectReg = objReg; - // inizializing necessary SoundControls + // Inizializing main SoundControls mainSndCtrl = sndSysMgr->mainSndCtrl; - ambientSndCtrl = sndSysMgr->defaultSndCtrl; - musicSndCtrl = sndSysMgr->defaultSndCtrl; + AddSndCtrl(AMBIENT_SNDCTRL, SNDCTRL_TYPE_AMBIENT); + AddSndCtrl(MUSIC_SNDCTRL, SNDCTRL_TYPE_MUSIC); + AddSndCtrl(ACTION_SNDCTRL, SNDCTRL_TYPE_NORMAL); + AddSndCtrl(EFFECT_SNDCTRL, SNDCTRL_TYPE_NORMAL); + AddSndCtrl(GUI_SNDCTRL, SNDCTRL_TYPE_NORMAL); + AddSndCtrl(VOICE_SNDCTRL, SNDCTRL_TYPE_NORMAL); + // Initializing voice queue + AddSndQueue(VOICE_QUEUE, GetSndCtrl(VOICE_SNDCTRL)); + loopBGM.SetCallback(this, &UpdateMusicCallback); combatMusic.SetCallback(this, &UpdateMusicCallback); @@ -230,7 +239,7 @@ if(sc == 0) { - return sc; + return 0; } switch(type) @@ -296,11 +305,19 @@ } -void SoundManager::AddSndQueue(int queueID, iSoundControl* sndCtrl) +bool SoundManager::AddSndQueue(int queueID, iSoundControl* sndCtrl) { + + if(soundQueues.Get(queueID, 0) != 0 || sndCtrl == 0) + { + return false; + } + SoundControl* sndControl = static_cast<SoundControl*>(sndCtrl); SoundQueue* sq = new SoundQueue(sndControl, VOLUME_NORM); soundQueues.Put(queueID, sq); + + return true; } Modified: soc/2011/sound/src/plugins/common/soundmanager/soundmanager.h =================================================================== --- soc/2011/sound/src/plugins/common/soundmanager/soundmanager.h 2011-06-07 17:49:39 UTC (rev 7372) +++ soc/2011/sound/src/plugins/common/soundmanager/soundmanager.h 2011-06-07 22:07:52 UTC (rev 7373) @@ -64,7 +64,7 @@ virtual iSoundControl* GetMainSndCtrl(); //SoundQueue managing - virtual void AddSndQueue(int queueID, iSoundControl* sndCtrl); + virtual bool AddSndQueue(int queueID, iSoundControl* sndCtrl); virtual void RemoveSndQueue(int queueID); virtual bool PushQueueItem(int queueID, const char* fileName); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |