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
|
|
|
|
|
|
|
#include "qbsp.h"
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============================================================================
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
PORTAL FILE GENERATION
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Save out name.prt for qvis to read
|
|
|
|
==============================================================================
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
#define PORTALFILE "PRT1"
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FILE *pf;
|
|
|
|
int num_visclusters; // clusters the player can be in
|
|
|
|
int num_visportals;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void WriteFloat( FILE *f, vec_t v ){
|
|
|
|
if ( fabs( v - Q_rint( v ) ) < 0.001 ) {
|
|
|
|
fprintf( f,"%i ",(int)Q_rint( v ) );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
fprintf( f,"%f ",v );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=================
|
|
|
|
WritePortalFile_r
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void WritePortalFile_r( node_t *node ){
|
|
|
|
int i, s;
|
|
|
|
portal_t *p;
|
|
|
|
winding_t *w;
|
|
|
|
vec3_t normal;
|
|
|
|
vec_t dist;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// decision node
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->planenum != PLANENUM_LEAF && !node->detail_seperator ) {
|
|
|
|
WritePortalFile_r( node->children[0] );
|
|
|
|
WritePortalFile_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( node->contents & CONTENTS_SOLID ) {
|
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
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = node->portals ; p ; p = p->next[s] )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
w = p->winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
s = ( p->nodes[1] == node );
|
|
|
|
if ( w && p->nodes[0] == node ) {
|
|
|
|
if ( !Portal_VisFlood( p ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
// write out to the file
|
|
|
|
|
|
|
|
// sometimes planes get turned around when they are very near
|
|
|
|
// the changeover point between different axis. interpret the
|
|
|
|
// plane the same way vis will, and flip the side orders if needed
|
2007-11-04 03:34:51 +00:00
|
|
|
// FIXME: is this still relevent?
|
2012-03-17 20:01:54 +00:00
|
|
|
WindingPlane( w, normal, &dist );
|
|
|
|
if ( DotProduct( p->plane.normal, normal ) < 0.99 ) { // backwards...
|
|
|
|
fprintf( pf,"%i %i %i ",w->numpoints, p->nodes[1]->cluster, p->nodes[0]->cluster );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
fprintf( pf,"%i %i %i ",w->numpoints, p->nodes[0]->cluster, p->nodes[1]->cluster );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < w->numpoints ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( pf,"(" );
|
|
|
|
WriteFloat( pf, w->p[i][0] );
|
|
|
|
WriteFloat( pf, w->p[i][1] );
|
|
|
|
WriteFloat( pf, w->p[i][2] );
|
|
|
|
fprintf( pf,") " );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( pf,"\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
FillLeafNumbers_r
|
|
|
|
|
|
|
|
All of the leafs under node will have the same cluster
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void FillLeafNumbers_r( node_t *node, int num ){
|
|
|
|
if ( node->planenum == PLANENUM_LEAF ) {
|
|
|
|
if ( node->contents & CONTENTS_SOLID ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
node->cluster = -1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
node->cluster = num;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
node->cluster = num;
|
2012-03-17 20:01:54 +00:00
|
|
|
FillLeafNumbers_r( node->children[0], num );
|
|
|
|
FillLeafNumbers_r( node->children[1], num );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
NumberLeafs_r
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void NumberLeafs_r( node_t *node ){
|
|
|
|
portal_t *p;
|
|
|
|
|
|
|
|
if ( node->planenum != PLANENUM_LEAF && !node->detail_seperator ) { // decision node
|
2007-11-04 03:34:51 +00:00
|
|
|
node->cluster = -99;
|
2012-03-17 20:01:54 +00:00
|
|
|
NumberLeafs_r( node->children[0] );
|
|
|
|
NumberLeafs_r( node->children[1] );
|
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
|
|
|
// either a leaf or a detail cluster
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->contents & CONTENTS_SOLID ) { // solid block, viewpoint never inside
|
2007-11-04 03:34:51 +00:00
|
|
|
node->cluster = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FillLeafNumbers_r( node, num_visclusters );
|
2007-11-04 03:34:51 +00:00
|
|
|
num_visclusters++;
|
|
|
|
|
|
|
|
// count the portals
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = node->portals ; p ; )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->nodes[0] == node ) { // only write out from first leaf
|
|
|
|
if ( Portal_VisFlood( p ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
num_visportals++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
p = p->next[0];
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
|
|
|
p = p->next[1];
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
CreateVisPortals_r
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void CreateVisPortals_r( node_t *node ){
|
2007-11-04 03:34:51 +00:00
|
|
|
// stop as soon as we get to a detail_seperator, which
|
|
|
|
// means that everything below is in a single cluster
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->planenum == PLANENUM_LEAF || node->detail_seperator ) {
|
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
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
MakeNodePortal( node );
|
|
|
|
SplitNodePortals( node );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CreateVisPortals_r( node->children[0] );
|
|
|
|
CreateVisPortals_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
FinishVisPortals_r
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void FinishVisPortals2_r( node_t *node ){
|
|
|
|
if ( node->planenum == PLANENUM_LEAF ) {
|
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
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
MakeNodePortal( node );
|
|
|
|
SplitNodePortals( node );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FinishVisPortals2_r( node->children[0] );
|
|
|
|
FinishVisPortals2_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void FinishVisPortals_r( node_t *node ){
|
|
|
|
if ( node->planenum == PLANENUM_LEAF ) {
|
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
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->detail_seperator ) {
|
|
|
|
FinishVisPortals2_r( node );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FinishVisPortals_r( node->children[0] );
|
|
|
|
FinishVisPortals_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int clusterleaf;
|
|
|
|
void SaveClusters_r( node_t *node ){
|
|
|
|
if ( node->planenum == PLANENUM_LEAF ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
dleafs[clusterleaf++].cluster = node->cluster;
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
SaveClusters_r( node->children[0] );
|
|
|
|
SaveClusters_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
WritePortalFile
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void WritePortalFile( tree_t *tree ){
|
|
|
|
char filename[1024];
|
2007-11-04 03:34:51 +00:00
|
|
|
node_t *headnode;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "--- WritePortalFile ---\n" );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
headnode = tree->headnode;
|
|
|
|
num_visclusters = 0;
|
|
|
|
num_visportals = 0;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FreeTreePortals_r( headnode );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
MakeHeadnodePortals( tree );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
CreateVisPortals_r( headnode );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// set the cluster field in every leaf and count the total number of portals
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
NumberLeafs_r( headnode );
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// write the file
|
2012-03-17 20:01:54 +00:00
|
|
|
sprintf( filename, "%s.prt", source );
|
|
|
|
Sys_Printf( "writing %s\n", filename );
|
|
|
|
pf = fopen( filename, "w" );
|
|
|
|
if ( !pf ) {
|
|
|
|
Error( "Error opening %s", filename );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fprintf( pf, "%s\n", PORTALFILE );
|
|
|
|
fprintf( pf, "%i\n", num_visclusters );
|
|
|
|
fprintf( pf, "%i\n", num_visportals );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "%5i visclusters\n", num_visclusters );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%5i visportals\n", num_visportals );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
WritePortalFile_r( headnode );
|
|
|
|
|
|
|
|
fclose( pf );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// we need to store the clusters out now because ordering
|
|
|
|
// issues made us do this after writebsp...
|
|
|
|
clusterleaf = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
SaveClusters_r( headnode );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|