]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/q3map2/writebsp.c
9cfa577baeb8459de4e28c3aae6e6feaf9b6a7ab
[xonotic/netradiant.git] / tools / quake3 / q3map2 / writebsp.c
1 /* -------------------------------------------------------------------------------
2
3    Copyright (C) 1999-2007 id Software, Inc. and contributors.
4    For a list of contributors, see the accompanying CONTRIBUTORS file.
5
6    This file is part of GtkRadiant.
7
8    GtkRadiant is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    GtkRadiant is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GtkRadiant; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
22    ----------------------------------------------------------------------------------
23
24    This code has been altered significantly from its original form, to support
25    several games based on the Quake III Arena engine, in the form of "Q3Map2."
26
27    ------------------------------------------------------------------------------- */
28
29
30
31 /* marker */
32 #define WRITEBSP_C
33
34
35
36 /* dependencies */
37 #include "q3map2.h"
38
39 #ifdef SMOKINGUNS
40 #define NUM_PREFIXINFO 11 //very important
41
42 //prefixInfo-stats
43 typedef struct {
44         char    *name;
45         int             surfaceFlags;
46 } prefixInfo_t;
47
48
49 static prefixInfo_t prefixInfo[] = {
50         { "metal",      Q_SURF_METAL},
51         { "wood",       Q_SURF_WOOD},
52         { "cloth",      Q_SURF_CLOTH},
53         { "dirt",       Q_SURF_DIRT},
54         { "glass",      Q_SURF_GLASS},
55         { "plant",      Q_SURF_PLANT},
56         { "sand",       Q_SURF_SAND},
57         { "snow",       Q_SURF_SNOW},
58         { "stone",      Q_SURF_STONE},
59         { "water",      Q_SURF_WATER},
60         { "grass",      Q_SURF_GRASS},
61 };
62
63 //Added by Spoon to recognize surfaceparms by shadernames
64 int GetSurfaceParm(const char *tex){
65         char surf[MAX_QPATH], tex2[MAX_QPATH];
66         int     i, j = 0;
67
68         strcpy(tex2, tex);
69
70         //find last dir
71         for(i = 0; i < 64 && tex2[i] != '\0'; i++){
72                 if(tex2[i] == '\\' || tex2[i] == '/')
73                         j=i+1;
74         }
75
76         strcpy(surf, tex2+j);
77
78         for(i=0; i<10; i++){
79                 if(surf[i] == '_')
80                         break;
81         }
82         surf[i] = '\0';
83
84         //Sys_Printf("%s\n", surf);
85
86         for(i=0; i < NUM_PREFIXINFO; i++){
87                 if(!Q_stricmp(surf, prefixInfo[i].name)){
88                         return prefixInfo[i].surfaceFlags;
89                 }
90         }
91         return 0;
92 }
93 #endif
94
95
96
97 /*
98    EmitShader()
99    emits a bsp shader entry
100  */
101
102 int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){
103         int i;
104         shaderInfo_t    *si;
105
106
107         /* handle special cases */
108         if ( shader == NULL ) {
109                 shader = "noshader";
110         }
111
112         /* try to find an existing shader */
113         for ( i = 0; i < numBSPShaders; i++ )
114         {
115                 /* ydnar: handle custom surface/content flags */
116 #ifndef SMOKINGUNS
117                 if ( surfaceFlags != NULL && bspShaders[ i ].surfaceFlags != *surfaceFlags ) {
118                         continue;
119                 }
120                 if ( contentFlags != NULL && bspShaders[ i ].contentFlags != *contentFlags ) {
121                         continue;
122                 }
123 #endif
124
125                 /* compare name */
126                 if ( !Q_stricmp( shader, bspShaders[ i ].shader ) ) {
127                         return i;
128                 }
129         }
130
131         /* get shaderinfo */
132         si = ShaderInfoForShader( shader );
133
134         /* emit a new shader */
135         AUTOEXPAND_BY_REALLOC_BSP( Shaders, 1024 );
136
137         numBSPShaders++;
138         strcpy( bspShaders[ i ].shader, shader );
139         bspShaders[ i ].surfaceFlags = si->surfaceFlags;
140 #ifdef SMOKINGUNS
141         bspShaders[ i ].surfaceFlags |= GetSurfaceParm(si->shader);
142 #endif
143         bspShaders[ i ].contentFlags = si->contentFlags;
144
145         /* handle custom content/surface flags */
146 #ifndef SMOKINGUNS
147         if ( surfaceFlags != NULL ) {
148                 bspShaders[ i ].surfaceFlags = *surfaceFlags;
149         }
150         if ( contentFlags != NULL ) {
151                 bspShaders[ i ].contentFlags = *contentFlags;
152         }
153 #endif
154
155         /* recursively emit any damage shaders */
156         if ( si->damageShader != NULL && si->damageShader[ 0 ] != '\0' ) {
157                 Sys_FPrintf( SYS_VRB, "Shader %s has damage shader %s\n", si->shader, si->damageShader );
158                 EmitShader( si->damageShader, NULL, NULL );
159         }
160
161         /* return it */
162         return i;
163 }
164
165
166
167 /*
168    EmitPlanes()
169    there is no oportunity to discard planes, because all of the original
170    brushes will be saved in the map
171  */
172
173 void EmitPlanes( void ){
174         int i;
175         bspPlane_t  *bp;
176         plane_t     *mp;
177
178
179         /* walk plane list */
180         mp = mapplanes;
181         for ( i = 0; i < nummapplanes; i++, mp++ )
182         {
183                 AUTOEXPAND_BY_REALLOC_BSP( Planes, 1024 );
184                 bp = &bspPlanes[ numBSPPlanes ];
185                 VectorCopy( mp->normal, bp->normal );
186                 bp->dist = mp->dist;
187                 numBSPPlanes++;
188         }
189
190         /* emit some statistics */
191         Sys_FPrintf( SYS_VRB, "%9d BSP planes\n", numBSPPlanes );
192 }
193
194
195
196 /*
197    EmitLeaf()
198    emits a leafnode to the bsp file
199  */
200
201 void EmitLeaf( node_t *node ){
202         bspLeaf_t       *leaf_p;
203         brush_t         *b;
204         drawSurfRef_t   *dsr;
205
206
207         /* check limits */
208         if ( numBSPLeafs >= MAX_MAP_LEAFS ) {
209                 Error( "MAX_MAP_LEAFS" );
210         }
211
212         leaf_p = &bspLeafs[numBSPLeafs];
213         numBSPLeafs++;
214
215         leaf_p->cluster = node->cluster;
216         leaf_p->area = node->area;
217
218         /* emit bounding box */
219         VectorCopy( node->mins, leaf_p->mins );
220         VectorCopy( node->maxs, leaf_p->maxs );
221
222         /* emit leaf brushes */
223         leaf_p->firstBSPLeafBrush = numBSPLeafBrushes;
224         for ( b = node->brushlist; b; b = b->next )
225         {
226                 /* something is corrupting brushes */
227                 if ( (size_t) b < 256 ) {
228                         Sys_FPrintf( SYS_WRN, "WARNING: Node brush list corrupted (0x%08X)\n", b );
229                         break;
230                 }
231                 //%     if( b->guard != 0xDEADBEEF )
232                 //%             Sys_Printf( "Brush %6d: 0x%08X Guard: 0x%08X Next: 0x%08X Original: 0x%08X Sides: %d\n", b->brushNum, b, b, b->next, b->original, b->numsides );
233
234                 AUTOEXPAND_BY_REALLOC_BSP( LeafBrushes, 1024 );
235                 bspLeafBrushes[ numBSPLeafBrushes ] = b->original->outputNum;
236                 numBSPLeafBrushes++;
237         }
238
239         leaf_p->numBSPLeafBrushes = numBSPLeafBrushes - leaf_p->firstBSPLeafBrush;
240
241         /* emit leaf surfaces */
242         if ( node->opaque ) {
243                 return;
244         }
245
246         /* add the drawSurfRef_t drawsurfs */
247         leaf_p->firstBSPLeafSurface = numBSPLeafSurfaces;
248         for ( dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
249         {
250                 AUTOEXPAND_BY_REALLOC_BSP( LeafSurfaces, 1024 );
251                 bspLeafSurfaces[ numBSPLeafSurfaces ] = dsr->outputNum;
252                 numBSPLeafSurfaces++;
253         }
254
255         leaf_p->numBSPLeafSurfaces = numBSPLeafSurfaces - leaf_p->firstBSPLeafSurface;
256 }
257
258
259 /*
260    EmitDrawNode_r()
261    recursively emit the bsp nodes
262  */
263
264 int EmitDrawNode_r( node_t *node ){
265         bspNode_t   *n;
266         int i, n0;
267
268
269         /* check for leafnode */
270         if ( node->planenum == PLANENUM_LEAF ) {
271                 EmitLeaf( node );
272                 return -numBSPLeafs;
273         }
274
275         /* emit a node */
276         AUTOEXPAND_BY_REALLOC_BSP( Nodes, 1024 );
277         n0 = numBSPNodes;
278         n = &bspNodes[ n0 ];
279         numBSPNodes++;
280
281         VectorCopy( node->mins, n->mins );
282         VectorCopy( node->maxs, n->maxs );
283
284         if ( node->planenum & 1 ) {
285                 Error( "WriteDrawNodes_r: odd planenum" );
286         }
287         n->planeNum = node->planenum;
288
289         //
290         // recursively output the other nodes
291         //
292         for ( i = 0 ; i < 2 ; i++ )
293         {
294                 if ( node->children[i]->planenum == PLANENUM_LEAF ) {
295                         n->children[i] = -( numBSPLeafs + 1 );
296                         EmitLeaf( node->children[i] );
297                 }
298                 else
299                 {
300                         n->children[i] = numBSPNodes;
301                         EmitDrawNode_r( node->children[i] );
302                         // n may have become invalid here, so...
303                         n = &bspNodes[ n0 ];
304                 }
305         }
306
307         return n - bspNodes;
308 }
309
310
311
312 /*
313    ============
314    SetModelNumbers
315    ============
316  */
317 void SetModelNumbers( void ){
318         int i;
319         int models;
320         char value[10];
321
322         models = 1;
323         for ( i = 1 ; i < numEntities ; i++ ) {
324                 if ( entities[i].brushes || entities[i].patches ) {
325                         sprintf( value, "*%i", models );
326                         models++;
327                         SetKeyValue( &entities[i], "model", value );
328                 }
329         }
330
331 }
332
333
334
335
336 /*
337    SetLightStyles()
338    sets style keys for entity lights
339  */
340
341 void SetLightStyles( void ){
342         int i, j, style, numStyles;
343         const char  *t;
344         entity_t    *e;
345         epair_t     *ep, *next;
346         char value[ 10 ];
347         char lightTargets[ MAX_SWITCHED_LIGHTS ][ 64 ];
348         int lightStyles[ MAX_SWITCHED_LIGHTS ];
349
350         /* -keeplights option: force lights to be kept and ignore what the map file says */
351         if ( keepLights ) {
352                 SetKeyValue( &entities[0], "_keepLights", "1" );
353         }
354
355         /* ydnar: determine if we keep lights in the bsp */
356         if ( KeyExists( &entities[ 0 ], "_keepLights" ) == qtrue ) {
357                 t = ValueForKey( &entities[ 0 ], "_keepLights" );
358                 keepLights = ( t[ 0 ] == '1' ) ? qtrue : qfalse;
359         }
360
361         /* any light that is controlled (has a targetname) must have a unique style number generated for it */
362         numStyles = 0;
363         for ( i = 1; i < numEntities; i++ )
364         {
365                 e = &entities[ i ];
366
367                 t = ValueForKey( e, "classname" );
368                 if ( Q_strncasecmp( t, "light", 5 ) ) {
369                         continue;
370                 }
371                 t = ValueForKey( e, "targetname" );
372                 if ( t[ 0 ] == '\0' ) {
373                         /* ydnar: strip the light from the BSP file */
374                         if ( keepLights == qfalse ) {
375                                 ep = e->epairs;
376                                 while ( ep != NULL )
377                                 {
378                                         next = ep->next;
379                                         free( ep->key );
380                                         free( ep->value );
381                                         free( ep );
382                                         ep = next;
383                                 }
384                                 e->epairs = NULL;
385                                 numStrippedLights++;
386                         }
387
388                         /* next light */
389                         continue;
390                 }
391
392                 /* get existing style */
393                 style = IntForKey( e, "style" );
394                 if ( style < LS_NORMAL || style > LS_NONE ) {
395                         Error( "Invalid lightstyle (%d) on entity %d", style, i );
396                 }
397
398                 /* find this targetname */
399                 for ( j = 0; j < numStyles; j++ )
400                         if ( lightStyles[ j ] == style && !strcmp( lightTargets[ j ], t ) ) {
401                                 break;
402                         }
403
404                 /* add a new style */
405                 if ( j >= numStyles ) {
406                         if ( numStyles == MAX_SWITCHED_LIGHTS ) {
407                                 Error( "MAX_SWITCHED_LIGHTS (%d) exceeded, reduce the number of lights with targetnames", MAX_SWITCHED_LIGHTS );
408                         }
409                         strcpy( lightTargets[ j ], t );
410                         lightStyles[ j ] = style;
411                         numStyles++;
412                 }
413
414                 /* set explicit style */
415                 sprintf( value, "%d", 32 + j );
416                 SetKeyValue( e, "style", value );
417
418                 /* set old style */
419                 if ( style != LS_NORMAL ) {
420                         sprintf( value, "%d", style );
421                         SetKeyValue( e, "switch_style", value );
422                 }
423         }
424
425         /* emit some statistics */
426         Sys_FPrintf( SYS_VRB, "%9d light entities stripped\n", numStrippedLights );
427 }
428
429
430
431 /*
432    BeginBSPFile()
433    starts a new bsp file
434  */
435
436 void BeginBSPFile( void ){
437         /* these values may actually be initialized if the file existed when loaded, so clear them explicitly */
438         numBSPModels = 0;
439         numBSPNodes = 0;
440         numBSPBrushSides = 0;
441         numBSPLeafSurfaces = 0;
442         numBSPLeafBrushes = 0;
443
444         /* leave leaf 0 as an error, because leafs are referenced as negative number nodes */
445         numBSPLeafs = 1;
446
447
448         /* ydnar: gs mods: set the first 6 drawindexes to 0 1 2 2 1 3 for triangles and quads */
449         numBSPDrawIndexes = 6;
450         AUTOEXPAND_BY_REALLOC_BSP( DrawIndexes, 1024 );
451         bspDrawIndexes[ 0 ] = 0;
452         bspDrawIndexes[ 1 ] = 1;
453         bspDrawIndexes[ 2 ] = 2;
454         bspDrawIndexes[ 3 ] = 0;
455         bspDrawIndexes[ 4 ] = 2;
456         bspDrawIndexes[ 5 ] = 3;
457 }
458
459
460
461 #ifdef SMOKINGUNS
462 //added by spoon to get back the changed surfaceflags
463 void RestoreSurfaceFlags(char *filename){
464         int i;
465         FILE    *texfile;
466         int             surfaceFlags[MAX_MAP_DRAW_SURFS];
467         int             numTexInfos;
468
469         //first parse the tex-file
470         texfile = fopen(filename, "r");
471         if(texfile){
472                 fscanf( texfile, "TEXFILE\n%i\n", &numTexInfos);
473                 //Sys_Printf("%i\n", numTexInfos);
474
475                 for(i=0; i<numTexInfos; i++){
476                         vec3_t color;
477                         fscanf( texfile, "%i %f %f %f\n", &surfaceFlags[i],
478                                 &color[0], &color[1], &color[2]);
479                         bspShaders[i].surfaceFlags = surfaceFlags[i];
480                         //Sys_Printf("%i\n", surfaceFlags[i]);
481                 }
482         } else
483                 Sys_Printf("couldn't find %s not tex-file is now writed without surfaceFlags!\n", filename);
484 }
485
486 void WriteTexFile( char* name){
487         FILE                    *texfile;
488         char                    filename[1024];
489         int                             i;
490
491         sprintf (filename, "%s.tex", name);
492
493         if(!compile_map){
494                 RestoreSurfaceFlags(filename);
495         }
496
497         Sys_Printf("Writing %s ...\n", filename);
498         texfile = fopen (filename, "w");
499
500         fprintf( texfile, "TEXFILE\n");
501
502         fprintf( texfile, "%i\n", numBSPShaders);
503         for ( i = 0 ; i < numBSPShaders ; i++ ) {
504                 shaderInfo_t    *se = ShaderInfoForShader(bspShaders[i].shader);
505
506                 fprintf( texfile, "\n%i %f %f %f", bspShaders[i].surfaceFlags,
507                         se->color[0], se->color[1], se->color[2]);
508
509
510                 bspShaders[i].surfaceFlags = i;
511         }
512         fclose(texfile);
513 }
514 #endif
515
516
517
518 /*
519    EndBSPFile()
520    finishes a new bsp and writes to disk
521  */
522
523 void EndBSPFile( qboolean do_write, const char *BSPFilePath, const char *surfaceFilePath ){
524
525         Sys_FPrintf( SYS_VRB, "--- EndBSPFile ---\n" );
526
527         EmitPlanes();
528
529         numBSPEntities = numEntities;
530         UnparseEntities();
531
532         if ( do_write ) {
533                 /* write the surface extra file */
534                 WriteSurfaceExtraFile( surfaceFilePath );
535
536 #ifdef SMOKINGUNS
537                 //only create tex file if it is the first compile
538                 WriteTexFile (source);
539 #endif
540
541                 /* write the bsp */
542                 Sys_Printf( "Writing %s\n", BSPFilePath );
543                 WriteBSPFile( BSPFilePath );
544         }
545 }
546
547
548
549 /*
550    EmitBrushes()
551    writes the brush list to the bsp
552  */
553
554 void EmitBrushes( brush_t *brushes, int *firstBrush, int *numBrushes ){
555         int j;
556         brush_t         *b;
557         bspBrush_t      *db;
558         bspBrushSide_t  *cp;
559
560
561         /* set initial brush */
562         if ( firstBrush != NULL ) {
563                 *firstBrush = numBSPBrushes;
564         }
565         if ( numBrushes != NULL ) {
566                 *numBrushes = 0;
567         }
568
569         /* walk list of brushes */
570         for ( b = brushes; b != NULL; b = b->next )
571         {
572                 /* check limits */
573                 AUTOEXPAND_BY_REALLOC_BSP( Brushes, 1024 );
574
575                 /* get bsp brush */
576                 b->outputNum = numBSPBrushes;
577                 db = &bspBrushes[ numBSPBrushes ];
578                 numBSPBrushes++;
579                 if ( numBrushes != NULL ) {
580                         ( *numBrushes )++;
581                 }
582
583                 db->shaderNum = EmitShader( b->contentShader->shader, &b->contentShader->contentFlags, &b->contentShader->surfaceFlags );
584                 db->firstSide = numBSPBrushSides;
585
586                 /* walk sides */
587                 db->numSides = 0;
588                 for ( j = 0; j < b->numsides; j++ )
589                 {
590                         /* set output number to bogus initially */
591                         b->sides[ j ].outputNum = -1;
592
593                         /* check count */
594                         AUTOEXPAND_BY_REALLOC_BSP( BrushSides, 1024 );
595
596                         /* emit side */
597                         b->sides[ j ].outputNum = numBSPBrushSides;
598                         cp = &bspBrushSides[ numBSPBrushSides ];
599                         db->numSides++;
600                         numBSPBrushSides++;
601                         cp->planeNum = b->sides[ j ].planenum;
602
603                         /* emit shader */
604                         if ( b->sides[ j ].shaderInfo ) {
605                                 cp->shaderNum = EmitShader( b->sides[ j ].shaderInfo->shader, &b->sides[ j ].shaderInfo->contentFlags, &b->sides[ j ].shaderInfo->surfaceFlags );
606                         }
607                         else{
608                                 cp->shaderNum = EmitShader( NULL, NULL, NULL );
609                         }
610                 }
611         }
612 }
613
614
615
616 /*
617    EmitFogs() - ydnar
618    turns map fogs into bsp fogs
619  */
620
621 void EmitFogs( void ){
622         int i, j;
623
624
625         /* setup */
626         numBSPFogs = numMapFogs;
627
628         /* walk list */
629         for ( i = 0; i < numMapFogs; i++ )
630         {
631                 /* set shader */
632                 strcpy( bspFogs[ i ].shader, mapFogs[ i ].si->shader );
633
634                 /* global fog doesn't have an associated brush */
635                 if ( mapFogs[ i ].brush == NULL ) {
636                         bspFogs[ i ].brushNum = -1;
637                         bspFogs[ i ].visibleSide = -1;
638                 }
639                 else
640                 {
641                         /* set brush */
642                         bspFogs[ i ].brushNum = mapFogs[ i ].brush->outputNum;
643
644                         /* try to use forced visible side */
645                         if ( mapFogs[ i ].visibleSide >= 0 ) {
646                                 bspFogs[ i ].visibleSide = mapFogs[ i ].visibleSide;
647                                 continue;
648                         }
649
650                         /* find visible side */
651                         for ( j = 0; j < 6; j++ )
652                         {
653                                 if ( mapFogs[ i ].brush->sides[ j ].visibleHull != NULL ) {
654                                         Sys_Printf( "Fog %d has visible side %d\n", i, j );
655                                         bspFogs[ i ].visibleSide = j;
656                                         break;
657                                 }
658                         }
659                 }
660         }
661 }
662
663
664
665 /*
666    BeginModel()
667    sets up a new brush model
668  */
669
670 void BeginModel( void ){
671         bspModel_t  *mod;
672         brush_t     *b;
673         entity_t    *e;
674         vec3_t mins, maxs;
675         vec3_t lgMins, lgMaxs;          /* ydnar: lightgrid mins/maxs */
676         parseMesh_t *p;
677         int i;
678
679
680         /* test limits */
681         AUTOEXPAND_BY_REALLOC_BSP( Models, 256 );
682
683         /* get model and entity */
684         mod = &bspModels[ numBSPModels ];
685         e = &entities[ mapEntityNum ];
686
687         /* ydnar: lightgrid mins/maxs */
688         ClearBounds( lgMins, lgMaxs );
689
690         /* bound the brushes */
691         ClearBounds( mins, maxs );
692         for ( b = e->brushes; b; b = b->next )
693         {
694                 /* ignore non-real brushes (origin, etc) */
695                 if ( b->numsides == 0 ) {
696                         continue;
697                 }
698                 AddPointToBounds( b->mins, mins, maxs );
699                 AddPointToBounds( b->maxs, mins, maxs );
700
701                 /* ydnar: lightgrid bounds */
702                 if ( b->compileFlags & C_LIGHTGRID ) {
703                         AddPointToBounds( b->mins, lgMins, lgMaxs );
704                         AddPointToBounds( b->maxs, lgMins, lgMaxs );
705                 }
706         }
707
708         /* bound patches */
709         for ( p = e->patches; p; p = p->next )
710         {
711                 for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ )
712                         AddPointToBounds( p->mesh.verts[i].xyz, mins, maxs );
713         }
714
715         /* ydnar: lightgrid mins/maxs */
716         if ( lgMins[ 0 ] < 99999 ) {
717                 /* use lightgrid bounds */
718                 VectorCopy( lgMins, mod->mins );
719                 VectorCopy( lgMaxs, mod->maxs );
720         }
721         else
722         {
723                 /* use brush/patch bounds */
724                 VectorCopy( mins, mod->mins );
725                 VectorCopy( maxs, mod->maxs );
726         }
727
728         /* note size */
729         Sys_FPrintf( SYS_VRB, "BSP bounds: { %f %f %f } { %f %f %f }\n", mins[ 0 ], mins[ 1 ], mins[ 2 ], maxs[ 0 ], maxs[ 1 ], maxs[ 2 ] );
730         Sys_FPrintf( SYS_VRB, "Lightgrid bounds: { %f %f %f } { %f %f %f }\n", lgMins[ 0 ], lgMins[ 1 ], lgMins[ 2 ], lgMaxs[ 0 ], lgMaxs[ 1 ], lgMaxs[ 2 ] );
731
732         /* set firsts */
733         mod->firstBSPSurface = numBSPDrawSurfaces;
734         mod->firstBSPBrush = numBSPBrushes;
735 }
736
737
738
739
740 /*
741    EndModel()
742    finish a model's processing
743  */
744
745 void EndModel( entity_t *e, node_t *headnode ){
746         bspModel_t  *mod;
747
748
749         /* note it */
750         Sys_FPrintf( SYS_VRB, "--- EndModel ---\n" );
751
752         /* emit the bsp */
753         mod = &bspModels[ numBSPModels ];
754         EmitDrawNode_r( headnode );
755
756         /* set surfaces and brushes */
757         mod->numBSPSurfaces = numBSPDrawSurfaces - mod->firstBSPSurface;
758         mod->firstBSPBrush = e->firstBrush;
759         mod->numBSPBrushes = e->numBrushes;
760
761         /* increment model count */
762         numBSPModels++;
763 }