forked from hitmen047/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvbsp.h
661 lines (508 loc) · 18.7 KB
/
vbsp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#if !defined( VBSP_H )
#define VBSP_H
#include "cmdlib.h"
#include "mathlib/vector.h"
#include "scriplib.h"
#include "polylib.h"
#include "threads.h"
#include "bsplib.h"
#include "qfiles.h"
#include "utilmatlib.h"
#include "ChunkFile.h"
#ifdef WIN32
#pragma warning( disable: 4706 )
#endif
class CUtlBuffer;
#define MAX_BRUSH_SIDES 128
#define CLIP_EPSILON 0.1
#define TEXINFO_NODE -1 // side is allready on a node
// this will output glview files for the given brushmodel. Brushmodel 1 is the world, 2 is the first brush entity, etc.
#define DEBUG_BRUSHMODEL 0
struct portal_t;
struct node_t;
struct plane_t : public dplane_t
{
plane_t *hash_chain;
plane_t() { normal.Init(); }
};
struct brush_texture_t
{
Vector UAxis;
Vector VAxis;
vec_t shift[2];
vec_t rotate;
vec_t textureWorldUnitsPerTexel[2];
vec_t lightmapWorldUnitsPerLuxel;
char name[TEXTURE_NAME_LENGTH];
int flags;
brush_texture_t() : UAxis(0,0,0), VAxis(0,0,0) {}
};
struct mapdispinfo_t;
struct side_t
{
int planenum;
int texinfo;
mapdispinfo_t *pMapDisp;
winding_t *winding;
side_t *original; // bspbrush_t sides will reference the mapbrush_t sides
int contents; // from miptex
int surf; // from miptex
qboolean visible; // choose visble planes first
qboolean tested; // this plane allready checked as a split
qboolean bevel; // don't ever use for bsp splitting
side_t *next;
int origIndex;
int id; // This is the unique id generated by worldcraft for this side.
unsigned int smoothingGroups;
CUtlVector<int> aOverlayIds; // List of overlays that reside on this side.
CUtlVector<int> aWaterOverlayIds; // List of water overlays that reside on this side.
bool m_bDynamicShadowsEnabled; // Goes into dface_t::SetDynamicShadowsEnabled().
};
struct mapbrush_t
{
int entitynum;
int brushnum;
int id; // The unique ID of this brush in the editor, used for reporting errors.
int contents;
Vector mins, maxs;
int numsides;
side_t *original_sides;
};
#define PLANENUM_LEAF -1
#define MAX_MAP_DETAILPROPS 524279
#define MAXEDGES 32
struct face_t
{
int id;
face_t *next; // on node
// the chain of faces off of a node can be merged or split,
// but each face_t along the way will remain in the chain
// until the entire tree is freed
face_t *merged; // if set, this face isn't valid anymore
face_t *split[2]; // if set, this face isn't valid anymore
portal_t *portal;
int texinfo;
int dispinfo;
// This is only for surfaces that are the boundaries of fog volumes
// (ie. water surfaces)
// All of the rest of the surfaces can look at their leaf to find out
// what fog volume they are in.
node_t *fogVolumeLeaf;
int planenum;
int contents; // faces in different contents can't merge
int outputnumber;
winding_t *w;
int numpoints;
qboolean badstartvert; // tjunctions cannot be fixed without a midpoint vertex
int vertexnums[MAXEDGES];
side_t *originalface; // save the "side" this face came from
int firstPrimID;
int numPrims;
unsigned int smoothingGroups;
};
void EmitFace( face_t *f, qboolean onNode );
struct mapdispinfo_t
{
face_t face;
int entitynum;
int power;
int minTess;
float smoothingAngle;
Vector uAxis;
Vector vAxis;
Vector startPosition;
float alphaValues[MAX_DISPVERTS];
float maxDispDist;
float dispDists[MAX_DISPVERTS];
Vector vectorDisps[MAX_DISPVERTS];
Vector vectorOffsets[MAX_DISPVERTS];
int contents;
int brushSideID;
unsigned short triTags[MAX_DISPTRIS];
int flags;
#ifdef VSVMFIO
float m_elevation; // "elevation"
Vector m_offsetNormals[ MAX_DISPTRIS ]; // "offset_normals"
#endif // VSVMFIO
};
extern int nummapdispinfo;
extern mapdispinfo_t mapdispinfo[MAX_MAP_DISPINFO];
extern float g_defaultLuxelSize;
extern float g_luxelScale;
extern float g_minLuxelScale;
extern bool g_BumpAll;
extern int g_nDXLevel;
int GetDispInfoEntityNum( mapdispinfo_t *pDisp );
void ComputeBoundsNoSkybox( );
struct bspbrush_t
{
int id;
bspbrush_t *next;
Vector mins, maxs;
int side, testside; // side of node during construction
mapbrush_t *original;
int numsides;
side_t sides[6]; // variably sized
};
#define MAX_NODE_BRUSHES 8
struct leafface_t
{
face_t *pFace;
leafface_t *pNext;
};
struct node_t
{
int id;
// both leafs and nodes
int planenum; // -1 = leaf node
node_t *parent;
Vector mins, maxs; // valid after portalization
bspbrush_t *volume; // one for each leaf/node
// nodes only
side_t *side; // the side that created the node
node_t *children[2];
face_t *faces; // these are the cutup ones that live in the plane of "side".
// leafs only
bspbrush_t *brushlist; // fragments of all brushes in this leaf
leafface_t *leaffacelist;
int contents; // OR of all brush contents
int occupied; // 1 or greater can reach entity
entity_t *occupant; // for leak file testing
int cluster; // for portalfile writing
int area; // for areaportals
portal_t *portals; // also on nodes during construction
int diskId; // dnodes or dleafs index after this has been emitted
};
struct portal_t
{
int id;
plane_t plane;
node_t *onnode; // NULL = outside box
node_t *nodes[2]; // [0] = front side of plane
portal_t *next[2];
winding_t *winding;
qboolean sidefound; // false if ->side hasn't been checked
side_t *side; // NULL = non-visible
face_t *face[2]; // output face in bsp file
};
struct tree_t
{
node_t *headnode;
node_t outside_node;
Vector mins, maxs;
bool leaked;
};
extern int entity_num;
struct LoadSide_t;
struct LoadEntity_t;
class CManifest;
class CMapFile
{
public:
CMapFile( void ) { Init(); }
void Init( void );
void AddPlaneToHash (plane_t *p);
int CreateNewFloatPlane (Vector& normal, vec_t dist);
int FindFloatPlane (Vector& normal, vec_t dist);
int PlaneFromPoints(const Vector &p0, const Vector &p1, const Vector &p2);
void AddBrushBevels (mapbrush_t *b);
qboolean MakeBrushWindings (mapbrush_t *ob);
void MoveBrushesToWorld( entity_t *mapent );
void MoveBrushesToWorldGeneral( entity_t *mapent );
void RemoveContentsDetailFromEntity( entity_t *mapent );
int SideIDToIndex( int brushSideID );
void AddLadderKeys( entity_t *mapent );
ChunkFileResult_t LoadEntityCallback(CChunkFile *pFile, int nParam);
void ForceFuncAreaPortalWindowContents();
ChunkFileResult_t LoadSideCallback(CChunkFile *pFile, LoadSide_t *pSideInfo);
ChunkFileResult_t LoadConnectionsKeyCallback(const char *szKey, const char *szValue, LoadEntity_t *pLoadEntity);
ChunkFileResult_t LoadSolidCallback(CChunkFile *pFile, LoadEntity_t *pLoadEntity);
void TestExpandBrushes(void);
static char m_InstancePath[ MAX_PATH ];
static void SetInstancePath( const char *pszInstancePath );
static const char *GetInstancePath( void ) { return m_InstancePath; }
static bool DeterminePath( const char *pszBaseFileName, const char *pszInstanceFileName, char *pszOutFileName );
void CheckForInstances( const char *pszFileName );
void MergeInstance( entity_t *pInstanceEntity, CMapFile *Instance );
void MergePlanes( entity_t *pInstanceEntity, CMapFile *Instance, Vector &InstanceOrigin, QAngle &InstanceAngle, matrix3x4_t &InstanceMatrix );
void MergeBrushes( entity_t *pInstanceEntity, CMapFile *Instance, Vector &InstanceOrigin, QAngle &InstanceAngle, matrix3x4_t &InstanceMatrix );
void MergeBrushSides( entity_t *pInstanceEntity, CMapFile *Instance, Vector &InstanceOrigin, QAngle &InstanceAngle, matrix3x4_t &InstanceMatrix );
void ReplaceInstancePair( epair_t *pPair, entity_t *pInstanceEntity );
void MergeEntities( entity_t *pInstanceEntity, CMapFile *Instance, Vector &InstanceOrigin, QAngle &InstanceAngle, matrix3x4_t &InstanceMatrix );
void MergeOverlays( entity_t *pInstanceEntity, CMapFile *Instance, Vector &InstanceOrigin, QAngle &InstanceAngle, matrix3x4_t &InstanceMatrix );
static int m_InstanceCount;
static int c_areaportals;
plane_t mapplanes[MAX_MAP_PLANES];
int nummapplanes;
#define PLANE_HASHES 1024
plane_t *planehash[PLANE_HASHES];
int nummapbrushes;
mapbrush_t mapbrushes[MAX_MAP_BRUSHES];
Vector map_mins, map_maxs;
int nummapbrushsides;
side_t brushsides[MAX_MAP_BRUSHSIDES];
brush_texture_t side_brushtextures[MAX_MAP_BRUSHSIDES];
int num_entities;
entity_t entities[MAX_MAP_ENTITIES];
int c_boxbevels;
int c_edgebevels;
int c_clipbrushes;
int g_ClipTexinfo;
class CConnectionPairs
{
public:
CConnectionPairs( epair_t *pair, CConnectionPairs *next )
{
m_Pair = pair;
m_Next = next;
}
epair_t *m_Pair;
CConnectionPairs *m_Next;
};
CConnectionPairs *m_ConnectionPairs;
int m_StartMapOverlays;
int m_StartMapWaterOverlays;
};
extern CMapFile *g_MainMap;
extern CMapFile *g_LoadingMap;
extern CUtlVector< CMapFile * > g_Maps;
extern int g_nMapFileVersion;
extern qboolean noprune;
extern qboolean nodetail;
extern qboolean fulldetail;
extern qboolean nomerge;
extern qboolean nomergewater;
extern qboolean nosubdiv;
extern qboolean nowater;
extern qboolean noweld;
extern qboolean noshare;
extern qboolean notjunc;
extern qboolean nocsg;
extern qboolean noopt;
extern qboolean dumpcollide;
extern qboolean nodetailcuts;
extern qboolean g_DumpStaticProps;
extern qboolean g_bSkyVis;
extern vec_t microvolume;
extern bool g_snapAxialPlanes;
extern bool g_NodrawTriggers;
extern bool g_DisableWaterLighting;
extern bool g_bAllowDetailCracks;
extern bool g_bAllowDynamicPropsAsStatic;
extern bool g_bNoVirtualMesh;
extern char outbase[32];
extern char source[1024];
extern char mapbase[ 64 ];
extern CUtlVector<int> g_SkyAreas;
bool LoadMapFile( const char *pszFileName );
int GetVertexnum( Vector& v );
bool Is3DSkyboxArea( int area );
//=============================================================================
// textures.c
struct textureref_t
{
char name[TEXTURE_NAME_LENGTH];
int flags;
float lightmapWorldUnitsPerLuxel;
int contents;
};
extern textureref_t textureref[MAX_MAP_TEXTURES];
int FindMiptex (const char *name);
int TexinfoForBrushTexture (plane_t *plane, brush_texture_t *bt, const Vector& origin);
int GetSurfaceProperties2( MaterialSystemMaterial_t matID, const char *pMatName );
extern int g_SurfaceProperties[MAX_MAP_TEXDATA];
void LoadSurfaceProperties( void );
int PointLeafnum ( dmodel_t* pModel, const Vector& p );
//=============================================================================
void FindGCD (int *v);
mapbrush_t *Brush_LoadEntity (entity_t *ent);
int PlaneTypeForNormal (Vector& normal);
qboolean MakeBrushPlanes (mapbrush_t *b);
int FindIntPlane (int *inormal, int *iorigin);
void CreateBrush (int brushnum);
//=============================================================================
// detail objects
//=============================================================================
void AddDetailBlocker( entity_t *pFuncDetailBlocker );
void LoadEmitDetailObjectDictionary( char const* pGameDir );
void EmitDetailObjects();
//=============================================================================
// static props
//=============================================================================
void EmitStaticProps();
bool LoadStudioModel( char const* pFileName, char const* pEntityType, CUtlBuffer& buf );
//=============================================================================
//=============================================================================
// procedurally created .vmt files
//=============================================================================
void EmitStaticProps();
// draw.c
extern Vector draw_mins, draw_maxs;
extern bool g_bLightIfMissing;
void Draw_ClearWindow (void);
void DrawWinding (winding_t *w);
void GLS_BeginScene (void);
void GLS_Winding (winding_t *w, int code);
void GLS_EndScene (void);
//=============================================================================
// csg
enum detailscreen_e
{
FULL_DETAIL = 0,
ONLY_DETAIL = 1,
NO_DETAIL = 2,
};
#define TRANSPARENT_CONTENTS (CONTENTS_GRATE|CONTENTS_WINDOW)
#include "csg.h"
//=============================================================================
// brushbsp
void WriteBrushList (char *name, bspbrush_t *brush, qboolean onlyvis);
bspbrush_t *CopyBrush (bspbrush_t *brush);
void SplitBrush (bspbrush_t *brush, int planenum,
bspbrush_t **front, bspbrush_t **back);
tree_t *AllocTree (void);
node_t *AllocNode (void);
bspbrush_t *AllocBrush (int numsides);
int CountBrushList (bspbrush_t *brushes);
void FreeBrush (bspbrush_t *brushes);
vec_t BrushVolume (bspbrush_t *brush);
node_t *NodeForPoint (node_t *node, Vector& origin);
void BoundBrush (bspbrush_t *brush);
void FreeBrushList (bspbrush_t *brushes);
node_t *PointInLeaf (node_t *node, Vector& point);
tree_t *BrushBSP (bspbrush_t *brushlist, Vector& mins, Vector& maxs);
#define PSIDE_FRONT 1
#define PSIDE_BACK 2
#define PSIDE_BOTH (PSIDE_FRONT|PSIDE_BACK)
#define PSIDE_FACING 4
int BrushBspBoxOnPlaneSide (const Vector& mins, const Vector& maxs, dplane_t *plane);
extern qboolean WindingIsTiny (winding_t *w);
//=============================================================================
// portals.c
int VisibleContents (int contents);
void MakeHeadnodePortals (tree_t *tree);
void MakeNodePortal (node_t *node);
void SplitNodePortals (node_t *node);
qboolean Portal_VisFlood (portal_t *p);
qboolean FloodEntities (tree_t *tree);
void FillOutside (node_t *headnode);
void FloodAreas (tree_t *tree);
void MarkVisibleSides (tree_t *tree, int start, int end, int detailScreen);
void MarkVisibleSides (tree_t *tree, mapbrush_t **ppBrushes, int nCount );
void FreePortal (portal_t *p);
void EmitAreaPortals (node_t *headnode);
void MakeTreePortals (tree_t *tree);
//=============================================================================
// glfile.c
void OutputWinding (winding_t *w, FileHandle_t glview);
void OutputWindingColor (winding_t *w, FileHandle_t glview, int r, int g, int b);
void WriteGLView (tree_t *tree, char *source);
void WriteGLViewFaces (tree_t *tree, const char *source);
void WriteGLViewBrushList( bspbrush_t *pList, const char *pName );
//=============================================================================
// leakfile.c
void LeakFile (tree_t *tree);
void AreaportalLeakFile( tree_t *tree, portal_t *pStartPortal, portal_t *pEndPortal, node_t *pStart );
//=============================================================================
// prtfile.c
void AddVisCluster( entity_t *pFuncVisCluster );
void WritePortalFile (tree_t *tree);
//=============================================================================
// writebsp.c
void SetModelNumbers (void);
void SetLightStyles (void);
void BeginBSPFile (void);
void WriteBSP (node_t *headnode, face_t *pLeafFaceList);
void EndBSPFile (void);
void BeginModel (void);
void EndModel (void);
extern int firstmodeledge;
extern int firstmodelface;
//=============================================================================
// faces.c
void MakeFaces (node_t *headnode);
void MakeDetailFaces (node_t *headnode);
face_t *FixTjuncs( node_t *headnode, face_t *pLeafFaceList );
face_t *AllocFace (void);
void FreeFace (face_t *f);
void FreeFaceList( face_t *pFaces );
void MergeFaceList(face_t **pFaceList);
void SubdivideFaceList(face_t **pFaceList);
extern face_t *edgefaces[MAX_MAP_EDGES][2];
//=============================================================================
// tree.c
void FreeTree (tree_t *tree);
void FreeTree_r (node_t *node);
void PrintTree_r (node_t *node, int depth);
void FreeTreePortals_r (node_t *node);
void PruneNodes_r (node_t *node);
void PruneNodes (node_t *node);
// Returns true if the entity is a func_occluder
bool IsFuncOccluder( int entity_num );
//=============================================================================
// ivp.cpp
class CPhysCollide;
void EmitPhysCollision();
void DumpCollideToGlView( CPhysCollide *pCollide, const char *pFilename );
void EmitWaterVolumesForBSP( dmodel_t *pModel, node_t *headnode );
//=============================================================================
// find + find or create the texdata
int FindTexData( const char *pName );
int FindOrCreateTexData( const char *pName );
// Add a clone of an existing texdata with a new name
int AddCloneTexData( dtexdata_t *pExistingTexData, char const *cloneTexDataName );
int FindOrCreateTexInfo( const texinfo_t &searchTexInfo );
int FindAliasedTexData( const char *pName, dtexdata_t *sourceTexture );
int FindTexInfo( const texinfo_t &searchTexInfo );
//=============================================================================
// normals.c
void SaveVertexNormals( void );
//=============================================================================
// cubemap.cpp
extern char *g_pParallaxObbStrs[MAX_MAP_CUBEMAPSAMPLES];
void Cubemap_InsertSample( const Vector& origin, int size, char* pParallaxObbStr);
void Cubemap_CreateDefaultCubemaps( void );
void Cubemap_SaveBrushSides( const char *pSideListStr );
void Cubemap_FixupBrushSidesMaterials( void );
void Cubemap_AttachDefaultCubemapToSpecularSides( void );
// Add skipped cubemaps that are referenced by the engine
void Cubemap_AddUnreferencedCubemaps( void );
//=============================================================================
// overlay.cpp
#define OVERLAY_MAP_STRLEN 256
struct mapoverlay_t
{
int nId;
unsigned short m_nRenderOrder;
char szMaterialName[OVERLAY_MAP_STRLEN];
float flU[2];
float flV[2];
float flFadeDistMinSq;
float flFadeDistMaxSq;
Vector vecUVPoints[4];
Vector vecOrigin;
Vector vecBasis[3];
CUtlVector<int> aSideList;
CUtlVector<int> aFaceList;
};
extern CUtlVector<mapoverlay_t> g_aMapOverlays;
extern CUtlVector<mapoverlay_t> g_aMapWaterOverlays;
int Overlay_GetFromEntity( entity_t *pMapEnt );
void Overlay_UpdateSideLists( int StartIndex );
void Overlay_AddFaceToLists( int iFace, side_t *pSide );
void Overlay_EmitOverlayFaces( void );
void OverlayTransition_UpdateSideLists( int StartIndex );
void OverlayTransition_AddFaceToLists( int iFace, side_t *pSide );
void OverlayTransition_EmitOverlayFaces( void );
void Overlay_Translate( mapoverlay_t *pOverlay, Vector &OriginOffset, QAngle &AngleOffset, matrix3x4_t &Matrix );
//=============================================================================
void RemoveAreaPortalBrushes_R( node_t *node );
dtexdata_t *GetTexData( int index );
#endif