Design question - Unit selection sounds

kungfoomasta

26-09-2009 00:41:20

I'm developing an RTS game, and I recently added in 2d unit voices when units are selected. Currently what I do is create a Sound object ever time a unit is selected. However this might lead to a lot of Sound objects floating around. Is there a way to create 1 sound object and change the wav that it plays? Or even better, create a sound that is destroyed after it finishes playing?

Is it possible to have something like this? :)

OgreOggSoundManager::createTemporarySound(...);

I also would need these Sounds to be accessible while they're playing. If a player selects the same unit over and over, I only play a sound if the unit is currently not speaking. (So I have to see if the sound is still playing or not)

Is there a better approach?

stickymango

26-09-2009 09:57:20

Hmmm, interesting concept, if theres a use for it then I'll add that in, quite like the idea of a temporary sound, it could almost be used like managed objects in .NET where they automatically clean themselves up after completing, you could therefore fire off sounds and not have to worry about clogging up the system with unused data, I know I'd use this in my applications :D

Regarding switching sound data for a sound, this should be quite simple for static sounds as they don't keep a handle to the file and load all their data into a shared buffer, streamed sounds would need re-designing for this functionality but may not be too difficult to do, I'll look into it.

stickymango

26-09-2009 10:27:11

What about adding a flag function for marking a sound for automatic destruction at any time, would save duplicated creation functions and would allow total user control over a sounds life, you could play a number of times then destroy. Would this be just as intuitive to use?

sound->markTemporary();
sound->isTemporary();

Kind of thing :?:

kungfoomasta

26-09-2009 18:33:09

that would work well!

stickymango

15-10-2009 16:24:32

Committed a solution, can you give it a whirl?

turn on i.e:
OgreOggISound* sound = 0;

// Create...
sound = createSound("Test", "test.ogg");

// If valid..
if ( sound ) {

// Mark for auto-destruction..
sound->markTemporary();

// Play - once completed playing in its entirety should destroy itself..
sound->play();
}

Test with:
sound->isTemporary();
At present once marked it cannot be disabled, seemed good enough to me... :)

kungfoomasta

15-10-2009 22:40:54

It seems to be working! :D

Basically when a unit is clicked I do the following:

if(!sm->soundExists("UnitSelectionSound"))
sm->playAmbientTemporarySound("UnitSelectionSound","someSound.ogg");


The end result is that a sound does not play until the preceding sound finishes. I'm assuming since the soundmanager tells me the sound does not exist that its being cleaned up properly.

stickymango

15-10-2009 22:46:32

You can call OgreOggSoundManager::getNumSounds() for confirmation ;)