]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Alternate approach: use renamed functions everywhere. divVerent/no-overwrite-builtins 1380/head
authorRudolf Polzer <divVerent@gmail.com>
Sun, 3 Nov 2024 22:21:33 +0000 (17:21 -0500)
committerRudolf Polzer <divVerent@gmail.com>
Tue, 5 Nov 2024 13:18:05 +0000 (08:18 -0500)
These are mapped to either builtin or fallback. With this, no
preprocessor magic or compiler dependence is needed.

qcsrc/common/checkextension.qc
qcsrc/common/checkextension.qh
qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc
qcsrc/common/gamemodes/gamemode/keepaway/sv_keepaway.qc
qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc
qcsrc/common/gamemodes/gamemode/tka/sv_tka.qc
qcsrc/common/monsters/sv_monsters.qc
qcsrc/common/weapons/weapon/porto.qc
qcsrc/lib/warpzone/common.qc
qcsrc/server/items/items.qc
qcsrc/server/world.qc

index a7325134d4b46f4f0210e03011aedb88ff8dc337..9f10501ef73d3d0352d841679379c9f419a00db6 100644 (file)
@@ -41,13 +41,13 @@ void CheckEngineExtensions(void)
 #ifdef SVQC // change to GAMEQC if/when we use nudgeoutofsolid in CSQC
        if (checkextension("DP_QC_NUDGEOUTOFSOLID"))
        {
-               nudgeoutofsolid_CheckedEngineExtensions_usebuiltin();
+               nudgeoutofsolid_OrFallback = nudgeoutofsolid;
        }
        else
        {
                LOG_WARN("Engine lacks DP_QC_NUDGEOUTOFSOLID, falling back to WarpZoneLib_MoveOutOfSolid().");
                // DP_QC_NUDGEOUTOFSOLID fixes many cases WarpZoneLib_MoveOutOfSolid() can't, usually in less CPU time
-               nudgeoutofsolid = WarpZoneLib_MoveOutOfSolid;
+               nudgeoutofsolid_OrFallback = WarpZoneLib_MoveOutOfSolid;
        }
 
        if (!world.fullspawndata)
@@ -57,14 +57,14 @@ void CheckEngineExtensions(void)
 #ifdef GAMEQC
        if (checkextension("DP_QC_FINDBOX"))
        {
-               findbox_CheckedEngineExtensions_usebuiltin();
-               findbox_tofield_CheckedEngineExtensions_usebuiltin();
+               findbox_OrFallback = findbox;
+               findbox_tofield_OrFallback = findbox_tofield;
        }
        else
        {
                LOG_WARN("Engine lacks DP_QC_FINDBOX, performance will be suboptimal.");
-               findbox = findbox_Fallback;
-               findbox_tofield = findbox_tofield_Fallback;
+               findbox_OrFallback = findbox_Fallback;
+               findbox_tofield_OrFallback = findbox_tofield_Fallback;
        }
 #endif
 
index e39dcc75b94c388ad1f0b2a63321b98bbd6ed6f3..0cdec8c920cff4dc1ae0ce231c750cd5c6706783 100644 (file)
@@ -1,31 +1,12 @@
 #pragma once
 
-// TODO: when https://github.com/graphitemaster/gmqcc/issues/211 is fixed,
-// remove the _usebuiltin functions and pre-initialize the variables directly.
-// Doing so already works in FTEQCC but not in GMQCC.
-//
-// The _usebuiltin functions are declared here so that the preprocessors based
-// remapping does not impact them yet.
-
 #ifdef GAMEQC
-var entity(vector mins, vector maxs, .entity tofield) findbox_tofield_CheckedEngineExtensions;
-void findbox_tofield_CheckedEngineExtensions_usebuiltin() {
-       findbox_tofield_CheckedEngineExtensions = findbox_tofield;
-}
-#define findbox_tofield findbox_tofield_CheckedEngineExtensions
-var entity(vector mins, vector maxs) findbox_CheckedEngineExtensions;
-void findbox_CheckedEngineExtensions_usebuiltin() {
-       findbox_CheckedEngineExtensions = findbox;
-}
-#define findbox findbox_CheckedEngineExtensions
+var entity(vector mins, vector maxs, .entity tofield) findbox_tofield_OrFallback = nil;
+var entity(vector mins, vector maxs) findbox_OrFallback = nil;
 #endif
 
 #ifdef SVQC // change to GAMEQC if/when we use nudgeoutofsolid in CSQC
-var float(entity ent) nudgeoutofsolid_CheckedEngineExtensions;
-void nudgeoutofsolid_CheckedEngineExtensions_usebuiltin() {
-       nudgeoutofsolid_CheckedEngineExtensions = nudgeoutofsolid;
-}
-#define nudgeoutofsolid nudgeoutofsolid_CheckedEngineExtensions
+var float(entity ent) nudgeoutofsolid_OrFallback = nil;
 #endif
 
 void CheckEngineExtensions(void);
index 39f45666db19a944fe151ae9ea4467798c27a5a8..62150f18824415a643797e9127957452e66a945b 100644 (file)
@@ -1,5 +1,6 @@
 #include "sv_ctf.qh"
 
+#include <common/checkextension.qh>
 #include <common/effects/all.qh>
 #include <common/mapobjects/teleporters.qh>
 #include <common/mapobjects/triggers.qh>
@@ -500,7 +501,7 @@ void ctf_Handle_Throw(entity player, entity receiver, int droptype)
        tracebox(player.origin - FLAG_DROP_OFFSET, flag.m_mins, flag.m_maxs, player.origin + FLAG_DROP_OFFSET, MOVE_NOMONSTERS, flag);
        flag.solid = SOLID_TRIGGER; // before setorigin to ensure area grid linking
        setorigin(flag, trace_endpos);
-       if (trace_startsolid && !nudgeoutofsolid(flag)) // TODO: trace_allsolid would perform better but isn't 100% reliable yet
+       if (trace_startsolid && !nudgeoutofsolid_OrFallback(flag)) // TODO: trace_allsolid would perform better but isn't 100% reliable yet
        {
                // the flag's bbox doesn't fit but we can assume the player's current bbox does
                tracebox(player.origin - FLAG_DROP_OFFSET, player.mins, player.maxs, player.origin + FLAG_DROP_OFFSET, MOVE_NOMONSTERS, flag);
index 9f694a0e09d55895fe0765330e9c2cc1430347de..fb761154897431389b07bd0d8049cf69cab05723 100644 (file)
@@ -1,5 +1,6 @@
 #include "sv_keepaway.qh"
 
+#include <common/checkextension.qh>
 #include <common/effects/all.qh>
 #include <server/client.qh>
 #include <server/gamelog.qh>
@@ -199,7 +200,7 @@ void ka_DropEvent(entity player) // runs any time that a player is supposed to l
        IL_PUSH(g_damagedbycontents, ball);
        ball.effects &= ~EF_NODRAW;
        setorigin(ball, player.origin + '0 0 10');
-       nudgeoutofsolid(ball); // a ball has a horizontally bigger bbox than a player
+       nudgeoutofsolid_OrFallback(ball); // a ball has a horizontally bigger bbox than a player
        ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom();
        ball.owner = NULL;
        navigation_dynamicgoal_set(ball, player);
index 15024ed88d9153780bcb103a26fb6899ad094e2b..d41560c968e401549442a88805edd1541f861fe2 100644 (file)
@@ -1,5 +1,6 @@
 #include "sv_keyhunt.qh"
 
+#include <common/checkextension.qh>
 #include <server/command/vote.qh>
 #include <server/gamelog.qh>
 #include <server/damage.qh>
@@ -291,7 +292,7 @@ void kh_Key_Detach(entity key) // runs every time a key is dropped or lost. Runs
        if(!IL_CONTAINS(g_items, key))
                IL_PUSH(g_items, key);
        set_movetype(key, MOVETYPE_TOSS);
-       nudgeoutofsolid(key); // a key has a bigger bbox than a player
+       nudgeoutofsolid_OrFallback(key); // a key has a bigger bbox than a player
        key.pain_finished = time + autocvar_g_balance_keyhunt_delay_return;
        key.damageforcescale = autocvar_g_balance_keyhunt_damageforcescale;
        key.takedamage = DAMAGE_YES;
index 0935b9709aed2d0c25df12b6a1a10ccd38d3b9ba..992692f28e0326c2bfc52117f19b7a6612c6392c 100644 (file)
@@ -1,5 +1,6 @@
 #include "sv_tka.qh"
 
+#include <common/checkextension.qh>
 #include <common/effects/all.qh>
 
 .entity ballcarried;
@@ -180,7 +181,7 @@ void tka_DropEvent(entity player) // runs any time that a player is supposed to
        ball.takedamage = DAMAGE_YES;
        ball.effects &= ~EF_NODRAW;
        setorigin(ball, player.origin + '0 0 10');
-       nudgeoutofsolid(ball); // a ball has a horizontally bigger bbox than a player
+       nudgeoutofsolid_OrFallback(ball); // a ball has a horizontally bigger bbox than a player
        ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom();
        ball.owner = NULL;
        navigation_dynamicgoal_set(ball, player);
index b71e1054d6db5e7d49f94d13f58442635b1d1614..f51bb9eb6a261a161e44fab540f97c107ede8a39 100644 (file)
@@ -1,5 +1,6 @@
 #include "sv_monsters.qh"
 
+#include <common/checkextension.qh>
 #include <common/constants.qh>
 #include <common/deathtypes/all.qh>
 #include <common/items/_mod.qh>
@@ -1543,7 +1544,7 @@ bool Monster_Spawn(entity this, bool check_appear, Monster mon)
                setorigin(this, trace_endpos);
        }
 
-       if (!nudgeoutofsolid(this))
+       if (!nudgeoutofsolid_OrFallback(this))
        {
                // Stuck and not fixable
                Monster_Remove(this);
index ef5c5d7780163e4be293d82ce8bb3500df27d1e1..9c961d750550bf3aa124d68b4a367b682fd4f737 100644 (file)
@@ -1,5 +1,7 @@
 #include "porto.qh"
 
+#include <common/checkextension.qh>
+
 #ifdef CSQC
 
 STATIC_INIT(Porto)
@@ -124,7 +126,7 @@ void W_Porto_Fail(entity this, float failhard)
                // FIXME: item properties should be obtained from the registry
                setsize(this, ITEM_D_MINS, ITEM_D_MAXS);
                setorigin(this, this.origin + trace_plane_normal);
-               if(nudgeoutofsolid(this))
+               if(nudgeoutofsolid_OrFallback(this))
                {
                        this.flags = FL_ITEM;
                        IL_PUSH(g_items, this);
index 65625a877dcef1ac88737eb5fa4c67917332e65b..b9d45803826ec7f5faaa38b76ada37baee02d7a1 100644 (file)
@@ -1,5 +1,7 @@
 #include "common.qh"
 
+#include <common/checkextension.qh>
+
 #if defined(CSQC)
     #include <client/items/items.qh>
 #elif defined(MENUQC)
@@ -134,7 +136,7 @@ float WarpZoneLib_BoxTouchesBrush_Recurse(vector mi, vector ma, entity e, entity
 
 float WarpZoneLib_BoxTouchesBrush(vector mi, vector ma, entity e, entity ig)
 {
-       // bones_was_here: TODO: when findbox() builtin is available, use it to
+       // bones_was_here: TODO: when findbox_OrFallback() builtin is available, use it to
        // optimise this into a single non-recursive function that only calls tracebox once
 
        float f, s;
index 6adc4f9b439d88c2fbd97d20adad62d6157db77f..5105fd3dcb776a7e4b0075299104ed4391e90f79 100644 (file)
@@ -1,5 +1,6 @@
 #include "items.qh"
 
+#include <common/checkextension.qh>
 #include <common/constants.qh>
 #include <common/deathtypes/all.qh>
 #include <common/gamemodes/gamemode/cts/cts.qh>
@@ -1062,7 +1063,7 @@ void StartItem(entity this, entity def)
                }
 
                // most loot items have a bigger horizontal size than a player
-               nudgeoutofsolid(this);
+               nudgeoutofsolid_OrFallback(this);
 
                // don't drop if in a NODROP zone (such as lava)
                traceline(this.origin, this.origin, MOVE_NORMAL, this);
index cf0448b2772d534fb52c5832e3adfe8157c5cde2..bd4a3b58c8bd5aff94bba2924c0dd15b99f57ea1 100644 (file)
@@ -2331,12 +2331,12 @@ void DropToFloor_QC(entity this)
                return;
        }
 
-       /* Prior to sv_legacy_bbox_expand 0, both droptofloor and nudgeoutofsolid were done for items
+       /* Prior to sv_legacy_bbox_expand 0, both droptofloor and nudgeoutofsolid_OrFallback were done for items
         * using box '-16 -16 0' '16 16 48' (without the FL_ITEM expansion applied),
         * which often resulted in bboxes partially in solids once expansion was applied.
         * We don't want bboxes in solids (bad for gameplay and culling),
         * but we also don't want items to land on a "skirting board" or the base of a sloping wall.
-        * For initial nudgeoutofsolid and droptofloor stages we use a small box
+        * For initial nudgeoutofsolid_OrFallback and droptofloor stages we use a small box
         * so they fall as far and in the same place as they traditionally would,
         * then we nudge the full size box out of solid, in a direction appropriate for the plane(s).
         */
@@ -2360,7 +2360,7 @@ void DropToFloor_QC(entity this)
         */
        if(!Q3COMPAT_COMMON && autocvar_sv_mapformat_is_quake3) // Xonotic, Nexuiz
        {
-               nudgeresult = nudgeoutofsolid(this);
+               nudgeresult = nudgeoutofsolid_OrFallback(this);
                if (!nudgeresult)
                        LOG_WARNF("DropToFloor_QC at \"%v\": COULD NOT FIX badly placed entity \"%s\" before drop", this.origin, this.classname);
                else if (nudgeresult > 0)
@@ -2426,12 +2426,12 @@ void DropToFloor_QC(entity this)
 
                // A side effect of using a small box to drop items (and do the initial nudge) is
                // the full size box can end up in collision with a sloping floor or terrain model.
-               nudgeresult = nudgeoutofsolid(this);
+               nudgeresult = nudgeoutofsolid_OrFallback(this);
                // No warns for successful nudge because it would spam about items on slopes/terrain.
        }
        else if (trace_allsolid && trace_fraction) // dropped using "proper" bbox but never left solid
        {
-               nudgeresult = nudgeoutofsolid(this);
+               nudgeresult = nudgeoutofsolid_OrFallback(this);
                if (nudgeresult > 0)
                        LOG_WARNF("DropToFloor_QC at \"%v\": FIXED badly placed entity \"%s\" after drop", this.origin, this.classname);
        }