]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add fallback path for when engine lacks DP_QC_FINDBOX
authorbones_was_here <bones_was_here@xonotic.au>
Fri, 1 Sep 2023 11:19:27 +0000 (21:19 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 12 Mar 2024 02:28:36 +0000 (12:28 +1000)
qcsrc/common/checkextension.qc

index 4906f8468bdfa30725481211bb3f52cd6ffe507d..3e1a69f005810f70cd15504b700e6d2141a2df62 100644 (file)
@@ -1,5 +1,32 @@
 #include "checkextension.qh"
 
+#ifdef GAMEQC
+entity findbox_tofield_Fallback(vector mins, vector maxs, .entity tofield)
+{
+       // 0.03125 minimum radius because findradius returns no results if radius is zero
+       // but findbox for a zero-sized box returns entities touching the specified point
+       entity chain = findradius_tofield(0.5 * (mins + maxs), max(0.03125, 0.5 * vlen(maxs - mins)), tofield);
+       entity prev = NULL;
+       for (entity e = chain; e; e = e.tofield)
+       {
+               if (boxesoverlap(e.absmin, e.absmax, mins, maxs))
+                       prev = e;
+               else // not in box so remove from chain
+               {
+                       if (prev)
+                               prev.tofield = e.tofield;
+                       else
+                               chain = chain.tofield;
+               }
+       }
+       return chain;
+}
+entity findbox_Fallback(vector mins, vector maxs)
+{
+       return findbox_tofield_Fallback(mins, maxs, chain);
+}
+#endif // GAMEQC
+
 void CheckEngineExtensions(void)
 {
        if (!cvar("pr_checkextension"))
@@ -20,5 +47,14 @@ void CheckEngineExtensions(void)
        }
 #endif
 
+#ifdef GAMEQC
+       if (!checkextension("DP_QC_FINDBOX"))
+       {
+               LOG_WARN("Engine lacks DP_QC_FINDBOX, performance will be suboptimal.");
+               findbox = findbox_Fallback;
+               findbox_tofield = findbox_tofield_Fallback;
+       }
+#endif
+
        // TODO: add proper warns/errors for other extensions we depend on
 }