2002-09-24 02:46:03 +00:00
|
|
|
/*
|
|
|
|
base-vis.c
|
|
|
|
|
|
|
|
PVS PHS generator tool
|
|
|
|
|
2002-09-25 01:51:58 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2002-09-24 02:46:03 +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
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#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"
|
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/mathlib.h"
|
|
|
|
#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-09-24 02:46:03 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
This is a rough first-order aproximation that is used to trivially reject
|
|
|
|
some of the final calculations.
|
|
|
|
*/
|
|
|
|
static void
|
2013-03-19 02:42:09 +00:00
|
|
|
SimpleFlood (basethread_t *thread, portal_t *srcportal, int clusternum)
|
2002-09-24 02:46:03 +00:00
|
|
|
{
|
|
|
|
int i;
|
2004-02-08 02:53:58 +00:00
|
|
|
cluster_t *cluster;
|
|
|
|
portal_t *portal;
|
2002-09-24 02:46:03 +00:00
|
|
|
|
2013-03-07 02:06:55 +00:00
|
|
|
if (set_is_member (srcportal->mightsee, clusternum))
|
2002-09-24 02:46:03 +00:00
|
|
|
return;
|
2013-03-07 02:06:55 +00:00
|
|
|
set_add (srcportal->mightsee, clusternum);
|
2013-03-19 02:42:09 +00:00
|
|
|
thread->clustersee++;
|
2002-09-24 02:46:03 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
cluster = &clusters[clusternum];
|
2002-09-24 02:46:03 +00:00
|
|
|
|
2003-02-04 23:26:26 +00:00
|
|
|
for (i = 0; i < cluster->numportals; i++) {
|
|
|
|
portal = cluster->portals[i];
|
2013-03-19 02:42:09 +00:00
|
|
|
if (!set_is_member (thread->portalsee, portal - portals))
|
2002-09-24 02:46:03 +00:00
|
|
|
continue;
|
2013-03-19 02:42:09 +00:00
|
|
|
SimpleFlood (thread, srcportal, portal->cluster);
|
2002-09-24 02:46:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-13 12:32:18 +00:00
|
|
|
static inline int
|
2021-03-28 10:55:47 +00:00
|
|
|
test_sphere (const vspheref_t *sphere, vec4f_t plane)
|
2013-03-13 12:32:18 +00:00
|
|
|
{
|
2021-05-24 06:02:18 +00:00
|
|
|
#ifdef __SSE3__
|
2021-03-28 10:55:47 +00:00
|
|
|
const vec4f_t zero = {};
|
|
|
|
float r = sphere->radius;
|
|
|
|
vec4f_t eps = { r, r, r, r };
|
|
|
|
vec4f_t d = _mm_addsub_ps (zero, dotf (sphere->center, plane));
|
|
|
|
vec4i_t c = (d - eps) >= 0;
|
|
|
|
|
|
|
|
c = (vec4i_t) _mm_hsub_epi32 ((__m128i) c, (__m128i) c);
|
|
|
|
return c[0];
|
2021-05-24 06:02:18 +00:00
|
|
|
#else
|
|
|
|
float d = DotProduct (sphere->center, plane) + plane[3];
|
|
|
|
int front = (d >= sphere->radius);
|
|
|
|
int back = (d <= -sphere->radius);
|
|
|
|
return front - back;
|
|
|
|
#endif
|
2013-03-13 12:32:18 +00:00
|
|
|
}
|
|
|
|
|
2002-09-24 02:46:03 +00:00
|
|
|
void
|
2013-03-19 02:42:09 +00:00
|
|
|
PortalBase (basethread_t *thread, portal_t *portal)
|
2002-09-24 02:46:03 +00:00
|
|
|
{
|
2021-03-28 10:55:47 +00:00
|
|
|
unsigned i, j, k;
|
|
|
|
vec4f_t d;
|
|
|
|
portal_t *tp;
|
|
|
|
winding_t *winding;
|
2013-03-14 05:01:26 +00:00
|
|
|
int tp_side, portal_side;
|
2013-03-13 12:32:18 +00:00
|
|
|
|
2013-03-19 02:42:09 +00:00
|
|
|
i = portal - portals;
|
2013-03-14 05:01:26 +00:00
|
|
|
|
2013-03-19 02:42:09 +00:00
|
|
|
for (j = 0, tp = portals; j < numportals * 2; j++, tp++) {
|
|
|
|
if (j == i)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If the target portal is behind the portals's plane, then it
|
|
|
|
// can't possibly be seen by the portal.
|
|
|
|
//
|
|
|
|
// If the portal is in front of the target's plane, then the target
|
|
|
|
// is of no interest as it is facing counter to the flow of
|
|
|
|
// visibility.
|
|
|
|
|
|
|
|
// First check using the bounding spheres of the two portals.
|
2021-03-28 10:55:47 +00:00
|
|
|
tp_side = test_sphere (&tp->sphere, portal->plane);
|
2013-03-19 02:42:09 +00:00
|
|
|
if (tp_side < 0) {
|
|
|
|
// The test portal definitely is entirely behind the portal's
|
|
|
|
// plane.
|
2021-03-28 02:59:58 +00:00
|
|
|
thread->spherecull++;
|
2013-03-19 02:42:09 +00:00
|
|
|
continue; // entirely behind
|
|
|
|
}
|
2021-03-28 10:55:47 +00:00
|
|
|
portal_side = test_sphere (&portal->sphere, tp->plane);
|
2013-03-19 02:42:09 +00:00
|
|
|
if (portal_side > 0) {
|
|
|
|
// The portal definitely is entirely in front of the test
|
|
|
|
// portal's plane.
|
2021-03-28 02:59:58 +00:00
|
|
|
thread->spherecull++;
|
2013-03-19 02:42:09 +00:00
|
|
|
continue; // entirely in front
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tp_side == 0) {
|
|
|
|
// The test portal's sphere touches the portal's plane, so
|
|
|
|
// do a more refined check.
|
|
|
|
winding = tp->winding;
|
|
|
|
for (k = 0; k < winding->numpoints; k++) {
|
2021-03-28 10:55:47 +00:00
|
|
|
d = dotf (winding->points[k], portal->plane);
|
|
|
|
if (d[0] > ON_EPSILON)
|
2013-03-19 02:42:09 +00:00
|
|
|
break;
|
2002-09-24 02:46:03 +00:00
|
|
|
}
|
2021-03-28 02:59:58 +00:00
|
|
|
if (k == winding->numpoints) {
|
|
|
|
thread->windingcull++;
|
2013-03-19 02:42:09 +00:00
|
|
|
continue; // no points on front
|
2021-03-28 02:59:58 +00:00
|
|
|
}
|
2013-03-19 02:42:09 +00:00
|
|
|
}
|
2002-09-24 02:46:03 +00:00
|
|
|
|
2013-03-19 02:42:09 +00:00
|
|
|
if (portal_side == 0) {
|
|
|
|
// The portal's sphere touches the test portal's plane, so
|
|
|
|
// do a more refined check.
|
|
|
|
winding = portal->winding;
|
|
|
|
for (k = 0; k < winding->numpoints; k++) {
|
2021-03-28 10:55:47 +00:00
|
|
|
d = dotf (winding->points[k], tp->plane);
|
|
|
|
if (d[0] < -ON_EPSILON)
|
2013-03-19 02:42:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-03-28 02:59:58 +00:00
|
|
|
if (k == winding->numpoints) {
|
|
|
|
thread->windingcull++;
|
2013-03-19 02:42:09 +00:00
|
|
|
continue; // no points on front
|
2021-03-28 02:59:58 +00:00
|
|
|
}
|
2002-09-24 02:46:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-19 02:42:09 +00:00
|
|
|
set_add (thread->portalsee, j);
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleFlood (thread, portal, portal->cluster);
|
|
|
|
portal->nummightsee = thread->clustersee;
|
2002-09-24 02:46:03 +00:00
|
|
|
}
|