From: Rudolf Polzer Date: Sun, 3 Nov 2024 22:21:33 +0000 (-0500) Subject: Alternate approach: use renamed functions everywhere. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=refs%2Fmerge-requests%2F1380%2Fhead;p=xonotic%2Fxonotic-data.pk3dir.git Alternate approach: use renamed functions everywhere. These are mapped to either builtin or fallback. With this, no preprocessor magic or compiler dependence is needed. --- diff --git a/qcsrc/common/checkextension.qc b/qcsrc/common/checkextension.qc index a7325134d..9f10501ef 100644 --- a/qcsrc/common/checkextension.qc +++ b/qcsrc/common/checkextension.qc @@ -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 diff --git a/qcsrc/common/checkextension.qh b/qcsrc/common/checkextension.qh index e39dcc75b..0cdec8c92 100644 --- a/qcsrc/common/checkextension.qh +++ b/qcsrc/common/checkextension.qh @@ -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); diff --git a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc index 39f45666d..62150f188 100644 --- a/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc +++ b/qcsrc/common/gamemodes/gamemode/ctf/sv_ctf.qc @@ -1,5 +1,6 @@ #include "sv_ctf.qh" +#include #include #include #include @@ -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); diff --git a/qcsrc/common/gamemodes/gamemode/keepaway/sv_keepaway.qc b/qcsrc/common/gamemodes/gamemode/keepaway/sv_keepaway.qc index 9f694a0e0..fb7611548 100644 --- a/qcsrc/common/gamemodes/gamemode/keepaway/sv_keepaway.qc +++ b/qcsrc/common/gamemodes/gamemode/keepaway/sv_keepaway.qc @@ -1,5 +1,6 @@ #include "sv_keepaway.qh" +#include #include #include #include @@ -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); diff --git a/qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc b/qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc index 15024ed88..d41560c96 100644 --- a/qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc +++ b/qcsrc/common/gamemodes/gamemode/keyhunt/sv_keyhunt.qc @@ -1,5 +1,6 @@ #include "sv_keyhunt.qh" +#include #include #include #include @@ -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; diff --git a/qcsrc/common/gamemodes/gamemode/tka/sv_tka.qc b/qcsrc/common/gamemodes/gamemode/tka/sv_tka.qc index 0935b9709..992692f28 100644 --- a/qcsrc/common/gamemodes/gamemode/tka/sv_tka.qc +++ b/qcsrc/common/gamemodes/gamemode/tka/sv_tka.qc @@ -1,5 +1,6 @@ #include "sv_tka.qh" +#include #include .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); diff --git a/qcsrc/common/monsters/sv_monsters.qc b/qcsrc/common/monsters/sv_monsters.qc index b71e1054d..f51bb9eb6 100644 --- a/qcsrc/common/monsters/sv_monsters.qc +++ b/qcsrc/common/monsters/sv_monsters.qc @@ -1,5 +1,6 @@ #include "sv_monsters.qh" +#include #include #include #include @@ -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); diff --git a/qcsrc/common/weapons/weapon/porto.qc b/qcsrc/common/weapons/weapon/porto.qc index ef5c5d778..9c961d750 100644 --- a/qcsrc/common/weapons/weapon/porto.qc +++ b/qcsrc/common/weapons/weapon/porto.qc @@ -1,5 +1,7 @@ #include "porto.qh" +#include + #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); diff --git a/qcsrc/lib/warpzone/common.qc b/qcsrc/lib/warpzone/common.qc index 65625a877..b9d458038 100644 --- a/qcsrc/lib/warpzone/common.qc +++ b/qcsrc/lib/warpzone/common.qc @@ -1,5 +1,7 @@ #include "common.qh" +#include + #if defined(CSQC) #include #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; diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index 6adc4f9b4..5105fd3dc 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -1,5 +1,6 @@ #include "items.qh" +#include #include #include #include @@ -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); diff --git a/qcsrc/server/world.qc b/qcsrc/server/world.qc index cf0448b27..bd4a3b58c 100644 --- a/qcsrc/server/world.qc +++ b/qcsrc/server/world.qc @@ -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); }