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 PORTALS_C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dependencies */
|
|
|
|
#include "q3map2.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ydnar: to fix broken portal windings */
|
|
|
|
extern qboolean FixWinding( winding_t *w );
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_active_portals;
|
|
|
|
int c_peak_portals;
|
|
|
|
int c_boundary;
|
|
|
|
int c_boundary_sides;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
===========
|
|
|
|
AllocPortal
|
|
|
|
===========
|
|
|
|
*/
|
|
|
|
portal_t *AllocPortal( void ){
|
|
|
|
portal_t *p;
|
|
|
|
|
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_active_portals++;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( c_active_portals > c_peak_portals ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_peak_portals = c_active_portals;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p = safe_malloc( sizeof( portal_t ) );
|
|
|
|
memset( p, 0, sizeof( portal_t ) );
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void FreePortal( portal_t *p ){
|
|
|
|
if ( p->winding ) {
|
|
|
|
FreeWinding( p->winding );
|
|
|
|
}
|
|
|
|
if ( numthreads == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_active_portals--;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
free( p );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
PortalPassable
|
|
|
|
returns true if the portal has non-opaque leafs on both sides
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
qboolean PortalPassable( portal_t *p ){
|
2007-11-04 03:34:51 +00:00
|
|
|
/* is this to global outside leaf? */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !p->onnode ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* this should never happen */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->nodes[ 0 ]->planenum != PLANENUM_LEAF ||
|
|
|
|
p->nodes[ 1 ]->planenum != PLANENUM_LEAF ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Error( "Portal_EntityFlood: not a leaf" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: added antiportal to supress portal generation for visibility blocking */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->compileFlags & C_ANTIPORTAL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* both leaves on either side of the portal must be passable */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->nodes[ 0 ]->opaque == qfalse && p->nodes[ 1 ]->opaque == qfalse ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* otherwise this isn't a passable portal */
|
|
|
|
return qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_tinyportals;
|
|
|
|
int c_badportals; /* ydnar */
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
AddPortalToNodes
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void AddPortalToNodes( portal_t *p, node_t *front, node_t *back ){
|
|
|
|
if ( p->nodes[0] || p->nodes[1] ) {
|
|
|
|
Error( "AddPortalToNode: allready included" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
p->nodes[0] = front;
|
|
|
|
p->next[0] = front->portals;
|
|
|
|
front->portals = p;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
p->nodes[1] = back;
|
|
|
|
p->next[1] = back->portals;
|
|
|
|
back->portals = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
RemovePortalFromNode
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void RemovePortalFromNode( portal_t *portal, node_t *l ){
|
|
|
|
portal_t **pp, *t;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// remove reference to the current portal
|
|
|
|
pp = &l->portals;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( 1 )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
t = *pp;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !t ) {
|
|
|
|
Error( "RemovePortalFromNode: portal not in leaf" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( t == portal ) {
|
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 ( t->nodes[0] == l ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
pp = &t->next[0];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( t->nodes[1] == l ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
pp = &t->next[1];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
Error( "RemovePortalFromNode: portal not bounding leaf" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( portal->nodes[0] == l ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
*pp = portal->next[0];
|
|
|
|
portal->nodes[0] = NULL;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( portal->nodes[1] == l ) {
|
|
|
|
*pp = portal->next[1];
|
2007-11-04 03:34:51 +00:00
|
|
|
portal->nodes[1] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void PrintPortal( portal_t *p ){
|
|
|
|
int i;
|
|
|
|
winding_t *w;
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
w = p->winding;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < w->numpoints ; i++ )
|
|
|
|
Sys_Printf( "(%5.0f,%5.0f,%5.0f)\n",w->p[i][0]
|
|
|
|
, w->p[i][1], w->p[i][2] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
MakeHeadnodePortals
|
|
|
|
|
|
|
|
The created portals will face the global outside_node
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
#define SIDESPACE 8
|
|
|
|
void MakeHeadnodePortals( tree_t *tree ){
|
|
|
|
vec3_t bounds[2];
|
|
|
|
int i, j, n;
|
|
|
|
portal_t *p, *portals[6];
|
|
|
|
plane_t bplanes[6], *pl;
|
2007-11-04 03:34:51 +00:00
|
|
|
node_t *node;
|
|
|
|
|
|
|
|
node = tree->headnode;
|
|
|
|
|
|
|
|
// pad with some space so there will never be null volume leafs
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
bounds[0][i] = tree->mins[i] - SIDESPACE;
|
|
|
|
bounds[1][i] = tree->maxs[i] + SIDESPACE;
|
|
|
|
if ( bounds[0][i] >= bounds[1][i] ) {
|
|
|
|
Error( "Backwards tree volume" );
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
tree->outside_node.planenum = PLANENUM_LEAF;
|
|
|
|
tree->outside_node.brushlist = NULL;
|
|
|
|
tree->outside_node.portals = NULL;
|
|
|
|
tree->outside_node.opaque = qfalse;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 3 ; i++ )
|
|
|
|
for ( j = 0 ; j < 2 ; j++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
n = j * 3 + i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
p = AllocPortal();
|
2007-11-04 03:34:51 +00:00
|
|
|
portals[n] = p;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
pl = &bplanes[n];
|
2012-03-17 20:01:54 +00:00
|
|
|
memset( pl, 0, sizeof( *pl ) );
|
|
|
|
if ( j ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
pl->normal[i] = -1;
|
|
|
|
pl->dist = -bounds[j][i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pl->normal[i] = 1;
|
|
|
|
pl->dist = bounds[j][i];
|
|
|
|
}
|
|
|
|
p->plane = *pl;
|
2012-03-17 20:01:54 +00:00
|
|
|
p->winding = BaseWindingForPlane( pl->normal, pl->dist );
|
|
|
|
AddPortalToNodes( p, node, &tree->outside_node );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// clip the basewindings by all the other planes
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 0 ; i < 6 ; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
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 ( j == i ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
ChopWindingInPlace( &portals[i]->winding, bplanes[j].normal, bplanes[j].dist, ON_EPSILON );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
BaseWindingForNode
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
#define BASE_WINDING_EPSILON 0.001
|
|
|
|
#define SPLIT_WINDING_EPSILON 0.001
|
|
|
|
|
|
|
|
winding_t *BaseWindingForNode( node_t *node ){
|
|
|
|
winding_t *w;
|
|
|
|
node_t *n;
|
|
|
|
plane_t *plane;
|
|
|
|
vec3_t normal;
|
|
|
|
vec_t dist;
|
|
|
|
|
|
|
|
w = BaseWindingForPlane( mapplanes[node->planenum].normal
|
|
|
|
, mapplanes[node->planenum].dist );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// clip by all the parents
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( n = node->parent ; n && w ; )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
plane = &mapplanes[n->planenum];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( n->children[0] == node ) { // take front
|
|
|
|
ChopWindingInPlace( &w, plane->normal, plane->dist, BASE_WINDING_EPSILON );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
2012-03-17 20:01:54 +00:00
|
|
|
{ // take back
|
|
|
|
VectorSubtract( vec3_origin, plane->normal, normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = -plane->dist;
|
2012-03-17 20:01:54 +00:00
|
|
|
ChopWindingInPlace( &w, normal, dist, BASE_WINDING_EPSILON );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
node = n;
|
|
|
|
n = n->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
MakeNodePortal
|
|
|
|
|
|
|
|
create the new portal by taking the full plane winding for the cutting plane
|
|
|
|
and clipping it by all of parents of this node
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void MakeNodePortal( node_t *node ){
|
|
|
|
portal_t *new_portal, *p;
|
|
|
|
winding_t *w;
|
|
|
|
vec3_t normal;
|
|
|
|
float dist;
|
|
|
|
int side;
|
|
|
|
|
|
|
|
w = BaseWindingForNode( node );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// clip the portal by all the other portals in the node
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = node->portals ; p && w; p = p->next[side] )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->nodes[0] == node ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorCopy( p->plane.normal, normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = p->plane.dist;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else if ( p->nodes[1] == node ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
VectorSubtract( vec3_origin, p->plane.normal, normal );
|
2007-11-04 03:34:51 +00:00
|
|
|
dist = -p->plane.dist;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
|
|
|
Error( "CutNodePortals_r: mislinked portal" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
ChopWindingInPlace( &w, normal, dist, CLIP_EPSILON );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !w ) {
|
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
|
|
|
/* ydnar: adding this here to fix degenerate windings */
|
|
|
|
#if 0
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( FixWinding( w ) == qfalse ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_badportals++;
|
|
|
|
FreeWinding( w );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( WindingIsTiny( w ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_tinyportals++;
|
2012-03-17 20:01:54 +00:00
|
|
|
FreeWinding( w );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
new_portal = AllocPortal();
|
2007-11-04 03:34:51 +00:00
|
|
|
new_portal->plane = mapplanes[node->planenum];
|
|
|
|
new_portal->onnode = node;
|
|
|
|
new_portal->winding = w;
|
|
|
|
new_portal->compileFlags = node->compileFlags;
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPortalToNodes( new_portal, node->children[0], node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============
|
|
|
|
SplitNodePortals
|
|
|
|
|
|
|
|
Move or split the portals that bound node so that the node's
|
|
|
|
children have portals instead of node.
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
void SplitNodePortals( node_t *node ){
|
|
|
|
portal_t *p, *next_portal, *new_portal;
|
|
|
|
node_t *f, *b, *other_node;
|
|
|
|
int side;
|
|
|
|
plane_t *plane;
|
|
|
|
winding_t *frontwinding, *backwinding;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
plane = &mapplanes[node->planenum];
|
|
|
|
f = node->children[0];
|
|
|
|
b = node->children[1];
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( p = node->portals ; p ; p = next_portal )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->nodes[0] == node ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( p->nodes[1] == node ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
side = 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
Error( "SplitNodePortals: mislinked portal" );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
next_portal = p->next[side];
|
|
|
|
|
|
|
|
other_node = p->nodes[!side];
|
2012-03-17 20:01:54 +00:00
|
|
|
RemovePortalFromNode( p, p->nodes[0] );
|
|
|
|
RemovePortalFromNode( p, p->nodes[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// cut the portal into two portals, one on each side of the cut plane
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
ClipWindingEpsilon( p->winding, plane->normal, plane->dist,
|
|
|
|
SPLIT_WINDING_EPSILON, &frontwinding, &backwinding );
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( frontwinding && WindingIsTiny( frontwinding ) ) {
|
|
|
|
if ( !f->tinyportals ) {
|
|
|
|
VectorCopy( frontwinding->p[0], f->referencepoint );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
f->tinyportals++;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !other_node->tinyportals ) {
|
|
|
|
VectorCopy( frontwinding->p[0], other_node->referencepoint );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
other_node->tinyportals++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FreeWinding( frontwinding );
|
2007-11-04 03:34:51 +00:00
|
|
|
frontwinding = NULL;
|
|
|
|
c_tinyportals++;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( backwinding && WindingIsTiny( backwinding ) ) {
|
|
|
|
if ( !b->tinyportals ) {
|
|
|
|
VectorCopy( backwinding->p[0], b->referencepoint );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
b->tinyportals++;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !other_node->tinyportals ) {
|
|
|
|
VectorCopy( backwinding->p[0], other_node->referencepoint );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
other_node->tinyportals++;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FreeWinding( backwinding );
|
2007-11-04 03:34:51 +00:00
|
|
|
backwinding = NULL;
|
|
|
|
c_tinyportals++;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !frontwinding && !backwinding ) { // tiny windings on both sides
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !frontwinding ) {
|
|
|
|
FreeWinding( backwinding );
|
|
|
|
if ( side == 0 ) {
|
|
|
|
AddPortalToNodes( p, b, other_node );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
AddPortalToNodes( p, other_node, b );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !backwinding ) {
|
|
|
|
FreeWinding( frontwinding );
|
|
|
|
if ( side == 0 ) {
|
|
|
|
AddPortalToNodes( p, f, other_node );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
AddPortalToNodes( p, other_node, f );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
// the winding is split
|
|
|
|
new_portal = AllocPortal();
|
2007-11-04 03:34:51 +00:00
|
|
|
*new_portal = *p;
|
|
|
|
new_portal->winding = backwinding;
|
2012-03-17 20:01:54 +00:00
|
|
|
FreeWinding( p->winding );
|
2007-11-04 03:34:51 +00:00
|
|
|
p->winding = frontwinding;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( side == 0 ) {
|
|
|
|
AddPortalToNodes( p, f, other_node );
|
|
|
|
AddPortalToNodes( new_portal, b, other_node );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
AddPortalToNodes( p, other_node, f );
|
|
|
|
AddPortalToNodes( new_portal, other_node, b );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node->portals = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
================
|
|
|
|
CalcNodeBounds
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
void CalcNodeBounds( node_t *node ){
|
|
|
|
portal_t *p;
|
|
|
|
int s;
|
|
|
|
int i;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
// calc mins/maxs for both leafs and nodes
|
2012-03-17 20:01:54 +00:00
|
|
|
ClearBounds( node->mins, node->maxs );
|
|
|
|
for ( p = node->portals ; p ; p = p->next[s] )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
s = ( p->nodes[1] == node );
|
|
|
|
for ( i = 0 ; i < p->winding->numpoints ; i++ )
|
|
|
|
AddPointToBounds( p->winding->p[i], node->mins, node->maxs );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
MakeTreePortals_r
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void MakeTreePortals_r( node_t *node ){
|
|
|
|
int i;
|
|
|
|
|
|
|
|
CalcNodeBounds( node );
|
|
|
|
if ( node->mins[0] >= node->maxs[0] ) {
|
|
|
|
Sys_Printf( "WARNING: node without a volume\n" );
|
|
|
|
Sys_Printf( "node has %d tiny portals\n", node->tinyportals );
|
|
|
|
Sys_Printf( "node reference point %1.2f %1.2f %1.2f\n", node->referencepoint[0],
|
|
|
|
node->referencepoint[1],
|
|
|
|
node->referencepoint[2] );
|
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 ( node->mins[i] < MIN_WORLD_COORD || node->maxs[i] > MAX_WORLD_COORD ) {
|
|
|
|
if ( node->portals && node->portals->winding ) {
|
|
|
|
xml_Winding( "WARNING: Node With Unbounded Volume", node->portals->winding->p, node->portals->winding->numpoints, qfalse );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
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
|
|
|
MakeTreePortals_r( node->children[0] );
|
|
|
|
MakeTreePortals_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==================
|
|
|
|
MakeTreePortals
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
void MakeTreePortals( tree_t *tree ){
|
|
|
|
Sys_FPrintf( SYS_VRB, "--- MakeTreePortals ---\n" );
|
|
|
|
MakeHeadnodePortals( tree );
|
|
|
|
MakeTreePortals_r( tree->headnode );
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "%9d tiny portals\n", c_tinyportals );
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "%9d bad portals\n", c_badportals ); /* ydnar */
|
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
|
|
|
FLOOD ENTITIES
|
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
|
|
|
int c_floodedleafs;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
FloodPortals_r
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void FloodPortals_r( node_t *node, int dist, qboolean skybox ){
|
|
|
|
int s;
|
|
|
|
portal_t *p;
|
|
|
|
|
|
|
|
|
|
|
|
if ( skybox ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
node->skybox = skybox;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( node->occupied || 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
|
|
|
c_floodedleafs++;
|
|
|
|
node->occupied = dist;
|
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
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
s = ( p->nodes[ 1 ] == node );
|
2007-11-04 03:34:51 +00:00
|
|
|
FloodPortals_r( p->nodes[ !s ], dist + 1, skybox );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
PlaceOccupant
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
|
|
|
|
qboolean PlaceOccupant( node_t *headnode, vec3_t origin, entity_t *occupant, qboolean skybox ){
|
|
|
|
vec_t d;
|
|
|
|
node_t *node;
|
|
|
|
plane_t *plane;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
// find the leaf to start in
|
|
|
|
node = headnode;
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( node->planenum != PLANENUM_LEAF )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
plane = &mapplanes[ node->planenum ];
|
|
|
|
d = DotProduct( origin, plane->normal ) - plane->dist;
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( d >= 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
node = node->children[ 0 ];
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
node = node->children[ 1 ];
|
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->opaque ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
node->occupant = occupant;
|
|
|
|
node->skybox = skybox;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
FloodPortals_r( node, 1, skybox );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
return qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
FloodEntities
|
|
|
|
|
|
|
|
Marks all nodes that can be reached by entites
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
|
|
|
|
qboolean FloodEntities( tree_t *tree ){
|
|
|
|
int i, s;
|
|
|
|
vec3_t origin, offset, scale, angles;
|
|
|
|
qboolean r, inside, tripped, skybox;
|
|
|
|
node_t *headnode;
|
|
|
|
entity_t *e;
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
headnode = tree->headnode;
|
|
|
|
Sys_FPrintf( SYS_VRB,"--- FloodEntities ---\n" );
|
|
|
|
inside = qfalse;
|
|
|
|
tree->outside_node.occupied = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
tripped = qfalse;
|
|
|
|
c_floodedleafs = 0;
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( i = 1; i < numEntities; i++ )
|
2007-11-04 03:34:51 +00:00
|
|
|
{
|
|
|
|
/* get entity */
|
|
|
|
e = &entities[ i ];
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get origin */
|
|
|
|
GetVectorForKey( e, "origin", origin );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( VectorCompare( origin, vec3_origin ) ) {
|
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
|
|
|
/* handle skybox entities */
|
|
|
|
value = ValueForKey( e, "classname" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !Q_stricmp( value, "_skybox" ) ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
skybox = qtrue;
|
|
|
|
skyboxPresent = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* invert origin */
|
|
|
|
VectorScale( origin, -1.0f, offset );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get scale */
|
|
|
|
VectorSet( scale, 64.0f, 64.0f, 64.0f );
|
|
|
|
value = ValueForKey( e, "_scale" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
s = sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( s == 1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
scale[ 1 ] = scale[ 0 ];
|
|
|
|
scale[ 2 ] = scale[ 0 ];
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* get "angle" (yaw) or "angles" (pitch yaw roll) */
|
|
|
|
VectorClear( angles );
|
|
|
|
angles[ 2 ] = FloatForKey( e, "angle" );
|
|
|
|
value = ValueForKey( e, "angles" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( value[ 0 ] != '\0' ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* set transform matrix (thanks spog) */
|
|
|
|
m4x4_identity( skyboxTransform );
|
|
|
|
m4x4_pivoted_transform_by_vec3( skyboxTransform, offset, angles, eXYZ, scale, origin );
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
skybox = qfalse;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* nudge off floor */
|
|
|
|
origin[ 2 ] += 1;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* debugging code */
|
|
|
|
//% if( i == 1 )
|
|
|
|
//% origin[ 2 ] += 4096;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* find leaf */
|
|
|
|
r = PlaceOccupant( headnode, origin, e, skybox );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( r ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
inside = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( ( !r || tree->outside_node.occupied ) && !tripped ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
xml_Select( "Entity leaked", e->mapEntityNum, 0, qfalse );
|
|
|
|
tripped = qtrue;
|
|
|
|
}
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "%9d flooded leafs\n", c_floodedleafs );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( !inside ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "no entities in open -- no filling\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else if ( tree->outside_node.occupied ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB, "entity reached from outside -- no filling\n" );
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (qboolean) ( inside && !tree->outside_node.occupied );
|
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
|
|
|
FLOOD AREAS
|
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
|
|
|
int c_areas;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
FloodAreas_r()
|
|
|
|
floods through leaf portals to tag leafs with an area
|
|
|
|
*/
|
|
|
|
|
|
|
|
void FloodAreas_r( node_t *node ){
|
|
|
|
int s;
|
|
|
|
portal_t *p;
|
|
|
|
brush_t *b;
|
|
|
|
|
|
|
|
|
|
|
|
if ( node->areaportal ) {
|
|
|
|
if ( node->area == -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
node->area = c_areas;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* this node is part of an area portal brush */
|
|
|
|
b = node->brushlist->original;
|
|
|
|
|
|
|
|
/* if the current area has already touched this portal, we are done */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->portalareas[ 0 ] == c_areas || b->portalareas[ 1 ] == c_areas ) {
|
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
|
|
|
// note the current area as bounding the portal
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->portalareas[ 1 ] != -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_Printf( "WARNING: areaportal brush %i touches > 2 areas\n", b->brushNum );
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->portalareas[ 0 ] != -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
b->portalareas[ 1 ] = c_areas;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2007-11-04 03:34:51 +00:00
|
|
|
b->portalareas[ 0 ] = c_areas;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->area != -1 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
if ( node->cluster == -1 ) {
|
|
|
|
return;
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
|
|
|
|
node->area = c_areas;
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: skybox nodes set the skybox area */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->skybox ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
skyboxArea = c_areas;
|
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
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
s = ( p->nodes[1] == node );
|
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: allow areaportal portals to block area flow */
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( p->compileFlags & C_AREAPORTAL ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
continue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !PortalPassable( p ) ) {
|
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
|
|
|
FloodAreas_r( p->nodes[ !s ] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
FindAreas_r
|
|
|
|
|
|
|
|
Just decend the tree, and for each node that hasn't had an
|
|
|
|
area set, flood fill out from there
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void FindAreas_r( node_t *node ){
|
|
|
|
if ( node->planenum != PLANENUM_LEAF ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
FindAreas_r( node->children[ 0 ] );
|
|
|
|
FindAreas_r( node->children[ 1 ] );
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( node->opaque || node->areaportal || node->area != -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
|
|
|
FloodAreas_r( node );
|
|
|
|
c_areas++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
CheckAreas_r
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void CheckAreas_r( node_t *node ){
|
|
|
|
brush_t *b;
|
|
|
|
|
|
|
|
if ( node->planenum != PLANENUM_LEAF ) {
|
|
|
|
CheckAreas_r( node->children[0] );
|
|
|
|
CheckAreas_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( node->cluster != -1 ) {
|
|
|
|
if ( node->area == -1 ) {
|
|
|
|
Sys_Printf( "WARNING: cluster %d has area set to -1\n", node->cluster );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( node->areaportal ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
b = node->brushlist->original;
|
|
|
|
|
|
|
|
// check if the areaportal touches two areas
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( b->portalareas[0] == -1 || b->portalareas[1] == -1 ) {
|
|
|
|
Sys_Printf( "WARNING: areaportal brush %i doesn't touch two areas\n", b->brushNum );
|
|
|
|
}
|
2007-11-04 03:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
FloodSkyboxArea_r() - ydnar
|
|
|
|
sets all nodes with the skybox area to skybox
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void FloodSkyboxArea_r( node_t *node ){
|
|
|
|
if ( skyboxArea < 0 ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( node->planenum != PLANENUM_LEAF ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
FloodSkyboxArea_r( node->children[ 0 ] );
|
|
|
|
FloodSkyboxArea_r( node->children[ 1 ] );
|
|
|
|
return;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
|
|
|
|
if ( node->opaque || node->area != skyboxArea ) {
|
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
|
|
|
node->skybox = qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
FloodAreas()
|
|
|
|
mark each leaf with an area, bounded by C_AREAPORTAL
|
|
|
|
*/
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void FloodAreas( tree_t *tree ){
|
2007-11-04 03:34:51 +00:00
|
|
|
Sys_FPrintf( SYS_VRB,"--- FloodAreas ---\n" );
|
|
|
|
FindAreas_r( tree->headnode );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* ydnar: flood all skybox nodes */
|
|
|
|
FloodSkyboxArea_r( tree->headnode );
|
2012-03-17 20:01:54 +00:00
|
|
|
|
2007-11-04 03:34:51 +00:00
|
|
|
/* check for areaportal brushes that don't touch two areas */
|
|
|
|
/* ydnar: fix this rather than just silence the warnings */
|
|
|
|
//% CheckAreas_r( tree->headnode );
|
|
|
|
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d areas\n", c_areas );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//======================================================
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int c_outside;
|
|
|
|
int c_inside;
|
|
|
|
int c_solid;
|
2007-11-04 03:34:51 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void FillOutside_r( node_t *node ){
|
|
|
|
if ( node->planenum != PLANENUM_LEAF ) {
|
|
|
|
FillOutside_r( node->children[0] );
|
|
|
|
FillOutside_r( node->children[1] );
|
2007-11-04 03:34:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// anything not reachable by an entity
|
|
|
|
// can be filled away
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !node->occupied ) {
|
2007-11-04 03:34:51 +00:00
|
|
|
if ( !node->opaque ) {
|
|
|
|
c_outside++;
|
|
|
|
node->opaque = qtrue;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_solid++;
|
|
|
|
}
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-04 03:34:51 +00:00
|
|
|
c_inside++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
=============
|
|
|
|
FillOutside
|
|
|
|
|
|
|
|
Fill all nodes that can't be reached by entities
|
|
|
|
=============
|
|
|
|
*/
|
|
|
|
void FillOutside( node_t *headnode ){
|
2007-11-04 03:34:51 +00:00
|
|
|
c_outside = 0;
|
|
|
|
c_inside = 0;
|
|
|
|
c_solid = 0;
|
|
|
|
Sys_FPrintf( SYS_VRB,"--- FillOutside ---\n" );
|
|
|
|
FillOutside_r( headnode );
|
|
|
|
Sys_FPrintf( SYS_VRB,"%9d solid leafs\n", c_solid );
|
|
|
|
Sys_Printf( "%9d leafs filled\n", c_outside );
|
|
|
|
Sys_FPrintf( SYS_VRB, "%9d inside leafs\n", c_inside );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//==============================================================
|