all: use the clamp() macro
This commit is contained in:
parent
ee09f33a5f
commit
cc01be15fe
13 changed files with 20 additions and 20 deletions
|
@ -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);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue