From e852a40733b93417b39f06db01dc04eb3f96f6a3 Mon Sep 17 00:00:00 2001 From: otta8634 Date: Thu, 5 Dec 2024 12:47:07 +0800 Subject: [PATCH] Replace most floor(...+0.5) instances with rint Only touched instances I could confirm the input is only ever positive, ... since rint(x) and floor(x+0.5) aren't identical if x<0 --- qcsrc/client/announcer.qc | 2 +- qcsrc/client/hud/hud_config.qc | 8 ++++---- qcsrc/client/hud/panel/physics.qc | 12 ++++++------ qcsrc/client/hud/panel/scoreboard.qc | 2 +- qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc | 2 +- .../gamemodes/gamemode/domination/cl_domination.qc | 2 +- qcsrc/common/sounds/all.qc | 2 +- qcsrc/common/util.qc | 4 ++-- qcsrc/common/util.qh | 2 +- qcsrc/lib/color.qh | 6 +++--- qcsrc/lib/string.qh | 4 ++-- qcsrc/menu/item/slider.qc | 2 +- qcsrc/menu/xonotic/keybinder.qc | 2 +- qcsrc/server/race.qc | 4 ++-- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/qcsrc/client/announcer.qc b/qcsrc/client/announcer.qc index cc85f31cc..2f7d15d39 100644 --- a/qcsrc/client/announcer.qc +++ b/qcsrc/client/announcer.qc @@ -70,7 +70,7 @@ void Announcer_Countdown(entity this) bool inround = (roundstarttime && time >= starttime); float countdown = (inround ? roundstarttime - time : starttime - time); - float countdown_rounded = floor(0.5 + countdown); + float countdown_rounded = rint(countdown); if (starttime != prev_starttime || roundstarttime != prev_roundstarttime || prev_inround != inround) this.skin = 0; // restart centerprint countdown diff --git a/qcsrc/client/hud/hud_config.qc b/qcsrc/client/hud/hud_config.qc index 726b2e78d..a36e6b9cf 100644 --- a/qcsrc/client/hud/hud_config.qc +++ b/qcsrc/client/hud/hud_config.qc @@ -176,8 +176,8 @@ void HUD_Panel_SetPos(vector pos) if(autocvar_hud_configure_grid) { - pos.x = floor((pos.x/vid_conwidth)/hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x; - pos.y = floor((pos.y/vid_conheight)/hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y; + pos.x = rint((pos.x/vid_conwidth)/hud_configure_gridSize.x) * hud_configure_realGridSize.x; + pos.y = rint((pos.y/vid_conheight)/hud_configure_gridSize.y) * hud_configure_realGridSize.y; } if(hud_configure_checkcollisions) @@ -353,8 +353,8 @@ void HUD_Panel_SetPosSize(vector mySize) // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken if(autocvar_hud_configure_grid) { - mySize.x = floor((mySize.x/vid_conwidth)/hud_configure_gridSize.x + 0.5) * hud_configure_realGridSize.x; - mySize.y = floor((mySize.y/vid_conheight)/hud_configure_gridSize.y + 0.5) * hud_configure_realGridSize.y; + mySize.x = rint((mySize.x/vid_conwidth)/hud_configure_gridSize.x) * hud_configure_realGridSize.x; + mySize.y = rint((mySize.y/vid_conheight)/hud_configure_gridSize.y) * hud_configure_realGridSize.y; } if(hud_configure_checkcollisions) diff --git a/qcsrc/client/hud/panel/physics.qc b/qcsrc/client/hud/panel/physics.qc index efbf045cd..d4c24f8bb 100644 --- a/qcsrc/client/hud/panel/physics.qc +++ b/qcsrc/client/hud/panel/physics.qc @@ -66,13 +66,13 @@ void HUD_Physics() float speed, conversion_factor = GetSpeedUnitFactor(autocvar_hud_speed_unit); vector vel = (csqcplayer ? csqcplayer.velocity : pmove_vel); - float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 ); + float max_speed = rint( autocvar_hud_panel_physics_speed_max * conversion_factor ); if (autocvar__hud_configure) - speed = floor( max_speed * 0.65 + 0.5 ); + speed = rint( max_speed * 0.65 ); else if(autocvar_hud_panel_physics_speed_vertical) - speed = floor( vlen(vel) * conversion_factor + 0.5 ); + speed = rint( vlen(vel) * conversion_factor ); else - speed = floor( vlen(vel - vel.z * '0 0 1') * conversion_factor + 0.5 ); + speed = rint( vlen(vel - vel.z * '0 0 1') * conversion_factor ); //compute acceleration float acceleration, f; @@ -188,7 +188,7 @@ void HUD_Physics() { if (autocvar__hud_configure) { - top_speed = floor( max_speed * 0.75 + 0.5 ); + top_speed = rint( max_speed * 0.75 ); f = 1; } else @@ -221,7 +221,7 @@ void HUD_Physics() peak_offsetX = (1 - min(top_speed, max_speed)/max_speed) * panel_size.x; else // if (speed_baralign == 2) peak_offsetX = min(top_speed, max_speed)/max_speed * panel_size.x * 0.5; - peak_size.x = floor(panel_size.x * 0.01 + 1.5); + peak_size.x = rint(panel_size.x * 0.01) + 1; peak_size.y = panel_size.y; if (speed_baralign == 2) // draw two peaks, on both sides { diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index af56134c2..5f707d048 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -1878,7 +1878,7 @@ vector Scoreboard_AccuracyStats_Draw(vector pos, vector rgb, vector bg_size) }); if (weapons_with_stats) - average_accuracy = floor((average_accuracy * 100 / weapons_with_stats) + 0.5); + average_accuracy = rint(average_accuracy * 100 / weapons_with_stats); panel_size.x += panel_bg_padding * 2; // restore initial width diff --git a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc index 39f45666d..0d547c616 100644 --- a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc +++ b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc @@ -800,7 +800,7 @@ void ctf_Handle_Pickup(entity flag, entity player, int pickuptype) case PICKUP_DROPPED: { pickup_dropped_score = (autocvar_g_ctf_flag_return_time > 0 ? bound(0, ((flag.ctf_droptime + autocvar_g_ctf_flag_return_time) - time) / autocvar_g_ctf_flag_return_time, 1) : 1); - pickup_dropped_score = floor((autocvar_g_ctf_score_pickup_dropped_late * (1 - pickup_dropped_score) + autocvar_g_ctf_score_pickup_dropped_early * pickup_dropped_score) + 0.5); + pickup_dropped_score = rint(autocvar_g_ctf_score_pickup_dropped_late * (1 - pickup_dropped_score) + autocvar_g_ctf_score_pickup_dropped_early * pickup_dropped_score); LOG_TRACE("pickup_dropped_score is ", ftos(pickup_dropped_score)); GameRules_scoring_add_team(player, SCORE, pickup_dropped_score); ctf_EventLog("pickup", flag.team, player); diff --git a/qcsrc/common/gamemodes/gamemode/domination/cl_domination.qc b/qcsrc/common/gamemodes/gamemode/domination/cl_domination.qc index b962f7b77..a60dc67ad 100644 --- a/qcsrc/common/gamemodes/gamemode/domination/cl_domination.qc +++ b/qcsrc/common/gamemodes/gamemode/domination/cl_domination.qc @@ -48,7 +48,7 @@ void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, int layout, in if (layout == 2) // average pps drawstring_aspect(myPos + eX * mySize.y, ftos_decimals(stat, 2), vec2((2/3) * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL); else // percentage of average pps - drawstring_aspect(myPos + eX * mySize.y, strcat( ftos(floor(pps_ratio*100 + 0.5)), "%" ), vec2((2/3) * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL); + drawstring_aspect(myPos + eX * mySize.y, strcat( ftos(rint(pps_ratio*100)), "%" ), vec2((2/3) * mySize.x, mySize.y), color, panel_fg_alpha, DRAWFLAG_NORMAL); } //draw the icon diff --git a/qcsrc/common/sounds/all.qc b/qcsrc/common/sounds/all.qc index c6418674c..c0ff5d10f 100644 --- a/qcsrc/common/sounds/all.qc +++ b/qcsrc/common/sounds/all.qc @@ -44,7 +44,7 @@ void soundtoat(int to, entity e, vector o, int chan, string samp, float vol, flo attenu = floor(attenu * 64); vol = floor(vol * 255); int sflags = 0; - int speed4000 = floor((_pitch * 0.01) * 4000 + 0.5); + int speed4000 = rint((_pitch * 0.01) * 4000); if (vol != 255) sflags |= SND_VOLUME; if (attenu != 64) sflags |= SND_ATTENUATION; if (entno >= 8192 || chan < 0 || chan > 7) sflags |= SND_LARGEENTITY; diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 4ad93f914..26024b9fc 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -493,7 +493,7 @@ float compressShortVector(vector vec) error("BOGUS vectoangles"); //print("angles: ", vtos(ang), "\n"); - p = floor(0.5 + (ang.x + 90) * (16 / 180)) & 15; // -90..90 to 0..14 + p = rint((ang.x + 90) * (16 / 180)) & 15; // -90..90 to 0..14 if(p == 0) { if(vec.z < 0) @@ -502,7 +502,7 @@ float compressShortVector(vector vec) y = 30; } else - y = floor(0.5 + ang.y * (32 / 360)) & 31; // 0..360 to 0..32 + y = rint(ang.y * (32 / 360)) & 31; // 0..360 to 0..32 len = invertLengthLog(vlen(vec)); //print("compressed: p:", ftos(p)); print(" y:", ftos(y)); print(" len:", ftos(len), "\n"); diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index e99689d27..1f22515fb 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -84,7 +84,7 @@ string build_mutator_list(string s); // for each element, funcPre is called first, then funcPre and funcPost for all its children, and funcPost last void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass); -#define TIME_TO_NTHS(t,n) floor((t) * (n) + 0.5) +#define TIME_TO_NTHS(t,n) rint((t) * (n)) const int TIME_DECIMALS = 2; const float TIME_FACTOR = 100; diff --git a/qcsrc/lib/color.qh b/qcsrc/lib/color.qh index 3a3a61fe3..ff4b01d2e 100644 --- a/qcsrc/lib/color.qh +++ b/qcsrc/lib/color.qh @@ -184,8 +184,8 @@ string rgb_to_hexcolor(vector rgb) { return strcat( "^x", - DEC_TO_HEXDIGIT(floor(rgb.x * 15 + 0.5)), - DEC_TO_HEXDIGIT(floor(rgb.y * 15 + 0.5)), - DEC_TO_HEXDIGIT(floor(rgb.z * 15 + 0.5)) + DEC_TO_HEXDIGIT(rint(rgb.x * 15)), + DEC_TO_HEXDIGIT(rint(rgb.y * 15)), + DEC_TO_HEXDIGIT(rint(rgb.z * 15)) ); } diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 6c542c8fc..a6ec04315 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -155,7 +155,7 @@ string clockedtime_tostring(int tm, bool hundredths, bool compact) return strcat("0:00.0", hundredths ? "0" : ""); } int acc = hundredths ? 6000 : 600; - tm = floor(tm + 0.5); + tm = rint(tm); int minutes = floor(tm / acc); int tm_without_minutes = tm - minutes * acc; // NOTE: the start digit of s is a placeholder and won't be displayed @@ -179,7 +179,7 @@ string clockedtime_tostring(int tm, bool hundredths, bool compact) ERASEABLE string format_time(float seconds) { - seconds = floor(seconds + 0.5); + seconds = rint(seconds); float days = floor(seconds / 864000); seconds -= days * 864000; float hours = floor(seconds / 36000); diff --git a/qcsrc/menu/item/slider.qc b/qcsrc/menu/item/slider.qc index 30f27f9fb..6a8859f09 100644 --- a/qcsrc/menu/item/slider.qc +++ b/qcsrc/menu/item/slider.qc @@ -162,7 +162,7 @@ // there's no need to round min and max value... also if we did, v could be set // to an out of bounds value due to precision errors if (f > 0 && f < 1 && me.valueStep) - v = floor(0.5 + v / me.valueStep) * me.valueStep; + v = rint(v / me.valueStep) * me.valueStep; me.setValue_noAnim(me, v); if(me.applyButton) if(me.previousValue != me.value) diff --git a/qcsrc/menu/xonotic/keybinder.qc b/qcsrc/menu/xonotic/keybinder.qc index 918826332..f7435f4e6 100644 --- a/qcsrc/menu/xonotic/keybinder.qc +++ b/qcsrc/menu/xonotic/keybinder.qc @@ -356,7 +356,7 @@ void XonoticKeyBinder_doubleClickListBoxItem(entity me, float i, vector where) void XonoticKeyBinder_setSelected(entity me, int i) { // handling of "unselectable" items - i = floor(0.5 + bound(0, i, me.nItems - 1)); + i = rint(bound(0, i, me.nItems - 1)); if (KEYBIND_IS_SPECIAL(KeyBinds_Functions[i])) { if (i > 0 && KeyBinds_Descriptions[i] == KeyBinds_Descriptions[i - 1]) diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index b2f62e123..d30cc724a 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -270,7 +270,7 @@ void race_send_speedaward(float msg) // send the best speed of the round WriteHeader(msg, TE_CSQC_RACE); WriteByte(msg, RACE_NET_SPEED_AWARD); - WriteInt24_t(msg, floor(speedaward_speed+0.5)); + WriteInt24_t(msg, rint(speedaward_speed)); WriteString(msg, speedaward_holder); } @@ -279,7 +279,7 @@ void race_send_speedaward_alltimebest(float msg) // send the best speed WriteHeader(msg, TE_CSQC_RACE); WriteByte(msg, RACE_NET_SPEED_AWARD_BEST); - WriteInt24_t(msg, floor(speedaward_alltimebest+0.5)); + WriteInt24_t(msg, rint(speedaward_alltimebest)); WriteString(msg, speedaward_alltimebest_holder); } -- 2.39.2