difficulty: make difficulty_value() a type-generic macro
This commit is contained in:
parent
ea5374bbc6
commit
2f48833004
2 changed files with 11 additions and 9 deletions
|
@ -59,10 +59,3 @@ void difficulty_preload(void) {
|
|||
preload_resource(RES_SPRITE, difficulty_sprite_name(diff), RESF_PERMANENT);
|
||||
}
|
||||
}
|
||||
|
||||
double difficulty_value(double easy, double normal, double hard, double lunatic) {
|
||||
uint idx = global.diff - D_Easy;
|
||||
double vals[NUM_SELECTABLE_DIFFICULTIES] = { easy, normal, hard, lunatic };
|
||||
assert(idx < ARRAY_SIZE(vals));
|
||||
return vals[idx];
|
||||
}
|
||||
|
|
|
@ -33,5 +33,14 @@ const Color *difficulty_color(Difficulty diff)
|
|||
|
||||
void difficulty_preload(void);
|
||||
|
||||
double difficulty_value(double easy, double normal, double hard, double lunatic)
|
||||
attr_pure;
|
||||
#define difficulty_value(easy, normal, hard, lunatic) ({ \
|
||||
typeof((easy)+(normal)+(hard)+(lunatic)) val; \
|
||||
switch(global.diff) { \
|
||||
case D_Easy: val = easy; break; \
|
||||
case D_Normal: val = normal; break; \
|
||||
case D_Hard: val = hard; break; \
|
||||
case D_Lunatic: val = lunatic; break; \
|
||||
default: UNREACHABLE; \
|
||||
} \
|
||||
val; \
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue