From cc01be15fe7d7e74c4ec978e602287550305d704 Mon Sep 17 00:00:00 2001 From: Andrei Alexeyev Date: Thu, 28 Sep 2023 15:27:33 +0200 Subject: [PATCH] all: use the clamp() macro --- src/boss.c | 6 +++--- src/enemy_classes.c | 2 +- src/item.c | 2 +- src/lasers/draw.c | 2 +- src/pixmap/pixmap_conversion.inc.h | 2 +- src/player.c | 6 +++--- src/renderer/gl33/gl33.c | 6 +++--- src/resource/texture_loader/basisu.c | 4 ++-- src/rwops/rwops_zlib.c | 2 +- src/stage.c | 2 +- src/stages/stage2/spells/wheel_of_fortune.c | 2 +- src/stages/stage4/spells/vlads_army.c | 2 +- src/stages/stage6/spells/ricci.c | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/boss.c b/src/boss.c index 5698ad02..f7f656b8 100644 --- a/src/boss.c +++ b/src/boss.c @@ -560,7 +560,7 @@ static void draw_spell_portrait(Boss *b, int time) { r_state_push(); r_shader("sprite_default"); - float char_in = clampf(a * 1.5f, 0, 1); + float char_in = clamp(a * 1.5f, 0, 1); float char_out = min(1, 2 - (2 * a)); float char_opacity_in = 0.75f * min(1, a * 5); float char_opacity = char_opacity_in * char_out * char_out; @@ -921,7 +921,7 @@ static DamageResult ent_damage_boss(EntityInterface *ent, const DamageInfo *dmg) if(pattern_time < max_damage_time) { float span = max_damage_time - min_damage_time; - factor = clampf((pattern_time - min_damage_time) / span, 0.0f, 1.0f); + factor = clamp((pattern_time - min_damage_time) / span, 0.0f, 1.0f); } if(factor == 0) { @@ -949,7 +949,7 @@ static void calc_spell_bonus(Attack *a, SpellBonus *bonus) { bool survival = a->type == AT_SurvivalSpell; bonus->failed = attack_was_failed(a); - int time_left = iclamp(a->starttime + a->timeout - global.frames, 0, a->timeout); + int time_left = clamp(a->starttime + a->timeout - global.frames, 0, a->timeout); double piv_factor = global.plr.point_item_value / (double)PLR_START_PIV; double base = a->bonus_base * 0.5 * (1 + piv_factor); diff --git a/src/enemy_classes.c b/src/enemy_classes.c index a24d19e7..dce6b262 100644 --- a/src/enemy_classes.c +++ b/src/enemy_classes.c @@ -515,7 +515,7 @@ void ecls_anyfairy_summon(Enemy *e, int duration) { for(int i = 1;;) { float f = i / (float)duration; - vp->base.opacity = glm_ease_quint_in(clampf(f * 2.0f, 0.0f, 1.0f)); + vp->base.opacity = glm_ease_quint_in(clamp(f * 2.0f, 0.0f, 1.0f)); vp->base.scale = lerpf(3.0f, 1.0f, glm_ease_back_out( glm_ease_sine_inout(f))); if(f >= fairy_delay) { diff --git a/src/item.c b/src/item.c index a2bdaf17..d0264341 100644 --- a/src/item.c +++ b/src/item.c @@ -107,7 +107,7 @@ static void ent_draw_item(EntityInterface *ent) { float alpha = 1; if(i->type == ITEM_PIV && !i->auto_collect) { - alpha = clampf(2.0f - (global.frames - i->birthtime) / 60.0f, 0.1f, 1.0f); + alpha = clamp(2.0f - (global.frames - i->birthtime) / 60.0f, 0.1f, 1.0f); } Color *c = RGBA_MUL_ALPHA(1, 1, 1, alpha); diff --git a/src/lasers/draw.c b/src/lasers/draw.c index ad39b4d0..aee5e695 100644 --- a/src/lasers/draw.c +++ b/src/lasers/draw.c @@ -167,7 +167,7 @@ static void laserdraw_sdf_fb_resize_strategy(void *userdata, IntExtent *fb_size, float vid_vp_w, vid_vp_h; video_get_viewport_size(&vid_vp_w, &vid_vp_h); float q = config_get_float(CONFIG_FG_QUALITY); - float factor = clampf(q * vid_vp_w / SCREEN_W, 0.5f, 1.0f); + float factor = clamp(q * vid_vp_w / SCREEN_W, 0.5f, 1.0f); w = roundf(PACKING_SPACE_SIZE_W * factor); h = roundf(PACKING_SPACE_SIZE_H * factor); diff --git a/src/pixmap/pixmap_conversion.inc.h b/src/pixmap/pixmap_conversion.inc.h index 86cd197d..db635aca 100644 --- a/src/pixmap/pixmap_conversion.inc.h +++ b/src/pixmap/pixmap_conversion.inc.h @@ -21,7 +21,7 @@ static _CONV_OUT_TYPE _CONV_VALUE_FUNC(_CONV_IN_TYPE val) { if(_CONV_OUT_IS_FLOAT) { return val; } else { - return (_CONV_OUT_TYPE)roundf(clampf(val, 0.0f, 1.0f) * (float)_CONV_OUT_MAX); + return (_CONV_OUT_TYPE)roundf(clamp(val, 0.0f, 1.0f) * (float)_CONV_OUT_MAX); } } else if(_CONV_OUT_IS_FLOAT) { return val * (1.0f / (float)_CONV_IN_MAX); diff --git a/src/player.c b/src/player.c index 56c250c0..2625b8df 100644 --- a/src/player.c +++ b/src/player.c @@ -125,7 +125,7 @@ static int player_track_effective_power_change(Player *plr) { bool player_set_power(Player *plr, short npow) { int old_stored = plr->power_stored; - int new_stored = iclamp(npow, 0, PLR_MAX_POWER_STORED); + int new_stored = clamp(npow, 0, PLR_MAX_POWER_STORED); plr->power_stored = new_stored; if(old_stored / 100 < new_stored / 100) { @@ -160,7 +160,7 @@ int player_get_effective_power(Player *plr) { p = plr->power_stored; } - return iclamp(p, 0, PLR_MAX_POWER_EFFECTIVE); + return clamp(p, 0, PLR_MAX_POWER_EFFECTIVE); } void player_move(Player *plr, cmplx delta) { @@ -183,7 +183,7 @@ void player_draw_overlay(Player *plr) { r_state_push(); r_shader("sprite_default"); - float char_in = clampf(a * 1.5f, 0, 1); + float char_in = clamp(a * 1.5f, 0, 1); float char_out = min(1, 2 - (2 * a)); float char_opacity_in = 0.75 * min(1, a * 5); float char_opacity = char_opacity_in * char_out * char_out; diff --git a/src/renderer/gl33/gl33.c b/src/renderer/gl33/gl33.c index 592e221e..7d34dbdf 100644 --- a/src/renderer/gl33/gl33.c +++ b/src/renderer/gl33/gl33.c @@ -236,7 +236,7 @@ static void gl33_init_texunits(void) { if(texunits_max == 0) { texunits_max = texunits_available; } else { - texunits_max = iclamp(texunits_max, texunits_min, texunits_available); + texunits_max = clamp(texunits_max, texunits_min, texunits_available); } texunits_capped = min(texunits_max, texunits_available); @@ -245,7 +245,7 @@ static void gl33_init_texunits(void) { if(R.texunits.limit == 0) { R.texunits.limit = texunits_available; } else { - R.texunits.limit = iclamp(R.texunits.limit, texunits_min, texunits_available); + R.texunits.limit = clamp(R.texunits.limit, texunits_min, texunits_available); } R.texunits.array = ALLOC_ARRAY(R.texunits.limit, typeof(*R.texunits.array)); @@ -506,7 +506,7 @@ static void gl33_sync_magic_uniforms(void) { int num_color_out; if(u[UMAGIC_COLOR_OUT_SIZES]) { - num_color_out = iclamp(u[UMAGIC_COLOR_OUT_SIZES]->array_size, 0, FRAMEBUFFER_MAX_OUTPUTS); + num_color_out = clamp(u[UMAGIC_COLOR_OUT_SIZES]->array_size, 0, FRAMEBUFFER_MAX_OUTPUTS); } else { num_color_out = 0; } diff --git a/src/resource/texture_loader/basisu.c b/src/resource/texture_loader/basisu.c index e00f5ccb..708956ca 100644 --- a/src/resource/texture_loader/basisu.c +++ b/src/resource/texture_loader/basisu.c @@ -591,11 +591,11 @@ static bool texture_loader_basisu_init_mipmaps( } int mip_bias = env_get("TAISEI_BASISU_MIP_BIAS", 0); - mip_bias = iclamp(mip_bias, 0, total_levels - 1); + mip_bias = clamp(mip_bias, 0, total_levels - 1); { int max_levels = env_get("TAISEI_BASISU_MAX_MIP_LEVELS", 0); if(max_levels > 0) { - total_levels = iclamp(total_levels, 1, mip_bias + max_levels); + total_levels = clamp(total_levels, 1, mip_bias + max_levels); } } bld->mip_bias = mip_bias; diff --git a/src/rwops/rwops_zlib.c b/src/rwops/rwops_zlib.c index a29b93ae..3669de31 100644 --- a/src/rwops/rwops_zlib.c +++ b/src/rwops/rwops_zlib.c @@ -317,7 +317,7 @@ static SDL_RWops *wrap_writer( z->window_bits = window_bits; if(clevel >= 0) { - clevel = iclamp(clevel, Z_BEST_SPEED, Z_BEST_COMPRESSION); + clevel = clamp(clevel, Z_BEST_SPEED, Z_BEST_COMPRESSION); } int status = deflateInit2( diff --git a/src/stage.c b/src/stage.c index dd602a04..31f23240 100644 --- a/src/stage.c +++ b/src/stage.c @@ -179,7 +179,7 @@ static void stage_start(StageInfo *stage) { global.plr.power_stored = config_get_int(CONFIG_PRACTICE_POWER); } - global.plr.power_stored = iclamp(global.plr.power_stored, 0, PLR_MAX_POWER_STORED); + global.plr.power_stored = clamp(global.plr.power_stored, 0, PLR_MAX_POWER_STORED); reset_all_sfx(); } diff --git a/src/stages/stage2/spells/wheel_of_fortune.c b/src/stages/stage2/spells/wheel_of_fortune.c index 3e537121..a4d33309 100644 --- a/src/stages/stage2/spells/wheel_of_fortune.c +++ b/src/stages/stage2/spells/wheel_of_fortune.c @@ -47,7 +47,7 @@ TASK(wheel, { BoxedBoss boss; real spin_dir; int duration; }) { } int max_delay = 60; - int min_delay = max_delay - iclamp((t - 100)/20, 0, 50) - 1; + int min_delay = max_delay - clamp((t - 100)/20, 0, 50) - 1; for(int i = 1; i < arms; i++) { real a = spin_dir * M_TAU / (arms - 1) * (i + (1 + 0.4 * d) * pow(t/200.0, 2)); diff --git a/src/stages/stage4/spells/vlads_army.c b/src/stages/stage4/spells/vlads_army.c index 74d3b06f..7854e15f 100644 --- a/src/stages/stage4/spells/vlads_army.c +++ b/src/stages/stage4/spells/vlads_army.c @@ -19,7 +19,7 @@ static void kurumi_extra_shield_draw(Enemy *e, EnemyDrawParams p) { // TODO: something nicer here - float h = clampf(e->hp / e->spawn_hp, 0, 1); + float h = clamp(e->hp / e->spawn_hp, 0, 1); h *= h; r_draw_sprite(&(SpriteParams) { diff --git a/src/stages/stage6/spells/ricci.c b/src/stages/stage6/spells/ricci.c index 8adb590a..cfce8f37 100644 --- a/src/stages/stage6/spells/ricci.c +++ b/src/stages/stage6/spells/ricci.c @@ -253,7 +253,7 @@ TASK(ricci_proj, { cmplx pos; cmplx velocity; BoxedEllyBaryons baryons; }) { p->pos = p->prevpos = ARGS.pos + ARGS.velocity * t + shift; - float a = 0.5f + 0.5f * max(0, tanhf((time - 80) / 100.0f)) * clampf(influence, 0.2f, 1); + float a = 0.5f + 0.5f * max(0, tanhf((time - 80) / 100.0f)) * clamp((float)influence, 0.2f, 1); a *= min(1, t / 20.0f); p->color.r = 0.5;