1 #ifndef HLBSP_H__
2 #define HLBSP_H__
3 
4 #if _MSC_VER >= 1000
5 #pragma once
6 #endif
7 
8 #include "cmdlib.h"
9 #include "messages.h"
10 #include "win32fix.h"
11 #include "log.h"
12 #include "hlassert.h"
13 #include "mathlib.h"
14 #include "bspfile.h"
15 #include "blockmem.h"
16 #include "filelib.h"
17 #include "threads.h"
18 #include "winding.h"
19 
20 #define ENTITIES_VOID "entities.void"
21 #define ENTITIES_VOID_EXT ".void"
22 
23 #define	BOGUS_RANGE	18000
24 
25 // the exact bounding box of the brushes is expanded some for the headnode
26 // volume.  is this still needed?
27 #define	SIDESPACE	24
28 
29 //============================================================================
30 
31 #define MIN_SUBDIVIDE_SIZE      64
32 
33 #ifdef ZHLT_GENERAL
34 #define MAX_SUBDIVIDE_SIZE      512
35 #else
36 #define MAX_SUBDIVIDE_SIZE      240
37 #endif
38 
39 #define DEFAULT_SUBDIVIDE_SIZE  240
40 
41 #define MIN_MAXNODE_SIZE        64
42 #define MAX_MAXNODE_SIZE        8192
43 #define DEFAULT_MAXNODE_SIZE    1024
44 
45 #define DEFAULT_NOFILL          false
46 #define DEFAULT_NOTJUNC         false
47 #define DEFAULT_NOCLIP          false
48 #define DEFAULT_NOOPT			false
49 #define DEFAULT_LEAKONLY        false
50 #define DEFAULT_WATERVIS        false
51 #define DEFAULT_CHART           false
52 #define DEFAULT_INFO            true
53 
54 #ifdef ZHLT_NULLTEX // AJM
55 #define DEFAULT_NULLTEX             true
56 #endif
57 
58 #ifdef ZHLT_PROGRESSFILE // AJM
59 #define DEFAULT_PROGRESSFILE NULL // progress file is only used if g_progressfile is non-null
60 #endif
61 
62 #ifdef SYSTEM_WIN32
63 #define DEFAULT_ESTIMATE        false
64 #endif
65 
66 #ifdef SYSTEM_POSIX
67 #define DEFAULT_ESTIMATE        true
68 #endif
69 
70 #ifdef ZHLT_DETAIL // AJM
71 #define DEFAULT_DETAIL      true
72 #endif
73 
74 #define	MAXEDGES			48                 // 32
75 #define	MAXPOINTS			28                 // don't let a base face get past this
76                                                                               // because it can be split more later
77 #define MAXNODESIZE     1024                               // Valve default is 1024
78 
79 typedef enum
80 {
81     face_normal = 0,
82     face_hint,
83     face_skip,
84 #ifdef ZHLT_NULLTEX // AJM
85     face_null,
86 #endif
87 #ifdef ZHLT_DETAIL // AJM
88     face_detail
89 #endif
90 }
91 facestyle_e;
92 
93 typedef struct face_s                                      // This structure is layed out so 'pts' is on a quad-word boundary (and the pointers are as well)
94 {
95     struct face_s*  next;
96     int             planenum;
97     int             texturenum;
98     int             contents;                              // contents in front of face
99 
100     struct face_s*  original;                              // face on node
101     int             outputnumber;                          // only valid for original faces after write surfaces
102     int             numpoints;
103     facestyle_e     facestyle;
104 
105     // vector quad word aligned
106     vec3_t          pts[MAXEDGES];                         // FIXME: change to use winding_t
107 
108 }
109 face_t;
110 
111 typedef struct surface_s
112 {
113     struct surface_s* next;
114     int             planenum;
115     vec3_t          mins, maxs;
116     struct node_s*  onnode;                                // true if surface has already been used
117     // as a splitting node
118     face_t*         faces;                                 // links to all the faces on either side of the surf
119 }
120 surface_t;
121 
122 typedef struct
123 {
124     vec3_t          mins, maxs;
125     surface_t*      surfaces;
126 }
127 surfchain_t;
128 
129 //
130 // there is a node_t structure for every node and leaf in the bsp tree
131 //
132 #define	PLANENUM_LEAF		-1
133 
134 typedef struct node_s
135 {
136     surface_t*      surfaces;
137 
138     vec3_t          mins, maxs;                            // bounding volume of portals;
139 
140     // information for decision nodes
141     int             planenum;                              // -1 = leaf node
142     struct node_s*  children[2];                           // only valid for decision nodes
143     face_t*         faces;                                 // decision nodes only, list for both sides
144 
145     // information for leafs
146     int             contents;                              // leaf nodes (0 for decision nodes)
147     face_t**        markfaces;                             // leaf nodes only, point to node faces
148     struct portal_s* portals;
149     int             visleafnum;                            // -1 = solid
150     int             valid;                                 // for flood filling
151     int             occupied;                              // light number in leaf for outside filling
152 }
153 node_t;
154 
155 #define	NUM_HULLS		4
156 
157 //=============================================================================
158 // solidbsp.c
159 extern void     SubdivideFace(face_t* f, face_t** prevptr);
160 extern node_t*  SolidBSP(const surfchain_t* const surfhead, bool report_progress);
161 
162 //=============================================================================
163 // merge.c
164 extern void     MergePlaneFaces(surface_t* plane);
165 extern void     MergeAll(surface_t* surfhead);
166 
167 //=============================================================================
168 // surfaces.c
169 extern void     MakeFaceEdges();
170 extern int      GetEdge(const vec3_t p1, const vec3_t p2, face_t* f);
171 
172 //=============================================================================
173 // portals.c
174 typedef struct portal_s
175 {
176     dplane_t        plane;
177     node_t*         onnode;                                // NULL = outside box
178     node_t*         nodes[2];                              // [0] = front side of plane
179     struct portal_s* next[2];
180     Winding*        winding;
181 }
182 portal_t;
183 
184 extern node_t   g_outside_node;                            // portals outside the world face this
185 
186 extern void     AddPortalToNodes(portal_t* p, node_t* front, node_t* back);
187 extern void     RemovePortalFromNode(portal_t* portal, node_t* l);
188 extern void     MakeHeadnodePortals(node_t* node, const vec3_t mins, const vec3_t maxs);
189 
190 extern void     FreePortals(node_t* node);
191 extern void     WritePortalfile(node_t* headnode);
192 
193 //=============================================================================
194 // tjunc.c
195 void            tjunc(node_t* headnode);
196 
197 //=============================================================================
198 // writebsp.c
199 extern void     WriteClipNodes(node_t* headnode);
200 extern void     WriteDrawNodes(node_t* headnode);
201 
202 extern void     BeginBSPFile();
203 extern void     FinishBSPFile();
204 
205 //=============================================================================
206 // outside.c
207 extern node_t*  FillOutside(node_t* node, bool leakfile, unsigned hullnum);
208 extern void     LoadAllowableOutsideList(const char* const filename);
209 extern void     FreeAllowableOutsideList();
210 
211 //=============================================================================
212 // misc functions
213 extern void     GetParamsFromEnt(entity_t* mapent);
214 
215 extern face_t*  AllocFace();
216 extern void     FreeFace(face_t* f);
217 
218 extern struct portal_s* AllocPortal();
219 extern void     FreePortal(struct portal_s* p);
220 
221 extern surface_t* AllocSurface();
222 extern void     FreeSurface(surface_t* s);
223 
224 extern node_t*  AllocNode();
225 
226 extern bool     CheckFaceForHint(const face_t* const f);
227 extern bool     CheckFaceForSkip(const face_t* const f);
228 #ifdef ZHLT_NULLTEX// AJM
229 extern bool     CheckFaceForNull(const face_t* const f);
230 #endif
231 
232 
233 // =====================================================================================
234 //Cpt_Andrew - UTSky Check
235 // =====================================================================================
236 extern bool     CheckFaceForEnv_Sky(const face_t* const f);
237 // =====================================================================================
238 
239 
240 #ifdef ZHLT_DETAIL // AJM
241 extern bool     CheckFaceForDetail(const face_t* const f);
242 #endif
243 
244 //=============================================================================
245 // cull.c
246 extern void     CullStuff();
247 
248 //=============================================================================
249 // qbsp.c
250 extern bool     g_nofill;
251 extern bool     g_notjunc;
252 extern bool     g_watervis;
253 extern bool     g_chart;
254 extern bool     g_estimate;
255 extern int      g_maxnode_size;
256 extern int      g_subdivide_size;
257 extern int      g_hullnum;
258 extern bool     g_bLeakOnly;
259 extern bool     g_bLeaked;
260 extern char     g_portfilename[_MAX_PATH];
261 extern char     g_pointfilename[_MAX_PATH];
262 extern char     g_linefilename[_MAX_PATH];
263 extern char     g_bspfilename[_MAX_PATH];
264 
265 
266 #ifdef ZHLT_DETAIL // AJM
267 extern bool g_bDetailBrushes;
268 #endif
269 
270 #ifdef ZHLT_NULLTEX // AJM
271 extern bool     g_bUseNullTex;
272 #endif
273 
274 extern face_t*  NewFaceFromFace(const face_t* const in);
275 extern void     SplitFace(face_t* in, const dplane_t* const split, face_t** front, face_t** back);
276 
277 #endif // qbsp.c====================================================================== HLBSP_H__
278