]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add REPLICATE_APPLYCHANGE macro
authorterencehill <piuntn@gmail.com>
Fri, 7 Jan 2022 22:42:59 +0000 (23:42 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 7 Jan 2022 22:42:59 +0000 (23:42 +0100)
qcsrc/common/replicate.qh
qcsrc/common/weapons/all.qh
qcsrc/lib/replicate.qh
qcsrc/server/command/getreplies.qc
qcsrc/server/weapons/selection.qh
qcsrc/server/weapons/weaponsystem.qh

index 3ee308914f998905ca55b9ae2d7f186a238029fc..db1054a743e84c50dbe6147f0b34db33cd39afca 100644 (file)
@@ -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");
index 0016790c86ef2b584c3599ae44d33db4aa7f6d1f..2bbb2afbec9c8696511f5dd0072c076a7ccbb173 100644 (file)
@@ -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);
index 873db04b81ed918a746c7373541f372c81818902..8b17b740aea1b4525a81006089458860cf78c323 100644 (file)
@@ -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
index 96ad99af068f8aa4b18b4e9d47c9782cf626d495..3f82484abe7d9e9e07fd4de62d2dadfddab206a9 100644 (file)
@@ -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);
 }
index 093d6612b348052416bbf609e26217583914b398..3e28b47455cd0413d1529ab0f779df2f7cfb7f91 100644 (file)
@@ -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);
+       }
+);
index 5291f98ddd7f6d5d8e21e80c5f99778808f8bfa9..c0e0c221fff9124a3a5bc81a4f6c66a9e184c760 100644 (file)
@@ -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); });