]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/tools/compilers/dmap/dmap.h
hello world
[icculus/iodoom3.git] / neo / tools / compilers / dmap / dmap.h
1 /*
2 ===========================================================================
3
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company. 
6
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).  
8
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code.  If not, see <http://www.gnu.org/licenses/>.
21
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code.  If not, please request a copy in writing from id Software at the address below.
23
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25
26 ===========================================================================
27 */
28
29 #include "../../../renderer/tr_local.h"
30
31
32 typedef struct primitive_s {
33         struct primitive_s *next;
34
35         // only one of these will be non-NULL
36         struct bspbrush_s *     brush;
37         struct mapTri_s *       tris;
38 } primitive_t;
39
40
41 typedef struct {
42         struct optimizeGroup_s  *groups;
43         // we might want to add other fields later
44 } uArea_t;
45
46 typedef struct {
47         idMapEntity *           mapEntity;              // points into mapFile_t data
48
49         idVec3                          origin;
50         primitive_t *           primitives;
51         struct tree_s *         tree;
52
53         int                                     numAreas;
54         uArea_t *                       areas;
55 } uEntity_t;
56
57
58 // chains of mapTri_t are the general unit of processing
59 typedef struct mapTri_s {
60         struct mapTri_s *       next;
61
62         const idMaterial *      material;
63         void *                          mergeGroup;             // we want to avoid merging triangles
64                                                                                         // from different fixed groups, like guiSurfs and mirrors
65         int                                     planeNum;                       // not set universally, just in some areas
66
67         idDrawVert                      v[3];
68         const struct hashVert_s *hashVert[3];
69         struct optVertex_s *optVert[3];
70 } mapTri_t;
71
72
73 typedef struct {
74         int                                     width, height;
75         idDrawVert *            verts;
76 } mesh_t;
77
78
79 #define MAX_PATCH_SIZE  32
80
81 #define PLANENUM_LEAF           -1
82
83 typedef struct parseMesh_s {
84         struct parseMesh_s *next;
85         mesh_t                          mesh;
86         const idMaterial *      material;
87 } parseMesh_t;
88
89 typedef struct bspface_s {
90         struct bspface_s *      next;
91         int                                     planenum;
92         bool                            portal;                 // all portals will be selected before
93                                                                                 // any non-portals
94         bool                            checked;                // used by SelectSplitPlaneNum()
95         idWinding *                     w;
96 } bspface_t;
97
98 typedef struct {
99         idVec4          v[2];           // the offset value will always be in the 0.0 to 1.0 range
100 } textureVectors_t;
101
102 typedef struct side_s {
103         int                                     planenum;
104
105         const idMaterial *      material;
106         textureVectors_t        texVec;
107
108         idWinding *                     winding;                // only clipped to the other sides of the brush
109         idWinding *                     visibleHull;    // also clipped to the solid parts of the world
110 } side_t;
111
112
113 typedef struct bspbrush_s {
114         struct bspbrush_s *     next;
115         struct bspbrush_s *     original;       // chopped up brushes will reference the originals
116
117         int                                     entitynum;                      // editor numbering for messages
118         int                                     brushnum;                       // editor numbering for messages
119
120         const idMaterial *      contentShader;  // one face's shader will determine the volume attributes
121
122         int                                     contents;
123         bool                            opaque;
124         int                                     outputNumber;           // set when the brush is written to the file list
125
126         idBounds                        bounds;
127         int                                     numsides;
128         side_t                          sides[6];                       // variably sized
129 } uBrush_t;
130
131
132 typedef struct drawSurfRef_s {
133         struct drawSurfRef_s *  nextRef;
134         int                                             outputNumber;
135 } drawSurfRef_t;
136
137
138 typedef struct node_s {
139         // both leafs and nodes
140         int                                     planenum;       // -1 = leaf node
141         struct node_s *         parent;
142         idBounds                        bounds;         // valid after portalization
143
144         // nodes only
145         side_t *                        side;           // the side that created the node
146         struct node_s *         children[2];
147         int                                     nodeNumber;     // set after pruning
148
149         // leafs only
150         bool                            opaque;         // view can never be inside
151
152         uBrush_t *                      brushlist;      // fragments of all brushes in this leaf
153                                                                         // needed for FindSideForPortal
154
155         int                                     area;           // determined by flood filling up to areaportals
156         int                                     occupied;       // 1 or greater can reach entity
157         uEntity_t *                     occupant;       // for leak file testing
158
159         struct uPortal_s *      portals;        // also on nodes during construction
160 } node_t;
161
162
163 typedef struct uPortal_s {
164         idPlane         plane;
165         node_t          *onnode;                // NULL = outside box
166         node_t          *nodes[2];              // [0] = front side of plane
167         struct uPortal_s        *next[2];
168         idWinding       *winding;
169 } uPortal_t;
170
171 // a tree_t is created by FaceBSP()
172 typedef struct tree_s {
173         node_t          *headnode;
174         node_t          outside_node;
175         idBounds        bounds;
176 } tree_t;
177
178 #define MAX_QPATH                       256                     // max length of a game pathname
179
180 typedef struct {
181         idRenderLightLocal      def;
182         char            name[MAX_QPATH];                // for naming the shadow volume surface and interactions
183         srfTriangles_t  *shadowTris;
184 } mapLight_t;
185
186 #define MAX_GROUP_LIGHTS        16
187
188 typedef struct optimizeGroup_s {
189         struct optimizeGroup_s  *nextGroup;
190
191         idBounds                        bounds;                 // set in CarveGroupsByLight
192
193         // all of these must match to add a triangle to the triList
194         bool                            smoothed;                               // curves will never merge with brushes
195         int                                     planeNum;
196         int                                     areaNum;
197         const idMaterial *      material;
198         int                                     numGroupLights;
199         mapLight_t *            groupLights[MAX_GROUP_LIGHTS];  // lights effecting this list
200         void *                          mergeGroup;             // if this differs (guiSurfs, mirrors, etc), the
201                                                                                 // groups will not be combined into model surfaces
202                                                                                 // after optimization
203         textureVectors_t        texVec;
204
205         bool                            surfaceEmited;
206
207         mapTri_t *                      triList;
208         mapTri_t *                      regeneratedTris;        // after each island optimization
209         idVec3                          axis[2];                        // orthogonal to the plane, so optimization can be 2D
210 } optimizeGroup_t;
211
212 // all primitives from the map are added to optimzeGroups, creating new ones as needed
213 // each optimizeGroup is then split into the map areas, creating groups in each area
214 // each optimizeGroup is then divided by each light, creating more groups
215 // the final list of groups is then tjunction fixed against all groups, then optimized internally
216 // multiple optimizeGroups will be merged together into .proc surfaces, but no further optimization
217 // is done on them
218
219
220 //=============================================================================
221
222 // dmap.cpp
223
224 typedef enum {
225         SO_NONE,                        // 0
226         SO_MERGE_SURFACES,      // 1
227         SO_CULL_OCCLUDED,       // 2
228         SO_CLIP_OCCLUDERS,      // 3
229         SO_CLIP_SILS,           // 4
230         SO_SIL_OPTIMIZE         // 5
231 } shadowOptLevel_t;
232
233 typedef struct {
234         // mapFileBase will contain the qpath without any extension: "maps/test_box"
235         char            mapFileBase[1024];
236
237         idMapFile       *dmapFile;
238
239         idPlaneSet      mapPlanes;
240
241         int                     num_entities;
242         uEntity_t       *uEntities;
243
244         int                     entityNum;
245
246         idList<mapLight_t*>     mapLights;
247
248         bool    verbose;
249
250         bool    glview;
251         bool    noOptimize;
252         bool    verboseentities;
253         bool    noCurves;
254         bool    fullCarve;
255         bool    noModelBrushes;
256         bool    noTJunc;
257         bool    nomerge;
258         bool    noFlood;
259         bool    noClipSides;            // don't cut sides by solid leafs, use the entire thing
260         bool    noLightCarve;           // extra triangle subdivision by light frustums
261         shadowOptLevel_t        shadowOptLevel;
262         bool    noShadow;                       // don't create optimized shadow volumes
263
264         idBounds        drawBounds;
265         bool    drawflag;
266
267         int             totalShadowTriangles;
268         int             totalShadowVerts;
269 } dmapGlobals_t;
270
271 extern dmapGlobals_t dmapGlobals;
272
273 int FindFloatPlane( const idPlane &plane, bool *fixedDegeneracies = NULL );
274
275
276 //=============================================================================
277
278 // brush.cpp
279
280 #ifndef CLIP_EPSILON
281 #define CLIP_EPSILON    0.1f
282 #endif
283
284 #define PSIDE_FRONT                     1
285 #define PSIDE_BACK                      2
286 #define PSIDE_BOTH                      (PSIDE_FRONT|PSIDE_BACK)
287 #define PSIDE_FACING            4
288
289 int     CountBrushList (uBrush_t *brushes);
290 uBrush_t *AllocBrush (int numsides);
291 void FreeBrush (uBrush_t *brushes);
292 void FreeBrushList (uBrush_t *brushes);
293 uBrush_t *CopyBrush (uBrush_t *brush);
294 void DrawBrushList (uBrush_t *brush);
295 void PrintBrush (uBrush_t *brush);
296 bool BoundBrush (uBrush_t *brush);
297 bool CreateBrushWindings (uBrush_t *brush);
298 uBrush_t        *BrushFromBounds( const idBounds &bounds );
299 float BrushVolume (uBrush_t *brush);
300 void WriteBspBrushMap( const char *name, uBrush_t *list );
301
302 void FilterBrushesIntoTree( uEntity_t *e );
303
304 void SplitBrush( uBrush_t *brush, int planenum, uBrush_t **front, uBrush_t **back);
305 node_t *AllocNode( void );
306
307
308 //=============================================================================
309
310 // map.cpp
311
312 bool            LoadDMapFile( const char *filename );
313 void            FreeOptimizeGroupList( optimizeGroup_t *groups );
314 void            FreeDMapFile( void );
315
316 //=============================================================================
317
318 // draw.cpp -- draw debug views either directly, or through glserv.exe
319
320 void Draw_ClearWindow( void );
321 void DrawWinding( const idWinding *w );
322 void DrawAuxWinding( const idWinding *w );
323
324 void DrawLine( idVec3 v1, idVec3 v2, int color );
325
326 void GLS_BeginScene( void );
327 void GLS_Winding( const idWinding *w, int code );
328 void GLS_Triangle( const mapTri_t *tri, int code );
329 void GLS_EndScene( void );
330
331
332
333 //=============================================================================
334
335 // portals.cpp
336
337 #define MAX_INTER_AREA_PORTALS  1024
338
339 typedef struct {
340         int             area0, area1;
341         side_t  *side;
342 } interAreaPortal_t;
343
344 extern  interAreaPortal_t interAreaPortals[MAX_INTER_AREA_PORTALS];
345 extern  int                                     numInterAreaPortals;
346
347 bool FloodEntities( tree_t *tree );
348 void FillOutside( uEntity_t *e );
349 void FloodAreas( uEntity_t *e );
350 void MakeTreePortals( tree_t *tree );
351 void FreePortal( uPortal_t *p );
352
353 //=============================================================================
354
355 // glfile.cpp -- write a debug file to be viewd with glview.exe
356
357 void OutputWinding( idWinding *w, idFile *glview );
358 void WriteGLView( tree_t *tree, char *source );
359
360 //=============================================================================
361
362 // leakfile.cpp
363
364 void LeakFile( tree_t *tree );
365
366 //=============================================================================
367
368 // facebsp.cpp
369
370 tree_t *AllocTree( void );
371
372 void FreeTree( tree_t *tree );
373
374 void FreeTree_r( node_t *node );
375 void FreeTreePortals_r( node_t *node );
376
377
378 bspface_t       *MakeStructuralBspFaceList( primitive_t *list );
379 bspface_t       *MakeVisibleBspFaceList( primitive_t *list );
380 tree_t          *FaceBSP( bspface_t *list );
381
382 //=============================================================================
383
384 // surface.cpp
385
386 mapTri_t *CullTrisInOpaqueLeafs( mapTri_t *triList, tree_t *tree );
387 void    ClipSidesByTree( uEntity_t *e );
388 void    SplitTrisToSurfaces( mapTri_t *triList, tree_t *tree );
389 void    PutPrimitivesInAreas( uEntity_t *e );
390 void    Prelight( uEntity_t *e );
391
392 //=============================================================================
393
394 // tritjunction.cpp
395
396 struct hashVert_s       *GetHashVert( idVec3 &v );
397 void    HashTriangles( optimizeGroup_t *groupList );
398 void    FreeTJunctionHash( void );
399 int             CountGroupListTris( const optimizeGroup_t *groupList );
400 void    FixEntityTjunctions( uEntity_t *e );
401 void    FixAreaGroupsTjunctions( optimizeGroup_t *groupList );
402 void    FixGlobalTjunctions( uEntity_t *e );
403
404 //=============================================================================
405
406 // optimize.cpp -- trianlge mesh reoptimization
407
408 // the shadow volume optimizer call internal optimizer routines, normal triangles
409 // will just be done by OptimizeEntity()
410
411
412 typedef struct optVertex_s {
413         idDrawVert      v;
414         idVec3  pv;                                     // projected against planar axis, third value is 0
415         struct optEdge_s *edges;
416         struct optVertex_s      *islandLink;
417         bool    addedToIsland;
418         bool    emited;                 // when regenerating triangles
419 } optVertex_t;
420
421 typedef struct optEdge_s {
422         optVertex_t     *v1, *v2;
423         struct optEdge_s        *islandLink;
424         bool    addedToIsland;
425         bool    created;                // not one of the original edges
426         bool    combined;               // combined from two or more colinear edges
427         struct optTri_s *frontTri, *backTri;
428         struct optEdge_s *v1link, *v2link;
429 } optEdge_t;
430
431 typedef struct optTri_s {
432         struct optTri_s *next;
433         idVec3          midpoint;
434         optVertex_t     *v[3];
435         bool    filled;
436 } optTri_t;
437
438 typedef struct {
439         optimizeGroup_t *group;
440         optVertex_t     *verts;
441         optEdge_t       *edges;
442         optTri_t        *tris;
443 } optIsland_t;
444
445
446 void    OptimizeEntity( uEntity_t *e );
447 void    OptimizeGroupList( optimizeGroup_t *groupList );
448
449 //=============================================================================
450
451 // tritools.cpp
452
453 mapTri_t        *AllocTri( void );
454 void            FreeTri( mapTri_t *tri );
455 int                     CountTriList( const mapTri_t *list );
456 mapTri_t        *MergeTriLists( mapTri_t *a, mapTri_t *b );
457 mapTri_t        *CopyTriList( const mapTri_t *a );
458 void            FreeTriList( mapTri_t *a );
459 mapTri_t        *CopyMapTri( const mapTri_t *tri );
460 float           MapTriArea( const mapTri_t *tri );
461 mapTri_t        *RemoveBadTris( const mapTri_t *tri );
462 void            BoundTriList( const mapTri_t *list, idBounds &b );
463 void            DrawTri( const mapTri_t *tri );
464 void            FlipTriList( mapTri_t *tris );
465 void            TriVertsFromOriginal( mapTri_t *tri, const mapTri_t *original );
466 void            PlaneForTri( const mapTri_t *tri, idPlane &plane );
467 idWinding       *WindingForTri( const mapTri_t *tri );
468 mapTri_t        *WindingToTriList( const idWinding *w, const mapTri_t *originalTri );
469 void            ClipTriList( const mapTri_t *list, const idPlane &plane, float epsilon, mapTri_t **front, mapTri_t **back );
470
471 //=============================================================================
472
473 // output.cpp
474
475 srfTriangles_t  *ShareMapTriVerts( const mapTri_t *tris );
476 void WriteOutputFile( void );
477
478 //=============================================================================
479
480 // shadowopt.cpp
481
482 srfTriangles_t *CreateLightShadow( optimizeGroup_t *shadowerGroups, const mapLight_t *light );
483 void            FreeBeamTree( struct beamTree_s *beamTree );
484
485 void            CarveTriByBeamTree( const struct beamTree_s *beamTree, const mapTri_t *tri, mapTri_t **lit, mapTri_t **unLit );