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>], [#include <pthread.h>],
[pthread_attr_t type; [pthread_attr_t type;
pthread_attr_init(&type);], pthread_attr_init(&type);],
[PTHREAD_FLAGS=-pthread], [PTHREAD_LDFLAGS=-pthread],
[PTHREAD_FLAGS=-lpthread] [PTHREAD_LDFLAGS=-lpthread]
) )
LDFLAGS="$save_ldflags" LDFLAGS="$save_ldflags"
PTHREAD_CFLAGS=-D_REENTRANT
fi fi
AC_SUBST(PTHREAD_FLAGS) AC_SUBST(PTHREAD_LDFLAGS)
AC_SUBST(PTHREAD_CFLAGS)
dnl ================================================================== dnl ==================================================================
dnl Checks for typedefs, structures, and compiler characteristics dnl Checks for typedefs, structures, and compiler characteristics

View file

@ -3,9 +3,10 @@ AUTOMAKE_OPTIONS= foreign
QFVIS_LIBS=@QFVIS_LIBS@ QFVIS_LIBS=@QFVIS_LIBS@
QFVIS_DEPS=@QFVIS_DEPS@ QFVIS_DEPS=@QFVIS_DEPS@
QFVIS_INCS=@QFVIS_INCS@ 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 if BUILD_QFVIS
qfvis=qfvis qfvis=qfvis
@ -16,8 +17,8 @@ endif
bin_PROGRAMS= $(qfvis) bin_PROGRAMS= $(qfvis)
EXTRA_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_LDADD= $(QFVIS_LIBS)
qfvis_DEPENDENCIES= $(QFVIS_DEPS) 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 "vis.h"
#include "options.h" #include "options.h"
static int leafsee;
static byte portalsee[MAX_PORTALS];
void void
CheckStack (leaf_t *leaf, threaddata_t *thread) CheckStack (leaf_t *leaf, threaddata_t *thread)
{ {
pstack_t *p; pstack_t *portal;
for (p = thread->pstack_head.next; p; p = p->next) for (portal = thread->pstack_head.next; portal; portal = portal->next)
if (p->leaf == leaf) if (portal->leaf == leaf)
Sys_Error ("CheckStack: leaf recursion"); Sys_Error ("CheckStack: leaf recursion");
} }
@ -208,7 +205,7 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
long *test, *might, *vis; long *test, *might, *vis;
qboolean more; qboolean more;
pstack_t stack; pstack_t stack;
portal_t *p; portal_t *portal;
plane_t backplane; plane_t backplane;
winding_t *source, *target; 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 // check all portals for flowing into other leafs
for (i = 0; i < leaf->numportals; i++) { 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 continue; // can't possibly see it
// if the portal can't see anything we haven't already seen, skip 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++; c_vistest++;
test = (long *) p->visbits; test = (long *) portal->visbits;
} else { } else {
c_mighttest++; c_mighttest++;
test = (long *) p->mightsee; test = (long *) portal->mightsee;
} }
more = false; more = false;
for (j = 0; j < bitlongs; j++) { for (j = 0; j < bitlongs; j++) {
@ -256,19 +254,19 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
continue; continue;
// get plane of portal, point normal into the neighbor leaf // get plane of portal, point normal into the neighbor leaf
stack.portalplane = p->plane; stack.portalplane = portal->plane;
VectorSubtract (vec3_origin, p->plane.normal, backplane.normal); VectorSubtract (vec3_origin, portal->plane.normal, backplane.normal);
backplane.dist = -p->plane.dist; backplane.dist = -portal->plane.dist;
if (_VectorCompare (prevstack->portalplane.normal, backplane.normal)) if (_VectorCompare (prevstack->portalplane.normal, backplane.normal))
continue; // can't go out a coplanar face continue; // can't go out a coplanar face
c_portalcheck++; c_portalcheck++;
stack.portal = p; stack.portal = portal;
stack.next = NULL; stack.next = NULL;
target = ClipWinding(p->winding, &thread->pstack_head.portalplane, target = ClipWinding(portal->winding, &thread->pstack_head.portalplane,
false); false);
if (!target) if (!target)
continue; continue;
@ -278,7 +276,7 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
stack.source = prevstack->source; stack.source = prevstack->source;
stack.pass = target; stack.pass = target;
RecursiveLeafFlow (p->leaf, thread, &stack); RecursiveLeafFlow (portal->leaf, thread, &stack);
FreeWinding (target); FreeWinding (target);
continue; continue;
} }
@ -335,7 +333,7 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
c_portalpass++; c_portalpass++;
// flow through it for real // flow through it for real
RecursiveLeafFlow (p->leaf, thread, &stack); RecursiveLeafFlow (portal->leaf, thread, &stack);
FreeWinding (source); FreeWinding (source);
FreeWinding (target); FreeWinding (target);
@ -345,100 +343,28 @@ RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
} }
void void
PortalFlow (portal_t *p) PortalFlow (portal_t *portal)
{ {
threaddata_t data; threaddata_t data;
LOCK; LOCK;
if (p->status != stat_selected) if (portal->status != stat_selected)
Sys_Error ("PortalFlow: reflowed"); Sys_Error ("PortalFlow: reflowed");
p->status = stat_working; portal->status = stat_working;
UNLOCK; UNLOCK;
p->visbits = calloc (1, bitbytes); portal->visbits = calloc (1, bitbytes);
memset (&data, 0, sizeof (data)); memset (&data, 0, sizeof (data));
data.leafvis = p->visbits; data.leafvis = portal->visbits;
data.base = p; data.base = portal;
data.pstack_head.portal = p; data.pstack_head.portal = portal;
data.pstack_head.source = p->winding; data.pstack_head.source = portal->winding;
data.pstack_head.portalplane = p->plane; data.pstack_head.portalplane = portal->plane;
data.pstack_head.mightsee = p->mightsee; data.pstack_head.mightsee = portal->mightsee;
RecursiveLeafFlow (p->leaf, &data, &data.pstack_head); RecursiveLeafFlow (portal->leaf, &data, &data.pstack_head);
p->status = stat_done; portal->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;
}
} }

View file

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