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