]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make cvar_cl_allow_uidtracking an int thanks to a patch to ReplicateVars: replicated...
authorterencehill <piuntn@gmail.com>
Wed, 5 Jan 2022 21:48:13 +0000 (22:48 +0100)
committerterencehill <piuntn@gmail.com>
Wed, 5 Jan 2022 22:14:12 +0000 (23:14 +0100)
cvar_cl_allow_uidtracking as string was networked on connection because code immediately detects a change (null value "" != default value "0"), not possible as int (null value 0 == default value 0)

qcsrc/client/main.qc
qcsrc/client/view.qc
qcsrc/common/replicate.qh
qcsrc/lib/replicate.qh

index ca49edd03c42b05442f35eddd6237f8fba8b1409..5dbfb7209d19127b0600039fbcaeaf16da0ff1ed 100644 (file)
@@ -57,6 +57,8 @@ void CSQC_Init()
                maxclients = i;
        }
 
+       ReplicateVars_Send_All();
+
        // needs to be done so early because of the constants they create
        static_init();
        static_init_late();
@@ -187,7 +189,7 @@ void Shutdown()
        deactivate_minigame();
        HUD_MinigameMenu_Close(NULL, NULL, NULL);
 
-       ReplicateVars(true); // destroy
+       ReplicateVars_Destroy();
 }
 
 void AuditLists()
index d423337df070b8d6818c8599623277d4c647c291..4086e1b199ecb9ba31adc1a44c48045a084ba70c 100644 (file)
@@ -1540,9 +1540,7 @@ void CSQC_UpdateView(entity this, float w, float h)
        stats_get();
        hud = STAT(HUD);
 
-       ReplicateVars(false);
-       if (ReplicateVars_NOT_SENDING())
-               ReplicateVars_DELAY(0.8 + random() * 0.4); // no need to check cvars every frame
+       ReplicateVars_Check();
 
        HUD_Scale_Disable();
 
index 478181029766a3aa7162c4c2bb6faa3e00225d99..127ee308255ceae7287011f1f3b13e013e916525 100644 (file)
@@ -4,7 +4,7 @@
 #if defined(CSQC)
        float autoswitch;
        bool cvar_cl_allow_uid2name;
-       string cvar_cl_allow_uidtracking;
+       float cvar_cl_allow_uidtracking;
        bool cvar_cl_allow_uidranking;
        float cvar_cl_autoscreenshot;
        float cvar_cl_autotaunt;
@@ -83,10 +83,9 @@ REPLICATE(cvar_cl_weapon_switch_fallback_to_impulse, bool, "cl_weapon_switch_fal
 float cvar_cl_newusekeysupported;
 REPLICATE(cvar_cl_newusekeysupported, bool, "cl_newusekeysupported");
 */
+// cvar_cl_allow_uidtracking is handled specially on the server
 #ifdef CSQC
-// handled specially on the server
-// FIXME change cvar_cl_allow_uidtracking type from string to float without breaking playerstats
-REPLICATE(cvar_cl_allow_uidtracking, string, "cl_allow_uidtracking");
+REPLICATE(cvar_cl_allow_uidtracking, int, "cl_allow_uidtracking");
 #endif
 
 REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority");
index 019194a6d55df61e608e4fe9d6c126fb73ed08ad..64d893a103b3dc53de35ca4e5eb736830c352b3a 100644 (file)
@@ -15,7 +15,7 @@
        #if defined(SVQC)
        ACCUMULATE void ReplicateVars(entity this, entity store, string thisname, int i) {}
        #elif defined(CSQC)
-       ACCUMULATE void ReplicateVars(bool would_destroy) {}
+       ACCUMULATE void ReplicateVars(int mode) {}
        #endif
 
        #define REPLICATE_3(fld, type, var) REPLICATE_4(fld, type, var, )
                #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, (fld != cvar(var)), { fld = cvar(var); }, )
                #define REPLICATE_int(fld, var, func) REPLICATE_7(fld, int, var, func, (fld != cvar(var)), { fld = cvar(var); }, )
 
+               void ReplicateVars_Destroy() { ReplicateVars(1); }
+               void ReplicateVars_Send_All() { ReplicateVars(-1); }
+               void ReplicateVars_Check()
+               {
+                       // if a cvar has changed send it and check cvars again next frame
+                       ReplicateVars(0);
+                       if (ReplicateVars_NOT_SENDING()) // if no cvar has changed
+                               ReplicateVars_DELAY(0.8 + random() * 0.4); // check cvars after a while
+               }
+               void ReplicateVars_Send(string cvarname) { localcmd(strcat("cl_cmd sendcvar ", cvarname, "\n")); }
+
                #define REPLICATE_7(fld, type, var, func, check, update, destroy) \
-                       void ReplicateVars(bool would_destroy) \
+                       void ReplicateVars(int mode) \
                        { \
-                               if (would_destroy) { destroy } \
+                               if (mode == 1) { destroy } \
+                               else if (mode == -1) { ReplicateVars_Send(var); update } \
                                else if (ReplicateVars_NOT_SENDING() && check) \
                                { \
-                                       localcmd(strcat("cl_cmd sendcvar ", var, "\n")); \
+                                       ReplicateVars_Send(var); \
                                        ReplicateVars_DELAY_1FRAME(); \
                                        update \
                                        return; \
@@ -87,7 +99,7 @@
                                float thecvar = cvar(cvarname); \
                                if(field != thecvar) \
                                { \
-                                       localcmd(strcat("cl_cmd sendcvar ", cvarname, "\n")); \
+                                       ReplicateVars_Send(cvarname); \
                                        ReplicateVars_DELAY_1FRAME(); \
                                        field = thecvar; \
                                        return; \