1 #ifndef HLCSG_H__
2 #define HLCSG_H__
3 
4 #if _MSC_VER >= 1000
5 #pragma once
6 #endif
7 
8 #include <deque>
9 #include <string>
10 #include <map>
11 
12 #include "cmdlib.h"
13 #include "messages.h"
14 #include "win32fix.h"
15 #include "log.h"
16 #include "hlassert.h"
17 #include "mathlib.h"
18 #include "scriplib.h"
19 #include "winding.h"
20 #include "threads.h"
21 #include "bspfile.h"
22 #include "blockmem.h"
23 #include "filelib.h"
24 #include "boundingbox.h"
25 // AJM: added in
26 #include "wadpath.h"
27 
28 #ifndef DOUBLEVEC_T
29 #error you must add -dDOUBLEVEC_T to the project!
30 #endif
31 
32 #define DEFAULT_BRUSH_UNION_THRESHOLD 0.0f
33 #define DEFAULT_TINY_THRESHOLD        0.5
34 #define DEFAULT_NOCLIP      false
35 #define DEFAULT_ONLYENTS    false
36 #define DEFAULT_WADTEXTURES true
37 #define DEFAULT_SKYCLIP     true
38 #define DEFAULT_CHART       false
39 #define DEFAULT_INFO        true
40 
41 #ifdef HLCSG_PRECISIONCLIP // KGP
42 #define FLOOR_Z 0.5
43 #define DEFAULT_CLIPTYPE clip_legacy
44 #endif
45 
46 #ifdef ZHLT_NULLTEX // AJM
47 #define DEFAULT_NULLTEX     true
48 #endif
49 
50 #ifdef HLCSG_CLIPECONOMY // AJM
51 #define DEFAULT_CLIPNAZI    true
52 #endif
53 
54 #ifdef HLCSG_AUTOWAD //  AJM
55 #define DEFAULT_WADAUTODETECT false
56 #endif
57 
58 #ifdef ZHLT_DETAIL // AJM
59 #define DEFAULT_DETAIL      true
60 #endif
61 
62 #ifdef ZHLT_PROGRESSFILE // AJM
63 #define DEFAULT_PROGRESSFILE NULL // progress file is only used if g_progressfile is non-null
64 #endif
65 
66 // AJM: added in
67 #define UNLESS(a)  if (!(a))
68 
69 #ifdef SYSTEM_WIN32
70 #define DEFAULT_ESTIMATE    false
71 #endif
72 
73 #ifdef SYSTEM_POSIX
74 #define DEFAULT_ESTIMATE    true
75 #endif
76 
77 #define BOGUS_RANGE    8192
78 
79 typedef struct
80 {
81     vec3_t          normal;
82     vec3_t          origin;
83     vec_t           dist;
84     planetypes      type;
85 } plane_t;
86 
87 
88 
89 typedef struct
90 {
91     vec3_t          UAxis;
92     vec3_t          VAxis;
93     vec_t           shift[2];
94     vec_t           rotate;
95     vec_t           scale[2];
96 } valve_vects;
97 
98 typedef struct
99 {
100     float           vects[2][4];
101 } quark_vects;
102 
103 typedef union
104 {
105     valve_vects     valve;
106     quark_vects     quark;
107 }
108 vects_union;
109 
110 extern int      g_nMapFileVersion;                         // map file version * 100 (ie 201), zero for pre-Worldcraft 2.0.1 maps
111 
112 typedef struct
113 {
114     char            txcommand;
115     vects_union     vects;
116     char            name[32];
117 } brush_texture_t;
118 
119 typedef struct side_s
120 {
121     brush_texture_t td;
122     vec_t           planepts[3][3];
123 } side_t;
124 
125 typedef struct bface_s
126 {
127     struct bface_s* next;
128     int             planenum;
129     plane_t*        plane;
130     Winding*        w;
131     int             texinfo;
132     bool            used;                                  // just for face counting
133     int             contents;
134     int             backcontents;
135     BoundingBox     bounds;
136 } bface_t;
137 
138 // NUM_HULLS should be no larger than MAX_MAP_HULLS
139 #define NUM_HULLS 4
140 
141 typedef struct
142 {
143     BoundingBox     bounds;
144     bface_t*        faces;
145 } brushhull_t;
146 
147 typedef struct brush_s
148 {
149     int             entitynum;
150     int             brushnum;
151 
152     int             firstside;
153     int             numsides;
154 
155 #ifdef HLCSG_CLIPECONOMY // AJM
156     unsigned int    noclip; // !!!FIXME: this should be a flag bitfield so we can use it for other stuff (ie. is this a detail brush...)
157 #endif
158 
159     int             contents;
160     brushhull_t     hulls[NUM_HULLS];
161 } brush_t;
162 
163 
164 //=============================================================================
165 // map.c
166 
167 extern int      g_nummapbrushes;
168 extern brush_t  g_mapbrushes[MAX_MAP_BRUSHES];
169 
170 #define MAX_MAP_SIDES   (MAX_MAP_BRUSHES*6)
171 
172 extern int      g_numbrushsides;
173 extern side_t   g_brushsides[MAX_MAP_SIDES];
174 
175 extern void     TextureAxisFromPlane(const plane_t* const pln, vec3_t xv, vec3_t yv);
176 extern void     LoadMapFile(const char* const filename);
177 
178 //=============================================================================
179 // textures.c
180 
181 typedef std::deque< std::string >::iterator WadInclude_i;
182 extern std::deque< std::string > g_WadInclude;  // List of substrings to wadinclude
183 
184 extern void     WriteMiptex();
185 extern int      TexinfoForBrushTexture(const plane_t* const plane, brush_texture_t* bt, const vec3_t origin);
186 
187 //=============================================================================
188 // brush.c
189 
190 extern brush_t* Brush_LoadEntity(entity_t* ent, int hullnum);
191 extern contents_t CheckBrushContents(const brush_t* const b);
192 
193 extern void     CreateBrush(intptr_t brushnum);
194 
195 //=============================================================================
196 // csg.c
197 
198 extern bool     g_chart;
199 extern bool     g_onlyents;
200 extern bool     g_noclip;
201 extern bool     g_wadtextures;
202 extern bool     g_skyclip;
203 extern bool     g_estimate;
204 extern const char* g_hullfile;
205 
206 #ifdef ZHLT_NULLTEX // AJM:
207 extern bool     g_bUseNullTex;
208 #endif
209 
210 #ifdef ZHLT_DETAIL // AJM
211 extern bool g_bDetailBrushes;
212 #endif
213 
214 #ifdef HLCSG_CLIPECONOMY // AJM:
215 extern bool     g_bClipNazi;
216 #endif
217 
218 #ifdef HLCSG_PRECISIONCLIP // KGP
219 #define EnumPrint(a) #a
220 typedef enum{clip_smallest,clip_normalized,clip_simple,clip_precise,clip_legacy} cliptype;
221 extern cliptype g_cliptype;
222 extern const char*	GetClipTypeString(cliptype);
223 #define TEX_BEVEL 32768
224 #endif
225 
226 #ifdef ZHLT_PROGRESSFILE // AJM
227 extern char*    g_progressfile ;
228 #endif
229 
230 extern vec_t    g_tiny_threshold;
231 extern vec_t    g_BrushUnionThreshold;
232 
233 extern plane_t  g_mapplanes[MAX_INTERNAL_MAP_PLANES];
234 extern int      g_nummapplanes;
235 
236 extern bface_t* NewFaceFromFace(const bface_t* const in);
237 extern bface_t* CopyFace(const bface_t* const f);
238 
239 extern void     FreeFace(bface_t* f);
240 
241 extern bface_t* CopyFaceList(bface_t* f);
242 extern void     FreeFaceList(bface_t* f);
243 
244 extern void     GetParamsFromEnt(entity_t* mapent);
245 
246 //=============================================================================
247 // wadinclude.c
248 // passed 'filename' is extensionless, the function cats ".wic" at runtime
249 
250 extern void     LoadWadincludeFile(const char* const filename);
251 extern void     SaveWadincludeFile(const char* const filename);
252 extern void     HandleWadinclude();
253 
254 //=============================================================================
255 // brushunion.c
256 void            CalculateBrushUnions(intptr_t brushnum);
257 
258 //============================================================================
259 // hullfile.cpp
260 extern vec3_t   g_hull_size[NUM_HULLS][2];
261 extern void     LoadHullfile(const char* filename);
262 
263 #ifdef HLCSG_WADCFG // AJM:
264 //============================================================================
265 // wadcfg.cpp
266 
267 extern void     LoadWadConfigFile();
268 extern void     ProcessWadConfiguration();
269 extern bool     g_bWadConfigsLoaded;
270 extern void     WadCfg_cleanup();
271 
272 #define MAX_WAD_CFG_NAME 32
273 extern char     wadconfigname[MAX_WAD_CFG_NAME];
274 
275 //JK: needed in wadcfg.cpp for *nix..
276 #ifndef SYSTEM_WIN32
277 extern char *g_apppath;
278 #endif
279 
280 //JK:
281 extern char *g_wadcfgfile;
282 
283 #endif // HLCSG_WADCFG
284 
285 #ifdef HLCSG_AUTOWAD
286 //============================================================================
287 // autowad.cpp      AJM
288 
289 extern bool     g_bWadAutoDetect;
290 extern int      g_numUsedTextures;
291 
292 extern void     GetUsedTextures();
293 extern bool     autowad_IsUsedTexture(const char* const texname);
294 //extern bool     autowad_IsUsedWad(const char* const path);
295 //extern void     autowad_PurgeName(const char* const texname);
296 extern void     autowad_cleanup();
297 extern void     autowad_UpdateUsedWads();
298 
299 #endif // HLCSG_AUTOWAD
300 
301 //=============================================================================
302 // properties.cpp
303 
304 #ifdef HLCSG_NULLIFY_INVISIBLE // KGP
305 #include <string>
306 #include <set>
307 extern void properties_initialize(const char* filename);
308 extern std::set<std::string> g_invisible_items;
309 #endif
310 
311 //============================================================================
312 #endif//HLCSG_H__
313