OpenMoHAA 0.82.1
Loading...
Searching...
No Matches
navigation_bsp.h
1/*
2===========================================================================
3Copyright (C) 2025 the OpenMoHAA team
4
5This file is part of OpenMoHAA source code.
6
7OpenMoHAA source code is free software; you can redistribute it
8and/or modify it under the terms of the GNU General Public License as
9published by the Free Software Foundation; either version 2 of the License,
10or (at your option) any later version.
11
12OpenMoHAA source code is distributed in the hope that it will be
13useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OpenMoHAA source code; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20===========================================================================
21*/
22
23// navigation -- Modern navigation system using Recast and Detour
24
25#pragma once
26
27#include "g_local.h"
28#include "../qcommon/container.h"
29#include "../qcommon/vector.h"
30#include "../qcommon/cm_polylib.h"
31
36struct navIndice_t {
37 int indice;
38
39 navIndice_t() noexcept {}
40
41 navIndice_t(int value) noexcept
42 : indice(value)
43 {
44 assert(value >= 0);
45 }
46
47 operator int() const noexcept { return indice; };
48
49 operator int *() noexcept { return &indice; };
50
51 operator const int *() const noexcept { return &indice; };
52};
53
58struct navVertice_t {
59 Vector xyz;
60
61 navVertice_t();
62 navVertice_t(const vec3_t& inXyz);
63 navVertice_t(const Vector& inXyz);
64};
65
73 Vector bounds[2];
74
75public:
76 void AddVertice(const navVertice_t& vert);
77 void AddIndex(navIndice_t index);
78};
79
84struct navModel_t {
86 Vector bounds[2];
87
88public:
89 void CalculateBounds();
90};
91
98struct navMap_t {
99 navModel_t worldMap;
100 Container<navModel_t> subModels;
101
102public:
103 navModel_t& GetWorldMap();
104 const navModel_t& GetWorldMap() const;
105
106 navModel_t& CreateModel();
107 int GetNumSubmodels() const;
108 const navModel_t& GetSubmodel(int index) const;
109};
110
111struct cshader_t {
112 char shader[64];
113 int surfaceFlags;
114 int contentFlags;
115 int subdivisions;
116};
117
118struct cbrushside_t {
119 cplane_t *plane;
120 int planenum;
121 int shaderNum;
122 int surfaceFlags;
123 winding_t *winding;
124
125 dsideequation_t *pEq;
126
127public:
128 cbrushside_t();
129 ~cbrushside_t();
130};
131
132struct cbrush_t {
133 int contents;
134 vec3_t bounds[2];
135 int numsides;
136 int shaderNum;
137 cbrushside_t *sides;
138};
139
140struct cmodel_t {
141 vec3_t mins;
142 vec3_t maxs;
143 int firstSurface;
144 int numSurfaces;
145 int firstBrush;
146 int numBrushes;
147};
148
150 char model[128];
151 vec3_t origin;
152 vec3_t angles;
153 vec3_t axis[3];
154 float scale;
155 dtiki_t *tiki;
156};
157
161qboolean IsTriangleDegenerate(const vec3_t *points, int a, int b, int c);
162void FanFaceSurface(navSurface_t& surface, const cbrushside_t& side);
163qboolean CreateBrushWindings(const Container<cplane_t>& planes, cbrush_t& brush);
164void G_StripFaceSurface(navSurface_t& surface, const winding_t *winding);
165
166//
167// Utilities
168//
169qboolean FixWinding(winding_t *w);
170qboolean G_PlaneFromPoints(vec4_t plane, vec3_t a, vec3_t b, vec3_t c);
171
175
176static const unsigned int MAX_GRID_SIZE = 129;
177static const unsigned int MAX_PATCH_SIZE = 32;
178
180 // lod information, which may be different
181 // than the culling information to allow for
182 // groups of curves that LOD as a unit
183 vec3_t lodOrigin;
184 float lodRadius;
185 int lodFixed;
186 int lodStitched;
187
188 // vertexes
189 int width, height;
190 float *widthLodError;
191 float *heightLodError;
192 int numVertices;
193 int numIndexes;
194
195 Vector *getVertices() { return (Vector *)((byte *)this + sizeof(surfaceGrid_t)); }
196
197 const Vector *getVertices() const { return (Vector *)((byte *)this + sizeof(surfaceGrid_t)); }
198
199 int *getIndices() { return (int *)((byte *)this + sizeof(surfaceGrid_t) + sizeof(Vector) * numVertices); }
200
201 const int *getIndices() const
202 {
203 return (int *)((byte *)this + sizeof(surfaceGrid_t) + sizeof(Vector) * numVertices);
204 }
205};
206
207surfaceGrid_t *G_SubdividePatchToGrid(int width, int height, Vector points[MAX_PATCH_SIZE * MAX_PATCH_SIZE], float subdivisions);
208void G_FreeSurfaceGridMesh(surfaceGrid_t *grid);
209
213
214typedef union varnodeUnpacked_u {
215 float fVariance;
216 int flags;
217 /*
218 struct {
219#if !Q3_BIG_ENDIAN
220 byte flags;
221 unsigned char unused[3];
222#else
223 unsigned char unused[3];
224 byte flags;
225#endif
226 } s;
227 */
228} varnodeUnpacked_t;
229
230#define TER_QUADS_PER_ROW 8
231#define TER_TRIS_PER_PATCH (TER_QUADS_PER_ROW * TER_QUADS_PER_ROW * 2)
232#define TER_PLANES_PER_TRI 5
233
235 cplane_t planes
236 [TER_PLANES_PER_TRI]; // 0 is the surface plane, 3 border planes follow and a cap to give it some finite volume
237};
238
240 vec3_t bounds[2];
241
242 baseshader_t *shader;
243
244 terTriangle_t tris[TER_TRIS_PER_PATCH];
245};
246
247struct terrainCollideSquare_t {
248 vec4_t plane[2];
249 winding_t *w;
250 int eMode;
251
252public:
253 terrainCollideSquare_t();
254 ~terrainCollideSquare_t();
255};
256
258 vec3_t vBounds[2];
259 terrainCollideSquare_t squares[8][8];
260};
261
262// Use a 32-bit int because there can be more than 65536 tris
263typedef unsigned int terraInt;
264
265void G_PrepareGenerateTerrainCollide(void);
266void G_GenerateTerrainCollide(cTerraPatch_t *patch, terrainCollide_t *tc);
267qboolean G_CreateTerPatchWindings(terrainCollide_t& tc);
268
270 vec3_t xyz;
271 float fVariance;
272 float fHgtAvg;
273 float fHgtAdd;
274 terraInt nRef;
275 terraInt iVertArray;
276 byte *pHgt;
277 terraInt iNext;
278 terraInt iPrev;
279};
280
282 terraInt iPt[3];
283 terraInt nSplit;
284 struct cTerraPatchUnpacked_t *patch;
285 varnodeUnpacked_t *varnode;
286 terraInt index;
287 byte lod;
288 byte byConstChecks;
289 terraInt iLeft;
290 terraInt iRight;
291 terraInt iBase;
292 terraInt iLeftChild;
293 terraInt iRightChild;
294 terraInt iParent;
295 terraInt iPrev;
296 terraInt iNext;
297};
298
300 terraInt iVertHead;
301 terraInt iTriHead;
302 terraInt iTriTail;
303 terraInt iMergeHead;
304 int nVerts;
305 int nTris;
306};
307
309 surfaceTerrain_t drawinfo;
310 float x0;
311 float y0;
312 float z0;
313 float zmax;
314 short int iNorth;
315 short int iEast;
316 short int iSouth;
317 short int iWest;
318 struct cTerraPatchUnpacked_t *pNextActive;
319 varnodeUnpacked_t varTree[2][63];
320 unsigned char heightmap[81];
321 byte flags;
322};
323
325 terraInt iFreeHead;
326 terraInt iCur;
327 size_t nFree;
328};
329
330extern terraTri_t *g_pTris;
331extern terrainVert_t *g_pVert;
332
333extern poolInfo_t g_tri;
334extern poolInfo_t g_vert;
335
336void G_PreTessellateTerrain(cTerraPatchUnpacked_t *terraPatches, size_t numTerraPatches);
337void G_DoTriSplitting(cTerraPatchUnpacked_t *terraPatches, size_t numTerraPatches);
338void G_DoGeomorphs(cTerraPatchUnpacked_t *terraPatches, size_t numTerraPatches);
339void G_TerrainFree();
340
344
345class gameLump_c;
346class bspMap_c;
347
353{
354public:
362 void ProcessBSPForNavigation(const char *mapname);
363
364private:
365 void LoadShaders(const gameLump_c& lump, Container<cshader_t>& shaders);
366 bool IsValidContentsForPlayer(int contents);
367 void LoadStaticModelDefs(const gameLump_c& lump);
368 void LoadPlanes(const gameLump_c& lump, Container<cplane_t>& planes);
369 void LoadBrushSides(
370 const gameLump_c& lump,
371 const Container<cshader_t>& shaders,
372 const Container<cplane_t>& planes,
374 );
375 void BoundBrush(cbrush_t *b);
376 void LoadBrushes(
377 const gameLump_c& lump,
378 const Container<cshader_t>& shaders,
379 const Container<cbrushside_t>& sides,
380 Container<cbrush_t>& brushes
381 );
382 void LoadLeafBrushes(const gameLump_c& lump, Container<int>& leafbrushes);
383 void LoadSubmodels(const gameLump_c& lump, Container<cmodel_t>& submodels);
384 void GenerateSideTriangles(navModel_t& model, const cbrush_t& brush, cbrushside_t& side);
385 void GenerateBrushTriangles(navModel_t& model, const Container<cplane_t>& planes, cbrush_t& brush);
386 void GenerateVerticesFromHull(bspMap_c& inBspMap, const Container<cshader_t>& shaders);
387 void RenderSurfaceGrid(const surfaceGrid_t *grid, navSurface_t& outSurface);
388 void ParseMesh(
389 const dsurface_t *ds, const drawVert_t *verts, const Container<cshader_t>& shaders, navSurface_t& outSurface
390 );
391 void ParseTriSurf(const dsurface_t *ds, const drawVert_t *verts, const int *indexes);
392 void ParseFace(const dsurface_t *ds, const drawVert_t *verts, const int *indexes);
393 void ParseFlare(const dsurface_t *ds, const drawVert_t *verts);
394 void LoadSurfaces(bspMap_c& inBspMap, const Container<cshader_t>& shaders);
395 void UnpackTerraPatch(const cTerraPatch_t *pPacked, cTerraPatchUnpacked_t *pUnpacked);
396 void SwapTerraPatch(cTerraPatch_t *pPatch);
397 void GenerateTerrainPatchMesh(const cTerraPatchUnpacked_t& patch);
398 void GenerateTerrainMesh(cTerraPatchUnpacked_t *terraPatches, size_t numTerraPatches);
399 void LoadAndRenderTerrain(bspMap_c& inBspMap, const Container<cshader_t>& shaders);
400 void CopyStaticModel(const cStaticModel_t *pSM, cStaticModelUnpacked_t *pUnpackedSM);
401
402public:
403 navMap_t navMap;
404};
Definition container.h:85
Navigation generated by a BSP file.
Definition navigation_bsp.h:353
void ProcessBSPForNavigation(const char *mapname)
Process the specified BSP map file and generate surfaces from it.
Definition navigation_bsp.cpp:1042
Definition vector.h:61
Definition navigation_bsp_lump.h:55
Definition navigation_bsp_lump.h:29
Definition navigation_bsp.h:149
Definition navigation_bsp.h:308
Definition navigation_bsp.h:132
Definition navigation_bsp.h:118
Definition navigation_bsp.h:140
Definition navigation_bsp.h:111
Definition qfiles.h:637
Definition qfiles.h:612
Definition qfiles.h:665
An index to a vertice in the navigation map.
Definition navigation_bsp.h:36
Navigation map. Contains indices and vertices renderer from LOD terrain, brushes and patches.
Definition navigation_bsp.h:98
Navigation model containing faces.
Definition navigation_bsp.h:84
Navigation surface containing indices and vertices.
Definition navigation_bsp.h:70
Vertice in the navigation map.
Definition navigation_bsp.h:58
Definition navigation_bsp.h:324
Definition navigation_bsp.h:179
Definition navigation_bsp.h:299
Definition navigation_bsp.h:239
Definition navigation_bsp.h:234
Definition navigation_bsp.h:281
Definition navigation_bsp.h:247
Definition navigation_bsp.h:257
Definition navigation_bsp.h:269
Definition cm_polylib.h:28
Definition navigation_bsp.h:214