difficulty: make difficulty_value() a type-generic macro

This commit is contained in:
Andrei Alexeyev 2023-01-31 06:17:50 +01:00
parent ea5374bbc6
commit 2f48833004
No known key found for this signature in database
GPG key ID: 72D26128040B9690
2 changed files with 11 additions and 9 deletions

View file

@ -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];
}

View file

@ -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; \
})