Artifact : SoundManager
|
What? How? The SoundManager I’ve created is done by having two Structs, one for handling the sound effects while the other one handles the music tracks. The Music and Sound Struct differs a little bit, due to how SFML handles sound and music. The Sound Struct keeps tracks on the Path to the sound file, a sf::SoundBuffer that contains the sound and the sf::Sound itself. This is as the Sound actually stores the sound effect inside the buffer that was created. The Music Struct however does not have the buffer, so it contains the Path to the file and the sf::Music. This is because the way that SFML uses the music is that it Streams the data that should be played directly from the path. and never stores it. These are then turned into vectors that i will call SoundBank and MusicBank
vector m_SoundBank; By having these banks sorted, it will be easy to go through what sound has already been used before. by simply comparing the path with the vector. and when its not found. It will then go over to the AddSound or AddMusic part of the play function. This is done with a new kind of for loop I just learned how to use, the syntax is shown in the picture above and it will go through every sound vector inside the soundbank. So it’s a For loop and an Iterator at the same time. Turned out very handy in a situation like this. Why? By having this sound manager the sound effects will easily be stored and reused rather than loading them in every time they are called. It also makes using sound where you want to use it much easier. It now takes one line of code, well assuming the sound manager is already initialized where the you want the sound to occur. as it would just be as simple as this : Soundmanager->PlaySound(“song.mp3″); Very easy to use and fail safe friendly as it will automaticly add not loaded sounds already. |

