mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-14 00:40:55 +00:00
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:
parent
ded572b31f
commit
5904859cca
5 changed files with 248 additions and 184 deletions
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
135
tools/qfvis/source/base-vis.c
Normal file
135
tools/qfvis/source/base-vis.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue