Finish the port of smart leak files.

This comes from the OpenQuartz version of qbsp.
This commit is contained in:
Bill Currie 2010-09-01 09:52:39 +09:00
parent 142defe9c0
commit 93517d40d8
3 changed files with 56 additions and 0 deletions

View File

@ -43,6 +43,7 @@ typedef struct {
qboolean extract_textures;
qboolean extract_entities;
qboolean extract_hull;
qboolean smart_leak;
qboolean usehulls;
qboolean watervis;
int hullnum;

View File

@ -61,6 +61,7 @@ static struct option const long_options[] = {
{"extract-textures", no_argument, 0, 256},
{"extract-entities", no_argument, 0, 257},
{"extract-hull", no_argument, 0, 258},
{"smart-leak", no_argument, 0, 259},
{"usehulls", no_argument, 0, 'u'},
{"hullnum", required_argument, 0, 'H'},
{"subdivide", required_argument, 0, 's'},
@ -176,6 +177,9 @@ DecodeArgs (int argc, char **argv)
options.extract = true;
options.extract_hull = true;
break;
case 259: // smart-leak
options.smart_leak = true;
break;
case 'u': // usehulls
options.usehulls = true;
break;

View File

@ -161,6 +161,52 @@ MarkLeakTrail (portal_t *n2)
}
}
static void
MarkLeakTrail2 (void)
{
int i;
int next, side;
node_t *n, *nextnode;
portal_t *p, *p2;
vec3_t wc;
vec_t *v;
leakfile = fopen (options.pointfile, "w");
if (!leakfile)
Sys_Error ("Couldn't open %s\n", options.pointfile);
n = &outside_node;
next = -1;
while ((n->o_dist > 1) || (next == -1)) {
nextnode = 0;
p2 = 0;
for (p = n->portals; p; p = p->next[side]) {
side = (p->nodes[1] == n);
if ((next == -1)
|| ((p->nodes[!side]->o_dist < next)
&& p->nodes[!side]->o_dist)) {
nextnode = p->nodes[!side];
next = nextnode->o_dist;
p2 = p;
}
}
if (!nextnode)
break;
n = nextnode;
VectorZero (wc);
for (i = 0; i < p2->winding->numpoints; i++)
VectorAdd (wc, p2->winding->points[i], wc);
VectorScale (wc, 1.0 / i, wc);
fprintf (leakfile, "%g %g %g", wc[0], wc[1], wc[2]);
}
v = entities[n->occupied].origin;
fprintf (leakfile, "%g %g %g\n", v[0], v[1], v[2]);
fclose (leakfile);
}
int hit_occupied;
/** Recurse through the map setting the outside nodes to solid.
@ -206,6 +252,8 @@ RecursiveFillOutside (node_t *l, qboolean fill)
if (RecursiveFillOutside (p->nodes[s], fill)) {
// leaked, so stop filling
if (options.smart_leak)
return true;
if (!options.hullnum) {
MarkLeakTrail (p);
DrawLeaf (l, 2);
@ -297,6 +345,9 @@ FillOutside (node_t *node)
printf ("leak file written to %s\n", options.pointfile);
printf ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
}
if (options.smart_leak)
MarkLeakTrail2 ();
// remove faces from filled in leafs
ClearOutFaces (node);
return false;