]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Limit sendcvar calls to one per frame
authorterencehill <piuntn@gmail.com>
Mon, 19 Aug 2019 17:20:10 +0000 (19:20 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 19 Aug 2019 17:20:10 +0000 (19:20 +0200)
qcsrc/client/defs.qh
qcsrc/client/view.qc
qcsrc/lib/replicate.qh

index 23760d74e1fffdf5e89839db0606d53fc56a53de..c8ed213c98557d74aa325801608efc625750db21 100644 (file)
@@ -175,10 +175,12 @@ REPLICATE(cvar_cl_weaponpriorities[9], string, "cl_weaponpriority9");
 .int cvar_value;
 void ReplicateVars(bool would_destroy)
 {
-       FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
-               string cvarname = sprintf("notification_%s", Get_Notif_CvarName(it));
-               REPLICATE_SIMPLE(it.cvar_value, cvarname);
-       });
+       if (!would_destroy)
+               FOREACH(Notifications, it.nent_type == MSG_CHOICE, {
+                       string cvarname = sprintf("notification_%s", Get_Notif_CvarName(it));
+                       // NOTE: REPLICATE_SIMPLE can return;
+                       REPLICATE_SIMPLE(it.cvar_value, cvarname);
+               });
 }
 
 float bgmtime;
index a7449494f60a4a3afa49b70321ff07699a3e2872..ac4d13a6e906d46a292864674ca2ba9bb5255207 100644 (file)
@@ -1541,7 +1541,6 @@ float oldr_useinfinitefarclip;
 float prev_myteam;
 int lasthud;
 float vh_notice_time;
-float ReplicateVars_time;
 void CSQC_UpdateView(entity this, float w, float h)
 {
        TC(int, w); TC(int, h);
@@ -1568,11 +1567,9 @@ void CSQC_UpdateView(entity this, float w, float h)
        // TODO remove references to sendcvar from cvar descriptions
        // TODO stop server from requesting cvar values to the client on connection as it's no longer necessary
 
-       if (time > ReplicateVars_time) // prevents network spam
-       {
-               ReplicateVars(false);
-               ReplicateVars_time = time + 0.8 + random() * 0.4;
-       }
+       ReplicateVars(false);
+       if (ReplicateVars_NOT_SENDING())
+               ReplicateVars_DELAY(0.8 + random() * 0.4); // no need to check cvars every frame
 
        HUD_Scale_Disable();
 
index 6b1dc20ff237adf823ebc6176f96e566fbd25d4b..7faa2ec2adc28d9d48c55abed01ed3a36c31417f 100644 (file)
                                store.fld = field; \
                        }
        #elif defined(CSQC)
+               float ReplicateVars_time;
+               #define ReplicateVars_NOT_SENDING() (time > ReplicateVars_time)
+               #define ReplicateVars_DELAY(t) ReplicateVars_time = time + t
+               #define ReplicateVars_DELAY_1FRAME() ReplicateVars_time = time
                #define REPLICATE_string(fld, var, func) REPLICATE_7(fld, float, var, func, (fld != cvar_string(var)), { strcpy(fld, cvar_string(var)); }, { strfree(fld); })
                #define REPLICATE_float(fld, var, func) REPLICATE_7(fld, float, var, func, (fld != cvar(var)), { fld = cvar(var); }, )
                #define REPLICATE_bool(fld, var, func) REPLICATE_7(fld, bool, var, func, (fld != cvar(var)), { fld = cvar(var); }, )
                        void ReplicateVars(bool would_destroy) \
                        { \
                                if (would_destroy > 0) { destroy } \
-                               else if (check) \
+                               else if (ReplicateVars_NOT_SENDING() && check) \
                                { \
                                        localcmd(strcat("cl_cmd sendcvar ", var, "\n")); \
+                                       ReplicateVars_DELAY_1FRAME(); \
                                        update \
+                                       return; \
                                } \
                        }
 
                #define REPLICATE_SIMPLE(field, cvarname) MACRO_BEGIN \
-                       if (field != cvar(cvarname)) \
+                       if (ReplicateVars_NOT_SENDING() && field != cvar(cvarname)) \
                        { \
                                localcmd(strcat("cl_cmd sendcvar ", cvarname, "\n")); \
+                               ReplicateVars_DELAY_1FRAME(); \
                                field = cvar(cvarname); \
+                               return; \
                        } \
                MACRO_END
        #endif