I have a set of #define's in a generated header such as this:
#define SFX_SOIL_DESTROY_1 2
#define SFX_SOIL_DESTROY_2 14
#define SFX_SOIL_PLACE_1 32
#define SFX_SOIL_PLACE_2 33
#define SFX_WOOD_DESTROY_1 5
I have a method that must return the correct define for the material type and sound type. Here is a long, inconcise solution:
int getSfx (MaterialType material, SoundType sound)
{
switch (material)
{
case SOIL:
{
switch (sound)
{
case DESTROY:
return rand()%2 ? SFX_SOIL_DESTROY_1 : SFX_SOIL_DESTROY_2;
case PLACE:
// And so on
Is there some sort of macro-hack that could condense this? Any help is greatly appreciated.
Storing it as data lookup is much faster and only requires processing once (when its set up). So, assuming material and sound are more or less zero-based sequential (otherwise do a lookup translation):
And then: