]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Show compact times (1.34 instead of 0:01.34) in some places (messages, scoreboard... 1015/head
authorterencehill <piuntn@gmail.com>
Tue, 26 Apr 2022 17:55:22 +0000 (19:55 +0200)
committerterencehill <piuntn@gmail.com>
Tue, 26 Apr 2022 17:55:22 +0000 (19:55 +0200)
12 files changed:
qcsrc/client/hud/panel/racetimer.qc
qcsrc/client/hud/panel/score.qc
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc
qcsrc/common/gamemodes/gamemode/race/cl_race.qc
qcsrc/common/gamemodes/gamemode/race/sv_race.qc
qcsrc/common/notifications/all.qh
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/lib/string.qh
qcsrc/server/command/getreplies.qc
qcsrc/server/race.qc

index 7ecdf1a8216afd975b9f8054ac49fa8cf0d2c153..9b812b81a302e1e311f76dabcfaabbf378a86dfb 100644 (file)
@@ -67,12 +67,12 @@ string MakeRaceString(int cp, float mytime, float theirtime, float othertime, fl
                if(mytime >= theirtime)
                        timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS));
                else
-                       timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime));
+                       timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime), false);
                col = "^3";
                if(mytime >= othertime)
                        othertimestr = strcat("+", ftos_decimals(mytime - othertime, TIME_DECIMALS));
                else
-                       othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime));
+                       othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime), false);
                othercol = "^7";
        }
 
@@ -172,7 +172,7 @@ void HUD_RaceTimer ()
                                else
                                        s = MakeRaceString(race_checkpoint, 0, -1, 0, 0, race_previousbestname);
                                if(race_time)
-                                       forcetime = TIME_ENCODED_TOSTRING(race_time);
+                                       forcetime = TIME_ENCODED_TOSTRING(race_time, false);
                        }
                }
                else
@@ -220,7 +220,7 @@ void HUD_RaceTimer ()
 
                if(race_laptime && race_checkpoint != 255)
                {
-                       s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime));
+                       s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime), false);
                        str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '0.6 0.6 0' * mySize.y));
                        drawstring(str_pos, s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL);
                }
index 164f60534d5138ee42310131e10af4dc5eb47944..c33fce08b16a1ae80a9d3a256e99551ea7424167 100644 (file)
@@ -179,7 +179,7 @@ void HUD_Score()
                                pl = NULL;
 
                score = me.(scores(ps_primary));
-               timer = TIME_ENCODED_TOSTRING(score);
+               timer = TIME_ENCODED_TOSTRING(score, false);
 
                draw_beginBoldFont();
                if (pl && ((!(scores_flags(ps_primary) & SFL_ZERO_IS_WORST)) || score)) {
index ed8715e022909cd1545784a29c222d3d1d130c92..624a9e8b52d05b482e0fcc3b4c1c50a09d74ae70 100644 (file)
@@ -1655,7 +1655,7 @@ vector Scoreboard_Rankings_Draw(vector pos, string ranktitle, entity pl, vector
 
                str = count_ordinal(i+1);
                drawstring(pos + text_ofs, str, hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL);
-               drawstring(pos + text_ofs + eX * ranksize, TIME_ENCODED_TOSTRING(t), hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL);
+               drawstring(pos + text_ofs + eX * ranksize, TIME_ENCODED_TOSTRING(t, true), hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL);
                str = ColorTranslateRGB(grecordholder[i]);
                if(cut)
                        str = textShortenToWidth(str, namesize, hud_fontsize, stringwidth_colors);
index 45457d1a4d8adb895ea40b39e4ad89b458d2b495..3e7c4159cf257baa0f6dbb411e2b337ca30a89e5 100644 (file)
@@ -325,7 +325,7 @@ MUTATOR_HOOKFUNCTION(cts, GetRecords)
                                continue;
 
                        string h = race_readName(MapInfo_Map_bspname, 1);
-                       ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
+                       ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r, false)), " ", h, "\n");
                }
        }
 
index 4311ce777aa813560420fa6cb2bc3fb0df62696f..a551b1546b6c5355e443d7dcc360c1fb22b75b88 100644 (file)
@@ -31,10 +31,10 @@ int race_CheckName(string net_name)
 void race_showTime(string text, vector pos, vector timeText_ofs, float theTime, vector textSize, float f)
 {
        drawstring_aspect(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-       drawstring_aspect(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+       drawstring_aspect(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime, false), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
        if (f < 1) {
                drawstring_aspect_expanding(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
-               drawstring_aspect_expanding(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
+               drawstring_aspect_expanding(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime, false), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f);
        }
 }
 
index 0ffda17a96407171e9e1cbada4d045894a80ba3b..f06df370d0668bb271f5ad1b43e15ec6c30ea387 100644 (file)
@@ -350,7 +350,7 @@ MUTATOR_HOOKFUNCTION(rc, GetRecords)
                                continue;
 
                        string h = race_readName(MapInfo_Map_bspname, 1);
-                       ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
+                       ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r, false)), " ", h, "\n");
                }
        }
 
index 45259741b355aa7d703c0e4db40a276abb53be5e..fb06d264af250212cea590a3e0b9b51224281898 100644 (file)
@@ -358,8 +358,8 @@ float autocvar_notification_show_sprees_center_specialonly = true;
        f1points: point or points depending on f1
        f1ord: count_ordinal of f1
        f1time: process_time of f1
-       f1race_time: mmssth of f1
-       f2race_time: mmssth of f2
+       f1race_time: TIME_ENCODED_TOSTRING of f1
+       f2race_time: TIME_ENCODED_TOSTRING of f2
        race_col: color of race time/position (i.e. good or bad)
        race_diff: show time difference between f2 and f3
        missing_teams: show which teams still need players
@@ -418,11 +418,11 @@ string BUFF_NAME(int i);
        ARG_CASE(ARG_CS,        "f1points",      (f1 == 1 ? _("point") : _("points"))) \
        ARG_CASE(ARG_CS_SV,     "f1ord",         count_ordinal(f1)) \
        ARG_CASE(ARG_CS_SV,     "f1time",        process_time(2, f1)) \
-       ARG_CASE(ARG_CS_SV_HA,  "f1race_time",   mmssth(f1)) \
-       ARG_CASE(ARG_CS_SV_HA,  "f2race_time",   mmssth(f2)) \
-       ARG_CASE(ARG_CS_SV_HA,  "f3race_time",   mmssth(f3)) \
+       ARG_CASE(ARG_CS_SV_HA,  "f1race_time",   TIME_ENCODED_TOSTRING(f1, true)) \
+       ARG_CASE(ARG_CS_SV_HA,  "f2race_time",   TIME_ENCODED_TOSTRING(f2, true)) \
+       ARG_CASE(ARG_CS_SV_HA,  "f3race_time",   TIME_ENCODED_TOSTRING(f3, true)) \
        ARG_CASE(ARG_CS_SV,     "race_col",      CCR(((f1 == 1) ? "^F1" : "^F2"))) \
-       ARG_CASE(ARG_CS_SV,     "race_diff",     ((f2 > f3) ? sprintf(CCR("^1[+%s]"), mmssth(f2 - f3)) : sprintf(CCR("^2[-%s]"), mmssth(f3 - f2)))) \
+       ARG_CASE(ARG_CS_SV,     "race_diff",     ((f2 > f3) ? sprintf(CCR("^1[+%s]"), TIME_ENCODED_TOSTRING(f2 - f3, true)) : sprintf(CCR("^2[-%s]"), TIME_ENCODED_TOSTRING(f3 - f2, true)))) \
        ARG_CASE(ARG_CS,        "missing_teams", notif_arg_missing_teams(f1)) \
        ARG_CASE(ARG_CS,        "pass_key",      getcommandkey(_("drop flag"), "+use")) \
        ARG_CASE(ARG_CS,        "nade_key",      getcommandkey(_("throw nade"), "dropweapon")) \
index 0b1b96880dc93985a6711c17a80183a795de0495..8ef6b2019f07c4a08d5467897214d5717ce03c56 100644 (file)
@@ -384,7 +384,7 @@ string ScoreString(int pFlags, float pValue)
        else if(pFlags & SFL_RANK)
                valstr = (pValue < 256 ? count_ordinal(pValue) : _("N/A"));
        else if(pFlags & SFL_TIME)
-               valstr = TIME_ENCODED_TOSTRING(pValue);
+               valstr = TIME_ENCODED_TOSTRING(pValue, true);
        else
                valstr = ftos(pValue);
 
index 3ca09994ac3be97da0b957c4c512138255b832bd..3c12463d3f536a870592e75a11fc32743d39789c 100644 (file)
@@ -88,7 +88,7 @@ void depthfirst(entity start, .entity up, .entity downleft, .entity right, void(
 
 const int TIME_DECIMALS = 2;
 const float TIME_FACTOR = 100;
-#define TIME_ENCODED_TOSTRING(n) mmssth(n)
+#define TIME_ENCODED_TOSTRING(n, compact) mmssth(n, compact)
 #define RACE_RECORD "/race100record/"
 #define CTS_RECORD "/cts100record/"
 #define CTF_RECORD "/ctf100record/"
index 6a37d5edd4bf1727d09175f683be74bff1f43671..c2e77aacc404eda78bc9303a80588fbdb45cc8ca 100644 (file)
@@ -139,23 +139,39 @@ string seconds_tostring(float seconds)
 
 /// \param[in] tm integer clocked time in tenths or hundredths, CANNOT be negative
 /// \param[in] hundredths if true append hundredths too, otherwise only tenths
+/// \param[in] compact if true leading 0s are omitted (except the seconds unit digit)
 /// \return clocked time as "m:ss.t" or "m:ss.th" string (rounded)
 ERASEABLE
-string clockedtime_tostring(int tm, bool hundredths)
+string clockedtime_tostring(int tm, bool hundredths, bool compact)
 {
        if (tm < 0)
-               return strcat("0:00:0", hundredths ? "0" : "");
+       {
+               if (compact)
+                       return strcat("0.0", hundredths ? "0" : "");
+               else
+                       return strcat("0:00.0", hundredths ? "0" : "");
+       }
        int acc = hundredths ? 6000 : 600;
        tm = floor(tm + 0.5);
        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
        string s = ftos(acc * 10 + tm_without_minutes);
-       return strcat(ftos(minutes), ":", substring(s, 1, 2), ".", substring(s, 3, hundredths ? 2 : 1));
+       if (!compact || minutes > 0)
+               return strcat(ftos(minutes), ":", substring(s, 1, 2), ".", substring(s, 3, hundredths ? 2 : 1));
+
+       int ofs = 2, digits = 1;
+       if (tm_without_minutes >= 10 * (hundredths ? 100 : 10))
+       {
+               ofs = 1;
+               digits = 2;
+       }
+       return strcat(substring(s, ofs, digits), ".", substring(s, 3, hundredths ? 2 : 1));
+
 }
 
-#define mmsst(tm) clockedtime_tostring(tm, false)
-#define mmssth(tm) clockedtime_tostring(tm, true)
+#define mmsst(tm, compact) clockedtime_tostring(tm, false, compact)
+#define mmssth(tm, compact) clockedtime_tostring(tm, true, compact)
 
 ERASEABLE
 string format_time(float seconds)
index 3f82484abe7d9e9e07fd4de62d2dadfddab206a9..b6bde0c68c210121793de4b84275bc83e195e7f6 100644 (file)
@@ -59,7 +59,7 @@ string getrankings()
 
                n = race_readName(map, i);
                p = count_ordinal(i);
-               s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
+               s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t, false)), " ", n, "\n");
        }
 
        MapInfo_ClearTemps();
index 4ecda0a9a09732b0411f164b1d4e3c175a729005..71ab29060d99747c7ac58e6ca53701bcf71c7519 100644 (file)
@@ -61,7 +61,7 @@ void write_recordmarker(entity pl, float tstart, float dt)
     // also write a marker into demo files for demotc-race-record-extractor to find
     stuffcmd(pl,
              strcat(
-                 strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt))),
+                 strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt), false)),
                  " ", ftos(tstart), " ", ftos(dt), "\n"));
 }