Is it ok to marry ourselves to SDL_Mixer? The code currently supports sound without it, but moving on, we really can't do a lot without something more advanced, and SDL_Mixer is the more advanced something we need.
I've looked over how the cycle effect in particular is handled, but I'm a tad confused. Where and how does it get handled within the game loop?
So I'm wanting to create a series of mappings, like maybe as enums or something. They'll be things like "CYCLE_ENGINE", "CYCLE_EXPLOSION", "GRIND_CYCLE_WALL", "GRIND_GRID_WALL", "ENTER_WINZONE". Most of them will be empty and not contain any sound files (until someone creates the sound effects for them). Then in the game loop, when it's time to trigger an effect, we'll call a static method on the player, something like eSoundPlayer::PlayEffect(CYCLE_EXPLOSION). Then SDL_Mixer will be told to fire off the CYCLE_EXPLOSION. We could pass some other parameters, like the player's position and the position where the sound originates, and the soundplayer can use that to determine how to play the sound (mix for 3d sound).
The soundplayer could then load a sound effect skin file that makes the mapping to actual sound file on disc conversion. This should be an xml file that follows the resource model given by the maps, and it will be loaded from the resource manager. So, next question coming.
The individual sound files that go in a sound effect skin should be stuck in an archive with the xml file that describes it. The resource manager should be able to retrieve that archive. Should it also be able to retrieve each file individually? So the sound effect skin could specify the urls for every file, and the resource manager could retrieve them one by one. Should it? Or should we just require a sound effect skin to be a complete archive of a given format (.tar.gz or .zip)? If we opt for the second solution, then do we need to use the resource manager to load each individual sound file, or should we use it to load just the skin descriptor file and then load the sound files ourselves in our own peculiar fashion?
I'm thinking about how to structure the music track. I like the idea of having a series of ogg files linked together as a song (for a primitive engine, that is), and then letting the game randomly select which ones to play at a given point in time. The end result of that is either the song will play indefinitely, or we need some way to specify that *this* song ends after 5 minutes, and you should start a new song. The obvious solution is to just make each song a complete self-contained file, and that's probably what it'll look like in the initial implementation. Maybe that'll be good enough?
So when the game starts, I'm wanting a nice, dramatic theme to play. Then I want that theme stated in a regular song, with a beat, and bass, and all that good stuff. This part I want to have play indefinitely until a round starts, so when the player joins a server and a round is in progress, the in-game portion of the music track won't start until the new round starts and the player starts playing.
So, when the splash screen is displayed, the title track will play. Say it's about 15 seconds in length. The user will interact with the application just like he does currently, we won't make him wait those 15 seconds. We could make him wait 3-4 seconds and have him watch a cool animation, but that's beyond the scope of a soundtrack.
So then the game will load the gui music track and repeat it until a round starts.
When a round starts, the game should do something based on the player's preference. Either it will play it's own in-game stuff, or it will play music the player has asked for. So we have several possibilities:
* The in-game soundtrack as I've described.
* Load an m3u playlist that contains complete self-contained songs that we've bundled with the game, and then just do a randomize on it.
* Load an m3u playlist that the user has built with his own stuff and do a randomize on that.
* Play a CD that's in the cdrom drive.
When the player leaves the game, fade out whatever's playing and go back to the gui music track. When the game shuts down, fade out whatever's playing and unload and free memory and crap.
So the eSoundPlayer class I'm envisioning should handle all sound effects and the music track (divorce this from any existing eSoundPlayer class that may exist). You call it to say "Play this effect". Or you can pass it events, like ROUND_START, MATCH_END, PLAYER_VICTORY, PLAYER_LOST, THIS_PLAYER_SUCKS. Then the eSoundPlayer class would play the appropriate tunes to go with it, as well as any special effects that go with it. So in an event queue, we need the eSoundPlayer to receive events. Does it need to send events? I can't think of a reason it would need to.
So it sits watch-dog over the game waiting for something to happen. Does it belong in its own thread? It has to manage tasks that aren't related to the game loop. It has to manage SDL_Mixer, specifically. When a song ends, it has to decide what to do next, either pick a random song to play, or just fart. Or both. But this is independent of the game loop. Should it be an updateable game object that gets called from the game loop to update, or a separate thread that updates itself as needed and sleeps the rest of the time? SDL_Mixer does the hard work of playing the music, so our sound player will sleep most of the time, making most update calls a quick if(asleep) return;, which shouldn't impact performance severely. On the other hand, sticking it in a thread means it only impacts performance when it needs to, and we let the kernel deal with it.