From: terencehill Date: Fri, 7 Jan 2022 22:42:59 +0000 (+0100) Subject: Add REPLICATE_APPLYCHANGE macro X-Git-Tag: xonotic-v0.8.5~204^2~8 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=75e86e2696af2742dd3399b95c42fea9741db044;p=xonotic%2Fxonotic-data.pk3dir.git Add REPLICATE_APPLYCHANGE macro --- diff --git a/qcsrc/common/replicate.qh b/qcsrc/common/replicate.qh index 3ee308914..db1054a74 100644 --- a/qcsrc/common/replicate.qh +++ b/qcsrc/common/replicate.qh @@ -10,7 +10,6 @@ REPLICATE_FIELD(int, cvar_cl_autoscreenshot); REPLICATE_FIELD(float, cvar_cl_autotaunt); REPLICATE_FIELD(bool, cvar_cl_clippedspectating); REPLICATE_FIELD(bool, cvar_cl_cts_noautoswitch); -REPLICATE_FIELD(int, cvar_cl_gunalign); REPLICATE_FIELD(float, cvar_cl_handicap); REPLICATE_FIELD(bool, cvar_cl_jetpack_jump); REPLICATE_FIELD(bool, cvar_cl_movement_track_canjump); @@ -29,11 +28,13 @@ REPLICATE(cvar_cl_autoswitch, bool, "cl_autoswitch"); REPLICATE(cvar_cl_allow_uid2name, int, "cl_allow_uid2name"); REPLICATE(cvar_cl_allow_uidranking, bool, "cl_allow_uidranking"); REPLICATE(cvar_cl_allow_uidtracking, int, "cl_allow_uidtracking"); +#ifdef SVQC +REPLICATE_APPLYCHANGE("cl_allow_uidtracking", { PlayerStats_GameReport_AddPlayer(this); }); +#endif REPLICATE(cvar_cl_autoscreenshot, int, "cl_autoscreenshot"); REPLICATE(cvar_cl_autotaunt, float, "cl_autotaunt"); REPLICATE(cvar_cl_clippedspectating, bool, "cl_clippedspectating"); REPLICATE(cvar_cl_cts_noautoswitch, bool, "cl_cts_noautoswitch"); -REPLICATE(cvar_cl_gunalign, int, "cl_gunalign"); REPLICATE(cvar_cl_handicap, float, "cl_handicap"); REPLICATE(cvar_cl_jetpack_jump, bool, "cl_jetpack_jump"); REPLICATE(cvar_cl_movement_track_canjump, bool, "cl_movement_track_canjump"); diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 0016790c8..2bbb2afbe 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -410,6 +410,9 @@ string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo string W_FixWeaponOrder_AllowIncomplete(entity this, string order); #endif +REPLICATE_FIELD(int, cvar_cl_gunalign); +REPLICATE(cvar_cl_gunalign, int, "cl_gunalign"); + REPLICATE_FIELD(string, cvar_cl_weaponpriority); REPLICATE_FIELD(string, cvar_cl_weaponpriorities[10]); REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList); diff --git a/qcsrc/lib/replicate.qh b/qcsrc/lib/replicate.qh index 873db04b8..8b17b740a 100644 --- a/qcsrc/lib/replicate.qh +++ b/qcsrc/lib/replicate.qh @@ -14,17 +14,30 @@ string strcat1(string s) = #115; // FRIK_FILE #ifdef GAMEQC /** + * \def REPLICATE(fld, type, cvar) * Replicate a client cvar into a server field * * @param fld The field to replicate into * @param type The field type - * @param cvar The cvar name + * @param cvarname + * @param fixup_func((entity this, string original_value)) optional parameter */ #define REPLICATE(...) EVAL_REPLICATE(OVERLOAD(REPLICATE, __VA_ARGS__)) #define EVAL_REPLICATE(...) __VA_ARGS__ #if defined(SVQC) ACCUMULATE void ReplicateVars(entity this, entity store, string thisname, int i) {} + ACCUMULATE void ReplicateVars_ApplyChange(entity this, entity store, string thisname, int i) {} + /** + * \def REPLICATE(cvarname, ApplyChange_code) + * Allow setting code to will be executed on cvar value changes + * + * @param cvarname + * @param ApplyChange_code code meant to be run on cvar value changes + */ + #define REPLICATE_APPLYCHANGE(var, ApplyChange_code) \ + void ReplicateVars_ApplyChange(entity this, entity store, string thisname, int i) \ + { if (thisname == var) { ApplyChange_code } } #elif defined(CSQC) ACCUMULATE void ReplicateVars(int mode) {} #endif diff --git a/qcsrc/server/command/getreplies.qc b/qcsrc/server/command/getreplies.qc index 96ad99af0..3f82484ab 100644 --- a/qcsrc/server/command/getreplies.qc +++ b/qcsrc/server/command/getreplies.qc @@ -395,22 +395,6 @@ void GetCvars(entity this, entity store, int f) Notification_GetCvars(this, store); ReplicateVars(this, store, s, f); - - // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early) if (f > 0) - { - if (s == "cl_weaponpriority") - { - for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) - { - .entity weaponentity = weaponentities[slot]; - if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0)) - this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity); - } - } - if (s == "cl_allow_uidtracking") - PlayerStats_GameReport_AddPlayer(this); - //if (s == "cl_gunalign") - //W_ResetGunAlign(this, store.cvar_cl_gunalign); - } + ReplicateVars_ApplyChange(this, store, s, f); } diff --git a/qcsrc/server/weapons/selection.qh b/qcsrc/server/weapons/selection.qh index 093d6612b..3e28b4745 100644 --- a/qcsrc/server/weapons/selection.qh +++ b/qcsrc/server/weapons/selection.qh @@ -41,3 +41,13 @@ void W_PreviousWeapon(entity this, float list, .entity weaponentity); // previously used if exists and has ammo, (second) best otherwise void W_LastWeapon(entity this, .entity weaponentity); + +// fix switchweapon (needed when spectating is disabled, as PutClientInServer comes too early) +REPLICATE_APPLYCHANGE("cl_weaponpriority", + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0)) + this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity); + } +); diff --git a/qcsrc/server/weapons/weaponsystem.qh b/qcsrc/server/weapons/weaponsystem.qh index 5291f98dd..c0e0c221f 100644 --- a/qcsrc/server/weapons/weaponsystem.qh +++ b/qcsrc/server/weapons/weaponsystem.qh @@ -75,3 +75,5 @@ bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponenti void weapon_prepareattack_do(entity actor, .entity weaponentity, float secondary, float attacktime); void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void(Weapon thiswep, entity actor, .entity weaponentity, int fire) func); + +//REPLICATE_APPLYCHANGE("cl_gunalign", { W_ResetGunAlign(this, store.cvar_cl_gunalign); });