OpenMoHAA 0.82.0
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};
116
117struct cbrushside_t {
118 cplane_t *plane;
119 int planenum;
120 int shaderNum;
121 int surfaceFlags;
122 winding_t *winding;
123
124 dsideequation_t *pEq;
125
126public:
127 cbrushside_t();
128 ~cbrushside_t();
129};
130
131struct cbrush_t {
132 int contents;
133 vec3_t bounds[2];
134 int numsides;
135 int shaderNum;
136 cbrushside_t *sides;
137};
138
139struct cmodel_t {
140 vec3_t mins;
141 vec3_t maxs;
142 int firstSurface;
143 int numSurfaces;
144 int firstBrush;
145 int numBrushes;
146};
147
149 char model[128];
150 vec3_t origin;
151 vec3_t angles;
152 vec3_t axis[3];
153 float scale;
154 dtiki_t *tiki;
155};
156
160qboolean IsTriangleDegenerate(const vec3_t *points, int a, int b, int c);
161void FanFaceSurface(navSurface_t& surface, const cbrushside_t& side);
162qboolean CreateBrushWindings(const Container<cplane_t>& planes, cbrush_t& brush);
163void G_StripFaceSurface(navSurface_t& surface, const winding_t *winding);
164
165//
166// Utilities
167//
168qboolean FixWinding(winding_t *w);
169qboolean G_PlaneFromPoints(vec4_t plane, vec3_t a, vec3_t b, vec3_t c);
170
174
175static const unsigned int MAX_GRID_SIZE = 129;
176static const unsigned int MAX_PATCH_SIZE = 32;
177
179 // lod information, which may be different
180 // than the culling information to allow for
181 // groups of curves that LOD as a unit
182 vec3_t lodOrigin;
183 float lodRadius;
184 int lodFixed;
185 int lodStitched;
186
187 // vertexes
188 int width, height;
189 float *widthLodError;
190 float *heightLodError;
191 int numVertices;
192 int numIndexes;
193
194 Vector *getVertices() { return (Vector *)((byte *)this + sizeof(surfaceGrid_t)); }
195
196 const Vector *getVertices() const { return (Vector *)((byte *)this + sizeof(surfaceGrid_t)); }
197
198 int *getIndices() { return (int *)((byte *)this + sizeof(surfaceGrid_t) + sizeof(Vector) * numVertices); }
199
200 const int *getIndices() const
201 {
202 return (int *)((byte *)this + sizeof(surfaceGrid_t) + sizeof(Vector) * numVertices);
203 }
204};
205
206surfaceGrid_t *G_SubdividePatchToGrid(int width, int height, Vector points[MAX_PATCH_SIZE * MAX_PATCH_SIZE]);
207void G_FreeSurfaceGridMesh(surfaceGrid_t *grid);
208
212
213typedef union varnodeUnpacked_u {
214 float fVariance;
215 int flags;
216 /*
217 struct {
218#if !Q3_BIG_ENDIAN
219 byte flags;
220 unsigned char unused[3];
221#else
222 unsigned char unused[3];
223 byte flags;
224#endif
225 } s;
226 */
227} varnodeUnpacked_t;
228
229#define TER_QUADS_PER_ROW 8
230#define TER_TRIS_PER_PATCH (TER_QUADS_PER_ROW * TER_QUADS_PER_ROW * 2)
231#define TER_PLANES_PER_TRI 5
232
234 cplane_t planes
235 [TER_PLANES_PER_TRI]; // 0 is the surface plane, 3 border planes follow and a cap to give it some finite volume
236};
237
239 vec3_t bounds[2];
240
241 baseshader_t *shader;
242
243 terTriangle_t tris[TER_TRIS_PER_PATCH];
244};
245
246struct terrainCollideSquare_t {
247 vec4_t plane[2];
248 winding_t *w;
249 int eMode;
250
251public:
252 terrainCollideSquare_t();
253 ~terrainCollideSquare_t();
254};
255
257 vec3_t vBounds[2];
258 terrainCollideSquare_t squares[8][8];
259};
260
261// Use a 32-bit int because there can be more than 65536 tris
262typedef unsigned int terraInt;
263
264void G_PrepareGenerateTerrainCollide(void);
265void G_GenerateTerrainCollide(cTerraPatch_t *patch, terrainCollide_t *tc);
266qboolean G_CreateTerPatchWindings(terrainCollide_t& tc);
267
269 vec3_t xyz;
270 float fVariance;
271 float fHgtAvg;
272 float fHgtAdd;
273 terraInt nRef;
274 terraInt iVertArray;
275 byte *pHgt;
276 terraInt iNext;
277 terraInt iPrev;
278};
279
281 terraInt iPt[3];
282 terraInt nSplit;
283 struct cTerraPatchUnpacked_t *patch;
284 varnodeUnpacked_t *varnode;
285 terraInt index;
286 byte lod;
287 byte byConstChecks;
288 terraInt iLeft;
289 terraInt iRight;
290 terraInt iBase;
291 terraInt iLeftChild;
292 terraInt iRightChild;
293 terraInt iParent;
294 terraInt iPrev;
295 terraInt iNext;
296};
297
299 terraInt iVertHead;
300 terraInt iTriHead;
301 terraInt iTriTail;
302 terraInt iMergeHead;
303 int nVerts;
304 int nTris;
305};
306
308 surfaceTerrain_t drawinfo;
309 float x0;
310 float y0;
311 float z0;
312 float zmax;
313 short int iNorth;
314 short int iEast;
315 short int iSouth;
316 short int iWest;
317 struct cTerraPatchUnpacked_t *pNextActive;
318 varnodeUnpacked_t varTree[2][63];
319 unsigned char heightmap[81];
320 byte flags;
321};
322
324 terraInt iFreeHead;
325 terraInt iCur;
326 size_t nFree;
327};
328
329extern terraTri_t *g_pTris;
330extern terrainVert_t *g_pVert;
331
332extern poolInfo_t g_tri;
333extern poolInfo_t g_vert;
334
335void G_PreTessellateTerrain(cTerraPatchUnpacked_t *terraPatches, size_t numTerraPatches);
336void G_DoTriSplitting(cTerraPatchUnpacked_t *terraPatches, size_t numTerraPatches);
337void G_DoGeomorphs(cTerraPatchUnpacked_t *terraPatches, size_t numTerraPatches);
338void G_TerrainFree();
339
343
344class gameLump_c;
345class bspMap_c;
346
352{
353public:
361 void ProcessBSPForNavigation(const char *mapname);
362
363private:
364 void LoadShaders(const gameLump_c& lump, Container<cshader_t>& shaders);
365 bool IsValidContentsForPlayer(int contents);
366 void LoadStaticModelDefs(const gameLump_c& lump);
367 void LoadPlanes(const gameLump_c& lump, Container<cplane_t>& planes);
368 void LoadBrushSides(
369 const gameLump_c& lump,
370 const Container<cshader_t>& shaders,
371 const Container<cplane_t>& planes,
373 );
374 void BoundBrush(cbrush_t *b);
375 void LoadBrushes(
376 const gameLump_c& lump,
377 const Container<cshader_t>& shaders,
378 const Container<cbrushside_t>& sides,
379 Container<cbrush_t>& brushes
380 );
381 void LoadLeafBrushes(const gameLump_c& lump, Container<int>& leafbrushes);
382 void LoadSubmodels(const gameLump_c& lump, Container<cmodel_t>& submodels);
383 void GenerateSideTriangles(navModel_t& model, const cbrush_t& brush, cbrushside_t& side);
384 void GenerateBrushTriangles(navModel_t& model, const Container<cplane_t>& planes, cbrush_t& brush);
385 void GenerateVerticesFromHull(bspMap_c& inBspMap, const Container<cshader_t>& shaders);
386 void RenderSurfaceGrid(const surfaceGrid_t *grid, navSurface_t& outSurface);
387 void ParseMesh(
388 const dsurface_t *ds, const drawVert_t *verts, const Container<cshader_t>& shaders, navSurface_t& outSurface
389 );
390 void ParseTriSurf(const dsurface_t *ds, const drawVert_t *verts, const int *indexes);
391 void ParseFace(const dsurface_t *ds, const drawVert_t *verts, const int *indexes);
392 void ParseFlare(const dsurface_t *ds, const drawVert_t *verts);
393 void LoadSurfaces(bspMap_c& inBspMap, const Container<cshader_t>& shaders);
394 void UnpackTerraPatch(const cTerraPatch_t *pPacked, cTerraPatchUnpacked_t *pUnpacked);
395 void SwapTerraPatch(cTerraPatch_t *pPatch);
396 void GenerateTerrainPatchMesh(const cTerraPatchUnpacked_t& patch);
397 void GenerateTerrainMesh(cTerraPatchUnpacked_t *terraPatches, size_t numTerraPatches);
398 void LoadAndRenderTerrain(bspMap_c& inBspMap, const Container<cshader_t>& shaders);
399 void CopyStaticModel(const cStaticModel_t *pSM, cStaticModelUnpacked_t *pUnpackedSM);
400
401public:
402 navMap_t navMap;
403};
Definition container.h:85
Navigation generated by a BSP file.
Definition navigation_bsp.h:352
void ProcessBSPForNavigation(const char *mapname)
Process the specified BSP map file and generate surfaces from it.
Definition navigation_bsp.cpp:1051
Definition vector.h:61
Definition navigation_bsp_lump.h:55
Definition navigation_bsp_lump.h:29
Definition navigation_bsp.h:148
Definition navigation_bsp.h:307
Definition navigation_bsp.h:131
Definition navigation_bsp.h:117
Definition navigation_bsp.h:139
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:323
Definition navigation_bsp.h:178
Definition navigation_bsp.h:298
Definition navigation_bsp.h:238
Definition navigation_bsp.h:233
Definition navigation_bsp.h:280
Definition navigation_bsp.h:246
Definition navigation_bsp.h:256
Definition navigation_bsp.h:268
Definition cm_polylib.h:28
Definition navigation_bsp.h:213