From: terencehill Date: Mon, 19 Aug 2019 17:20:10 +0000 (+0200) Subject: Limit sendcvar calls to one per frame X-Git-Tag: xonotic-v0.8.5~1371^2~2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=e37161179426d2bb0b543ab2783d353d24963037;p=xonotic%2Fxonotic-data.pk3dir.git Limit sendcvar calls to one per frame --- diff --git a/qcsrc/client/defs.qh b/qcsrc/client/defs.qh index 23760d74e..c8ed213c9 100644 --- a/qcsrc/client/defs.qh +++ b/qcsrc/client/defs.qh @@ -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; diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index a7449494f..ac4d13a6e 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -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(); diff --git a/qcsrc/lib/replicate.qh b/qcsrc/lib/replicate.qh index 6b1dc20ff..7faa2ec2a 100644 --- a/qcsrc/lib/replicate.qh +++ b/qcsrc/lib/replicate.qh @@ -59,6 +59,10 @@ 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); }, ) @@ -68,18 +72,22 @@ 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