]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Show racetimer's Race/CTS checkpoint splits in console
authorDr. Jaska <drjaska83@gmail.com>
Thu, 30 May 2024 20:46:47 +0000 (20:46 +0000)
committerDr. Jaska <drjaska83@gmail.com>
Thu, 30 May 2024 20:46:47 +0000 (20:46 +0000)
qcsrc/client/hud/panel/racetimer.qc
qcsrc/client/hud/panel/racetimer.qh
qcsrc/client/main.qc

index 9b812b81a302e1e311f76dabcfaabbf378a86dfb..072e6a0d1466a9201b703e5bff94302f6aba9e15 100644 (file)
@@ -1,6 +1,7 @@
 #include "racetimer.qh"
 
 #include <client/draw.qh>
+#include <common/ent_cs.qh>
 
 // Race timer (#8)
 
@@ -173,6 +174,25 @@ void HUD_RaceTimer ()
                                        s = MakeRaceString(race_checkpoint, 0, -1, 0, 0, race_previousbestname);
                                if(race_time)
                                        forcetime = TIME_ENCODED_TOSTRING(race_time, false);
+
+                               // store checkpoint splits string for later printing
+                               // check if we advanced to next cp
+                               if (!entcs_IsSpectating(player_localnum) && race_checkpoint_splits_previous != race_checkpoint)
+                               {
+                                       // are we somehow overwriting something? how?
+                                       if (race_checkpoint_splits[race_checkpoint_splits_previous+1])
+                                       {
+                                               LOG_WARNF("race_checkpoint_splits: overwriting #%f %s\n",
+                                                       race_checkpoint_splits_previous+1,
+                                                       race_checkpoint_splits[race_checkpoint_splits_previous+1]);
+                                               strfree(race_checkpoint_splits[race_checkpoint_splits_previous+1]);
+                                       }
+
+                                       strcpy(race_checkpoint_splits[race_checkpoint_splits_previous+1], sprintf("%s %s", forcetime, s));
+
+                                       // don't use ++ in case that checkpoints have jumps like 10th to 20th
+                                       race_checkpoint_splits_previous = race_checkpoint;
+                               }
                        }
                }
                else
index a12e69f7987a3575905a5879fec6f5cb81c70186..2efcd08150431b7d8044841e22d44fc99c46ddee 100644 (file)
@@ -9,6 +9,8 @@ float race_checkpoint;
 float race_time;
 float race_laptime;
 float race_checkpointtime;
+string race_checkpoint_splits[255];
+int race_checkpoint_splits_previous = 0;
 float race_previousbesttime;
 float race_mypreviousbesttime;
 string race_previousbestname;
index 650f80c01fbca61e833621bfcb9119afbb977b6a..8116b1d34906af2f8484a0d418a17a10f22f2bdf 100644 (file)
@@ -1195,6 +1195,29 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                                race_penaltyaccumulator = 0;
                                race_laptime = time; // valid
                        }
+
+                       // show checkpoint splits after a run
+                       // specs can switch players for confusing splits, deny service
+                       // if hit 255 finish line or if finish line is 0 or if restarted
+                       if (!entcs_IsSpectating(player_localnum)
+                       && (race_checkpoint == 255
+                       || race_checkpoint < race_checkpoint_splits_previous))
+                       {
+                               LOG_HELP("Checkpoint Splits:\n");
+                               for (int i = 0; i < 255; ++i)
+                               {
+                                       // does this index have a split?
+                                       if (race_checkpoint_splits[i])
+                                       {
+                                               // print it and free it
+                                               LOG_HELP(race_checkpoint_splits[i]);
+                                               strfree(race_checkpoint_splits[i]);
+                                       }
+                               }
+
+                               // allow registering 0th cp in case we start at 254 start line
+                               race_checkpoint_splits_previous = 0;
+                       }
                        break;
 
                case RACE_NET_CHECKPOINT_CLEAR: