split the base vis functions out of flow.c, add -D_REENTRANT to the compile

for qfvis and a bunch of whitespace
This commit is contained in:
Bill Currie 2002-09-24 02:46:03 +00:00
parent ded572b31f
commit 5904859cca
5 changed files with 248 additions and 184 deletions

View file

@ -167,12 +167,14 @@ if test "x$ac_cv_header_pthread_h" = "xyes"; then
[#include <pthread.h>],
[pthread_attr_t type;
pthread_attr_init(&type);],
[PTHREAD_FLAGS=-pthread],
[PTHREAD_FLAGS=-lpthread]
[PTHREAD_LDFLAGS=-pthread],
[PTHREAD_LDFLAGS=-lpthread]
)
LDFLAGS="$save_ldflags"
PTHREAD_CFLAGS=-D_REENTRANT
fi
AC_SUBST(PTHREAD_FLAGS)
AC_SUBST(PTHREAD_LDFLAGS)
AC_SUBST(PTHREAD_CFLAGS)
dnl ==================================================================
dnl Checks for typedefs, structures, and compiler characteristics

View file

@ -3,9 +3,10 @@ AUTOMAKE_OPTIONS= foreign
QFVIS_LIBS=@QFVIS_LIBS@
QFVIS_DEPS=@QFVIS_DEPS@
QFVIS_INCS=@QFVIS_INCS@
PTHREAD_FLAGS=@PTHREAD_FLAGS@
PTHREAD_LDFLAGS=@PTHREAD_LDFLAGS@
PTHREAD_CFLAGS=@PTHREAD_CFLAGS@
INCLUDES= -I$(top_srcdir)/include $(QFVIS_INCS)
INCLUDES= -I$(top_srcdir)/include $(QFVIS_INCS) $(PTHREAD_CFLAGS)
if BUILD_QFVIS
qfvis=qfvis
@ -16,8 +17,8 @@ endif
bin_PROGRAMS= $(qfvis)
EXTRA_PROGRAMS= qfvis
qfvis_SOURCES= flow.c options.c qfvis.c soundphs.c
qfvis_SOURCES= base-vis.c flow.c options.c qfvis.c soundphs.c
qfvis_LDFLAGS= $(PTHREAD_FLAGS)
qfvis_LDFLAGS= $(PTHREAD_LDFLAGS)
qfvis_LDADD= $(QFVIS_LIBS)
qfvis_DEPENDENCIES= $(QFVIS_DEPS)

View file

@ -0,0 +1,135 @@
/*
base-vis.c
PVS PHS generator tool
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
*/
static const char rcsid[] =
"$Id$";
#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"
#include "vis.h"
#include "options.h"
static int leafsee;
static byte portalsee[MAX_PORTALS];
/*
This is a rough first-order aproximation that is used to trivially reject
some of the final calculations.
*/
static void
SimpleFlood (portal_t *srcportal, int leafnum)
{
int i;
leaf_t *leaf;
portal_t *portal;
if (srcportal->mightsee[leafnum >> 3] & (1 << (leafnum & 7)))
return;
srcportal->mightsee[leafnum >> 3] |= (1 << (leafnum & 7));
leafsee++;
leaf = &leafs[leafnum];
for (i = 0; i < leaf->numportals; i++) {
portal = leaf->portals[i];
if (!portalsee[portal - portals])
continue;
SimpleFlood (srcportal, portal->leaf);
}
}
void
BasePortalVis (void)
{
int i, j, k;
float d;
portal_t *tp, *portal;
winding_t *winding;
for (i = 0, portal = portals; i < numportals * 2; i++, portal++) {
portal->mightsee = calloc (1, bitbytes);
memset (portalsee, 0, numportals * 2);
for (j = 0, tp = portals; j < numportals * 2; j++, tp++) {
if (j == i)
continue;
winding = tp->winding;
for (k = 0; k < winding->numpoints; k++) {
d = DotProduct (winding->points[k],
portal->plane.normal) - portal->plane.dist;
if (d > ON_EPSILON)
break;
}
if (k == winding->numpoints)
continue; // no points on front
winding = portal->winding;
for (k = 0; k < winding->numpoints; k++) {
d = DotProduct (winding->points[k],
tp->plane.normal) - tp->plane.dist;
if (d < -ON_EPSILON)
break;
}
if (k == winding->numpoints)
continue; // no points on front
portalsee[j] = 1;
}
leafsee = 0;
SimpleFlood (portal, portal->leaf);
portal->nummightsee = leafsee;
}
}

View file

@ -59,16 +59,13 @@ static const char rcsid[] =
#include "vis.h"
#include "options.h"
static int leafsee;
static byte portalsee[MAX_PORTALS];
void
CheckStack (leaf_t *leaf, threaddata_t *thread)
{
pstack_t *p;
pstack_t *portal;
for (p = thread->pstack_head.next; p; p = p->next)
if (p->leaf == leaf)
for (portal = thread->pstack_head.next; portal; portal = portal->next)
if (portal->leaf == leaf)
Sys_Error ("CheckStack: leaf recursion");
}
@ -208,7 +205,7 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
long *test, *might, *vis;
qboolean more;
pstack_t stack;
portal_t *p;
portal_t *portal;
plane_t backplane;
winding_t *source, *target;
@ -233,17 +230,18 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
// check all portals for flowing into other leafs
for (i = 0; i < leaf->numportals; i++) {
p = leaf->portals[i];
portal = leaf->portals[i];
if (!(prevstack->mightsee[p->leaf >> 3] & (1 << (p->leaf & 7))))
if (!(prevstack->mightsee[portal->leaf >> 3]
& (1 << (portal->leaf & 7))))
continue; // can't possibly see it
// if the portal can't see anything we haven't already seen, skip it
if (p->status == stat_done) {
if (portal->status == stat_done) {
c_vistest++;
test = (long *) p->visbits;
test = (long *) portal->visbits;
} else {
c_mighttest++;
test = (long *) p->mightsee;
test = (long *) portal->mightsee;
}
more = false;
for (j = 0; j < bitlongs; j++) {
@ -256,19 +254,19 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
continue;
// get plane of portal, point normal into the neighbor leaf
stack.portalplane = p->plane;
VectorSubtract (vec3_origin, p->plane.normal, backplane.normal);
backplane.dist = -p->plane.dist;
stack.portalplane = portal->plane;
VectorSubtract (vec3_origin, portal->plane.normal, backplane.normal);
backplane.dist = -portal->plane.dist;
if (_VectorCompare (prevstack->portalplane.normal, backplane.normal))
continue; // can't go out a coplanar face
c_portalcheck++;
stack.portal = p;
stack.portal = portal;
stack.next = NULL;
target = ClipWinding(p->winding, &thread->pstack_head.portalplane,
target = ClipWinding(portal->winding, &thread->pstack_head.portalplane,
false);
if (!target)
continue;
@ -278,7 +276,7 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
stack.source = prevstack->source;
stack.pass = target;
RecursiveLeafFlow (p->leaf, thread, &stack);
RecursiveLeafFlow (portal->leaf, thread, &stack);
FreeWinding (target);
continue;
}
@ -335,7 +333,7 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
c_portalpass++;
// flow through it for real
RecursiveLeafFlow (p->leaf, thread, &stack);
RecursiveLeafFlow (portal->leaf, thread, &stack);
FreeWinding (source);
FreeWinding (target);
@ -345,100 +343,28 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
}
void
PortalFlow (portal_t *p)
PortalFlow (portal_t *portal)
{
threaddata_t data;
LOCK;
if (p->status != stat_selected)
if (portal->status != stat_selected)
Sys_Error ("PortalFlow: reflowed");
p->status = stat_working;
portal->status = stat_working;
UNLOCK;
p->visbits = calloc (1, bitbytes);
portal->visbits = calloc (1, bitbytes);
memset (&data, 0, sizeof (data));
data.leafvis = p->visbits;
data.base = p;
data.leafvis = portal->visbits;
data.base = portal;
data.pstack_head.portal = p;
data.pstack_head.source = p->winding;
data.pstack_head.portalplane = p->plane;
data.pstack_head.mightsee = p->mightsee;
data.pstack_head.portal = portal;
data.pstack_head.source = portal->winding;
data.pstack_head.portalplane = portal->plane;
data.pstack_head.mightsee = portal->mightsee;
RecursiveLeafFlow (p->leaf, &data, &data.pstack_head);
RecursiveLeafFlow (portal->leaf, &data, &data.pstack_head);
p->status = stat_done;
}
/*
This is a rough first-order aproximation that is used to trivially reject
some of the final calculations.
*/
void
SimpleFlood (portal_t *srcportal, int leafnum)
{
int i;
leaf_t *leaf;
portal_t *p;
if (srcportal->mightsee[leafnum >> 3] & (1 << (leafnum & 7)))
return;
srcportal->mightsee[leafnum >> 3] |= (1 << (leafnum & 7));
leafsee++;
leaf = &leafs[leafnum];
for (i = 0; i < leaf->numportals; i++) {
p = leaf->portals[i];
if (!portalsee[p - portals])
continue;
SimpleFlood (srcportal, p->leaf);
}
}
void
BasePortalVis (void)
{
int i, j, k;
float d;
portal_t *tp, *p;
winding_t *winding;
for (i = 0, p = portals; i < numportals * 2; i++, p++) {
p->mightsee = calloc (1, bitbytes);
memset (portalsee, 0, numportals * 2);
for (j = 0, tp = portals; j < numportals * 2; j++, tp++) {
if (j == i)
continue;
winding = tp->winding;
for (k = 0; k < winding->numpoints; k++) {
d = DotProduct (winding->points[k],
p->plane.normal) - p->plane.dist;
if (d > ON_EPSILON)
break;
}
if (k == winding->numpoints)
continue; // no points on front
winding = p->winding;
for (k = 0; k < winding->numpoints; k++) {
d = DotProduct (winding->points[k],
tp->plane.normal) - tp->plane.dist;
if (d < -ON_EPSILON)
break;
}
if (k == winding->numpoints)
continue; // no points on front
portalsee[j] = 1;
}
leafsee = 0;
SimpleFlood (p, p->leaf);
p->nummightsee = leafsee;
}
portal->status = stat_done;
}

View file

@ -68,33 +68,33 @@ pthread_mutex_t *my_mutex;
bsp_t *bsp;
options_t options;
options_t options;
int c_chains;
int c_mighttest;
int c_portaltest;
int c_portalpass;
int c_portalcheck;
int c_vistest;
int c_chains;
int c_mighttest;
int c_portaltest;
int c_portalpass;
int c_portalcheck;
int c_vistest;
int numportals;
int portalleafs;
int originalvismapsize;
int totalvis;
int count_sep;
int bitbytes; // (portalleafs + 63)>>3
int bitlongs;
int numportals;
int portalleafs;
int originalvismapsize;
int totalvis;
int count_sep;
int bitbytes; // (portalleafs + 63)>>3
int bitlongs;
portal_t *portals;
leaf_t *leafs;
dstring_t *visdata;
byte *uncompressed; // [bitbytes * portalleafs]
portal_t *portals;
leaf_t *leafs;
dstring_t *visdata;
byte *uncompressed; // [bitbytes * portalleafs]
void
PlaneFromWinding (winding_t *winding, plane_t *plane)
{
vec3_t v1, v2;
vec3_t v1, v2;
// calc plane
VectorSubtract (winding->points[2], winding->points[1], v1);
@ -104,11 +104,11 @@ PlaneFromWinding (winding_t *winding, plane_t *plane)
plane->dist = DotProduct (winding->points[0], plane->normal);
}
winding_t *
winding_t *
NewWinding (int points)
{
winding_t *winding;
int size;
winding_t *winding;
int size;
if (points > MAX_POINTS_ON_WINDING)
Sys_Error ("NewWinding: %i points", points);
@ -126,11 +126,11 @@ FreeWinding (winding_t *winding)
free (winding);
}
winding_t *
winding_t *
CopyWinding (winding_t *winding)
{
int size;
winding_t *copy;
int size;
winding_t *copy;
size = (int) ((winding_t *) 0)->points[winding->numpoints];
copy = malloc (size);
@ -150,17 +150,17 @@ CopyWinding (winding_t *winding)
If keepon is true, an exactly on-plane winding will be saved, otherwise
it will be clipped away.
*/
winding_t *
winding_t *
ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
{
int maxpts, i, j;
int sides[MAX_POINTS_ON_WINDING];
int counts[3];
vec_t dists[MAX_POINTS_ON_WINDING];
vec_t dot;
vec_t *p1, *p2;
vec3_t mid;
winding_t *neww;
int maxpts, i, j;
int sides[MAX_POINTS_ON_WINDING];
int counts[3];
vec_t dists[MAX_POINTS_ON_WINDING];
vec_t dot;
vec_t *p1, *p2;
vec3_t mid;
winding_t *neww;
counts[0] = counts[1] = counts[2] = 0;
@ -245,12 +245,12 @@ ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
Returns the portals from the least complex, so the later ones can reuse
the earlier information.
*/
portal_t *
portal_t *
GetNextPortal (void)
{
int j;
portal_t *p, *tp;
int min;
int j;
portal_t *p, *tp;
int min;
LOCK;
@ -275,7 +275,7 @@ GetNextPortal (void)
void *
LeafThread (void *thread)
{
portal_t *portal;
portal_t *portal;
do {
portal = GetNextPortal ();
@ -297,10 +297,10 @@ LeafThread (void *thread)
int
CompressRow (byte *vis, byte *dest)
{
int j;
int rep;
int visrow;
byte *dest_p;
int j;
int rep;
int visrow;
byte *dest_p;
dest_p = dest;
visrow = (portalleafs + 7) >> 3;
@ -331,11 +331,11 @@ CompressRow (byte *vis, byte *dest)
void
LeafFlow (int leafnum)
{
byte *outbuffer;
byte compressed[MAX_MAP_LEAFS / 8];
int numvis, i, j;
leaf_t *leaf;
portal_t *portal;
byte *outbuffer;
byte compressed[MAX_MAP_LEAFS / 8];
int numvis, i, j;
leaf_t *leaf;
portal_t *portal;
// flow through all portals, collecting visible bits
outbuffer = uncompressed + leafnum * bitbytes;
@ -372,7 +372,7 @@ LeafFlow (int leafnum)
void
CalcPortalVis (void)
{
int i;
int i;
// fastvis just uses mightsee for a very loose bound
if (options.minimal) {
@ -385,7 +385,7 @@ CalcPortalVis (void)
#ifdef HAVE_PTHREAD_H
{
pthread_t work_threads[MAX_THREADS];
pthread_t work_threads[MAX_THREADS];
void *status;
pthread_attr_t attrib;
@ -428,7 +428,7 @@ CalcPortalVis (void)
void
CalcVis (void)
{
int i;
int i;
BasePortalVis ();
CalcPortalVis ();
@ -444,7 +444,7 @@ CalcVis (void)
qboolean
PlaneCompare (plane_t *p1, plane_t *p2)
{
int i;
int i;
if (fabs (p1->dist - p2->dist) > 0.01)
return false;
@ -456,17 +456,17 @@ PlaneCompare (plane_t *p1, plane_t *p2)
return true;
}
sep_t *
sep_t *
FindPassages (winding_t *source, winding_t *pass)
{
double length;
float d;
int counts[3];
int i, j, k, l;
plane_t plane;
qboolean fliptest;
sep_t *sep, *list;
vec3_t v1, v2;
double length;
float d;
int counts[3];
int i, j, k, l;
plane_t plane;
qboolean fliptest;
sep_t *sep, *list;
vec3_t v1, v2;
list = NULL;
@ -564,11 +564,11 @@ FindPassages (winding_t *source, winding_t *pass)
void
CalcPassages (void)
{
int count, count2, i, j, k;
leaf_t *leaf;
portal_t *p1, *p2;
sep_t *sep;
passage_t *passages;
int count, count2, i, j, k;
leaf_t *leaf;
portal_t *p1, *p2;
sep_t *sep;
passage_t *passages;
if (options.verbosity >= 0)
printf ("building passages...\n");
@ -618,14 +618,14 @@ CalcPassages (void)
void
LoadPortals (char *name)
{
char magic[80];
FILE *f;
int leafnums[2];
int numpoints, i, j;
leaf_t *leaf;
plane_t plane;
portal_t *portal;
winding_t *winding;
char magic[80];
FILE *f;
int leafnums[2];
int numpoints, i, j;
leaf_t *leaf;
plane_t plane;
portal_t *portal;
winding_t *winding;
if (!strcmp (name, "-"))
f = stdin;