| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#define WRITEBSP_C |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
#include "q3map2.h" |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 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 |
| 62 |
|
| 63 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){ |
| 102 |
int i; |
| 103 |
shaderInfo_t *si; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
if ( shader == NULL ) { |
| 108 |
shader = "noshader"; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
for ( i = 0; i < numBSPShaders; i++ ) |
| 113 |
{ |
| 114 |
|
| 115 |
if ( !game->texFile ) |
| 116 |
{ |
| 117 |
|
| 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 |
|
| 132 |
if ( !Q_stricmp( shader, bspShaders[ i ].shader ) ) { |
| 133 |
return i; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
qboolean hadSurfaceFlags = surfaceFlags != NULL; |
| 140 |
int savedSurfaceFlags = hadSurfaceFlags ? *surfaceFlags : 0; |
| 141 |
qboolean hadContentFlags = contentFlags != NULL; |
| 142 |
int savedContentFlags = hadContentFlags ? *contentFlags : 0; |
| 143 |
|
| 144 |
|
| 145 |
si = ShaderInfoForShader( shader ); |
| 146 |
|
| 147 |
|
| 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 |
|
| 158 |
bspShaders[ i ].surfaceFlags |= GetSurfaceParm(si->shader); |
| 159 |
} |
| 160 |
|
| 161 |
|
| 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 |
|
| 168 |
return i; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
void EmitPlanes( void ){ |
| 180 |
int i; |
| 181 |
bspPlane_t *bp; |
| 182 |
plane_t *mp; |
| 183 |
|
| 184 |
|
| 185 |
|
| 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 |
|
| 197 |
Sys_FPrintf( SYS_VRB, "%9d BSP planes\n", numBSPPlanes ); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
void EmitLeaf( node_t *node ){ |
| 208 |
bspLeaf_t *leaf_p; |
| 209 |
brush_t *b; |
| 210 |
drawSurfRef_t *dsr; |
| 211 |
|
| 212 |
|
| 213 |
|
| 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 |
|
| 225 |
VectorCopy( node->mins, leaf_p->mins ); |
| 226 |
VectorCopy( node->maxs, leaf_p->maxs ); |
| 227 |
|
| 228 |
|
| 229 |
leaf_p->firstBSPLeafBrush = numBSPLeafBrushes; |
| 230 |
for ( b = node->brushlist; b; b = b->next ) |
| 231 |
{ |
| 232 |
|
| 233 |
if ( (size_t) b < 256 ) { |
| 234 |
Sys_FPrintf( SYS_WRN, "WARNING: Node brush list corrupted (0x%08X)\n", b ); |
| 235 |
break; |
| 236 |
} |
| 237 |
|
| 238 |
|
| 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 |
|
| 248 |
if ( node->opaque ) { |
| 249 |
return; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 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 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
int EmitDrawNode_r( node_t *node ){ |
| 271 |
bspNode_t *n; |
| 272 |
int i, n0; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
if ( node->planenum == PLANENUM_LEAF ) { |
| 277 |
EmitLeaf( node ); |
| 278 |
return -numBSPLeafs; |
| 279 |
} |
| 280 |
|
| 281 |
|
| 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 |
|
| 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 |
|
| 309 |
n = &bspNodes[ n0 ]; |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
return n - bspNodes; |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 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 |
|
| 344 |
|
| 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 |
|
| 357 |
if ( keepLights ) { |
| 358 |
SetKeyValue( &entities[0], "_keepLights", "1" ); |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
if ( KeyExists( &entities[ 0 ], "_keepLights" ) == qtrue ) { |
| 363 |
t = ValueForKey( &entities[ 0 ], "_keepLights" ); |
| 364 |
keepLights = ( t[ 0 ] == '1' ) ? qtrue : qfalse; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 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 |
|
| 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 |
|
| 395 |
continue; |
| 396 |
} |
| 397 |
|
| 398 |
|
| 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 |
|
| 405 |
for ( j = 0; j < numStyles; j++ ) |
| 406 |
if ( lightStyles[ j ] == style && !strcmp( lightTargets[ j ], t ) ) { |
| 407 |
break; |
| 408 |
} |
| 409 |
|
| 410 |
|
| 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 |
|
| 421 |
sprintf( value, "%d", 32 + j ); |
| 422 |
SetKeyValue( e, "style", value ); |
| 423 |
|
| 424 |
|
| 425 |
if ( style != LS_NORMAL ) { |
| 426 |
sprintf( value, "%d", style ); |
| 427 |
SetKeyValue( e, "switch_style", value ); |
| 428 |
} |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
Sys_FPrintf( SYS_VRB, "%9d light entities stripped\n", numStrippedLights ); |
| 433 |
} |
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
void BeginBSPFile( void ){ |
| 443 |
|
| 444 |
numBSPModels = 0; |
| 445 |
numBSPNodes = 0; |
| 446 |
numBSPBrushSides = 0; |
| 447 |
numBSPLeafSurfaces = 0; |
| 448 |
numBSPLeafBrushes = 0; |
| 449 |
|
| 450 |
|
| 451 |
numBSPLeafs = 1; |
| 452 |
|
| 453 |
|
| 454 |
|
| 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 |
|
| 469 |
|
| 470 |
|
| 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 |
|
| 480 |
texfile = fopen( filename, "r" ); |
| 481 |
|
| 482 |
if ( texfile ) { |
| 483 |
fscanf( texfile, "TEXFILE\n%i\n", &numTexInfos ); |
| 484 |
|
| 485 |
|
| 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 |
|
| 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 |
|
| 506 |
|
| 507 |
|
| 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 |
|
| 542 |
|
| 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 |
|
| 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 |
|
| 567 |
WriteTexFile( filename ); |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
Sys_Printf( "Writing %s\n", BSPFilePath ); |
| 572 |
WriteBSPFile( BSPFilePath ); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 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 |
|
| 591 |
if ( firstBrush != NULL ) { |
| 592 |
*firstBrush = numBSPBrushes; |
| 593 |
} |
| 594 |
if ( numBrushes != NULL ) { |
| 595 |
*numBrushes = 0; |
| 596 |
} |
| 597 |
|
| 598 |
|
| 599 |
for ( b = brushes; b != NULL; b = b->next ) |
| 600 |
{ |
| 601 |
|
| 602 |
AUTOEXPAND_BY_REALLOC_BSP( Brushes, 1024 ); |
| 603 |
|
| 604 |
|
| 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 |
|
| 616 |
db->numSides = 0; |
| 617 |
for ( j = 0; j < b->numsides; j++ ) |
| 618 |
{ |
| 619 |
|
| 620 |
b->sides[ j ].outputNum = -1; |
| 621 |
|
| 622 |
|
| 623 |
AUTOEXPAND_BY_REALLOC_BSP( BrushSides, 1024 ); |
| 624 |
|
| 625 |
|
| 626 |
b->sides[ j ].outputNum = numBSPBrushSides; |
| 627 |
cp = &bspBrushSides[ numBSPBrushSides ]; |
| 628 |
db->numSides++; |
| 629 |
numBSPBrushSides++; |
| 630 |
cp->planeNum = b->sides[ j ].planenum; |
| 631 |
|
| 632 |
|
| 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 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
void EmitFogs( void ){ |
| 651 |
int i, j; |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
numBSPFogs = numMapFogs; |
| 656 |
|
| 657 |
|
| 658 |
for ( i = 0; i < numMapFogs; i++ ) |
| 659 |
{ |
| 660 |
|
| 661 |
strcpy( bspFogs[ i ].shader, mapFogs[ i ].si->shader ); |
| 662 |
|
| 663 |
|
| 664 |
if ( mapFogs[ i ].brush == NULL ) { |
| 665 |
bspFogs[ i ].brushNum = -1; |
| 666 |
bspFogs[ i ].visibleSide = -1; |
| 667 |
} |
| 668 |
else |
| 669 |
{ |
| 670 |
|
| 671 |
bspFogs[ i ].brushNum = mapFogs[ i ].brush->outputNum; |
| 672 |
|
| 673 |
|
| 674 |
if ( mapFogs[ i ].visibleSide >= 0 ) { |
| 675 |
bspFogs[ i ].visibleSide = mapFogs[ i ].visibleSide; |
| 676 |
continue; |
| 677 |
} |
| 678 |
|
| 679 |
|
| 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 |
|
| 696 |
|
| 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; |
| 705 |
parseMesh_t *p; |
| 706 |
int i; |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
AUTOEXPAND_BY_REALLOC_BSP( Models, 256 ); |
| 711 |
|
| 712 |
|
| 713 |
mod = &bspModels[ numBSPModels ]; |
| 714 |
e = &entities[ mapEntityNum ]; |
| 715 |
|
| 716 |
|
| 717 |
ClearBounds( lgMins, lgMaxs ); |
| 718 |
|
| 719 |
|
| 720 |
ClearBounds( mins, maxs ); |
| 721 |
for ( b = e->brushes; b; b = b->next ) |
| 722 |
{ |
| 723 |
|
| 724 |
if ( b->numsides == 0 ) { |
| 725 |
continue; |
| 726 |
} |
| 727 |
AddPointToBounds( b->mins, mins, maxs ); |
| 728 |
AddPointToBounds( b->maxs, mins, maxs ); |
| 729 |
|
| 730 |
|
| 731 |
if ( b->compileFlags & C_LIGHTGRID ) { |
| 732 |
AddPointToBounds( b->mins, lgMins, lgMaxs ); |
| 733 |
AddPointToBounds( b->maxs, lgMins, lgMaxs ); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
|
| 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 |
|
| 745 |
if ( lgMins[ 0 ] < 99999 ) { |
| 746 |
|
| 747 |
VectorCopy( lgMins, mod->mins ); |
| 748 |
VectorCopy( lgMaxs, mod->maxs ); |
| 749 |
} |
| 750 |
else |
| 751 |
{ |
| 752 |
|
| 753 |
VectorCopy( mins, mod->mins ); |
| 754 |
VectorCopy( maxs, mod->maxs ); |
| 755 |
} |
| 756 |
|
| 757 |
|
| 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 |
|
| 762 |
mod->firstBSPSurface = numBSPDrawSurfaces; |
| 763 |
mod->firstBSPBrush = numBSPBrushes; |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
void EndModel( entity_t *e, node_t *headnode ){ |
| 775 |
bspModel_t *mod; |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
Sys_FPrintf( SYS_VRB, "--- EndModel ---\n" ); |
| 780 |
|
| 781 |
|
| 782 |
mod = &bspModels[ numBSPModels ]; |
| 783 |
EmitDrawNode_r( headnode ); |
| 784 |
|
| 785 |
|
| 786 |
mod->numBSPSurfaces = numBSPDrawSurfaces - mod->firstBSPSurface; |
| 787 |
mod->firstBSPBrush = e->firstBrush; |
| 788 |
mod->numBSPBrushes = e->numBrushes; |
| 789 |
|
| 790 |
|
| 791 |
numBSPModels++; |
| 792 |
} |