]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Replace most floor(...+0.5) instances with rint k9er/use-rint 1391/head
authorotta8634 <k9wolf@pm.me>
Thu, 5 Dec 2024 04:47:07 +0000 (12:47 +0800)
committerotta8634 <k9wolf@pm.me>
Thu, 5 Dec 2024 04:47:07 +0000 (12:47 +0800)
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

14 files changed:
qcsrc/client/announcer.qc
qcsrc/client/hud/hud_config.qc
qcsrc/client/hud/panel/physics.qc
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc
qcsrc/common/gamemodes/gamemode/domination/cl_domination.qc
qcsrc/common/sounds/all.qc
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/lib/color.qh
qcsrc/lib/string.qh
qcsrc/menu/item/slider.qc
qcsrc/menu/xonotic/keybinder.qc
qcsrc/server/race.qc

index cc85f31ccab7b62ee8fc9bfadcb55e47db795b8f..2f7d15d395f9ea7cb2178b634572d4f977f6e123 100644 (file)
@@ -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
index 726b2e78d9565097699d67bcb5a46018d8194d33..a36e6b9cf97cb026db3b180a156cf555ea875354 100644 (file)
@@ -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)
index efbf045cd5d5908d4c3defa10eb7f4c0700121a8..d4c24f8bbc808d94b476ddf2ac2d3cdb6cfaf0bc 100644 (file)
@@ -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
                                {
index af56134c2affa170ff7a142f5cb8b9c17336ee1b..5f707d048e7b6894382495cb477a5a3be55533d8 100644 (file)
@@ -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
 
index 39f45666db19a944fe151ae9ea4467798c27a5a8..0d547c61625af8810830e888556958a071ff6940 100644 (file)
@@ -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);
index b962f7b773ecbef956cceae3ae192d1ce344b4f1..a60dc67adb5a7f96572f900b157407328798bc19 100644 (file)
@@ -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
index c6418674ce099365cab02d585d6104101d89cee3..c0ff5d10f268573a8c43c779d9c8c02ff11f9034 100644 (file)
@@ -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;
index 4ad93f9142685d212400df6aae3783b3725b375c..26024b9fcb728524659ae21633e419f2cc6a2a8d 100644 (file)
@@ -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");
index e99689d27ea0560dc9731faa4cc28dbff56137ab..1f22515fbf462835ca11006c7a21a407314c268b 100644 (file)
@@ -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;
index 3a3a61fe33731b1ad0116acce5ba5ac2982d826c..ff4b01d2e6e5ed25062d856b141e2419a7174154 100644 (file)
@@ -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))
                     );
 }
index 6c542c8fc107c097eb7fe46d38f683d7e83f2bb0..a6ec043150af420b7bc4c9bbd6e662361f936b7e 100644 (file)
@@ -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);
index 30f27f9fbda751336e218757443ca18e488444ed..6a8859f09cbbcd48c21310dbbb036e1a876a0bca 100644 (file)
                                // 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)
index 9188263324a0b6a1b27441adf4c636122bcc95e8..f7435f4e64c28dababc704abd1cb892dc7b8fff5 100644 (file)
@@ -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])
index b2f62e1234f87341f613958755d95221b1ef04b4..d30cc724a5ee0b8fcfd765f6d534bebae699532e 100644 (file)
@@ -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);
 }