]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/checkextension.qc
Add fallback path for when engine lacks DP_QC_FINDBOX
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / checkextension.qc
1 #include "checkextension.qh"
2
3 #ifdef GAMEQC
4 entity findbox_tofield_Fallback(vector mins, vector maxs, .entity tofield)
5 {
6         // 0.03125 minimum radius because findradius returns no results if radius is zero
7         // but findbox for a zero-sized box returns entities touching the specified point
8         entity chain = findradius_tofield(0.5 * (mins + maxs), max(0.03125, 0.5 * vlen(maxs - mins)), tofield);
9         entity prev = NULL;
10         for (entity e = chain; e; e = e.tofield)
11         {
12                 if (boxesoverlap(e.absmin, e.absmax, mins, maxs))
13                         prev = e;
14                 else // not in box so remove from chain
15                 {
16                         if (prev)
17                                 prev.tofield = e.tofield;
18                         else
19                                 chain = chain.tofield;
20                 }
21         }
22         return chain;
23 }
24 entity findbox_Fallback(vector mins, vector maxs)
25 {
26         return findbox_tofield_Fallback(mins, maxs, chain);
27 }
28 #endif // GAMEQC
29
30 void CheckEngineExtensions(void)
31 {
32         if (!cvar("pr_checkextension"))
33                 LOG_FATAL("Engine lacks the QC extension system.");
34
35         if (!checkextension("DP_QC_URI_GET") || !checkextension("DP_QC_URI_POST"))
36                 LOG_WARN("Engine lacks HTTP support, XonStat and map downloads are unavailable.");
37
38         if (!checkextension("DP_CRYPTO"))
39                 LOG_WARN("Engine lacks DP_CRYPTO, Player IDs (required for XonStat and CTS/CTF records) are unavailable.");
40
41 #ifdef SVQC // change to GAMEQC if/when we use nudgeoutofsolid in CSQC
42         if (!checkextension("DP_QC_NUDGEOUTOFSOLID"))
43         {
44                 LOG_WARN("Engine lacks DP_QC_NUDGEOUTOFSOLID, falling back to WarpZoneLib_MoveOutOfSolid().");
45                 // DP_QC_NUDGEOUTOFSOLID fixes many cases WarpZoneLib_MoveOutOfSolid() can't, usually in less CPU time
46                 nudgeoutofsolid = WarpZoneLib_MoveOutOfSolid;
47         }
48 #endif
49
50 #ifdef GAMEQC
51         if (!checkextension("DP_QC_FINDBOX"))
52         {
53                 LOG_WARN("Engine lacks DP_QC_FINDBOX, performance will be suboptimal.");
54                 findbox = findbox_Fallback;
55                 findbox_tofield = findbox_tofield_Fallback;
56         }
57 #endif
58
59         // TODO: add proper warns/errors for other extensions we depend on
60 }