2007-11-04 03:34:51 +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
|
|
|
// map.c
|
|
|
|
|
|
|
|
#include "qbsp.h"
|
|
|
|
|
|
|
|
extern qboolean onlyents;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int nummapbrushes;
|
|
|
|
mapbrush_t mapbrushes[MAX_MAP_BRUSHES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int nummapbrushsides;
|
|
|
|
side_t brushsides[MAX_MAP_SIDES];
|
|
|
|
brush_texture_t side_brushtextures[MAX_MAP_SIDES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int nummapplanes;
|
|
|
|
plane_t mapplanes[MAX_MAP_PLANES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define PLANE_HASHES 1024
|
|
|
|
plane_t *planehash[PLANE_HASHES];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
vec3_t map_mins, map_maxs;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// undefine to make plane finding use linear sort
|
2012-03-17 20:01:54 +00:00
|
|
|
#define USE_HASHING
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void TestExpandBrushes( void );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_boxbevels;
|
|
|
|
int c_edgebevels;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_areaportals;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_clipbrushes;
|
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
|
|
|
PLANE FINDING
|
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
|
|
|
=================
|
|
|
|
PlaneTypeForNormal
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
int PlaneTypeForNormal( vec3_t normal ){
|
|
|
|
vec_t ax, ay, az;
|
|
|
|
|
|
|
|
// NOTE: should these have an epsilon around 1.0?
|
|
|
|
if ( normal[0] == 1.0 || normal[0] == -1.0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return PLANE_X;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( normal[1] == 1.0 || normal[1] == -1.0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return PLANE_Y;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( normal[2] == 1.0 || normal[2] == -1.0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return PLANE_Z;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ax = fabs( normal[0] );
|
|
|
|
ay = fabs( normal[1] );
|
|
|
|
az = fabs( normal[2] );
|
|
|
|
|
|
|
|
if ( ax >= ay && ax >= az ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return PLANE_ANYX;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( ay >= ax && ay >= az ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return PLANE_ANYY;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return PLANE_ANYZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
PlaneEqual
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
#define NORMAL_EPSILON 0.00001
|
|
|
|
#define DIST_EPSILON 0.01
|
|
|
|
qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist ){
|
2007-11-04 03:34:51 +00:00
|
|
|
#if 1
|
|
|
|
if (
|
2012-03-17 20:01:54 +00:00
|
|
|
fabs( p->normal[0] - normal[0] ) < NORMAL_EPSILON
|
|
|
|
&& fabs( p->normal[1] - normal[1] ) < NORMAL_EPSILON
|
|
|
|
&& fabs( p->normal[2] - normal[2] ) < NORMAL_EPSILON
|
|
|
|
&& fabs( p->dist - dist ) < DIST_EPSILON ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->normal[0] == normal[0]
|
|
|
|
&& p->normal[1] == normal[1]
|
|
|
|
&& p->normal[2] == normal[2]
|
|
|
|
&& p->dist == dist ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return true;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
AddPlaneToHash
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void AddPlaneToHash( plane_t *p ){
|
|
|
|
int hash;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
hash = (int)fabs( p->dist ) / 8;
|
|
|
|
hash &= ( PLANE_HASHES - 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
p->hash_chain = planehash[hash];
|
|
|
|
planehash[hash] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
CreateNewFloatPlane
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
int CreateNewFloatPlane( vec3_t normal, vec_t dist ){
|
|
|
|
plane_t *p, temp;
|
|
|
|
|
|
|
|
if ( VectorLength( normal ) < 0.5 ) {
|
|
|
|
Error( "FloatPlane: bad normal" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
// create a new plane
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( nummapplanes + 2 > MAX_MAP_PLANES ) {
|
|
|
|
Error( "MAX_MAP_PLANES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
p = &mapplanes[nummapplanes];
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( normal, p->normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
p->dist = dist;
|
2012-03-17 20:01:54 +00:00
|
|
|
p->type = ( p + 1 )->type = PlaneTypeForNormal( p->normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorSubtract( vec3_origin, normal, ( p + 1 )->normal );
|
|
|
|
( p + 1 )->dist = -dist;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
nummapplanes += 2;
|
|
|
|
|
|
|
|
// allways put axial planes facing positive first
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->type < 3 ) {
|
|
|
|
if ( p->normal[0] < 0 || p->normal[1] < 0 || p->normal[2] < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
// flip order
|
|
|
|
temp = *p;
|
2012-03-17 20:01:54 +00:00
|
|
|
*p = *( p + 1 );
|
|
|
|
*( p + 1 ) = temp;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPlaneToHash( p );
|
|
|
|
AddPlaneToHash( p + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
return nummapplanes - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPlaneToHash( p );
|
|
|
|
AddPlaneToHash( p + 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
return nummapplanes - 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============
|
|
|
|
SnapVector
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void SnapVector( vec3_t normal ){
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( fabs( normal[i] - 1 ) < NORMAL_EPSILON ) {
|
|
|
|
VectorClear( normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
normal[i] = 1;
|
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( fabs( normal[i] - -1 ) < NORMAL_EPSILON ) {
|
|
|
|
VectorClear( normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
normal[i] = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============
|
|
|
|
SnapPlane
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void SnapPlane( vec3_t normal, vec_t *dist ){
|
|
|
|
SnapVector( normal );
|
|
|
|
|
|
|
|
if ( fabs( *dist - Q_rint( *dist ) ) < DIST_EPSILON ) {
|
|
|
|
*dist = Q_rint( *dist );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
FindFloatPlane
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
#ifndef USE_HASHING
|
2012-03-17 20:01:54 +00:00
|
|
|
int FindFloatPlane( vec3_t normal, vec_t dist ){
|
|
|
|
int i;
|
|
|
|
plane_t *p;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SnapPlane( normal, &dist );
|
|
|
|
for ( i = 0, p = mapplanes ; i < nummapplanes ; i++, p++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( PlaneEqual( p, normal, dist ) ) {
|
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
|
|
|
return CreateNewFloatPlane( normal, dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
int FindFloatPlane( vec3_t normal, vec_t dist ){
|
|
|
|
int i;
|
|
|
|
plane_t *p;
|
|
|
|
int hash, h;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
SnapPlane( normal, &dist );
|
|
|
|
hash = (int)fabs( dist ) / 8;
|
|
|
|
hash &= ( PLANE_HASHES - 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// search the border bins as well
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = -1 ; i <= 1 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
h = ( hash + i ) & ( PLANE_HASHES - 1 );
|
|
|
|
for ( p = planehash[h] ; p ; p = p->hash_chain )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( PlaneEqual( p, normal, dist ) ) {
|
|
|
|
return p - mapplanes;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return CreateNewFloatPlane( normal, dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
PlaneFromPoints
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
int PlaneFromPoints( int *p0, int *p1, int *p2 ){
|
|
|
|
vec3_t t1, t2, normal;
|
|
|
|
vec_t dist;
|
|
|
|
|
|
|
|
VectorSubtract( p0, p1, t1 );
|
|
|
|
VectorSubtract( p2, p1, t2 );
|
|
|
|
CrossProduct( t1, t2, normal );
|
|
|
|
VectorNormalize( normal, normal );
|
|
|
|
|
|
|
|
dist = DotProduct( p0, normal );
|
|
|
|
|
|
|
|
return FindFloatPlane( normal, dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===========
|
|
|
|
BrushContents
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
int BrushContents( mapbrush_t *b ){
|
|
|
|
int contents;
|
|
|
|
side_t *s;
|
|
|
|
int i;
|
|
|
|
int trans;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
s = &b->original_sides[0];
|
|
|
|
contents = s->contents;
|
|
|
|
trans = texinfo[s->texinfo].flags;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1 ; i < b->numsides ; i++, s++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s = &b->original_sides[i];
|
|
|
|
trans |= texinfo[s->texinfo].flags;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s->contents != contents ) {
|
|
|
|
Sys_Printf( "Entity %i, Brush %i: mixed face contents\n"
|
|
|
|
, b->entitynum, b->brushnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if any side is translucent, mark the contents
|
|
|
|
// and change solid to window
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( trans & ( SURF_TRANS33 | SURF_TRANS66 ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
contents |= CONTENTS_TRANSLUCENT;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( contents & CONTENTS_SOLID ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
contents &= ~CONTENTS_SOLID;
|
|
|
|
contents |= CONTENTS_WINDOW;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
AddBrushBevels
|
|
|
|
|
|
|
|
Adds any additional planes necessary to allow the brush to be expanded
|
|
|
|
against axial bounding boxes
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void AddBrushBevels( mapbrush_t *b ){
|
|
|
|
int axis, dir;
|
|
|
|
int i, j, k, l, order;
|
|
|
|
side_t sidetemp;
|
|
|
|
brush_texture_t tdtemp;
|
|
|
|
side_t *s, *s2;
|
|
|
|
vec3_t normal;
|
|
|
|
float dist;
|
|
|
|
winding_t *w, *w2;
|
|
|
|
vec3_t vec, vec2;
|
|
|
|
float d;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// add the axial planes
|
|
|
|
//
|
|
|
|
order = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( axis = 0 ; axis < 3 ; axis++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( dir = -1 ; dir <= 1 ; dir += 2, order++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
// see if the plane is allready present
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0, s = b->original_sides ; i < b->numsides ; i++,s++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapplanes[s->planenum].normal[axis] == dir ) {
|
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
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i == b->numsides ) { // add a new side
|
|
|
|
if ( nummapbrushsides == MAX_MAP_BRUSHSIDES ) {
|
|
|
|
Error( "MAX_MAP_BRUSHSIDES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
nummapbrushsides++;
|
|
|
|
b->numsides++;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorClear( normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
normal[axis] = dir;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( dir == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = b->maxs[axis];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = -b->mins[axis];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
s->planenum = FindFloatPlane( normal, dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
s->texinfo = b->original_sides[0].texinfo;
|
|
|
|
s->contents = b->original_sides[0].contents;
|
|
|
|
s->bevel = true;
|
|
|
|
c_boxbevels++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the plane is not in it canonical order, swap it
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i != order ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sidetemp = b->original_sides[order];
|
|
|
|
b->original_sides[order] = b->original_sides[i];
|
|
|
|
b->original_sides[i] = sidetemp;
|
|
|
|
|
|
|
|
j = b->original_sides - brushsides;
|
2012-03-17 20:01:54 +00:00
|
|
|
tdtemp = side_brushtextures[j + order];
|
|
|
|
side_brushtextures[j + order] = side_brushtextures[j + i];
|
|
|
|
side_brushtextures[j + i] = tdtemp;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// add the edge bevels
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->numsides == 6 ) {
|
|
|
|
return; // pure axial
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
// test the non-axial plane edges
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 6 ; i < b->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s = b->original_sides + i;
|
|
|
|
w = s->winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
for ( j = 0 ; j < w->numpoints ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
k = ( j + 1 ) % w->numpoints;
|
|
|
|
VectorSubtract( w->p[j], w->p[k], vec );
|
|
|
|
if ( VectorNormalize( vec, vec ) < 0.5 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
SnapVector( vec );
|
|
|
|
for ( k = 0 ; k < 3 ; k++ )
|
|
|
|
if ( vec[k] == -1 || vec[k] == 1 ) {
|
|
|
|
break;
|
|
|
|
} // axial
|
|
|
|
if ( k != 3 ) {
|
|
|
|
continue; // only test non-axial edges
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
// try the six possible slanted axials from this edge
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( axis = 0 ; axis < 3 ; axis++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( dir = -1 ; dir <= 1 ; dir += 2 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
// construct a plane
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorClear( vec2 );
|
2007-11-04 03:34:51 +00:00
|
|
|
vec2[axis] = dir;
|
2012-03-17 20:01:54 +00:00
|
|
|
CrossProduct( vec, vec2, normal );
|
|
|
|
if ( VectorNormalize( normal, normal ) < 0.5 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
dist = DotProduct( w->p[j], normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// if all the points on all the sides are
|
|
|
|
// behind this plane, it is a proper edge bevel
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( k = 0 ; k < b->numsides ; k++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
// if this plane has allready been used, skip it
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( PlaneEqual( &mapplanes[b->original_sides[k].planenum]
|
|
|
|
, normal, dist ) ) {
|
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
|
|
|
|
|
|
|
w2 = b->original_sides[k].winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w2 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
for ( l = 0 ; l < w2->numpoints ; l++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
d = DotProduct( w2->p[l], normal ) - dist;
|
|
|
|
if ( d > 0.1 ) {
|
|
|
|
break; // point in front
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( l != w2->numpoints ) {
|
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
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( k != b->numsides ) {
|
|
|
|
continue; // wasn't part of the outer hull
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
// add this plane
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( nummapbrushsides == MAX_MAP_BRUSHSIDES ) {
|
|
|
|
Error( "MAX_MAP_BRUSHSIDES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
nummapbrushsides++;
|
|
|
|
s2 = &b->original_sides[b->numsides];
|
2012-03-17 20:01:54 +00:00
|
|
|
s2->planenum = FindFloatPlane( normal, dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
s2->texinfo = b->original_sides[0].texinfo;
|
|
|
|
s2->contents = b->original_sides[0].contents;
|
|
|
|
s2->bevel = true;
|
|
|
|
c_edgebevels++;
|
|
|
|
b->numsides++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
MakeBrushWindings
|
|
|
|
|
|
|
|
makes basewindigs for sides and mins / maxs for the brush
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
qboolean MakeBrushWindings( mapbrush_t *ob ){
|
|
|
|
int i, j;
|
|
|
|
winding_t *w;
|
|
|
|
side_t *side;
|
|
|
|
plane_t *plane;
|
|
|
|
|
|
|
|
ClearBounds( ob->mins, ob->maxs );
|
|
|
|
|
|
|
|
for ( i = 0 ; i < ob->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
plane = &mapplanes[ob->original_sides[i].planenum];
|
2012-03-17 20:01:54 +00:00
|
|
|
w = BaseWindingForPlane( plane->normal, plane->dist );
|
|
|
|
for ( j = 0 ; j < ob->numsides && w; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i == j ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( ob->original_sides[j].bevel ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
plane = &mapplanes[ob->original_sides[j].planenum ^ 1];
|
|
|
|
ChopWindingInPlace( &w, plane->normal, plane->dist, 0 ); //CLIP_EPSILON);
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
side = &ob->original_sides[i];
|
|
|
|
side->winding = w;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( w ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side->visible = true;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < w->numpoints ; j++ )
|
|
|
|
AddPointToBounds( w->p[j], ob->mins, ob->maxs );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( ob->mins[0] < -4096 || ob->maxs[0] > 4096 ) {
|
|
|
|
Sys_Printf( "entity %i, brush %i: bounds out of range\n", ob->entitynum, ob->brushnum );
|
|
|
|
}
|
|
|
|
if ( ob->mins[0] > 4096 || ob->maxs[0] < -4096 ) {
|
|
|
|
Sys_Printf( "entity %i, brush %i: no visible sides on brush\n", ob->entitynum, ob->brushnum );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
ParseBrush
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void ParseBrush( entity_t *mapent ){
|
|
|
|
mapbrush_t *b;
|
|
|
|
int i,j, k;
|
|
|
|
int mt;
|
|
|
|
side_t *side, *s2;
|
|
|
|
int planenum;
|
|
|
|
brush_texture_t td;
|
|
|
|
int planepts[3][3];
|
|
|
|
|
|
|
|
if ( nummapbrushes == MAX_MAP_BRUSHES ) {
|
|
|
|
Error( "nummapbrushes == MAX_MAP_BRUSHES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
b = &mapbrushes[nummapbrushes];
|
|
|
|
b->original_sides = &brushsides[nummapbrushsides];
|
2012-03-17 20:01:54 +00:00
|
|
|
b->entitynum = num_entities - 1;
|
2007-11-04 03:34:51 +00:00
|
|
|
b->brushnum = nummapbrushes - mapent->firstbrush;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetToken( true ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !strcmp( token, "}" ) ) {
|
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
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( nummapbrushsides == MAX_MAP_BRUSHSIDES ) {
|
|
|
|
Error( "MAX_MAP_BRUSHSIDES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
side = &brushsides[nummapbrushsides];
|
|
|
|
|
|
|
|
// read the three point plane definition
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( i != 0 ) {
|
|
|
|
GetToken( true );
|
|
|
|
}
|
|
|
|
if ( strcmp( token, "(" ) ) {
|
|
|
|
Error( "parsing brush" );
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( false );
|
|
|
|
planepts[i][j] = atoi( token );
|
|
|
|
}
|
|
|
|
|
|
|
|
GetToken( false );
|
|
|
|
if ( strcmp( token, ")" ) ) {
|
|
|
|
Error( "parsing brush" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// read the texturedef
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
GetToken( false );
|
|
|
|
strcpy( td.name, token );
|
|
|
|
|
|
|
|
GetToken( false );
|
|
|
|
td.shift[0] = atoi( token );
|
|
|
|
GetToken( false );
|
|
|
|
td.shift[1] = atoi( token );
|
|
|
|
GetToken( false );
|
|
|
|
td.rotate = atoi( token );
|
|
|
|
GetToken( false );
|
|
|
|
td.scale[0] = atof( token );
|
|
|
|
GetToken( false );
|
|
|
|
td.scale[1] = atof( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// find default flags and values
|
2012-03-17 20:01:54 +00:00
|
|
|
mt = FindMiptex( td.name );
|
2007-11-04 03:34:51 +00:00
|
|
|
td.flags = textureref[mt].flags;
|
|
|
|
td.value = textureref[mt].value;
|
|
|
|
side->contents = textureref[mt].contents;
|
|
|
|
side->surf = td.flags = textureref[mt].flags;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( TokenAvailable() ) {
|
|
|
|
GetToken( false );
|
|
|
|
side->contents = atoi( token );
|
|
|
|
GetToken( false );
|
|
|
|
side->surf = td.flags = atoi( token );
|
|
|
|
GetToken( false );
|
|
|
|
td.value = atoi( token );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// translucent objects are automatically classified as detail
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( side->surf & ( SURF_TRANS33 | SURF_TRANS66 ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side->contents |= CONTENTS_DETAIL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( side->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side->contents |= CONTENTS_DETAIL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( fulldetail ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side->contents &= ~CONTENTS_DETAIL;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !( side->contents & ( ( LAST_VISIBLE_CONTENTS - 1 )
|
|
|
|
| CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP | CONTENTS_MIST ) ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side->contents |= CONTENTS_SOLID;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// hints and skips are never detail, and have no content
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( side->surf & ( SURF_HINT | SURF_SKIP ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side->contents = 0;
|
|
|
|
side->surf &= ~CONTENTS_DETAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// find the plane number
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
planenum = PlaneFromPoints( planepts[0], planepts[1], planepts[2] );
|
|
|
|
if ( planenum == -1 ) {
|
|
|
|
Sys_Printf( "Entity %i, Brush %i: plane with no normal\n"
|
|
|
|
, b->entitynum, b->brushnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// see if the plane has been used already
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( k = 0 ; k < b->numsides ; k++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s2 = b->original_sides + k;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s2->planenum == planenum ) {
|
|
|
|
Sys_Printf( "Entity %i, Brush %i: duplicate plane\n"
|
|
|
|
, b->entitynum, b->brushnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s2->planenum == ( planenum ^ 1 ) ) {
|
|
|
|
Sys_Printf( "Entity %i, Brush %i: mirrored plane\n"
|
|
|
|
, b->entitynum, b->brushnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( k != b->numsides ) {
|
|
|
|
continue; // duplicated
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
//
|
|
|
|
// keep this side
|
|
|
|
//
|
|
|
|
|
|
|
|
side = b->original_sides + b->numsides;
|
|
|
|
side->planenum = planenum;
|
2012-03-17 20:01:54 +00:00
|
|
|
side->texinfo = TexinfoForBrushTexture( &mapplanes[planenum],
|
|
|
|
&td, vec3_origin );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// save the td off in case there is an origin brush and we
|
|
|
|
// have to recalculate the texinfo
|
|
|
|
side_brushtextures[nummapbrushsides] = td;
|
|
|
|
|
|
|
|
nummapbrushsides++;
|
|
|
|
b->numsides++;
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// get the content for the entire brush
|
2012-03-17 20:01:54 +00:00
|
|
|
b->contents = BrushContents( b );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
// allow detail brushes to be removed
|
|
|
|
if ( nodetail && ( b->contents & CONTENTS_DETAIL ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
b->numsides = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allow water brushes to be removed
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( nowater && ( b->contents & ( CONTENTS_LAVA | CONTENTS_SLIME | CONTENTS_WATER ) ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
b->numsides = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create windings for sides and bounds for brush
|
2012-03-17 20:01:54 +00:00
|
|
|
MakeBrushWindings( b );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// brushes that will not be visible at all will never be
|
|
|
|
// used as bsp splitters
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->contents & ( CONTENTS_PLAYERCLIP | CONTENTS_MONSTERCLIP ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_clipbrushes++;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < b->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
b->original_sides[i].texinfo = TEXINFO_NODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// origin brushes are removed, but they set
|
|
|
|
// the rotation origin for the rest of the brushes
|
|
|
|
// in the entity. After the entire entity is parsed,
|
|
|
|
// the planenums and texinfos will be adjusted for
|
|
|
|
// the origin brush
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->contents & CONTENTS_ORIGIN ) {
|
|
|
|
char string[32];
|
|
|
|
vec3_t origin;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( num_entities == 1 ) {
|
|
|
|
Error( "Entity %i, Brush %i: origin brushes not allowed in world"
|
|
|
|
, b->entitynum, b->brushnum );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorAdd( b->mins, b->maxs, origin );
|
|
|
|
VectorScale( origin, 0.5, origin );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2] );
|
|
|
|
SetKeyValue( &entities[b->entitynum], "origin", string );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( origin, entities[b->entitynum].origin );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// don't keep this brush
|
|
|
|
b->numsides = 0;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
AddBrushBevels( b );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
nummapbrushes++;
|
2012-03-17 20:01:54 +00:00
|
|
|
mapent->numbrushes++;
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
MoveBrushesToWorld
|
|
|
|
|
|
|
|
Takes all of the brushes from the current entity and
|
|
|
|
adds them to the world's brush list.
|
|
|
|
|
|
|
|
Used by func_group and func_areaportal
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void MoveBrushesToWorld( entity_t *mapent ){
|
|
|
|
int newbrushes;
|
|
|
|
int worldbrushes;
|
|
|
|
mapbrush_t *temp;
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// this is pretty gross, because the brushes are expected to be
|
|
|
|
// in linear order for each entity
|
|
|
|
|
|
|
|
newbrushes = mapent->numbrushes;
|
|
|
|
worldbrushes = entities[0].numbrushes;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
temp = malloc( newbrushes * sizeof( mapbrush_t ) );
|
|
|
|
memcpy( temp, mapbrushes + mapent->firstbrush, newbrushes * sizeof( mapbrush_t ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#if 0 // let them keep their original brush numbers
|
|
|
|
for ( i = 0 ; i < newbrushes ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
temp[i].entitynum = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// make space to move the brushes (overlapped copy)
|
2012-03-17 20:01:54 +00:00
|
|
|
memmove( mapbrushes + worldbrushes + newbrushes,
|
|
|
|
mapbrushes + worldbrushes,
|
|
|
|
sizeof( mapbrush_t ) * ( nummapbrushes - worldbrushes - newbrushes ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// copy the new brushes down
|
2012-03-17 20:01:54 +00:00
|
|
|
memcpy( mapbrushes + worldbrushes, temp, sizeof( mapbrush_t ) * newbrushes );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// fix up indexes
|
|
|
|
entities[0].numbrushes += newbrushes;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1 ; i < num_entities ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
entities[i].firstbrush += newbrushes;
|
2012-03-17 20:01:54 +00:00
|
|
|
free( temp );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
mapent->numbrushes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
ParseMapEntity
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
qboolean ParseMapEntity( void ){
|
|
|
|
entity_t *mapent;
|
|
|
|
epair_t *e;
|
|
|
|
side_t *s;
|
|
|
|
int i, j;
|
|
|
|
int startbrush, startsides;
|
|
|
|
vec_t newdist;
|
|
|
|
mapbrush_t *b;
|
|
|
|
|
|
|
|
if ( !GetToken( true ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return false;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( strcmp( token, "{" ) ) {
|
|
|
|
Error( "ParseEntity: { not found" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( num_entities == MAX_MAP_ENTITIES ) {
|
|
|
|
Error( "num_entities == MAX_MAP_ENTITIES" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
startbrush = nummapbrushes;
|
|
|
|
startsides = nummapbrushsides;
|
|
|
|
|
|
|
|
mapent = &entities[num_entities];
|
|
|
|
num_entities++;
|
2012-03-17 20:01:54 +00:00
|
|
|
memset( mapent, 0, sizeof( *mapent ) );
|
2007-11-04 03:34:51 +00:00
|
|
|
mapent->firstbrush = nummapbrushes;
|
|
|
|
mapent->numbrushes = 0;
|
|
|
|
// mapent->portalareas[0] = -1;
|
|
|
|
// mapent->portalareas[1] = -1;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !GetToken( true ) ) {
|
|
|
|
Error( "ParseEntity: EOF without closing brace" );
|
|
|
|
}
|
|
|
|
if ( !strcmp( token, "}" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
break;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( !strcmp( token, "{" ) ) {
|
|
|
|
ParseBrush( mapent );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
e = ParseEpair();
|
2007-11-04 03:34:51 +00:00
|
|
|
e->next = mapent->epairs;
|
|
|
|
mapent->epairs = e;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
} while ( 1 );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GetVectorForKey( mapent, "origin", mapent->origin );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// if there was an origin brush, offset all of the planes and texinfo
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapent->origin[0] || mapent->origin[1] || mapent->origin[2] ) {
|
|
|
|
for ( i = 0 ; i < mapent->numbrushes ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
b = &mapbrushes[mapent->firstbrush + i];
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < b->numsides ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s = &b->original_sides[j];
|
|
|
|
newdist = mapplanes[s->planenum].dist -
|
2012-03-17 20:01:54 +00:00
|
|
|
DotProduct( mapplanes[s->planenum].normal, mapent->origin );
|
|
|
|
s->planenum = FindFloatPlane( mapplanes[s->planenum].normal, newdist );
|
|
|
|
s->texinfo = TexinfoForBrushTexture( &mapplanes[s->planenum],
|
|
|
|
&side_brushtextures[s - brushsides], mapent->origin );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
MakeBrushWindings( b );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// group entities are just for editor convenience
|
|
|
|
// toss all brushes into the world entity
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( "func_group", ValueForKey( mapent, "classname" ) ) ) {
|
|
|
|
MoveBrushesToWorld( mapent );
|
2007-11-04 03:34:51 +00:00
|
|
|
mapent->numbrushes = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// areaportal entities move their brushes, but don't eliminate
|
|
|
|
// the entity
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !strcmp( "func_areaportal", ValueForKey( mapent, "classname" ) ) ) {
|
|
|
|
char str[128];
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapent->numbrushes != 1 ) {
|
|
|
|
Error( "Entity %i: func_areaportal can only be a single brush", num_entities - 1 );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
b = &mapbrushes[nummapbrushes - 1];
|
2007-11-04 03:34:51 +00:00
|
|
|
b->contents = CONTENTS_AREAPORTAL;
|
|
|
|
c_areaportals++;
|
|
|
|
mapent->areaportalnum = c_areaportals;
|
|
|
|
// set the portal number as "style"
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( str, "%i", c_areaportals );
|
|
|
|
SetKeyValue( mapent, "style", str );
|
|
|
|
MoveBrushesToWorld( mapent );
|
2007-11-04 03:34:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===================================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
LoadMapFile
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void LoadMapFile( char *filename ){
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "--- LoadMapFile ---\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
LoadScriptFile( filename );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
nummapbrushsides = 0;
|
|
|
|
num_entities = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
while ( ParseMapEntity() )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ClearBounds( map_mins, map_maxs );
|
|
|
|
for ( i = 0 ; i < entities[0].numbrushes ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( mapbrushes[i].mins[0] > 4096 ) {
|
|
|
|
continue; // no valid points
|
|
|
|
}
|
|
|
|
AddPointToBounds( mapbrushes[i].mins, map_mins, map_maxs );
|
|
|
|
AddPointToBounds( mapbrushes[i].maxs, map_mins, map_maxs );
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i brushes\n", nummapbrushes );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i clipbrushes\n", c_clipbrushes );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i total sides\n", nummapbrushsides );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i boxbevels\n", c_boxbevels );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i edgebevels\n", c_edgebevels );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i entities\n", num_entities );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i planes\n", nummapplanes );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i areaportals\n", c_areaportals );
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "size: %5.0f,%5.0f,%5.0f to %5.0f,%5.0f,%5.0f\n", map_mins[0],map_mins[1],map_mins[2],
|
2012-03-17 20:01:54 +00:00
|
|
|
map_maxs[0],map_maxs[1],map_maxs[2] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// TestExpandBrushes ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//====================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
TestExpandBrushes
|
|
|
|
|
|
|
|
Expands all the brush planes and saves a new map out
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void TestExpandBrushes( void ){
|
|
|
|
FILE *f;
|
|
|
|
side_t *s;
|
|
|
|
int i, j, bn;
|
|
|
|
winding_t *w;
|
|
|
|
char *name = "expanded.map";
|
|
|
|
mapbrush_t *brush;
|
|
|
|
vec_t dist;
|
|
|
|
|
|
|
|
Sys_Printf( "writing %s\n", name );
|
|
|
|
f = fopen( name, "wb" );
|
|
|
|
if ( !f ) {
|
|
|
|
Error( "Can't write %s\b", name );
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf( f, "{\n\"classname\" \"worldspawn\"\n" );
|
|
|
|
|
|
|
|
for ( bn = 0 ; bn < nummapbrushes ; bn++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
brush = &mapbrushes[bn];
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( f, "{\n" );
|
|
|
|
for ( i = 0 ; i < brush->numsides ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
s = brush->original_sides + i;
|
|
|
|
dist = mapplanes[s->planenum].dist;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( j = 0 ; j < 3 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
dist += fabs( 16 * mapplanes[s->planenum].normal[j] );
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
w = BaseWindingForPlane( mapplanes[s->planenum].normal, dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( f,"( %i %i %i ) ", (int)w->p[0][0], (int)w->p[0][1], (int)w->p[0][2] );
|
|
|
|
fprintf( f,"( %i %i %i ) ", (int)w->p[1][0], (int)w->p[1][1], (int)w->p[1][2] );
|
|
|
|
fprintf( f,"( %i %i %i ) ", (int)w->p[2][0], (int)w->p[2][1], (int)w->p[2][2] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( f, "%s 0 0 0 1 1\n", texinfo[s->texinfo].texture );
|
|
|
|
FreeWinding( w );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( f, "}\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( f, "}\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( f );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Error( "can't proceed after expanding brushes" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|