From: terencehill Date: Thu, 6 Jan 2022 22:48:34 +0000 (+0100) Subject: Make work the string fixup function called inside REPLICATE so we can get rid of... X-Git-Tag: xonotic-v0.8.5~204^2~10 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=874747aabfd4c231b79083ad7dccc5534f477b6e;p=xonotic%2Fxonotic-data.pk3dir.git Make work the string fixup function called inside REPLICATE so we can get rid of all the GetCvars_handleString_Fixup calls --- diff --git a/qcsrc/common/replicate.qh b/qcsrc/common/replicate.qh index a8818718b..2c362be79 100644 --- a/qcsrc/common/replicate.qh +++ b/qcsrc/common/replicate.qh @@ -21,8 +21,6 @@ REPLICATE_FIELD(float, cvar_cl_voice_directional_taunt_attenuation); REPLICATE_FIELD(bool, cvar_cl_weapon_switch_reload); REPLICATE_FIELD(bool, cvar_cl_weapon_switch_fallback_to_impulse); REPLICATE_FIELD(int, cvar_cl_weaponimpulsemode); -REPLICATE_FIELD(string, cvar_cl_weaponpriority); -REPLICATE_FIELD(string, cvar_cl_weaponpriorities[10]); REPLICATE_FIELD(string, cvar_g_xonoticversion); #endif @@ -57,16 +55,4 @@ float cvar_cl_newusekeysupported; REPLICATE(cvar_cl_newusekeysupported, bool, "cl_newusekeysupported"); */ -REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority"); - -REPLICATE(cvar_cl_weaponpriorities[0], string, "cl_weaponpriority0"); -REPLICATE(cvar_cl_weaponpriorities[1], string, "cl_weaponpriority1"); -REPLICATE(cvar_cl_weaponpriorities[2], string, "cl_weaponpriority2"); -REPLICATE(cvar_cl_weaponpriorities[3], string, "cl_weaponpriority3"); -REPLICATE(cvar_cl_weaponpriorities[4], string, "cl_weaponpriority4"); -REPLICATE(cvar_cl_weaponpriorities[5], string, "cl_weaponpriority5"); -REPLICATE(cvar_cl_weaponpriorities[6], string, "cl_weaponpriority6"); -REPLICATE(cvar_cl_weaponpriorities[7], string, "cl_weaponpriority7"); -REPLICATE(cvar_cl_weaponpriorities[8], string, "cl_weaponpriority8"); -REPLICATE(cvar_cl_weaponpriorities[9], string, "cl_weaponpriority9"); #endif diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 7ef3cc1e8..f44668061 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -826,3 +826,12 @@ NET_HANDLE(w_muzzleflash, bool isNew) #endif #endif + +#ifdef SVQC +string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo) +{ + string o = W_FixWeaponOrder_ForceComplete(wo); + strcpy(CS_CVAR(this).weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(o)); + return o; +} +#endif diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 24057a0b8..0016790c8 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -403,9 +403,25 @@ REPLICATE(cvar_cl_accuracy_data_receive, bool, "cl_accuracy_data_receive"); #ifdef SVQC void wframe_send(entity actor, entity weaponentity, int wepframe, float attackrate, bool restartanim); -#endif -#ifdef SVQC void W_MuzzleFlash(Weapon thiswep, entity actor, .entity weaponentity, vector shotorg, vector shotdir); + +string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo); +string W_FixWeaponOrder_AllowIncomplete(entity this, string order); #endif + +REPLICATE_FIELD(string, cvar_cl_weaponpriority); +REPLICATE_FIELD(string, cvar_cl_weaponpriorities[10]); +REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList); +REPLICATE(cvar_cl_weaponpriorities[0], string, "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[1], string, "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[2], string, "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[3], string, "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[4], string, "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[5], string, "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[6], string, "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[7], string, "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[8], string, "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete); +REPLICATE(cvar_cl_weaponpriorities[9], string, "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete); + #endif diff --git a/qcsrc/lib/replicate.qh b/qcsrc/lib/replicate.qh index 44a185d49..873db04b8 100644 --- a/qcsrc/lib/replicate.qh +++ b/qcsrc/lib/replicate.qh @@ -1,5 +1,9 @@ #pragma once +#ifdef SVQC +// copies a string to a tempstring (so one can strunzone it) +string strcat1(string s) = #115; // FRIK_FILE +#endif #if defined(CSQC) #define REPLICATE_FIELD(type, name) type name @@ -34,7 +38,7 @@ { strfree(field); }, \ { \ /* also initialize to the default value of func when requesting cvars */ \ - string s = func(field); \ + string s = func(this, strcat1(field)); \ if (s != field) \ { \ strcpy(field, s); \ diff --git a/qcsrc/server/command/getreplies.qc b/qcsrc/server/command/getreplies.qc index c6e967de3..96ad99af0 100644 --- a/qcsrc/server/command/getreplies.qc +++ b/qcsrc/server/command/getreplies.qc @@ -304,6 +304,7 @@ string getmonsterlist() ============= GetCvars ============= +Superseded by REPLICATE Called with: 0: sends the request >0: receives a cvar from name=argv(f) value=argv(f+1) @@ -373,12 +374,6 @@ void GetCvars_handleFloatOnce(entity this, entity store, string thisname, float stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n")); } } -string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo) -{ - string o = W_FixWeaponOrder_ForceComplete(wo); - strcpy(CS_CVAR(this).weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(o)); - return o; -} /** * @param f -1: cleanup, 0: request, 1: receive @@ -401,18 +396,6 @@ void GetCvars(entity this, entity store, int f) ReplicateVars(this, store, s, f); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete); - GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete); - // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early) if (f > 0) { diff --git a/qcsrc/server/main.qh b/qcsrc/server/main.qh index e189601a7..172e0a9e5 100644 --- a/qcsrc/server/main.qh +++ b/qcsrc/server/main.qh @@ -28,9 +28,6 @@ void remove_safely(entity e); void remove_unsafely(entity e); -// copies a string to a tempstring (so one can strunzone it) -string strcat1(string s) = #115; // FRIK_FILE - #ifdef PROFILING float client_cefc_accumulator; float client_cefc_accumulatortime; diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index ee5d18a69..c9c8ab851 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -317,8 +317,17 @@ MUTATOR_HOOKABLE(PlayerPreThink, EV_PlayerPreThink); /**/ MUTATOR_HOOKABLE(GetPressedKeys, EV_GetPressedKeys); -/** is meant to call GetCvars_handle*(get_cvars_s, get_cvars_f, cvarfield, "cvarname") for cvars this mutator needs from the client */ -// NOTE: requesting cvar values (get_cvars_f 0) is deprecated +/** + * is meant to call GetCvars_handle* for cvars this mutator needs from the client, e.g.: + MUTATOR_HOOKFUNCTION(mymutator, GetCvars) + { + GetCvars_handleFloat(this, store, s, f, cvar_mycvar, "mycvar"); + return false; + } + * Usually you can just use REPLICATE instead of this hook, e.g.: + REPLICATE(cvar_mycvar, int, "mycvar"); + * NOTE: requesting cvar values (get_cvars_f 0) is deprecated + */ #define EV_GetCvars(i, o) \ /**/ i(float, get_cvars_f) \ /**/ i(string, get_cvars_s) \