2002-09-19 18:51:19 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program 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.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
This program 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.
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
See file, 'COPYING', for details.
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2003-01-15 15:31:36 +00:00
|
|
|
|
|
|
|
static __attribute__ ((unused)) const char rcsid[] =
|
|
|
|
"$Id$";
|
|
|
|
|
2002-09-19 19:12:16 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include "string.h"
|
|
|
|
#endif
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
|
|
|
#include "bsp5.h"
|
2002-09-20 21:48:34 +00:00
|
|
|
#include "options.h"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
node_t outside_node; // portals outside the world face this
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
AddPortalToNodes (portal_t *p, node_t *front, node_t *back)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
|
|
|
if (p->nodes[0] || p->nodes[1])
|
|
|
|
Sys_Error ("AddPortalToNode: allready included");
|
|
|
|
|
|
|
|
p->nodes[0] = front;
|
|
|
|
p->next[0] = front->portals;
|
|
|
|
front->portals = p;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
p->nodes[1] = back;
|
|
|
|
p->next[1] = back->portals;
|
|
|
|
back->portals = p;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
RemovePortalFromNode (portal_t *portal, node_t *l)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
portal_t **pp, *t;
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// remove reference to the current portal
|
2002-09-19 16:58:48 +00:00
|
|
|
pp = &l->portals;
|
2002-09-19 17:14:23 +00:00
|
|
|
while (1) {
|
2002-09-19 16:58:48 +00:00
|
|
|
t = *pp;
|
|
|
|
if (!t)
|
2002-09-19 17:14:23 +00:00
|
|
|
Sys_Error ("RemovePortalFromNode: portal not in leaf");
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
if (t == portal)
|
2002-09-19 16:58:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (t->nodes[0] == l)
|
|
|
|
pp = &t->next[0];
|
|
|
|
else if (t->nodes[1] == l)
|
|
|
|
pp = &t->next[1];
|
|
|
|
else
|
|
|
|
Sys_Error ("RemovePortalFromNode: portal not bounding leaf");
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
if (portal->nodes[0] == l) {
|
2002-09-19 16:58:48 +00:00
|
|
|
*pp = portal->next[0];
|
|
|
|
portal->nodes[0] = NULL;
|
2002-09-19 17:14:23 +00:00
|
|
|
} else if (portal->nodes[1] == l) {
|
|
|
|
*pp = portal->next[1];
|
2002-09-19 16:58:48 +00:00
|
|
|
portal->nodes[1] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
MakeHeadnodePortals
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
The created portals will face the global outside_node
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
MakeHeadnodePortals (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int side, i, j, n;
|
2002-09-19 17:14:23 +00:00
|
|
|
plane_t bplanes[6], *pl;
|
2002-09-19 18:51:19 +00:00
|
|
|
portal_t *p, *portals[6];
|
|
|
|
vec3_t bounds[2];
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
Draw_ClearWindow ();
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// pad with some space so there will never be null volume leafs
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
bounds[0][i] = brushset->mins[i] - SIDESPACE;
|
|
|
|
bounds[1][i] = brushset->maxs[i] + SIDESPACE;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
outside_node.contents = CONTENTS_SOLID;
|
|
|
|
outside_node.portals = NULL;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
n = j * 3 + i;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
|
|
|
p = AllocPortal ();
|
|
|
|
portals[n] = p;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
pl = &bplanes[n];
|
2002-09-19 17:14:23 +00:00
|
|
|
memset (pl, 0, sizeof (*pl));
|
|
|
|
if (j) {
|
2002-09-19 16:58:48 +00:00
|
|
|
pl->normal[i] = -1;
|
|
|
|
pl->dist = -bounds[j][i];
|
2002-09-19 17:14:23 +00:00
|
|
|
} else {
|
2002-09-19 16:58:48 +00:00
|
|
|
pl->normal[i] = 1;
|
|
|
|
pl->dist = bounds[j][i];
|
|
|
|
}
|
|
|
|
p->planenum = FindPlane (pl, &side);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
p->winding = BaseWindingForPlane (pl);
|
|
|
|
if (side)
|
|
|
|
AddPortalToNodes (p, &outside_node, node);
|
|
|
|
else
|
|
|
|
AddPortalToNodes (p, node, &outside_node);
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// clip the basewindings by all the other planes
|
2002-09-19 17:14:23 +00:00
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
for (j = 0; j < 6; j++) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (j == i)
|
|
|
|
continue;
|
2002-09-19 17:14:23 +00:00
|
|
|
portals[i]->winding =
|
|
|
|
ClipWinding (portals[i]->winding, &bplanes[j], true);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
PlaneFromWinding (winding_t *w, plane_t *plane)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
vec3_t v1, v2;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// calc plane
|
2002-09-19 16:58:48 +00:00
|
|
|
VectorSubtract (w->points[2], w->points[1], v1);
|
|
|
|
VectorSubtract (w->points[0], w->points[1], v2);
|
|
|
|
CrossProduct (v2, v1, plane->normal);
|
2002-09-25 21:35:49 +00:00
|
|
|
_VectorNormalize (plane->normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
plane->dist = DotProduct (w->points[0], plane->normal);
|
|
|
|
}
|
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
static int cutnode_detail;
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
CutNodePortals_r (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 18:51:19 +00:00
|
|
|
int side;
|
2002-09-19 17:14:23 +00:00
|
|
|
node_t *f, *b, *other_node;
|
2002-09-19 18:51:19 +00:00
|
|
|
plane_t *plane, clipplane;
|
2002-09-19 17:14:23 +00:00
|
|
|
portal_t *p, *new_portal, *next_portal;
|
|
|
|
winding_t *w, *frontwinding, *backwinding;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
// CheckLeafPortalConsistancy (node);
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// seperate the portals on node into it's children
|
2002-09-19 18:51:19 +00:00
|
|
|
if (node->contents)
|
2002-09-19 17:14:23 +00:00
|
|
|
return; // at a leaf, no more dividing
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
if (node->detail && cutnode_detail)
|
|
|
|
return;
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
plane = &planes[node->planenum];
|
|
|
|
|
|
|
|
f = node->children[0];
|
|
|
|
b = node->children[1];
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// create the new portal by taking the full plane winding for the cutting
|
|
|
|
// plane and clipping it by all of the planes from the other portals
|
2002-09-19 16:58:48 +00:00
|
|
|
new_portal = AllocPortal ();
|
|
|
|
new_portal->planenum = node->planenum;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
w = BaseWindingForPlane (&planes[node->planenum]);
|
2002-09-23 16:27:17 +00:00
|
|
|
side = 0;
|
2002-09-19 17:14:23 +00:00
|
|
|
for (p = node->portals; p; p = p->next[side]) {
|
2002-09-19 16:58:48 +00:00
|
|
|
clipplane = planes[p->planenum];
|
|
|
|
if (p->nodes[0] == node)
|
|
|
|
side = 0;
|
2002-09-19 17:14:23 +00:00
|
|
|
else if (p->nodes[1] == node) {
|
2002-09-19 16:58:48 +00:00
|
|
|
clipplane.dist = -clipplane.dist;
|
2003-09-03 22:00:08 +00:00
|
|
|
VectorNegate (clipplane.normal, clipplane.normal);
|
2002-09-19 16:58:48 +00:00
|
|
|
side = 1;
|
2002-09-19 17:14:23 +00:00
|
|
|
} else
|
2002-09-19 16:58:48 +00:00
|
|
|
Sys_Error ("CutNodePortals_r: mislinked portal");
|
|
|
|
|
|
|
|
w = ClipWinding (w, &clipplane, true);
|
2002-09-19 17:14:23 +00:00
|
|
|
if (!w) {
|
2002-09-19 16:58:48 +00:00
|
|
|
printf ("WARNING: CutNodePortals_r:new portal was clipped away\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
if (w) {
|
|
|
|
// if the plane was not clipped on all sides, there was an error
|
|
|
|
new_portal->winding = w;
|
2002-09-19 16:58:48 +00:00
|
|
|
AddPortalToNodes (new_portal, f, b);
|
|
|
|
}
|
2002-09-19 18:51:19 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// partition the portals
|
2002-09-19 17:14:23 +00:00
|
|
|
for (p = node->portals; p; p = next_portal) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (p->nodes[0] == node)
|
|
|
|
side = 0;
|
|
|
|
else if (p->nodes[1] == node)
|
|
|
|
side = 1;
|
|
|
|
else
|
|
|
|
Sys_Error ("CutNodePortals_r: mislinked portal");
|
|
|
|
next_portal = p->next[side];
|
|
|
|
|
|
|
|
other_node = p->nodes[!side];
|
|
|
|
RemovePortalFromNode (p, p->nodes[0]);
|
|
|
|
RemovePortalFromNode (p, p->nodes[1]);
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// cut the portal into two portals, one on each side of the cut plane
|
2002-09-19 16:58:48 +00:00
|
|
|
DivideWinding (p->winding, plane, &frontwinding, &backwinding);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
if (!frontwinding) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (side == 0)
|
|
|
|
AddPortalToNodes (p, b, other_node);
|
|
|
|
else
|
|
|
|
AddPortalToNodes (p, other_node, b);
|
|
|
|
continue;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
if (!backwinding) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (side == 0)
|
|
|
|
AddPortalToNodes (p, f, other_node);
|
|
|
|
else
|
|
|
|
AddPortalToNodes (p, other_node, f);
|
|
|
|
continue;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
// the winding is split
|
2002-09-19 16:58:48 +00:00
|
|
|
new_portal = AllocPortal ();
|
|
|
|
*new_portal = *p;
|
|
|
|
new_portal->winding = backwinding;
|
|
|
|
FreeWinding (p->winding);
|
|
|
|
p->winding = frontwinding;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
if (side == 0) {
|
2002-09-19 16:58:48 +00:00
|
|
|
AddPortalToNodes (p, f, other_node);
|
|
|
|
AddPortalToNodes (new_portal, b, other_node);
|
2002-09-19 17:14:23 +00:00
|
|
|
} else {
|
2002-09-19 16:58:48 +00:00
|
|
|
AddPortalToNodes (p, other_node, f);
|
|
|
|
AddPortalToNodes (new_portal, other_node, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
DrawLeaf (f, 1);
|
|
|
|
DrawLeaf (b, 2);
|
|
|
|
|
|
|
|
CutNodePortals_r (f);
|
|
|
|
CutNodePortals_r (b);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-09-23 16:27:17 +00:00
|
|
|
PortalizeWorld
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
Builds the exact polyhedrons for the nodes and leafs
|
2002-09-19 16:58:48 +00:00
|
|
|
*/
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2002-09-19 18:51:19 +00:00
|
|
|
PortalizeWorld (node_t *headnode)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
|
|
|
qprintf ("----- portalize ----\n");
|
|
|
|
|
|
|
|
MakeHeadnodePortals (headnode);
|
2003-02-04 23:26:26 +00:00
|
|
|
cutnode_detail = 0;
|
|
|
|
CutNodePortals_r (headnode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
PortalizeWorldDetail
|
|
|
|
|
|
|
|
Like PortalizeWorld, but stop at detail nodes - Alexander Malmberg.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
PortalizeWorldDetail (node_t *headnode)
|
|
|
|
{
|
|
|
|
qprintf ("----- portalize ----\n");
|
|
|
|
|
|
|
|
MakeHeadnodePortals (headnode);
|
|
|
|
cutnode_detail = 1;
|
2002-09-19 17:14:23 +00:00
|
|
|
CutNodePortals_r (headnode);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2002-09-19 18:51:19 +00:00
|
|
|
FreeAllPortals (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
portal_t *p, *nextp;
|
|
|
|
|
|
|
|
if (!node->contents) {
|
2002-09-19 16:58:48 +00:00
|
|
|
FreeAllPortals (node->children[0]);
|
|
|
|
FreeAllPortals (node->children[1]);
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (p = node->portals; p; p = nextp) {
|
2002-09-19 16:58:48 +00:00
|
|
|
if (p->nodes[0] == node)
|
|
|
|
nextp = p->next[0];
|
|
|
|
else
|
|
|
|
nextp = p->next[1];
|
|
|
|
RemovePortalFromNode (p, p->nodes[0]);
|
|
|
|
RemovePortalFromNode (p, p->nodes[1]);
|
|
|
|
FreeWinding (p->winding);
|
|
|
|
FreePortal (p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// PORTAL FILE GENERATION
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
#define PORTALFILE "PRT1-AM"
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
FILE *pf;
|
|
|
|
int num_visleafs; // leafs the player can be in
|
|
|
|
int num_visportals;
|
2003-02-04 23:26:26 +00:00
|
|
|
int num_realleafs;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-09-03 22:00:08 +00:00
|
|
|
//FIXME make work with transparent water
|
2003-02-04 23:26:26 +00:00
|
|
|
static int
|
|
|
|
HasContents (node_t *n, int cont)
|
|
|
|
{
|
|
|
|
if (n->contents == cont)
|
|
|
|
return 1;
|
|
|
|
if (n->contents)
|
|
|
|
return 0;
|
|
|
|
if (HasContents (n->children[0], cont))
|
|
|
|
return 1;
|
|
|
|
return HasContents (n->children[1], cont);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ShareContents (node_t *n1, node_t *n2)
|
|
|
|
{
|
|
|
|
if (n1->contents) {
|
|
|
|
if (n1->contents == CONTENTS_SOLID)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return HasContents (n2, n1->contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ShareContents (n1->children[0], n2))
|
|
|
|
return 1;
|
|
|
|
return ShareContents (n1->children[1], n2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SameContents (node_t *n1, node_t *n2)
|
|
|
|
{
|
|
|
|
if (n1->contents == CONTENTS_SOLID || n2->contents == CONTENTS_SOLID)
|
|
|
|
return 0;
|
|
|
|
if (n1->detail && n2->detail)
|
|
|
|
ShareContents (n1, n2);
|
|
|
|
if (n1->detail)
|
|
|
|
return HasContents (n1, n2->contents);
|
|
|
|
if (n2->detail)
|
|
|
|
return HasContents (n2, n1->contents);
|
|
|
|
return n1->contents == n2->contents;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
WritePortalFile_r (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
int i;
|
2002-09-19 18:51:19 +00:00
|
|
|
plane_t *pl, plane2;
|
2002-09-19 17:14:23 +00:00
|
|
|
portal_t *p;
|
|
|
|
winding_t *w;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
if (!node->contents && !node->detail) {
|
2002-09-19 16:58:48 +00:00
|
|
|
WritePortalFile_r (node->children[0]);
|
|
|
|
WritePortalFile_r (node->children[1]);
|
|
|
|
return;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (node->contents == CONTENTS_SOLID)
|
|
|
|
return;
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
for (p = node->portals; p;) {
|
2002-09-19 16:58:48 +00:00
|
|
|
w = p->winding;
|
|
|
|
if (w && p->nodes[0] == node
|
2003-02-04 23:26:26 +00:00
|
|
|
&& SameContents (p->nodes[0], p->nodes[1])) {
|
2002-09-19 17:14:23 +00:00
|
|
|
// write out to the file
|
|
|
|
|
2002-09-19 18:51:19 +00:00
|
|
|
// 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
|
2002-09-19 16:58:48 +00:00
|
|
|
pl = &planes[p->planenum];
|
|
|
|
PlaneFromWinding (w, &plane2);
|
2002-09-19 18:51:19 +00:00
|
|
|
if (DotProduct (pl->normal, plane2.normal) < 0.99) { // backwards..
|
|
|
|
fprintf (pf, "%i %i %i ", w->numpoints,
|
|
|
|
p->nodes[1]->visleafnum, p->nodes[0]->visleafnum);
|
2002-09-19 17:14:23 +00:00
|
|
|
} else
|
2002-09-19 18:51:19 +00:00
|
|
|
fprintf (pf, "%i %i %i ", w->numpoints,
|
|
|
|
p->nodes[0]->visleafnum, p->nodes[1]->visleafnum);
|
2003-09-03 22:00:08 +00:00
|
|
|
for (i = 0; i < w->numpoints - 1; i++) {
|
|
|
|
fprintf (pf, "(%g %g %g) ",
|
|
|
|
w->points[i][0], w->points[i][0], w->points[i][0]);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2003-09-03 22:00:08 +00:00
|
|
|
fprintf (pf, "(%g %g %g)\n",
|
|
|
|
w->points[i][0], w->points[i][0], w->points[i][0]);
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
if (p->nodes[0] == node)
|
|
|
|
p = p->next[0];
|
|
|
|
else
|
|
|
|
p = p->next[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
static void
|
|
|
|
WritePortalLeafs_r (node_t *n)
|
|
|
|
{
|
|
|
|
if (!n->contents) {
|
|
|
|
WritePortalLeafs_r (n->children[0]);
|
|
|
|
WritePortalLeafs_r (n->children[1]);
|
|
|
|
} else {
|
|
|
|
if (n->visleafnum != -1)
|
|
|
|
fprintf (pf, "%i\n", n->visleafnum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetCluster_r (node_t *n, int num)
|
|
|
|
{
|
|
|
|
if (n->contents == CONTENTS_SOLID) {
|
|
|
|
// solid block, viewpoint never inside
|
|
|
|
n->visleafnum = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n->visleafnum = num;
|
|
|
|
if (!n->contents) {
|
|
|
|
SetCluster_r (n->children[0], num);
|
|
|
|
SetCluster_r (n->children[1], num);
|
|
|
|
} else
|
|
|
|
num_realleafs++;
|
|
|
|
}
|
|
|
|
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2002-09-19 18:51:19 +00:00
|
|
|
NumberLeafs_r (node_t *node)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-19 17:14:23 +00:00
|
|
|
portal_t *p;
|
2002-09-19 16:58:48 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
if (!node->contents && !node->detail) {
|
2002-09-23 16:27:17 +00:00
|
|
|
// decision node
|
2002-09-19 16:58:48 +00:00
|
|
|
node->visleafnum = -99;
|
|
|
|
NumberLeafs_r (node->children[0]);
|
|
|
|
NumberLeafs_r (node->children[1]);
|
|
|
|
return;
|
|
|
|
}
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
Draw_ClearWindow ();
|
|
|
|
DrawLeaf (node, 1);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
if (node->contents == CONTENTS_SOLID) {
|
|
|
|
// solid block, viewpoint never inside
|
2002-09-19 16:58:48 +00:00
|
|
|
node->visleafnum = -1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->visleafnum = num_visleafs++;
|
2002-09-19 17:14:23 +00:00
|
|
|
|
|
|
|
for (p = node->portals; p;) {
|
2002-09-23 16:27:17 +00:00
|
|
|
if (p->nodes[0] == node) {
|
|
|
|
// only write out from first leaf
|
2003-02-04 23:26:26 +00:00
|
|
|
if (SameContents(p->nodes[0], p->nodes[1]))
|
2002-09-19 16:58:48 +00:00
|
|
|
num_visportals++;
|
|
|
|
p = p->next[0];
|
2002-09-19 17:14:23 +00:00
|
|
|
} else
|
|
|
|
p = p->next[1];
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
2003-02-04 23:26:26 +00:00
|
|
|
|
|
|
|
if (node->detail) {
|
|
|
|
SetCluster_r (node->children[0], node->visleafnum);
|
|
|
|
SetCluster_r (node->children[1], node->visleafnum);
|
|
|
|
} else {
|
|
|
|
num_realleafs++;
|
|
|
|
}
|
2002-09-19 16:58:48 +00:00
|
|
|
}
|
|
|
|
|
2002-09-19 17:14:23 +00:00
|
|
|
void
|
2002-09-19 18:51:19 +00:00
|
|
|
WritePortalfile (node_t *headnode)
|
2002-09-19 16:58:48 +00:00
|
|
|
{
|
2002-09-23 16:27:17 +00:00
|
|
|
// set the visleafnum field in every leaf and count the total number of
|
|
|
|
// portals
|
2002-09-19 16:58:48 +00:00
|
|
|
num_visleafs = 0;
|
|
|
|
num_visportals = 0;
|
2003-02-04 23:26:26 +00:00
|
|
|
num_realleafs = 0;
|
2002-09-19 16:58:48 +00:00
|
|
|
NumberLeafs_r (headnode);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-23 16:27:17 +00:00
|
|
|
// write the file
|
2002-09-20 21:48:34 +00:00
|
|
|
printf ("writing %s\n", options.portfile);
|
|
|
|
pf = fopen (options.portfile, "w");
|
2002-09-19 16:58:48 +00:00
|
|
|
if (!pf)
|
2002-09-20 21:48:34 +00:00
|
|
|
Sys_Error ("Error opening %s", options.portfile);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
fprintf (pf, "%s\n", PORTALFILE);
|
|
|
|
fprintf (pf, "%i\n", num_visleafs);
|
|
|
|
fprintf (pf, "%i\n", num_visportals);
|
2003-02-04 23:26:26 +00:00
|
|
|
fprintf (pf, "%i\n", num_realleafs);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
WritePortalFile_r (headnode);
|
2002-09-19 17:14:23 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
WritePortalLeafs_r (headnode);
|
|
|
|
|
2002-09-19 16:58:48 +00:00
|
|
|
fclose (pf);
|
|
|
|
}
|