]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add support for racesplits as spectator.
authorDes <xon@damianv.com.ar>
Mon, 16 Sep 2024 14:29:47 +0000 (11:29 -0300)
committerDes <xon@damianv.com.ar>
Mon, 16 Sep 2024 14:29:47 +0000 (11:29 -0300)
This will only show checkpoints hitted when you are spectating, not cp hits by
player before you started spectating them.

qcsrc/client/hud/panel/racesplits.qc
qcsrc/client/hud/panel/racetimer.qc

index facb0dfee56b3c18b703991de9d1e1880a1fcc3d..a0ffb3a68f680f37860cecb80fae32fcbd3a8103 100644 (file)
@@ -64,43 +64,35 @@ void HUD_RaceSplits()
        string s;
        if(!autocvar__hud_configure)
        {
-               if(spectatee_status)
-               {
-               //      RaceSplit(_("Splits not supported while spectating"));
+               int mlines[HUD_RACESPLITS_MAX_NRLINES];
+               int ln = nrlines -1;
+               // show up to race_nextcheckpoint (not including) or everything
+               // if you are before start (0 or 254)
+               // (except race_laptime != 0 for race, means next is
+               // start+finish so don't show previous lap finish)
+               int i;
+               if (race_checkpoint != 0 && race_checkpoint != 254)
+               { // middle of run/race
+                       i = race_checkpoint;
                }
-
-               if(!spectatee_status)
+               else if (ISGAMETYPE(RACE) && race_nextcheckpoint == 0)
+               { // before start, but on race, so don't keep old finish visible
+                       i = 253;
+               }
+               else
+               { // before start, not on race (cts), keep old run cps visible
+                       i = 255;
+               }
+               for (; ln >= 0 && i >= 0; --i)
                {
-                       int mlines[HUD_RACESPLITS_MAX_NRLINES];
-                       int ln = nrlines -1;
-                       // show up to race_nextcheckpoint (not including) or everything
-                       // if you are before start (0 or 254)
-                       // (except race_laptime != 0 for race, means next is
-                       // start+finish so don't show previous lap finish)
-                       int i;
-                       if (race_checkpoint != 0 && race_checkpoint != 254)
-                       { // middle of run/race
-                               i = race_checkpoint;
-                       }
-                       else if (ISGAMETYPE(RACE) && race_nextcheckpoint == 0)
-                       { // before start, but on race, so don't keep old finish visible
-                               i = 253;
-                       }
-                       else
-                       { // before start, not on race (cts), keep old run cps visible
-                               i = 255;
-                       }
-                       for (; ln >= 0 && i >= 0; --i)
+                       if (race_checkpoint_splits[i])
                        {
-                               if (race_checkpoint_splits[i])
-                               {
-                                       mlines[ln] = i;
-                                       --ln;
-                               }
+                               mlines[ln] = i;
+                               --ln;
                        }
-                       for (int j = 0; j < nrlines; ++j)
-                               RaceSplit(race_checkpoint_splits[mlines[j]]);
                }
+               for (int j = 0; j < nrlines; ++j)
+                       RaceSplit(race_checkpoint_splits[mlines[j]]);
        }
        else
        {
index 0d8f7ac27e371f8b6a7bb36f5baffe061176348a..8742183c11035b7d6c135809dfbccbb32741d16c 100644 (file)
@@ -10,6 +10,7 @@ float racetimer_lastcheckpoint;
 string racetimer_checkpoint_comparison;
 string racetimer_checkpoint_time;
 bool racetimer_have_stored_splits;
+float racetimer_have_stored_splits_player;
 
 // Race timer (#8)
 
@@ -104,13 +105,14 @@ string MakeRaceString(int cp, float mytime, float theirtime, float othertime, fl
                return strcat(col, sprintf("%s (%s %s)", cpname, timestr, strcat(ColorTranslateRGB(theirname), col, lapstr)));
 }
 
-void ClearRaceSplits() {
+void ClearRaceSplits(bool quiet) {
        bool once = true;
        racetimer_lastcheckpoint = 0;
        for (int i = 0; i <= 255; ++i)
        {
                if(race_checkpoint_splits[i]
-               && autocvar_cl_race_checkpoint_splits_console)
+               && autocvar_cl_race_checkpoint_splits_console
+               && !quiet)
                {
                        if(once)
                        {
@@ -126,17 +128,21 @@ void ClearRaceSplits() {
 
 void StoreRaceSplits(float race_checkpoint, string forcetime, string s) {
        // store checkpoint splits string for later printing
-       if (!entcs_IsSpectating(player_localnum))
+       if (spectatee_status
+           && racetimer_have_stored_splits
+           && racetimer_have_stored_splits_player != spectatorlist[0]) // we changed spectated player
        {
-               // 0 or 255 go to 255 as finish, strcpy does the free if needed
-               strcpy(race_checkpoint_splits[race_checkpoint ? race_checkpoint : 255], (forcetime != "") ? sprintf("%s %s", forcetime, s) : s);
+               ClearRaceSplits(true);
        }
 
+       // 0 or 255 go to 255 as finish, strcpy does the free if needed
+       strcpy(race_checkpoint_splits[race_checkpoint ? race_checkpoint : 255], (forcetime != "") ? sprintf("%s %s", forcetime, s) : s);
        // cache
        racetimer_lastcheckpoint = race_checkpoint;
        strcpy(racetimer_checkpoint_comparison, s);
        strcpy(racetimer_checkpoint_time, forcetime);
        racetimer_have_stored_splits = true;
+       racetimer_have_stored_splits_player = ((spectatee_status) ? spectatorlist[0] : player_localnum);
 }
 
 void HUD_RaceTimer ()
@@ -213,7 +219,8 @@ void HUD_RaceTimer ()
                {
                        if(race_checkpoint != 254 && race_time != 0)
                        {
-                               if (race_checkpoint == racetimer_lastcheckpoint)
+                               if (race_checkpoint == racetimer_lastcheckpoint // same cp *and* player
+                                   && racetimer_have_stored_splits_player == (spectatee_status ? spectatorlist[0] : player_localnum))
                                {
                                        // use cached strings
                                        s = racetimer_checkpoint_comparison;
@@ -255,7 +262,7 @@ void HUD_RaceTimer ()
                        {
                                // clean cp splits on start
                                if(racetimer_have_stored_splits && race_time == 0)
-                                       ClearRaceSplits();
+                                       ClearRaceSplits(false);
                        }
                }
                else
@@ -313,7 +320,7 @@ void HUD_RaceTimer ()
        else
        {
                if(racetimer_have_stored_splits && (race_time == 0 || time < STAT(GAMESTARTTIME)))
-                       ClearRaceSplits();
+                       ClearRaceSplits(false);
 
                if(race_mycheckpointtime)
                {