Automagical Sounds.lua
Posted: 04 Feb 2010, 04:56
The following sounds.lua will load and configure all sounds in the /sounds directory. Putting sounds into sub-directories will automatically configure them properly for their use in your game. The only sound files that should remain in the root are Spring defaults (and we can even take care of that, too, if we want).
For example, if you drop a sound into sounds/explosions, it will be set up with distance attenuation, priority, maxconcurrent (very important for performance and avoiding clipping) and other things... completely automatically.
With this and FLOZi's code from this thread, it is potentially possible that all games can be made able to handle World Builder (or other third-party level design tools that want to use Units as valid game objects) without any other modifications. No incompatible resources tables, no problems with sounds, all UnitDefs and WeaponDefs would be valid.
So... I'd really like to urge people to read through it, compare it with your own sounds.lua, and let's figure out if I'm missing any categories or sub-categories or just a setting you think is worth putting into this, and get people converted so that you can all use these things without major modifications to your games. Sticking your sounds into the sub-folders is a 5-minute job; this takes the guesswork and errors out of the process.
Anyhow, that's it for now. I am hoping people will see that we've got a real opportunity to get everybody on the same page here. FLOZi's code (which this is a simpler variant of) means that we're really looking at a breakthrough here, for finally letting level-design tools and games exist together peacefully.
This picture shows you what your /sounds folder should look like. It supports sub-folders, so /sounds/Explosions/ArghSounds/mysound.wav is valid and will operate properly.

For example, if you drop a sound into sounds/explosions, it will be set up with distance attenuation, priority, maxconcurrent (very important for performance and avoiding clipping) and other things... completely automatically.
With this and FLOZi's code from this thread, it is potentially possible that all games can be made able to handle World Builder (or other third-party level design tools that want to use Units as valid game objects) without any other modifications. No incompatible resources tables, no problems with sounds, all UnitDefs and WeaponDefs would be valid.
So... I'd really like to urge people to read through it, compare it with your own sounds.lua, and let's figure out if I'm missing any categories or sub-categories or just a setting you think is worth putting into this, and get people converted so that you can all use these things without major modifications to your games. Sticking your sounds into the sub-folders is a 5-minute job; this takes the guesswork and errors out of the process.
Anyhow, that's it for now. I am hoping people will see that we've got a real opportunity to get everybody on the same page here. FLOZi's code (which this is a simpler variant of) means that we're really looking at a breakthrough here, for finally letting level-design tools and games exist together peacefully.
This picture shows you what your /sounds folder should look like. It supports sub-folders, so /sounds/Explosions/ArghSounds/mysound.wav is valid and will operate properly.