Pause All function?

kungfoomasta

09-02-2007 23:43:08

Does there exist a way to pause all sounds?

You could easily create one by iterating through the sounds and pausing them all, but a global pause and maybe global stop would be good, simple functions to add. :wink:

KungFooMasta

t0tAl_mElTd0wN

09-02-2007 23:50:13

I like the idea. I'll do that right now :)

[edit] All done! Great suggestion. Perhaps what I'll do at some point is have a resume function that will take only the ones that had been paused and resume them, thus restoring your sound state to exactly how it was before the pause (great for pausing games and such)

kungfoomasta

10-02-2007 00:56:37

lol! I totally forgot about resuming, but yah, they need to work together, lol. Awesome that you put it in! :D

KungFooMasta

t0tAl_mElTd0wN

10-02-2007 01:22:47

Alright! All done.

CaseyB: All I did was create two new functions and a private variable

in OgreALSoundManager.cpp:

void SoundManager::pauseAllSounds()
{
SoundMap::iterator soundItr = mSoundMap.begin();
for(; soundItr != mSoundMap.end(); soundItr++)
{
if(!soundItr->second->isPaused())
{
soundItr->second->pause();
mPauseResumeAll[soundItr->first] = static_cast<Sound*>(soundItr->second);
}
}
}

void SoundManager::resumeAllSounds()
{
SoundMap::iterator soundItr = mPauseResumeAll.begin();
for(; soundItr != mPauseResumeAll.end(); soundItr++)
{
if(soundItr->second->isPaused())
soundItr->second->play();
}
mPauseResumeAll.empty();
}


in OgreALSoundManager.h:

virtual void pauseAllSounds();
/** Resumes all sounds that were paused with the previous call to pauseAllSounds(). */
virtual void resumeAllSounds();
/** Destroys the specified sound. @param name The name of the sound to destroy */

etc...
SoundMap mPauseResumeAll;

How it works is this:
When pauseAllSounds() is called, it adds all currently playing sounds to the list of 'managed' sounds, and sets them paused. When resumeAllSounds() is called, it iterates through that list, sets each one to playing, and then empties the list. If you change the state of a sound manually, no problem. resumeAllSounds() will simply ignore it. This may be desirable for in-game music when pausing a menu (*pause all* *resume music* shouldn't create any sort of break in the sound, and if it does, it'll be covered up by the sudden change in volume as all the other sounds stop)

Look good?

kungfoomasta

10-02-2007 04:42:03

Looks good to me! :)

KungFooMasta

CaseyB

10-02-2007 06:10:55

You haveif(!soundItr->second->isPaused())but wouldn't that put sounds that are stopped in the list too? So shouldn't it be just sounds that are playing? Likeif(soundItr->second->isPlaying())Other than that I like it!

t0tAl_mElTd0wN

10-02-2007 06:29:50

Ah. Alright, I didn't know there was a distinction between paused and stopped ;)

I'll make that change real quick here in just a second

independentCreations

28-03-2007 01:23:12

this would also work and requires no editing of OgreAL


Ogre::SceneManager::MovableObjectIterator itr = mSceneMan->getMovableObjectIterator(OgreAL::SoundFactory::FACTORY_TYPE_NAME);
while(itr.hasMoreElements())
{
OgreAL::Sound * sound = (OgreAL::Sound*)itr.getNext();
sound->pause();
}

CaseyB

30-03-2007 16:09:03

This will definitely work for pauseAll, but then you'd run into problems with resumeAll because you wouldn't know which ones were playing before. These functions have been included in the SVN version of OgreAL already so they take care of the complexity for you! ;)

CaseyB

12-04-2007 05:30:31

Huh, I just tried to use this and somehow they got lost from SVN, I've added them back in, sorry for any inconvenience.