2008-07-25 07:31:37 +00:00
|
|
|
/* -------------------------------------------------------------------------------
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
----------------------------------------------------------------------------------
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This code has been altered significantly from its original form, to support
|
|
|
|
several games based on the Quake III Arena engine, in the form of "Q3Map2."
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
------------------------------------------------------------------------------- */
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* marker */
|
|
|
|
#define WRITEBSP_C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dependencies */
|
|
|
|
#include "q3map2.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
EmitShader()
|
|
|
|
emits a bsp shader entry
|
|
|
|
*/
|
|
|
|
|
|
|
|
int EmitShader( const char *shader, int *contentFlags, int *surfaceFlags ){
|
|
|
|
int i;
|
|
|
|
shaderInfo_t *si;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle special cases */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( shader == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
shader = "noshader";
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* try to find an existing shader */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numBSPShaders; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* ydnar: handle custom surface/content flags */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceFlags != NULL && bspShaders[ i ].surfaceFlags != *surfaceFlags ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( contentFlags != NULL && bspShaders[ i ].contentFlags != *contentFlags ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* compare name */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( shader, bspShaders[ i ].shader ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return i;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get shaderinfo */
|
|
|
|
si = ShaderInfoForShader( shader );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit a new shader */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i == MAX_MAP_SHADERS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "MAX_MAP_SHADERS" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
numBSPShaders++;
|
2015-09-08 01:09:48 +00:00
|
|
|
Q_strncpyz( bspShaders[ i ].shader, shader, sizeof( bspShaders[ i ].shader ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
bspShaders[ i ].surfaceFlags = si->surfaceFlags;
|
|
|
|
bspShaders[ i ].contentFlags = si->contentFlags;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* handle custom content/surface flags */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( surfaceFlags != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bspShaders[ i ].surfaceFlags = *surfaceFlags;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( contentFlags != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bspShaders[ i ].contentFlags = *contentFlags;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* recursively emit any damage shaders */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( si->damageShader != NULL && si->damageShader[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "Shader %s has damage shader %s\n", si->shader, si->damageShader );
|
|
|
|
EmitShader( si->damageShader, NULL, NULL );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* return it */
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
EmitPlanes()
|
|
|
|
there is no oportunity to discard planes, because all of the original
|
|
|
|
brushes will be saved in the map
|
|
|
|
*/
|
|
|
|
|
|
|
|
void EmitPlanes( void ){
|
|
|
|
int i;
|
|
|
|
bspPlane_t *bp;
|
|
|
|
plane_t *mp;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* walk plane list */
|
|
|
|
mp = mapplanes;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < nummapplanes; i++, mp++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
bp = &bspPlanes[ numBSPPlanes ];
|
|
|
|
VectorCopy( mp->normal, bp->normal );
|
|
|
|
bp->dist = mp->dist;
|
|
|
|
numBSPPlanes++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit some statistics */
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d BSP planes\n", numBSPPlanes );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
EmitLeaf()
|
|
|
|
emits a leafnode to the bsp file
|
|
|
|
*/
|
|
|
|
|
|
|
|
void EmitLeaf( node_t *node ){
|
|
|
|
bspLeaf_t *leaf_p;
|
|
|
|
brush_t *b;
|
|
|
|
drawSurfRef_t *dsr;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* check limits */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numBSPLeafs >= MAX_MAP_LEAFS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "MAX_MAP_LEAFS" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
leaf_p = &bspLeafs[numBSPLeafs];
|
|
|
|
numBSPLeafs++;
|
|
|
|
|
|
|
|
leaf_p->cluster = node->cluster;
|
|
|
|
leaf_p->area = node->area;
|
|
|
|
|
|
|
|
/* emit bounding box */
|
|
|
|
VectorCopy( node->mins, leaf_p->mins );
|
|
|
|
VectorCopy( node->maxs, leaf_p->maxs );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit leaf brushes */
|
|
|
|
leaf_p->firstBSPLeafBrush = numBSPLeafBrushes;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = node->brushlist; b; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* something is corrupting brushes */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( (size_t) b < 256 ) {
|
2015-09-16 14:11:16 +00:00
|
|
|
Sys_FPrintf( SYS_WRN, "WARNING: Node brush list corrupted (0x%08X)\n", b );
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
//% if( b->guard != 0xDEADBEEF )
|
|
|
|
//% 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 );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( numBSPLeafBrushes >= MAX_MAP_LEAFBRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "MAX_MAP_LEAFBRUSHES" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
bspLeafBrushes[ numBSPLeafBrushes ] = b->original->outputNum;
|
|
|
|
numBSPLeafBrushes++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
leaf_p->numBSPLeafBrushes = numBSPLeafBrushes - leaf_p->firstBSPLeafBrush;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit leaf surfaces */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->opaque ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add the drawSurfRef_t drawsurfs */
|
|
|
|
leaf_p->firstBSPLeafSurface = numBSPLeafSurfaces;
|
|
|
|
for ( dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numBSPLeafSurfaces >= MAX_MAP_LEAFFACES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "MAX_MAP_LEAFFACES" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
bspLeafSurfaces[ numBSPLeafSurfaces ] = dsr->outputNum;
|
2012-03-17 20:01:54 +00:00
|
|
|
numBSPLeafSurfaces++;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
leaf_p->numBSPLeafSurfaces = numBSPLeafSurfaces - leaf_p->firstBSPLeafSurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
EmitDrawNode_r()
|
|
|
|
recursively emit the bsp nodes
|
|
|
|
*/
|
|
|
|
|
|
|
|
int EmitDrawNode_r( node_t *node ){
|
|
|
|
bspNode_t *n;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* check for leafnode */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->planenum == PLANENUM_LEAF ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
EmitLeaf( node );
|
|
|
|
return -numBSPLeafs;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit a node */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numBSPNodes == MAX_MAP_NODES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "MAX_MAP_NODES" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
n = &bspNodes[ numBSPNodes ];
|
|
|
|
numBSPNodes++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( node->mins, n->mins );
|
|
|
|
VectorCopy( node->maxs, n->maxs );
|
|
|
|
|
|
|
|
if ( node->planenum & 1 ) {
|
|
|
|
Error( "WriteDrawNodes_r: odd planenum" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
n->planeNum = node->planenum;
|
|
|
|
|
|
|
|
//
|
|
|
|
// recursively output the other nodes
|
2012-03-17 20:01:54 +00:00
|
|
|
//
|
|
|
|
for ( i = 0 ; i < 2 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->children[i]->planenum == PLANENUM_LEAF ) {
|
|
|
|
n->children[i] = -( numBSPLeafs + 1 );
|
|
|
|
EmitLeaf( node->children[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
n->children[i] = numBSPNodes;
|
|
|
|
EmitDrawNode_r( node->children[i] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n - bspNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
============
|
|
|
|
SetModelNumbers
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
void SetModelNumbers( void ){
|
|
|
|
int i;
|
|
|
|
int models;
|
2015-09-06 22:41:21 +00:00
|
|
|
char value[16];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
models = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1 ; i < numEntities ; i++ ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
if ( entities[i].brushes || entities[i].patches ) {
|
2015-09-08 01:09:48 +00:00
|
|
|
snprintf( value, sizeof( value ), "*%i", models );
|
2007-11-04 03:34:51 +00:00
|
|
|
models++;
|
2012-03-17 20:01:54 +00:00
|
|
|
SetKeyValue( &entities[i], "model", value );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
SetLightStyles()
|
|
|
|
sets style keys for entity lights
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SetLightStyles( void ){
|
|
|
|
int i, j, style, numStyles;
|
|
|
|
qboolean keepLights;
|
|
|
|
const char *t;
|
|
|
|
entity_t *e;
|
|
|
|
epair_t *ep, *next;
|
2015-09-06 22:41:21 +00:00
|
|
|
char value[ 16 ];
|
2012-03-17 20:01:54 +00:00
|
|
|
char lightTargets[ MAX_SWITCHED_LIGHTS ][ 64 ];
|
|
|
|
int lightStyles[ MAX_SWITCHED_LIGHTS ];
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: determine if we keep lights in the bsp */
|
|
|
|
t = ValueForKey( &entities[ 0 ], "_keepLights" );
|
2012-03-17 20:01:54 +00:00
|
|
|
keepLights = ( t[ 0 ] == '1' ) ? qtrue : qfalse;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* any light that is controlled (has a targetname) must have a unique style number generated for it */
|
|
|
|
numStyles = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1; i < numEntities; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
e = &entities[ i ];
|
|
|
|
|
|
|
|
t = ValueForKey( e, "classname" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( Q_strncasecmp( t, "light", 5 ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
t = ValueForKey( e, "targetname" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( t[ 0 ] == '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: strip the light from the BSP file */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( keepLights == qfalse ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
ep = e->epairs;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( ep != NULL )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
next = ep->next;
|
|
|
|
free( ep->key );
|
|
|
|
free( ep->value );
|
|
|
|
free( ep );
|
|
|
|
ep = next;
|
|
|
|
}
|
|
|
|
e->epairs = NULL;
|
|
|
|
numStrippedLights++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* next light */
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get existing style */
|
|
|
|
style = IntForKey( e, "style" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( style < LS_NORMAL || style > LS_NONE ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Invalid lightstyle (%d) on entity %d", style, i );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* find this targetname */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < numStyles; j++ )
|
|
|
|
if ( lightStyles[ j ] == style && !strcmp( lightTargets[ j ], t ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* add a new style */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( j >= numStyles ) {
|
|
|
|
if ( numStyles == MAX_SWITCHED_LIGHTS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "MAX_SWITCHED_LIGHTS (%d) exceeded, reduce the number of lights with targetnames", MAX_SWITCHED_LIGHTS );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2015-09-08 01:09:48 +00:00
|
|
|
Q_strncpyz( lightTargets[ j ], t, sizeof( lightTargets[ j ] ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
lightStyles[ j ] = style;
|
|
|
|
numStyles++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set explicit style */
|
2015-09-08 01:09:48 +00:00
|
|
|
snprintf( value, sizeof( value ), "%d", 32 + j );
|
2007-11-04 03:34:51 +00:00
|
|
|
SetKeyValue( e, "style", value );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set old style */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( style != LS_NORMAL ) {
|
2015-09-08 01:09:48 +00:00
|
|
|
snprintf( value, sizeof( value ), "%d", style );
|
2007-11-04 03:34:51 +00:00
|
|
|
SetKeyValue( e, "switch_style", value );
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit some statistics */
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d light entities stripped\n", numStrippedLights );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
BeginBSPFile()
|
|
|
|
starts a new bsp file
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void BeginBSPFile( void ){
|
2007-11-04 03:34:51 +00:00
|
|
|
/* these values may actually be initialized if the file existed when loaded, so clear them explicitly */
|
|
|
|
numBSPModels = 0;
|
|
|
|
numBSPNodes = 0;
|
|
|
|
numBSPBrushSides = 0;
|
|
|
|
numBSPLeafSurfaces = 0;
|
|
|
|
numBSPLeafBrushes = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* leave leaf 0 as an error, because leafs are referenced as negative number nodes */
|
|
|
|
numBSPLeafs = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: gs mods: set the first 6 drawindexes to 0 1 2 2 1 3 for triangles and quads */
|
|
|
|
numBSPDrawIndexes = 6;
|
|
|
|
bspDrawIndexes[ 0 ] = 0;
|
|
|
|
bspDrawIndexes[ 1 ] = 1;
|
|
|
|
bspDrawIndexes[ 2 ] = 2;
|
|
|
|
bspDrawIndexes[ 3 ] = 0;
|
|
|
|
bspDrawIndexes[ 4 ] = 2;
|
|
|
|
bspDrawIndexes[ 5 ] = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
EndBSPFile()
|
|
|
|
finishes a new bsp and writes to disk
|
|
|
|
*/
|
|
|
|
|
|
|
|
void EndBSPFile( void ){
|
|
|
|
char path[ 1024 ];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2008-08-24 03:20:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "--- EndBSPFile ---\n" );
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
EmitPlanes();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
numBSPEntities = numEntities;
|
|
|
|
UnparseEntities();
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* write the surface extra file */
|
|
|
|
WriteSurfaceExtraFile( source );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* write the bsp */
|
2015-09-06 22:41:21 +00:00
|
|
|
snprintf( path, sizeof( path ), "%s.bsp", source );
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Writing %s\n", path );
|
|
|
|
WriteBSPFile( path );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
EmitBrushes()
|
|
|
|
writes the brush list to the bsp
|
|
|
|
*/
|
|
|
|
|
|
|
|
void EmitBrushes( brush_t *brushes, int *firstBrush, int *numBrushes ){
|
|
|
|
int j;
|
|
|
|
brush_t *b;
|
|
|
|
bspBrush_t *db;
|
|
|
|
bspBrushSide_t *cp;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set initial brush */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( firstBrush != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*firstBrush = numBSPBrushes;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( numBrushes != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*numBrushes = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* walk list of brushes */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( b = brushes; b != NULL; b = b->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* check limits */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numBSPBrushes == MAX_MAP_BRUSHES ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "MAX_MAP_BRUSHES (%d)", numBSPBrushes );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get bsp brush */
|
|
|
|
b->outputNum = numBSPBrushes;
|
|
|
|
db = &bspBrushes[ numBSPBrushes ];
|
|
|
|
numBSPBrushes++;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numBrushes != NULL ) {
|
|
|
|
( *numBrushes )++;
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
db->shaderNum = EmitShader( b->contentShader->shader, &b->contentShader->contentFlags, &b->contentShader->surfaceFlags );
|
|
|
|
db->firstSide = numBSPBrushSides;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* walk sides */
|
|
|
|
db->numSides = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < b->numsides; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* set output number to bogus initially */
|
|
|
|
b->sides[ j ].outputNum = -1;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* check count */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numBSPBrushSides == MAX_MAP_BRUSHSIDES ) {
|
|
|
|
Error( "MAX_MAP_BRUSHSIDES " );
|
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit side */
|
|
|
|
b->sides[ j ].outputNum = numBSPBrushSides;
|
|
|
|
cp = &bspBrushSides[ numBSPBrushSides ];
|
|
|
|
db->numSides++;
|
|
|
|
numBSPBrushSides++;
|
|
|
|
cp->planeNum = b->sides[ j ].planenum;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit shader */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->sides[ j ].shaderInfo ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
cp->shaderNum = EmitShader( b->sides[ j ].shaderInfo->shader, &b->sides[ j ].shaderInfo->contentFlags, &b->sides[ j ].shaderInfo->surfaceFlags );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
cp->shaderNum = EmitShader( NULL, NULL, NULL );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
EmitFogs() - ydnar
|
|
|
|
turns map fogs into bsp fogs
|
|
|
|
*/
|
|
|
|
|
|
|
|
void EmitFogs( void ){
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* setup */
|
|
|
|
numBSPFogs = numMapFogs;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* walk list */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < numMapFogs; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* set shader */
|
2015-09-08 01:09:48 +00:00
|
|
|
Q_strncpyz( bspFogs[ i ].shader, mapFogs[ i ].si->shader, sizeof( bspFogs[ i ].shader ) );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* global fog doesn't have an associated brush */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapFogs[ i ].brush == NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bspFogs[ i ].brushNum = -1;
|
|
|
|
bspFogs[ i ].visibleSide = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* set brush */
|
|
|
|
bspFogs[ i ].brushNum = mapFogs[ i ].brush->outputNum;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* try to use forced visible side */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapFogs[ i ].visibleSide >= 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
bspFogs[ i ].visibleSide = mapFogs[ i ].visibleSide;
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* find visible side */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0; j < 6; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapFogs[ i ].brush->sides[ j ].visibleHull != NULL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "Fog %d has visible side %d\n", i, j );
|
|
|
|
bspFogs[ i ].visibleSide = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
BeginModel()
|
|
|
|
sets up a new brush model
|
|
|
|
*/
|
|
|
|
|
|
|
|
void BeginModel( void ){
|
|
|
|
bspModel_t *mod;
|
|
|
|
brush_t *b;
|
|
|
|
entity_t *e;
|
|
|
|
vec3_t mins, maxs;
|
|
|
|
vec3_t lgMins, lgMaxs; /* ydnar: lightgrid mins/maxs */
|
|
|
|
parseMesh_t *p;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* test limits */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( numBSPModels == MAX_MAP_MODELS ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "MAX_MAP_MODELS" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get model and entity */
|
|
|
|
mod = &bspModels[ numBSPModels ];
|
|
|
|
e = &entities[ mapEntityNum ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: lightgrid mins/maxs */
|
|
|
|
ClearBounds( lgMins, lgMaxs );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* bound the brushes */
|
|
|
|
ClearBounds( mins, maxs );
|
|
|
|
for ( b = e->brushes; b; b = b->next )
|
|
|
|
{
|
|
|
|
/* ignore non-real brushes (origin, etc) */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->numsides == 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
AddPointToBounds( b->mins, mins, maxs );
|
|
|
|
AddPointToBounds( b->maxs, mins, maxs );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: lightgrid bounds */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->compileFlags & C_LIGHTGRID ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
AddPointToBounds( b->mins, lgMins, lgMaxs );
|
|
|
|
AddPointToBounds( b->maxs, lgMins, lgMaxs );
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* bound patches */
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = e->patches; p; p = p->next )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
AddPointToBounds( p->mesh.verts[i].xyz, mins, maxs );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: lightgrid mins/maxs */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( lgMins[ 0 ] < 99999 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
/* use lightgrid bounds */
|
|
|
|
VectorCopy( lgMins, mod->mins );
|
|
|
|
VectorCopy( lgMaxs, mod->maxs );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* use brush/patch bounds */
|
|
|
|
VectorCopy( mins, mod->mins );
|
|
|
|
VectorCopy( maxs, mod->maxs );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* note size */
|
|
|
|
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 ] );
|
|
|
|
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 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set firsts */
|
|
|
|
mod->firstBSPSurface = numBSPDrawSurfaces;
|
|
|
|
mod->firstBSPBrush = numBSPBrushes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
EndModel()
|
|
|
|
finish a model's processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
void EndModel( entity_t *e, node_t *headnode ){
|
|
|
|
bspModel_t *mod;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* note it */
|
|
|
|
Sys_FPrintf( SYS_VRB, "--- EndModel ---\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* emit the bsp */
|
|
|
|
mod = &bspModels[ numBSPModels ];
|
|
|
|
EmitDrawNode_r( headnode );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set surfaces and brushes */
|
|
|
|
mod->numBSPSurfaces = numBSPDrawSurfaces - mod->firstBSPSurface;
|
|
|
|
mod->firstBSPBrush = e->firstBrush;
|
|
|
|
mod->numBSPBrushes = e->numBrushes;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* increment model count */
|
|
|
|
numBSPModels++;
|
|
|
|
}
|