Debian Codegraph @

tools/quake3/q3map2/writebsp.c

raw symbols SCIP
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 if ( !doingBSP ){
126 si = ShaderInfoForShader( shader );
127 if ( si->remapShader && si->remapShader[ 0 ] ) {
128 shader = si->remapShader;
129 }
130 }
131 /* compare name */
132 if ( !Q_stricmp( shader, bspShaders[ i ].shader ) ) {
133 return i;
134 }
135 }
136
137 /* Backup flags before reallocating in case the data is moved,
138 to avoid use-after-free. */
139 qboolean hadSurfaceFlags = surfaceFlags != NULL;
140 int savedSurfaceFlags = hadSurfaceFlags ? *surfaceFlags : 0;
141 qboolean hadContentFlags = contentFlags != NULL;
142 int savedContentFlags = hadContentFlags ? *contentFlags : 0;
143
144 /* get shaderinfo */
145 si = ShaderInfoForShader( shader );
146
147 /* emit a new shader */
148 AUTOEXPAND_BY_REALLOC0_BSP( Shaders, 1024 );
149
150 numBSPShaders++;
151 strcpy( bspShaders[ i ].shader, shader );
152 bspShaders[ i ].surfaceFlags = hadSurfaceFlags ? savedSurfaceFlags : si->surfaceFlags;
153 bspShaders[ i ].contentFlags = hadContentFlags ? savedContentFlags : si->contentFlags;
154
155 if ( game->texFile )
156 {
157 /* Smokin'Guns like tex file */
158 bspShaders[ i ].surfaceFlags |= GetSurfaceParm(si->shader);
159 }
160
161 /* recursively emit any damage shaders */
162 if ( si->damageShader != NULL && si->damageShader[ 0 ] != '\0' ) {
163 Sys_FPrintf( SYS_VRB, "Shader %s has damage shader %s\n", si->shader, si->damageShader );
164 EmitShader( si->damageShader, NULL, NULL );
165 }
166
167 /* return it */
168 return i;
169 }
170
171
172
173 /*
174 EmitPlanes()
175 there is no oportunity to discard planes, because all of the original
176 brushes will be saved in the map
177 */
178
179 void EmitPlanes( void ){
180 int i;
181 bspPlane_t *bp;
182 plane_t *mp;
183
184
185 /* walk plane list */
186 mp = mapplanes;
187 for ( i = 0; i < nummapplanes; i++, mp++ )
188 {
189 AUTOEXPAND_BY_REALLOC_BSP( Planes, 1024 );
190 bp = &bspPlanes[ numBSPPlanes ];
191 VectorCopy( mp->normal, bp->normal );
192 bp->dist = mp->dist;
193 numBSPPlanes++;
194 }
195
196 /* emit some statistics */
197 Sys_FPrintf( SYS_VRB, "%9d BSP planes\n", numBSPPlanes );
198 }
199
200
201
202 /*
203 EmitLeaf()
204 emits a leafnode to the bsp file
205 */
206
207 void EmitLeaf( node_t *node ){
208 bspLeaf_t *leaf_p;
209 brush_t *b;
210 drawSurfRef_t *dsr;
211
212
213 /* check limits */
214 if ( numBSPLeafs >= MAX_MAP_LEAFS ) {
215 Error( "MAX_MAP_LEAFS" );
216 }
217
218 leaf_p = &bspLeafs[numBSPLeafs];
219 numBSPLeafs++;
220
221 leaf_p->cluster = node->cluster;
222 leaf_p->area = node->area;
223
224 /* emit bounding box */
225 VectorCopy( node->mins, leaf_p->mins );
226 VectorCopy( node->maxs, leaf_p->maxs );
227
228 /* emit leaf brushes */
229 leaf_p->firstBSPLeafBrush = numBSPLeafBrushes;
230 for ( b = node->brushlist; b; b = b->next )
231 {
232 /* something is corrupting brushes */
233 if ( (size_t) b < 256 ) {
234 Sys_FPrintf( SYS_WRN, "WARNING: Node brush list corrupted (0x%08X)\n", b );
235 break;
236 }
237 //% if( b->guard != 0xDEADBEEF )
238 //% 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 );
239
240 AUTOEXPAND_BY_REALLOC_BSP( LeafBrushes, 1024 );
241 bspLeafBrushes[ numBSPLeafBrushes ] = b->original->outputNum;
242 numBSPLeafBrushes++;
243 }
244
245 leaf_p->numBSPLeafBrushes = numBSPLeafBrushes - leaf_p->firstBSPLeafBrush;
246
247 /* emit leaf surfaces */
248 if ( node->opaque ) {
249 return;
250 }
251
252 /* add the drawSurfRef_t drawsurfs */
253 leaf_p->firstBSPLeafSurface = numBSPLeafSurfaces;
254 for ( dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
255 {
256 AUTOEXPAND_BY_REALLOC_BSP( LeafSurfaces, 1024 );
257 bspLeafSurfaces[ numBSPLeafSurfaces ] = dsr->outputNum;
258 numBSPLeafSurfaces++;
259 }
260
261 leaf_p->numBSPLeafSurfaces = numBSPLeafSurfaces - leaf_p->firstBSPLeafSurface;
262 }
263
264
265 /*
266 EmitDrawNode_r()
267 recursively emit the bsp nodes
268 */
269
270 int EmitDrawNode_r( node_t *node ){
271 bspNode_t *n;
272 int i, n0;
273
274
275 /* check for leafnode */
276 if ( node->planenum == PLANENUM_LEAF ) {
277 EmitLeaf( node );
278 return -numBSPLeafs;
279 }
280
281 /* emit a node */
282 AUTOEXPAND_BY_REALLOC_BSP( Nodes, 1024 );
283 n0 = numBSPNodes;
284 n = &bspNodes[ n0 ];
285 numBSPNodes++;
286
287 VectorCopy( node->mins, n->mins );
288 VectorCopy( node->maxs, n->maxs );
289
290 if ( node->planenum & 1 ) {
291 Error( "WriteDrawNodes_r: odd planenum" );
292 }
293 n->planeNum = node->planenum;
294
295 //
296 // recursively output the other nodes
297 //
298 for ( i = 0 ; i < 2 ; i++ )
299 {
300 if ( node->children[i]->planenum == PLANENUM_LEAF ) {
301 n->children[i] = -( numBSPLeafs + 1 );
302 EmitLeaf( node->children[i] );
303 }
304 else
305 {
306 n->children[i] = numBSPNodes;
307 EmitDrawNode_r( node->children[i] );
308 // n may have become invalid here, so...
309 n = &bspNodes[ n0 ];
310 }
311 }
312
313 return n - bspNodes;
314 }
315
316
317
318 /*
319 ============
320 SetModelNumbers
321 ============
322 */
323 void SetModelNumbers( void ){
324 int i;
325 int models;
326 char value[10];
327
328 models = 1;
329 for ( i = 1 ; i < numEntities ; i++ ) {
330 if ( entities[i].brushes || entities[i].patches ) {
331 sprintf( value, "*%i", models );
332 models++;
333 SetKeyValue( &entities[i], "model", value );
334 }
335 }
336
337 }
338
339
340
341
342 /*
343 SetLightStyles()
344 sets style keys for entity lights
345 */
346
347 void SetLightStyles( void ){
348 int i, j, style, numStyles;
349 const char *t;
350 entity_t *e;
351 epair_t *ep, *next;
352 char value[ 10 ];
353 char lightTargets[ MAX_SWITCHED_LIGHTS ][ 64 ];
354 int lightStyles[ MAX_SWITCHED_LIGHTS ];
355
356 /* -keeplights option: force lights to be kept and ignore what the map file says */
357 if ( keepLights ) {
358 SetKeyValue( &entities[0], "_keepLights", "1" );
359 }
360
361 /* ydnar: determine if we keep lights in the bsp */
362 if ( KeyExists( &entities[ 0 ], "_keepLights" ) == qtrue ) {
363 t = ValueForKey( &entities[ 0 ], "_keepLights" );
364 keepLights = ( t[ 0 ] == '1' ) ? qtrue : qfalse;
365 }
366
367 /* any light that is controlled (has a targetname) must have a unique style number generated for it */
368 numStyles = 0;
369 for ( i = 1; i < numEntities; i++ )
370 {
371 e = &entities[ i ];
372
373 t = ValueForKey( e, "classname" );
374 if ( Q_strncasecmp( t, "light", 5 ) ) {
375 continue;
376 }
377 t = ValueForKey( e, "targetname" );
378 if ( t[ 0 ] == '\0' ) {
379 /* ydnar: strip the light from the BSP file */
380 if ( keepLights == qfalse ) {
381 ep = e->epairs;
382 while ( ep != NULL )
383 {
384 next = ep->next;
385 free( ep->key );
386 free( ep->value );
387 free( ep );
388 ep = next;
389 }
390 e->epairs = NULL;
391 numStrippedLights++;
392 }
393
394 /* next light */
395 continue;
396 }
397
398 /* get existing style */
399 style = IntForKey( e, "style" );
400 if ( style < LS_NORMAL || style > LS_NONE ) {
401 Error( "Invalid lightstyle (%d) on entity %d", style, i );
402 }
403
404 /* find this targetname */
405 for ( j = 0; j < numStyles; j++ )
406 if ( lightStyles[ j ] == style && !strcmp( lightTargets[ j ], t ) ) {
407 break;
408 }
409
410 /* add a new style */
411 if ( j >= numStyles ) {
412 if ( numStyles == MAX_SWITCHED_LIGHTS ) {
413 Error( "MAX_SWITCHED_LIGHTS (%d) exceeded, reduce the number of lights with targetnames", MAX_SWITCHED_LIGHTS );
414 }
415 strcpy( lightTargets[ j ], t );
416 lightStyles[ j ] = style;
417 numStyles++;
418 }
419
420 /* set explicit style */
421 sprintf( value, "%d", 32 + j );
422 SetKeyValue( e, "style", value );
423
424 /* set old style */
425 if ( style != LS_NORMAL ) {
426 sprintf( value, "%d", style );
427 SetKeyValue( e, "switch_style", value );
428 }
429 }
430
431 /* emit some statistics */
432 Sys_FPrintf( SYS_VRB, "%9d light entities stripped\n", numStrippedLights );
433 }
434
435
436
437 /*
438 BeginBSPFile()
439 starts a new bsp file
440 */
441
442 void BeginBSPFile( void ){
443 /* these values may actually be initialized if the file existed when loaded, so clear them explicitly */
444 numBSPModels = 0;
445 numBSPNodes = 0;
446 numBSPBrushSides = 0;
447 numBSPLeafSurfaces = 0;
448 numBSPLeafBrushes = 0;
449
450 /* leave leaf 0 as an error, because leafs are referenced as negative number nodes */
451 numBSPLeafs = 1;
452
453
454 /* ydnar: gs mods: set the first 6 drawindexes to 0 1 2 2 1 3 for triangles and quads */
455 numBSPDrawIndexes = 6;
456 AUTOEXPAND_BY_REALLOC_BSP( DrawIndexes, 1024 );
457 bspDrawIndexes[ 0 ] = 0;
458 bspDrawIndexes[ 1 ] = 1;
459 bspDrawIndexes[ 2 ] = 2;
460 bspDrawIndexes[ 3 ] = 0;
461 bspDrawIndexes[ 4 ] = 2;
462 bspDrawIndexes[ 5 ] = 3;
463 }
464
465
466
467 /*
468 RestoreSurfaceFlags()
469 read Smokin'Guns like tex file
470 added by spoon to get back the changed surfaceflags
471 */
472
473 void RestoreSurfaceFlags( char *filename ) {
474 int i;
475 FILE *texfile;
476 int surfaceFlags[ MAX_MAP_DRAW_SURFS ];
477 int numTexInfos;
478
479 /* first parse the tex file */
480 texfile = fopen( filename, "r" );
481
482 if ( texfile ) {
483 fscanf( texfile, "TEXFILE\n%i\n", &numTexInfos );
484
485 /* Sys_Printf( "%i\n", numTexInfos ); */
486
487 for ( i = 0; i < numTexInfos; i++ ) {
488 vec3_t color;
489
490 fscanf( texfile, "%i %f %f %f\n", &surfaceFlags[ i ],
491 &color[ 0 ], &color[ 1 ], &color[ 2 ]);
492
493 bspShaders[ i ].surfaceFlags = surfaceFlags[ i ];
494
495 /* Sys_Printf( "%i\n", surfaceFlags[ i ] ); */
496 }
497 } else {
498 Sys_Printf("couldn't find %s not tex-file is now writed without surfaceFlags!\n", filename);
499 }
500 }
501
502
503
504 /*
505 WriteTexFile()
506 write Smokin'Guns like tex file
507 added by spoon
508 */
509
510 void WriteTexFile( char* filename ) {
511 FILE *texfile;
512 int i;
513
514 if ( !compile_map ) {
515 RestoreSurfaceFlags( filename );
516 }
517
518 Sys_Printf( "Writing %s ...\n", filename );
519
520 texfile = fopen ( filename, "w" );
521
522 fprintf( texfile, "TEXFILE\n" );
523
524 fprintf( texfile, "%i\n", numBSPShaders );
525
526 for ( i = 0 ; i < numBSPShaders ; i++ ) {
527 shaderInfo_t *se = ShaderInfoForShader( bspShaders[ i ].shader );
528
529 fprintf( texfile, "\n%i %f %f %f", bspShaders[ i ].surfaceFlags,
530 se->color[ 0 ], se->color[ 1 ], se->color[ 2 ] );
531
532 bspShaders[ i ].surfaceFlags = i;
533 }
534
535 fclose( texfile );
536 }
537
538
539
540 /*
541 EndBSPFile()
542 finishes a new bsp and writes to disk
543 */
544
545 void EndBSPFile( qboolean do_write, const char *BSPFilePath, const char *surfaceFilePath ){
546
547 Sys_FPrintf( SYS_VRB, "--- EndBSPFile ---\n" );
548
549 EmitPlanes();
550
551 numBSPEntities = numEntities;
552 UnparseEntities();
553
554 if ( do_write ) {
555 /* write the surface extra file */
556 WriteSurfaceExtraFile( surfaceFilePath );
557
558 if ( game->texFile )
559 {
560 char basename[ 1024 ];
561 char filename[ 1024 ];
562 strncpy( basename, BSPFilePath, sizeof(basename) );
563 StripExtension( 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 }