2002-08-25 23:06:23 +00:00
|
|
|
/*
|
|
|
|
flow.c
|
|
|
|
|
|
|
|
PVS PHS generator tool
|
|
|
|
|
2002-09-25 01:51:58 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-08-25 23:06:23 +00:00
|
|
|
Copyright (C) 2002 Colin Thompson
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
2013-03-07 05:31:00 +00:00
|
|
|
Boston, MA 02111-1307, USA
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "QF/bspfile.h"
|
2021-01-01 09:58:26 +00:00
|
|
|
#include "QF/cmem.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/cmd.h"
|
2002-08-25 23:06:23 +00:00
|
|
|
#include "QF/mathlib.h"
|
2002-08-27 07:16:28 +00:00
|
|
|
#include "QF/quakefs.h"
|
|
|
|
#include "QF/sys.h"
|
|
|
|
|
2020-06-21 14:15:17 +00:00
|
|
|
#include "tools/qfvis/include/vis.h"
|
|
|
|
#include "tools/qfvis/include/options.h"
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2003-09-24 00:59:53 +00:00
|
|
|
static int
|
2003-02-04 23:26:26 +00:00
|
|
|
CheckStack (cluster_t *cluster, threaddata_t *thread)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
2013-03-07 05:31:00 +00:00
|
|
|
pstack_t *portal;
|
2012-05-21 23:23:22 +00:00
|
|
|
|
2013-03-18 03:47:59 +00:00
|
|
|
for (portal = thread->pstack_head.next; portal; portal = portal->next) {
|
2003-09-24 00:59:53 +00:00
|
|
|
if (portal->cluster == cluster) {
|
|
|
|
printf ("CheckStack: cluster recursion\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2013-03-16 13:58:59 +00:00
|
|
|
if (!portal->cluster)
|
|
|
|
break;
|
|
|
|
}
|
2003-09-24 00:59:53 +00:00
|
|
|
return 0;
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-16 13:58:59 +00:00
|
|
|
static pstack_t *
|
2013-03-18 04:30:50 +00:00
|
|
|
new_stack (threaddata_t *td)
|
2013-03-16 13:58:59 +00:00
|
|
|
{
|
|
|
|
pstack_t *stack;
|
|
|
|
|
2013-03-18 03:47:59 +00:00
|
|
|
stack = malloc (sizeof (pstack_t));
|
|
|
|
stack->next = 0;
|
2013-03-18 04:30:50 +00:00
|
|
|
stack->mightsee = set_new_size_r (&td->set_pool, portalclusters);
|
2021-03-27 14:04:13 +00:00
|
|
|
td->stats.stack_alloc++;
|
2013-03-16 13:58:59 +00:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2013-03-08 13:20:29 +00:00
|
|
|
static sep_t *
|
|
|
|
new_separator (threaddata_t *thread)
|
|
|
|
{
|
|
|
|
sep_t *sep;
|
|
|
|
|
2021-01-01 09:58:26 +00:00
|
|
|
sep = CMEMALLOC (32, sep_t, thread->sep, thread->memsuper);
|
2021-03-27 14:04:13 +00:00
|
|
|
thread->stats.sep_alloc++;
|
2013-03-08 13:20:29 +00:00
|
|
|
return sep;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
delete_separator (threaddata_t *thread, sep_t *sep)
|
|
|
|
{
|
2021-03-27 14:04:13 +00:00
|
|
|
thread->stats.sep_free++;
|
2021-01-01 09:58:26 +00:00
|
|
|
CMEMFREE (thread->sep, sep);
|
2013-03-08 13:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-03-15 07:00:39 +00:00
|
|
|
free_separators (threaddata_t *thread, sep_t *sep_list)
|
2013-03-08 13:20:29 +00:00
|
|
|
{
|
2021-03-27 14:04:13 +00:00
|
|
|
unsigned count = thread->stats.sep_alloc - thread->stats.sep_free;
|
|
|
|
if (count > thread->stats.sep_highwater) {
|
|
|
|
thread->stats.sep_highwater = count;
|
|
|
|
}
|
|
|
|
count = 0;
|
2013-03-15 07:00:39 +00:00
|
|
|
while (sep_list) {
|
|
|
|
sep_t *sep = sep_list;
|
|
|
|
sep_list = sep->next;
|
|
|
|
delete_separator (thread, sep);
|
2021-03-27 14:04:13 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (count > thread->stats.sep_maxbulk) {
|
|
|
|
thread->stats.sep_maxbulk = count;
|
2013-03-08 13:20:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-17 01:16:47 +00:00
|
|
|
static inline int
|
|
|
|
test_zero (float d)
|
|
|
|
{
|
|
|
|
if (d < -ON_EPSILON)
|
|
|
|
return -1;
|
|
|
|
else if (d > ON_EPSILON)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-19 08:00:00 +00:00
|
|
|
static int
|
|
|
|
calc_plane (const vec3_t v1, const vec3_t v2, int flip, const vec3_t p,
|
|
|
|
plane_t *plane)
|
|
|
|
{
|
|
|
|
vec_t length;
|
|
|
|
|
|
|
|
if (flip < 0) {
|
|
|
|
//CrossProduct (v2, v1, plane.normal);
|
|
|
|
plane->normal[0] = v2[1] * v1[2] - v2[2] * v1[1];
|
|
|
|
plane->normal[1] = v2[2] * v1[0] - v2[0] * v1[2];
|
|
|
|
plane->normal[2] = v2[0] * v1[1] - v2[1] * v1[0];
|
|
|
|
} else {
|
|
|
|
//CrossProduct (v1, v2, plane.normal);
|
|
|
|
plane->normal[0] = v1[1] * v2[2] - v1[2] * v2[1];
|
|
|
|
plane->normal[1] = v1[2] * v2[0] - v1[0] * v2[2];
|
|
|
|
plane->normal[2] = v1[0] * v2[1] - v1[1] * v2[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
length = DotProduct (plane->normal, plane->normal);
|
|
|
|
|
|
|
|
// if points don't make a valid plane, skip it
|
|
|
|
if (length < ON_EPSILON)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
length = 1 / sqrt (length);
|
|
|
|
VectorScale (plane->normal, length, plane->normal);
|
|
|
|
plane->dist = DotProduct (p, plane->normal);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
test_plane (const plane_t *plane, const winding_t *pass, int index)
|
|
|
|
{
|
|
|
|
int s1, s2;
|
|
|
|
int k;
|
|
|
|
vec_t d;
|
|
|
|
|
|
|
|
k = (index + 1) % pass->numpoints;
|
|
|
|
d = DotProduct (pass->points[k], plane->normal) - plane->dist;
|
|
|
|
s1 = test_zero (d);
|
|
|
|
k = (index + pass->numpoints - 1) % pass->numpoints;
|
|
|
|
d = DotProduct (pass->points[k], plane->normal) - plane->dist;
|
|
|
|
s2 = test_zero (d);
|
|
|
|
if (s1 == 0 && s2 == 0)
|
|
|
|
return 0;
|
|
|
|
if (s1 < 0 || s2 < 0)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-03-19 10:04:12 +00:00
|
|
|
static inline sep_t *
|
|
|
|
create_separator (threaddata_t *thread, const plane_t *src_pl,
|
|
|
|
const vec3_t p1, const vec3_t v1,
|
|
|
|
const winding_t *pass, int index, int flip)
|
|
|
|
{
|
|
|
|
int fliptest;
|
|
|
|
vec_t d;
|
|
|
|
vec3_t v2;
|
|
|
|
plane_t plane;
|
|
|
|
sep_t *sep;
|
|
|
|
|
|
|
|
d = DotProduct (pass->points[index], src_pl->normal) - src_pl->dist;
|
|
|
|
if ((fliptest = test_zero (d)) == 0)
|
|
|
|
return 0; // The point lies in the source plane
|
|
|
|
|
|
|
|
VectorSubtract (pass->points[index], p1, v2);
|
|
|
|
if (!calc_plane (v1, v2, fliptest, pass->points[index], &plane))
|
|
|
|
return 0; // point does not form a valid plane
|
|
|
|
|
|
|
|
if (!test_plane (&plane, pass, index))
|
|
|
|
return 0; // not the right point
|
|
|
|
|
|
|
|
sep = new_separator (thread);
|
|
|
|
// flip the normal if we want the back side
|
|
|
|
if (flip) {
|
|
|
|
VectorNegate (plane.normal, sep->plane.normal);
|
|
|
|
sep->plane.dist = -plane.dist;
|
|
|
|
} else {
|
|
|
|
sep->plane = plane;
|
|
|
|
}
|
|
|
|
return sep;
|
|
|
|
}
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
/*
|
2013-03-15 07:00:39 +00:00
|
|
|
Find the planes separating source from pass. The planes form a double
|
|
|
|
pyramid with source as the base (ie, source's edges will all be in one
|
|
|
|
plane each) and the vertex of the pyramid is between source and pass.
|
|
|
|
Edges from pass may or may not be in a plane, but each vertex will be in
|
|
|
|
at least one plane.
|
|
|
|
|
|
|
|
If flip is false, the planes will be such that the space enclosed by the
|
|
|
|
planes and on the pass side of the vertex are on the front sides of the
|
|
|
|
planes. If flip is true, then the space on the source side of the vertex
|
|
|
|
and enclosed by the planes is on the front side of the planes.
|
2013-03-19 10:04:12 +00:00
|
|
|
|
|
|
|
// find a vertex of pass that makes a plane that puts all of the
|
|
|
|
// vertexes of pass on the front side and all of the vertexes of
|
|
|
|
// source on the back side
|
2002-08-25 23:06:23 +00:00
|
|
|
*/
|
2013-03-15 07:00:39 +00:00
|
|
|
static sep_t *
|
2013-03-17 12:52:08 +00:00
|
|
|
FindSeparators (threaddata_t *thread,
|
|
|
|
const winding_t *source, const plane_t src_pl,
|
|
|
|
const winding_t *pass, int flip)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
2021-01-01 07:32:36 +00:00
|
|
|
unsigned i, j, l;
|
2013-03-19 10:04:12 +00:00
|
|
|
vec3_t v1;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-19 10:04:12 +00:00
|
|
|
sep_t *separators = 0, *sep;
|
2013-03-08 13:20:29 +00:00
|
|
|
|
2013-03-07 05:31:00 +00:00
|
|
|
for (i = 0; i < source->numpoints; i++) {
|
2002-08-25 23:06:23 +00:00
|
|
|
l = (i + 1) % source->numpoints;
|
|
|
|
VectorSubtract (source->points[l], source->points[i], v1);
|
|
|
|
|
|
|
|
for (j = 0; j < pass->numpoints; j++) {
|
2013-03-19 10:04:12 +00:00
|
|
|
sep = create_separator (thread, &src_pl, source->points[i], v1,
|
|
|
|
pass, j, flip);
|
|
|
|
if (sep) {
|
|
|
|
sep->next = separators;
|
|
|
|
separators = sep;
|
|
|
|
break;
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
}
|
2013-03-07 05:31:00 +00:00
|
|
|
}
|
2013-03-15 07:00:39 +00:00
|
|
|
return separators;
|
|
|
|
}
|
|
|
|
|
|
|
|
static winding_t *
|
2021-01-01 09:58:26 +00:00
|
|
|
ClipToSeparators (threaddata_t *thread, const sep_t *separators, winding_t *target)
|
2013-03-15 07:00:39 +00:00
|
|
|
{
|
|
|
|
const sep_t *sep;
|
|
|
|
|
|
|
|
for (sep = separators; target && sep; sep = sep->next) {
|
2021-01-01 09:58:26 +00:00
|
|
|
target = ClipWinding (thread, target, &sep->plane, false);
|
2013-03-15 07:00:39 +00:00
|
|
|
}
|
2013-03-07 05:31:00 +00:00
|
|
|
return target;
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 10:39:27 +00:00
|
|
|
static inline set_t *
|
|
|
|
select_test_set (portal_t *portal, threaddata_t *thread)
|
|
|
|
{
|
|
|
|
set_t *test;
|
|
|
|
|
|
|
|
if (portal->status == stat_done) {
|
|
|
|
thread->stats.vistest++;
|
|
|
|
test = portal->visbits;
|
|
|
|
} else {
|
|
|
|
thread->stats.mighttest++;
|
|
|
|
test = portal->mightsee;
|
|
|
|
}
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
mightsee_more (set_t *might, const set_t *prev_might, const set_t *test,
|
|
|
|
const set_t *vis)
|
|
|
|
{
|
2013-03-16 12:51:41 +00:00
|
|
|
unsigned i;
|
|
|
|
set_bits_t more = 0;
|
|
|
|
|
|
|
|
// might = intersection (prev_might, test)
|
|
|
|
// more = (might is not a subset of vis)
|
|
|
|
for (i = 0; i < SET_WORDS (might); i++) {
|
|
|
|
might->map[i] = prev_might->map[i] & test->map[i];
|
|
|
|
more |= might->map[i] & ~vis->map[i];
|
|
|
|
}
|
|
|
|
return more != 0;
|
2013-03-14 10:39:27 +00:00
|
|
|
}
|
|
|
|
|
2002-08-25 23:06:23 +00:00
|
|
|
/*
|
2003-02-04 23:26:26 +00:00
|
|
|
RecursiveClusterFlow
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
Flood fill through the clusters
|
|
|
|
If src_portal is NULL, this is the originating cluster
|
2002-08-25 23:06:23 +00:00
|
|
|
*/
|
2003-01-06 18:28:13 +00:00
|
|
|
static void
|
2013-03-14 10:35:43 +00:00
|
|
|
RecursiveClusterFlow (int clusternum, threaddata_t *thread, pstack_t *prevstack)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
2013-03-07 05:31:00 +00:00
|
|
|
int i;
|
2013-03-07 05:28:15 +00:00
|
|
|
set_t *might;
|
2013-03-07 05:31:00 +00:00
|
|
|
const set_t *test, *vis;
|
|
|
|
cluster_t *cluster;
|
2013-03-16 13:58:59 +00:00
|
|
|
pstack_t *stack;
|
2013-03-17 12:52:08 +00:00
|
|
|
portal_t *target_portal;
|
2013-03-07 05:31:00 +00:00
|
|
|
plane_t backplane;
|
2013-03-17 12:52:08 +00:00
|
|
|
const plane_t *source_plane, *pass_plane;
|
|
|
|
const winding_t *pass_winding;
|
|
|
|
winding_t *source_winding, *target_winding;
|
2013-03-07 05:31:00 +00:00
|
|
|
|
2013-03-14 02:33:47 +00:00
|
|
|
thread->stats.chains++;
|
2013-03-07 05:31:00 +00:00
|
|
|
|
2013-03-16 13:58:59 +00:00
|
|
|
if (!prevstack->next)
|
2013-03-18 04:30:50 +00:00
|
|
|
prevstack->next = new_stack (thread);
|
2013-03-16 13:58:59 +00:00
|
|
|
stack = prevstack->next;
|
|
|
|
stack->cluster = 0;
|
|
|
|
|
2013-03-07 05:31:00 +00:00
|
|
|
cluster = &clusters[clusternum];
|
|
|
|
if (CheckStack(cluster, thread))
|
2003-09-24 00:59:53 +00:00
|
|
|
return;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
// mark the cluster as visible
|
2013-03-07 02:06:55 +00:00
|
|
|
if (!set_is_member (thread->clustervis, clusternum)) {
|
|
|
|
set_add (thread->clustervis, clusternum);
|
2002-08-25 23:06:23 +00:00
|
|
|
thread->base->numcansee++;
|
2013-03-07 05:31:00 +00:00
|
|
|
}
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-16 13:58:59 +00:00
|
|
|
stack->cluster = cluster;
|
2013-03-17 10:18:38 +00:00
|
|
|
stack->pass_portal = NULL;
|
2013-03-16 13:58:59 +00:00
|
|
|
stack->separators[0] = 0;
|
|
|
|
stack->separators[1] = 0;
|
2013-03-18 03:47:59 +00:00
|
|
|
might = stack->mightsee;
|
2013-03-07 05:31:00 +00:00
|
|
|
vis = thread->clustervis;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-18 03:47:59 +00:00
|
|
|
source_plane = &thread->pstack_head.pass_plane;
|
2013-03-17 12:52:08 +00:00
|
|
|
pass_winding = prevstack->pass_winding;
|
|
|
|
pass_plane = &prevstack->pass_plane;
|
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
// check all portals for flowing into other clusters
|
2013-03-07 05:31:00 +00:00
|
|
|
for (i = 0; i < cluster->numportals; i++) {
|
2013-03-17 12:52:08 +00:00
|
|
|
target_portal = cluster->portals[i];
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-18 03:47:59 +00:00
|
|
|
if (!set_is_member (prevstack->mightsee, target_portal->cluster))
|
2002-08-25 23:06:23 +00:00
|
|
|
continue; // can't possibly see it
|
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
// if target_portal can't see anything we haven't already seen, skip it
|
|
|
|
test = select_test_set (target_portal, thread);
|
2013-03-18 03:47:59 +00:00
|
|
|
if (!mightsee_more (might, prevstack->mightsee, test, vis)) {
|
2013-03-14 10:39:27 +00:00
|
|
|
// can't see anything new
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
2013-03-14 10:39:27 +00:00
|
|
|
}
|
2002-09-23 22:54:28 +00:00
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
// get plane of target_portal, point normal into the neighbor cluster
|
|
|
|
VectorNegate (target_portal->plane.normal, backplane.normal);
|
|
|
|
backplane.dist = -target_portal->plane.dist;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
if (_VectorCompare (pass_plane->normal, backplane.normal))
|
2002-08-25 23:06:23 +00:00
|
|
|
continue; // can't go out a coplanar face
|
|
|
|
|
2013-03-14 02:33:47 +00:00
|
|
|
thread->stats.portalcheck++;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
target_winding = target_portal->winding;
|
2021-01-01 09:58:26 +00:00
|
|
|
target_winding = ClipWinding (thread, target_winding, source_plane, false);
|
2013-03-17 12:52:08 +00:00
|
|
|
if (!target_winding)
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
if (!pass_winding) {
|
2010-01-13 06:42:26 +00:00
|
|
|
// the second cluster can be blocked only if coplanar
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-17 10:18:38 +00:00
|
|
|
stack->source_winding = prevstack->source_winding;
|
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
stack->pass_winding = target_winding;
|
|
|
|
stack->pass_plane = target_portal->plane;
|
|
|
|
stack->pass_portal = target_portal;
|
2013-03-17 10:18:38 +00:00
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
RecursiveClusterFlow (target_portal->cluster, thread, stack);
|
2021-01-01 09:58:26 +00:00
|
|
|
FreeWinding (thread, target_winding);
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-01 09:58:26 +00:00
|
|
|
target_winding = ClipWinding (thread, target_winding, pass_plane, false);
|
2013-03-17 12:52:08 +00:00
|
|
|
if (!target_winding)
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
// copy source_winding because it likely is already a copy and thus
|
|
|
|
// if it gets clipped away, earlier stack levels will get corrupted
|
2021-01-01 09:58:26 +00:00
|
|
|
source_winding = CopyWinding (thread, prevstack->source_winding);
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2021-01-01 09:58:26 +00:00
|
|
|
source_winding = ClipWinding (thread, source_winding, &backplane, false);
|
2013-03-17 12:52:08 +00:00
|
|
|
if (!source_winding) {
|
2021-01-01 09:58:26 +00:00
|
|
|
FreeWinding (thread, target_winding);
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-03-14 02:33:47 +00:00
|
|
|
thread->stats.portaltest++;
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.targettested++;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
if (options.level > 0) {
|
2013-03-17 12:52:08 +00:00
|
|
|
winding_t *old = target_winding;
|
2013-03-16 13:58:59 +00:00
|
|
|
if (!stack->separators[0])
|
2013-03-17 12:52:08 +00:00
|
|
|
stack->separators[0] = FindSeparators (thread,
|
|
|
|
source_winding,
|
|
|
|
*source_plane,
|
|
|
|
pass_winding, 0);
|
2021-01-01 09:58:26 +00:00
|
|
|
target_winding = ClipToSeparators (thread,
|
|
|
|
stack->separators[0],
|
2013-03-17 12:52:08 +00:00
|
|
|
target_winding);
|
|
|
|
if (!target_winding) {
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.targetclipped++;
|
2021-01-01 09:58:26 +00:00
|
|
|
FreeWinding (thread, source_winding);
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-17 12:52:08 +00:00
|
|
|
if (target_winding != old)
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.targettrimmed++;
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.level > 1) {
|
2013-03-17 12:52:08 +00:00
|
|
|
winding_t *old = target_winding;
|
2013-03-16 13:58:59 +00:00
|
|
|
if (!stack->separators[1])
|
2013-03-17 12:52:08 +00:00
|
|
|
stack->separators[1] = FindSeparators (thread,
|
|
|
|
pass_winding,
|
|
|
|
*pass_plane,
|
|
|
|
source_winding, 1);
|
2021-01-01 09:58:26 +00:00
|
|
|
target_winding = ClipToSeparators (thread,
|
|
|
|
stack->separators[1],
|
2013-03-17 12:52:08 +00:00
|
|
|
target_winding);
|
|
|
|
if (!target_winding) {
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.targetclipped++;
|
2021-01-01 09:58:26 +00:00
|
|
|
FreeWinding (thread, source_winding);
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-17 12:52:08 +00:00
|
|
|
if (target_winding != old)
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.targettrimmed++;
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.sourcetested++;
|
2002-08-25 23:06:23 +00:00
|
|
|
if (options.level > 2) {
|
2013-03-17 12:52:08 +00:00
|
|
|
winding_t *old = source_winding;
|
2013-03-15 07:00:39 +00:00
|
|
|
sep_t *sep;
|
2013-03-17 12:52:08 +00:00
|
|
|
sep = FindSeparators (thread,
|
|
|
|
target_winding, target_portal->plane,
|
|
|
|
pass_winding, 0);
|
2021-01-01 09:58:26 +00:00
|
|
|
source_winding = ClipToSeparators (thread, sep, source_winding);
|
2013-03-15 07:00:39 +00:00
|
|
|
free_separators (thread, sep);
|
2013-03-17 12:52:08 +00:00
|
|
|
if (!source_winding) {
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.sourceclipped++;
|
2021-01-01 09:58:26 +00:00
|
|
|
FreeWinding (thread, target_winding);
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-17 12:52:08 +00:00
|
|
|
if (source_winding != old)
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.sourcetrimmed++;
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.level > 3) {
|
2013-03-17 12:52:08 +00:00
|
|
|
winding_t *old = source_winding;
|
2013-03-15 07:00:39 +00:00
|
|
|
sep_t *sep;
|
2013-03-17 12:52:08 +00:00
|
|
|
sep = FindSeparators (thread, pass_winding, *pass_plane,
|
|
|
|
target_winding, 1);
|
2021-01-01 09:58:26 +00:00
|
|
|
source_winding = ClipToSeparators (thread, sep, source_winding);
|
2013-03-15 07:00:39 +00:00
|
|
|
free_separators (thread, sep);
|
2013-03-17 12:52:08 +00:00
|
|
|
if (!source_winding) {
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.sourceclipped++;
|
2021-01-01 09:58:26 +00:00
|
|
|
FreeWinding (thread, target_winding);
|
2002-08-25 23:06:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-17 12:52:08 +00:00
|
|
|
if (source_winding != old)
|
2013-03-14 10:40:31 +00:00
|
|
|
thread->stats.sourcetrimmed++;
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
stack->source_winding = source_winding;
|
|
|
|
stack->pass_winding = target_winding;
|
2013-03-17 10:18:38 +00:00
|
|
|
|
2013-03-17 12:52:08 +00:00
|
|
|
stack->pass_plane = target_portal->plane;
|
|
|
|
stack->pass_portal = target_portal;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-14 02:33:47 +00:00
|
|
|
thread->stats.portalpass++;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
|
|
|
// flow through it for real
|
2013-03-17 12:52:08 +00:00
|
|
|
RecursiveClusterFlow (target_portal->cluster, thread, stack);
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2021-01-01 09:58:26 +00:00
|
|
|
FreeWinding (thread, source_winding);
|
|
|
|
FreeWinding (thread, target_winding);
|
2013-03-07 05:31:00 +00:00
|
|
|
}
|
2013-03-16 13:58:59 +00:00
|
|
|
free_separators (thread, stack->separators[1]);
|
|
|
|
free_separators (thread, stack->separators[0]);
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-14 02:33:47 +00:00
|
|
|
PortalFlow (threaddata_t *data, portal_t *portal)
|
2002-08-25 23:06:23 +00:00
|
|
|
{
|
2013-03-18 06:03:11 +00:00
|
|
|
WRLOCK_PORTAL (portal);
|
2013-03-07 05:31:00 +00:00
|
|
|
if (portal->status != stat_selected)
|
2002-09-22 21:32:36 +00:00
|
|
|
Sys_Error ("PortalFlow: reflowed");
|
2013-03-07 05:31:00 +00:00
|
|
|
portal->status = stat_working;
|
2013-03-18 06:03:11 +00:00
|
|
|
UNLOCK_PORTAL (portal);
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-18 04:30:50 +00:00
|
|
|
portal->visbits = set_new_size_r (&data->set_pool, portalclusters);
|
|
|
|
|
2013-03-14 02:33:47 +00:00
|
|
|
data->clustervis = portal->visbits;
|
|
|
|
data->base = portal;
|
2002-08-25 23:06:23 +00:00
|
|
|
|
2013-03-18 03:47:59 +00:00
|
|
|
data->pstack_head.cluster = 0;
|
|
|
|
data->pstack_head.pass_portal = portal;
|
|
|
|
data->pstack_head.source_winding = portal->winding;
|
|
|
|
data->pstack_head.pass_winding = 0;
|
|
|
|
data->pstack_head.pass_plane = portal->plane;
|
|
|
|
data->pstack_head.mightsee = portal->mightsee;
|
|
|
|
data->pstack_head.separators[0] = 0;
|
|
|
|
data->pstack_head.separators[1] = 0;
|
|
|
|
|
|
|
|
RecursiveClusterFlow (portal->cluster, data, &data->pstack_head);
|
2002-08-25 23:06:23 +00:00
|
|
|
}
|