]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Network player speed on checkpoints messages and use it for strafehud start speed
authorDes - <gitlab@damianv.com.ar>
Wed, 9 Oct 2024 16:27:20 +0000 (16:27 +0000)
committerterencehill <piuntn@gmail.com>
Wed, 9 Oct 2024 16:27:20 +0000 (16:27 +0000)
qcsrc/client/hud/panel/racetimer.qh
qcsrc/client/hud/panel/strafehud.qc
qcsrc/client/main.qc
qcsrc/server/race.qc

index d213584df1eb74b437d3fb12a8ad76a6f8a227fc..054fe82870636ccc85cd2c719b423ce396b52b26 100644 (file)
@@ -7,6 +7,8 @@ bool autocvar_hud_panel_racetimer_dynamichud    = true;
 // QUALIFYING
 float race_checkpoint;
 float race_time;
+float race_timespeed;
+float race_timebestspeed;
 float race_laptime;
 float race_checkpointtime;
 string race_checkpoint_splits[256];
@@ -15,7 +17,9 @@ float race_mypreviousbesttime;
 string race_previousbestname;
 float race_nextcheckpoint;
 float race_nextbesttime;
+float race_nextbestspeed;
 float race_mybesttime;
+float race_mybestspeed;
 string race_nextbestname;
 float race_penaltyaccumulator; // qualifying: total penalty time in tenths
 float race_penaltyeventtime; // time when the player got the penalty
index f81ef075e6842aa344297eaf25bdb65ffe2f94cf..da198d93415747e7a267c6628b551e98bfe1c833 100644 (file)
@@ -1245,7 +1245,7 @@ void HUD_StrafeHUD()
                                if((race_checkpointtime > 0) && (starttime != race_checkpointtime))
                                {
                                        starttime = race_checkpointtime;
-                                       startspeed = speed;
+                                       startspeed = race_timespeed;
                                }
                        }
 
index 9cf0185ed268b7d01e4bdbe35b4221ab3d4b72f2..db6d014419eadbd77b5b6faec4d8c403ece6fe13 100644 (file)
@@ -1181,6 +1181,9 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                        race_previousbesttime = ReadInt24_t();
                        race_mypreviousbesttime = ReadInt24_t();
                        string pbestname = ReadString();
+                       race_timespeed = ReadFloat();
+                       race_timebestspeed = ReadFloat();
+                       race_mybestspeed = ReadFloat();
                        if(autocvar_cl_race_cptimes_onlyself)
                        {
                                race_previousbesttime = race_mypreviousbesttime;
@@ -1215,10 +1218,15 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew)
                        if(b != RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING) // not while spectating (matches server)
                                race_mybesttime = ReadInt24_t();
                        string newname = ReadString();
+                       race_nextbestspeed = ReadFloat();
+                       if(b != RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING) // not while spectating (matches server)
+                               race_mybestspeed = ReadFloat();
                        if(autocvar_cl_race_cptimes_onlyself && b != RACE_NET_CHECKPOINT_NEXT_SPEC_QUALIFYING)
                        {
                                race_nextbesttime = race_mybesttime;
+                               race_nextbestspeed = race_mybestspeed;
                                race_mybesttime = 0;
+                               race_mybestspeed = 0;
                                strcpy(race_nextbestname, "");
                        }
                        else
index 078f9e1923a7bf300adb9ec879d790e59567693d..d85761a4ccb95ecd33bd8698b7fd733ff8122dcf 100644 (file)
@@ -157,12 +157,14 @@ const float MAX_CHECKPOINTS = 255;
 .entity sprite;
 
 float race_checkpoint_records[MAX_CHECKPOINTS];
+float race_checkpoint_recordspeeds[MAX_CHECKPOINTS];
 string race_checkpoint_recordholders[MAX_CHECKPOINTS];
 float race_checkpoint_lasttimes[MAX_CHECKPOINTS];
 float race_checkpoint_lastlaps[MAX_CHECKPOINTS];
 entity race_checkpoint_lastplayers[MAX_CHECKPOINTS];
 
 .float race_checkpoint_record[MAX_CHECKPOINTS];
+.float race_checkpoint_recordspeed[MAX_CHECKPOINTS];
 
 float race_highest_checkpoint;
 float race_timed_checkpoint;
@@ -211,13 +213,17 @@ void race_SendNextCheckpoint(entity e, float spec) // qualifying only
 
        int cp = e.race_checkpoint;
        float recordtime;
+       float recordspeed;
        float myrecordtime = e.race_checkpoint_record[cp];
+       float myrecordspeed = e.race_checkpoint_recordspeed[cp];
        string recordholder;
        if (autocvar_g_race_cptimes_onlyself) {
                recordtime = myrecordtime;
+               recordspeed = myrecordspeed;
                recordholder = "";
        } else {
                recordtime = race_checkpoint_records[cp];
+               recordspeed = race_checkpoint_recordspeeds[cp];
                recordholder = race_checkpoint_recordholders[cp];
 
                if(recordholder == e.netname)
@@ -244,6 +250,10 @@ void race_SendNextCheckpoint(entity e, float spec) // qualifying only
                if(!spec)
                        WriteInt24_t(MSG_ONE, myrecordtime);
                WriteString(MSG_ONE, recordholder);
+               // All speeds networked as floats to have decimal precision
+               WriteFloat(MSG_ONE, recordspeed);
+               if(!spec)
+                       WriteFloat(MSG_ONE, myrecordspeed);
        });
 }
 
@@ -514,6 +524,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
        if(g_race_qualifying)
        {
                float recordtime;
+               float recordtimespeed;
                string recordholder;
 
                if(tvalid)
@@ -522,11 +533,13 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                        {
                                // return their own checkpoint time
                                recordtime = e.race_checkpoint_record[cp];
+                               recordtimespeed = e.race_checkpoint_recordspeed[cp];
                                recordholder = "";
                        }
                        else
                        {
                                recordtime = race_checkpoint_records[cp];
+                               recordtimespeed = race_checkpoint_recordspeeds[cp];
                                // make a tempstring copy, as we'll possibly strunzone it
                                recordholder = strcat(race_checkpoint_recordholders[cp]);
 
@@ -545,6 +558,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                                if(t < recordtime || recordtime == 0)
                                {
                                        race_checkpoint_records[cp] = t;
+                                       race_checkpoint_recordspeeds[cp] = vlen(vec2(e.velocity));
                                        strcpy(race_checkpoint_recordholders[cp], e.netname);
                                        if(g_race_qualifying)
                                                FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.race_checkpoint == cp, { race_SendNextCheckpoint(it, 0); });
@@ -557,6 +571,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                        // dummies
                        t = 0;
                        recordtime = 0;
+                       recordtimespeed = 0;
                        recordholder = "";
                }
 
@@ -576,6 +591,10 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                                                WriteInt24_t(MSG_ONE, recordtime); // previously best time
                                                WriteInt24_t(MSG_ONE, ((tvalid) ? it.race_checkpoint_record[cp] : 0)); // previously best time
                                                WriteString(MSG_ONE, recordholder); // record holder
+                                               // All speeds networked as floats to have decimal precision
+                                               WriteFloat(MSG_ONE, vlen(vec2(e.velocity))); // speed of cp hit
+                                               WriteFloat(MSG_ONE, recordtimespeed); // speed of previous best cp hit
+                                               WriteFloat(MSG_ONE, ((tvalid) ? it.race_checkpoint_recordspeed[cp] : 0)); // speed of my previous best cp hit
                                        }
                                });
                        }
@@ -586,7 +605,10 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
                        float myrecordtime = e.race_checkpoint_record[cp];
                        if(t != 0)
                                if(t < myrecordtime || myrecordtime == 0)
+                               {
                                        e.race_checkpoint_record[cp] = t;
+                                       e.race_checkpoint_recordspeed[cp] = vlen(vec2(e.velocity));
+                               }
                }
        }
        else // RACE! Not Qualifying
@@ -1219,7 +1241,10 @@ spawnfunc(info_player_race)
 void race_ClearPlayerRecords(entity player)
 {
        for(int i = 0; i < MAX_CHECKPOINTS; ++i)
+       {
                player.race_checkpoint_record[i] = 0;
+               player.race_checkpoint_recordspeed[i] = 0;
+       }
 }
 
 void race_ClearRecords()
@@ -1227,6 +1252,7 @@ void race_ClearRecords()
        for(int j = 0; j < MAX_CHECKPOINTS; ++j)
        {
                race_checkpoint_records[j] = 0;
+               race_checkpoint_recordspeeds[j] = 0;
                strfree(race_checkpoint_recordholders[j]);
        }