Whitespace.

This commit is contained in:
Ragnvald Maartmann-Moe IV 2002-09-19 02:37:52 +00:00
parent b3f842ba65
commit 6376ebb253
13 changed files with 571 additions and 643 deletions

View file

@ -32,21 +32,21 @@
#define DEFAULTLIGHTLEVEL 300
typedef struct epair_s {
struct epair_s *next;
char key[MAX_KEY];
char value[MAX_VALUE];
struct epair_s *next;
char key[MAX_KEY];
char value[MAX_VALUE];
} epair_t;
typedef struct entity_s {
char classname[64];
vec3_t origin;
float angle;
int light;
int style;
char target[32];
char targetname[32];
struct epair_s *epairs;
struct entity_s *targetent;
char classname[64];
vec3_t origin;
float angle;
int light;
int style;
char target[32];
char targetname[32];
struct epair_s *epairs;
struct entity_s *targetent;
} entity_t;
extern entity_t entities[MAX_MAP_ENTITIES];

View file

@ -60,4 +60,3 @@ void TransformSample (vec3_t in, vec3_t out);
void RotateSample (vec3_t in, vec3_t out);
#endif// __light_h

View file

@ -74,27 +74,26 @@ char lighttargets[32][64];
int
LightStyleForTargetname (char *targetname, qboolean alloc)
{
int i;
for (i = 0; i < numlighttargets; i++)
int i;
for (i = 0; i < numlighttargets; i++)
if (!strcmp (lighttargets[i], targetname))
return 32 + i;
if (!alloc)
if (!alloc)
return -1;
strcpy (lighttargets[i], targetname);
numlighttargets++;
return numlighttargets - 1 + 32;
strcpy (lighttargets[i], targetname);
numlighttargets++;
return numlighttargets - 1 + 32;
}
void
MatchTargets (void)
{
int i, j;
int i, j;
for (i = 0; i < num_entities; i++) {
for (i = 0; i < num_entities; i++) {
if (!entities[i].target[0])
continue;
@ -118,26 +117,26 @@ MatchTargets (void)
sprintf (s, "%i", entities[i].style);
SetKeyValue (&entities[i], "style", s);
}
}
}
}
void
LoadEntities (void)
{
const char *data;
entity_t *entity;
char key[64];
epair_t *epair;
double vec[3];
int i;
data = dentdata;
const char *data;
char key[64];
double vec[3];
entity_t *entity;
epair_t *epair;
int i;
data = dentdata;
// start parsing
num_entities = 0;
num_entities = 0;
// go through all the entities
while (1) {
while (1) {
// parse the opening brace
data = COM_Parse (data);
if (!data)
@ -188,7 +187,7 @@ LoadEntities (void)
// scan into doubles, then assign
// which makes it vec_t size independent
if (sscanf (com_token, "%lf %lf %lf",
&vec[0], &vec[1], &vec[2]) != 3)
&vec[0], &vec[1], &vec[2]) != 3)
fprintf (stderr, "LoadEntities: not 3 values for origin");
for (i = 0; i < 3; i++)
entity->origin[i] = vec[i];
@ -218,23 +217,23 @@ LoadEntities (void)
SetKeyValue (entity, "style", s);
}
}
}
}
if (options.verbosity >= 0)
printf ("%d entities read\n", num_entities);
MatchTargets ();
MatchTargets ();
}
char *
ValueForKey (entity_t *ent, char *key)
{
epair_t *ep;
epair_t *ep;
for (ep = ent->epairs; ep; ep = ep->next)
for (ep = ent->epairs; ep; ep = ep->next)
if (!strcmp (ep->key, key))
return ep->value;
return "";
return "";
}
void
@ -242,52 +241,52 @@ SetKeyValue (entity_t *ent, char *key, char *value)
{
epair_t *ep;
for (ep = ent->epairs; ep; ep = ep->next)
for (ep = ent->epairs; ep; ep = ep->next)
if (!strcmp (ep->key, key)) {
strcpy (ep->value, value);
return;
}
ep = malloc (sizeof (*ep));
ep->next = ent->epairs;
ent->epairs = ep;
strcpy (ep->key, key);
strcpy (ep->value, value);
ep = malloc (sizeof (*ep));
ep->next = ent->epairs;
ent->epairs = ep;
strcpy (ep->key, key);
strcpy (ep->value, value);
}
float
FloatForKey (entity_t *ent, char *key)
{
char *k;
char *k;
k = ValueForKey (ent, key);
return atof (k);
return atof (k);
}
void
GetVectorForKey (entity_t *ent, char *key, vec3_t vec)
{
char *k;
char *k;
k = ValueForKey (ent, key);
sscanf (k, "%f %f %f", &vec[0], &vec[1], &vec[2]);
k = ValueForKey (ent, key);
sscanf (k, "%f %f %f", &vec[0], &vec[1], &vec[2]);
}
void
WriteEntitiesToString (void)
{
char *buf, *end;
char line[128];
epair_t *ep;
int i;
char *buf, *end;
char line[128];
epair_t *ep;
int i;
buf = dentdata;
end = buf;
*end = 0;
buf = dentdata;
end = buf;
*end = 0;
if (options.verbosity >= 0)
printf ("%i switchable light styles\n", numlighttargets);
for (i = 0; i < num_entities; i++) {
for (i = 0; i < num_entities; i++) {
ep = entities[i].epairs;
if (!ep)
continue; // ent got removed
@ -305,6 +304,6 @@ WriteEntitiesToString (void)
if (end > buf + MAX_MAP_ENTSTRING)
fprintf (stderr, "Entity text too long");
}
entdatasize = end - buf + 1;
}
entdatasize = end - buf + 1;
}

View file

@ -26,10 +26,10 @@
*/
static const char rcsid[] =
"$Id$";
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@ -58,25 +58,25 @@ static const char rcsid[] =
#define SINGLEMAP (18*18*4)
typedef struct {
vec_t lightmaps[MAXLIGHTMAPS][SINGLEMAP];
int numlightstyles;
vec_t *light;
vec_t facedist;
vec3_t facenormal;
vec_t lightmaps[MAXLIGHTMAPS][SINGLEMAP];
int numlightstyles;
vec_t *light;
vec_t facedist;
vec3_t facenormal;
int numsurfpt;
vec3_t surfpt[SINGLEMAP];
int numsurfpt;
vec3_t surfpt[SINGLEMAP];
vec3_t texorg;
vec3_t worldtotex[2]; // s = (world - texorg) . worldtotex[0]
vec3_t textoworld[2]; // world = texorg + s * textoworld[0]
vec3_t texorg;
vec3_t worldtotex[2]; // s = (world - texorg) . worldtotex[0]
vec3_t textoworld[2]; // world = texorg + s * textoworld[0]
vec_t exactmins[2], exactmaxs[2];
vec_t exactmins[2], exactmaxs[2];
int texmins[2], texsize[2];
int lightstyles[256];
int surfnum;
dface_t *face;
int texmins[2], texsize[2];
int lightstyles[256];
int surfnum;
dface_t *face;
} lightinfo_t;
int c_bad;
@ -90,23 +90,22 @@ int c_culldistplane, c_proper;
vec_t
CastRay (vec3_t p1, vec3_t p2)
{
int i;
vec_t t;
qboolean trace;
int i;
qboolean trace;
vec_t t;
trace = TestLine (p1, p2);
trace = TestLine (p1, p2);
if (!trace)
if (!trace)
return -1; // ray was blocked
t = 0;
for (i = 0; i < 3; i++)
t = 0;
for (i = 0; i < 3; i++)
t += (p2[i] - p1[i]) * (p2[i] - p1[i]);
if (t == 0)
if (t == 0)
t = 1; // don't blow up...
return sqrt (t);
return sqrt (t);
}
/*
@ -135,61 +134,60 @@ towards the center until it is valid.
void
CalcFaceVectors (lightinfo_t *l)
{
texinfo_t *tex;
int i, j;
vec3_t texnormal;
float distscale;
vec_t dist, len;
texinfo_t *tex;
int i, j;
vec3_t texnormal;
float distscale;
vec_t dist, len;
tex = &texinfo[l->face->texinfo];
tex = &texinfo[l->face->texinfo];
// convert from float to vec_t
for (i = 0; i < 2; i++)
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
l->worldtotex[i][j] = tex->vecs[i][j];
// calculate a normal to the texture axis. points can
// be moved along this without changing their S/T
texnormal[0] = tex->vecs[1][1] * tex->vecs[0][2] -
tex->vecs[1][2] * tex->vecs[0][1];
texnormal[1] = tex->vecs[1][2] * tex->vecs[0][0] -
tex->vecs[1][0] * tex->vecs[0][2];
texnormal[2] = tex->vecs[1][0] * tex->vecs[0][1] -
tex->vecs[1][1] * tex->vecs[0][0];
VectorNormalize (texnormal);
texnormal[0] = tex->vecs[1][1] * tex->vecs[0][2] -
tex->vecs[1][2] * tex->vecs[0][1];
texnormal[1] = tex->vecs[1][2] * tex->vecs[0][0] -
tex->vecs[1][0] * tex->vecs[0][2];
texnormal[2] = tex->vecs[1][0] * tex->vecs[0][1] -
tex->vecs[1][1] * tex->vecs[0][0];
VectorNormalize (texnormal);
// flip it towards plane normal
distscale = DotProduct (texnormal, l->facenormal);
if (!distscale)
distscale = DotProduct (texnormal, l->facenormal);
if (!distscale)
fprintf (stderr, "Texture axis perpendicular to face");
if (distscale < 0) {
if (distscale < 0) {
distscale = -distscale;
VectorSubtract (vec3_origin, texnormal, texnormal);
}
}
// distscale is the ratio of the distance along the
// texture normal to the distance along the plane normal
distscale = 1 / distscale;
distscale = 1 / distscale;
for (i = 0; i < 2; i++) {
for (i = 0; i < 2; i++) {
len = VectorLength (l->worldtotex[i]);
dist = DotProduct (l->worldtotex[i], l->facenormal);
dist *= distscale;
VectorMA (l->worldtotex[i], -dist, texnormal, l->textoworld[i]);
VectorScale (l->textoworld[i], (1 / len) * (1 / len), l->textoworld[i]);
}
VectorScale (l->textoworld[i], (1 / len) * (1 / len),
l->textoworld[i]);
}
// calculate texorg on the texture plane
for (i = 0; i < 3; i++)
for (i = 0; i < 3; i++)
l->texorg[i] = -tex->vecs[0][3] * l->textoworld[0][i] -
tex->vecs[1][3] * l->textoworld[1][i];
// project back to the face plane
dist = DotProduct (l->texorg, l->facenormal) - l->facedist - 1;
dist *= distscale;
VectorMA (l->texorg, -dist, texnormal, l->texorg);
dist = DotProduct (l->texorg, l->facenormal) - l->facedist - 1;
dist *= distscale;
VectorMA (l->texorg, -dist, texnormal, l->texorg);
}
/*
@ -201,21 +199,20 @@ CalcFaceVectors (lightinfo_t *l)
void
CalcFaceExtents (lightinfo_t *l)
{
dface_t *s;
vec_t mins[2], maxs[2], val;
int i, j, e;
dvertex_t *v;
texinfo_t *tex;
dface_t *s;
dvertex_t *v;
int i, j, e;
texinfo_t *tex;
vec_t mins[2], maxs[2], val;
s = l->face;
s = l->face;
mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999;
mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999;
tex = &texinfo[s->texinfo];
tex = &texinfo[s->texinfo];
for (i = 0; i < s->numedges; i++) {
for (i = 0; i < s->numedges; i++) {
e = dsurfedges[s->firstedge + i];
if (e >= 0)
v = dvertexes + dedges[e].v[0];
@ -231,9 +228,9 @@ CalcFaceExtents (lightinfo_t *l)
if (val > maxs[j])
maxs[j] = val;
}
}
}
for (i = 0; i < 2; i++) {
for (i = 0; i < 2; i++) {
l->exactmins[i] = mins[i];
l->exactmaxs[i] = maxs[i];
@ -244,7 +241,7 @@ CalcFaceExtents (lightinfo_t *l)
l->texsize[i] = maxs[i] - mins[i];
if (l->texsize[i] > 17)
fprintf (stderr, "Bad surface extents");
}
}
}
/*
@ -256,44 +253,40 @@ CalcFaceExtents (lightinfo_t *l)
void
CalcPoints (lightinfo_t *l)
{
int i;
int s, t, j;
int w, h, step;
vec_t starts, startt, us, ut;
vec_t *surf;
vec_t mids, midt;
vec3_t facemid, move;
int step, i, j , s, t, w, h;
vec_t mids, midt, starts, startt, us, ut;
vec_t *surf;
vec3_t facemid, move;
// fill in surforg
// the points are biased towards the center of the surface
// to help avoid edge cases just inside walls
surf = l->surfpt[0];
mids = (l->exactmaxs[0] + l->exactmins[0]) / 2;
midt = (l->exactmaxs[1] + l->exactmins[1]) / 2;
surf = l->surfpt[0];
mids = (l->exactmaxs[0] + l->exactmins[0]) / 2;
midt = (l->exactmaxs[1] + l->exactmins[1]) / 2;
for (j = 0; j < 3; j++)
for (j = 0; j < 3; j++)
facemid[j] = l->texorg[j] +
l->textoworld[0][j] * mids +
l->textoworld[1][j] * midt;
l->textoworld[0][j] * mids +
l->textoworld[1][j] * midt;
if (extrasamples) {
if (extrasamples) {
// extra filtering
h = (l->texsize[1] + 1) * 2;
w = (l->texsize[0] + 1) * 2;
starts = (l->texmins[0] - 0.5) * 16;
startt = (l->texmins[1] - 0.5) * 16;
step = 8;
} else {
} else {
h = l->texsize[1] + 1;
w = l->texsize[0] + 1;
starts = l->texmins[0] * 16;
startt = l->texmins[1] * 16;
step = 16;
}
}
l->numsurfpt = w * h;
for (t = 0; t < h; t++) {
l->numsurfpt = w * h;
for (t = 0; t < h; t++) {
for (s = 0; s < w; s++, surf += 3) {
us = starts + s * step;
ut = startt + t * step;
@ -304,8 +297,8 @@ CalcPoints (lightinfo_t *l)
// calculate texture point
for (j = 0; j < 3; j++)
surf[j] = l->texorg[j] +
l->textoworld[0][j] * us +
l->textoworld[1][j] * ut;
l->textoworld[0][j] * us +
l->textoworld[1][j] * ut;
if (CastRay (facemid, surf) != -1)
break; // got it
@ -339,48 +332,39 @@ CalcPoints (lightinfo_t *l)
if (i == 2)
c_bad++;
}
}
}
}
void
SingleLightFace (entity_t *light, lightinfo_t *l)
{
vec_t dist;
vec3_t incoming;
vec_t angle;
vec_t add;
vec_t *surf;
qboolean hit;
int mapnum;
int size;
int c, i;
vec3_t rel;
vec3_t spotvec;
vec_t falloff;
vec_t *lightsamp;
int mapnum, size, c, i;
qboolean hit;
vec3_t incoming, rel, spotvec;
vec_t add, angle, dist, falloff;
vec_t *lightsamp, *surf;
VectorSubtract (light->origin, bsp_origin, rel);
dist = options.distance * (DotProduct (rel, l->facenormal) - l->facedist);
VectorSubtract (light->origin, bsp_origin, rel);
dist = options.distance * (DotProduct (rel, l->facenormal) - l->facedist);
// don't bother with lights behind the surface
if (dist <= 0)
if (dist <= 0)
return;
// don't bother with light too far away
if (dist > light->light) {
if (dist > light->light) {
c_culldistplane++;
return;
}
}
if (light->targetent) {
if (light->targetent) {
VectorSubtract (light->targetent->origin, light->origin, spotvec);
VectorNormalize (spotvec);
if (!light->angle)
falloff = -cos (20 * M_PI / 180);
else
falloff = -cos (light->angle / 2 * M_PI / 180);
} else
} else
falloff = 0;
mapnum = 0;
for (mapnum = 0; mapnum < l->numlightstyles; mapnum++)
@ -437,114 +421,108 @@ SingleLightFace (entity_t *light, lightinfo_t *l)
void
FixMinlight (lightinfo_t *l)
{
int i, j;
float minlight;
float minlight;
int i, j;
minlight = minlights[l->surfnum];
minlight = minlights[l->surfnum];
// if minlight is set, there must be a style 0 light map
if (!minlight)
if (!minlight)
return;
for (i = 0; i < l->numlightstyles; i++) {
for (i = 0; i < l->numlightstyles; i++) {
if (l->lightstyles[i] == 0)
break;
}
if (i == l->numlightstyles) {
}
if (i == l->numlightstyles) {
if (l->numlightstyles == MAXLIGHTMAPS)
return; // oh well..
for (j = 0; j < l->numsurfpt; j++)
l->lightmaps[i][j] = minlight;
l->lightstyles[i] = 0;
l->numlightstyles++;
} else {
} else {
for (j = 0; j < l->numsurfpt; j++)
if (l->lightmaps[i][j] < minlight)
l->lightmaps[i][j] = minlight;
}
}
}
void
LightFace (int surfnum)
{
dface_t *f;
lightinfo_t l;
int s, t;
int i, j, c;
vec_t total;
int size;
int lightmapwidth, lightmapsize;
byte *out;
vec_t *light;
int w, h;
byte *out;
dface_t *f;
int lightmapwidth, lightmapsize, size, c, i, j, s, t, w, h;
lightinfo_t l;
vec_t total;
vec_t *light;
f = dfaces + surfnum;
f = dfaces + surfnum;
// some surfaces don't need lightmaps
f->lightofs = -1;
for (j = 0; j < MAXLIGHTMAPS; j++)
f->lightofs = -1;
for (j = 0; j < MAXLIGHTMAPS; j++)
f->styles[j] = 255;
if (texinfo[f->texinfo].flags & TEX_SPECIAL)
if (texinfo[f->texinfo].flags & TEX_SPECIAL)
// non-lit texture
return;
memset(&l, 0, sizeof (l));
l.surfnum = surfnum;
l.face = f;
memset(&l, 0, sizeof (l));
l.surfnum = surfnum;
l.face = f;
// rotate plane
VectorCopy (dplanes[f->planenum].normal, l.facenormal);
l.facedist = dplanes[f->planenum].dist;
if (f->side) {
VectorCopy (dplanes[f->planenum].normal, l.facenormal);
l.facedist = dplanes[f->planenum].dist;
if (f->side) {
VectorSubtract (vec3_origin, l.facenormal, l.facenormal);
l.facedist = -l.facedist;
}
}
CalcFaceVectors (&l);
CalcFaceExtents (&l);
CalcPoints (&l);
CalcFaceVectors (&l);
CalcFaceExtents (&l);
CalcPoints (&l);
lightmapwidth = l.texsize[0] + 1;
lightmapwidth = l.texsize[0] + 1;
size = lightmapwidth * (l.texsize[1] + 1);
if (size > SINGLEMAP)
size = lightmapwidth * (l.texsize[1] + 1);
if (size > SINGLEMAP)
fprintf (stderr, "Bad lightmap size");
for (i = 0; i < MAXLIGHTMAPS; i++)
for (i = 0; i < MAXLIGHTMAPS; i++)
l.lightstyles[i] = 255;
// cast all lights
l.numlightstyles = 0;
for (i = 0; i < num_entities; i++) {
l.numlightstyles = 0;
for (i = 0; i < num_entities; i++) {
if (entities[i].light)
SingleLightFace (&entities[i], &l);
}
FixMinlight (&l);
FixMinlight (&l);
if (!l.numlightstyles)
if (!l.numlightstyles)
// no light hitting it
return;
// save out the values
for (i = 0; i < MAXLIGHTMAPS; i++)
for (i = 0; i < MAXLIGHTMAPS; i++)
f->styles[i] = l.lightstyles[i];
lightmapsize = size * l.numlightstyles;
lightmapsize = size * l.numlightstyles;
out = GetFileSpace (lightmapsize);
f->lightofs = out - filebase;
out = GetFileSpace (lightmapsize);
f->lightofs = out - filebase;
// extra filtering
h = (l.texsize[1] + 1) * 2;
w = (l.texsize[0] + 1) * 2;
h = (l.texsize[1] + 1) * 2;
w = (l.texsize[0] + 1) * 2;
for (i = 0; i < l.numlightstyles; i++) {
for (i = 0; i < l.numlightstyles; i++) {
if (l.lightstyles[i] == 0xff)
fprintf (stderr, "Wrote empty lightmap");
fprintf (stderr, "Wrote empty lightmap");
light = l.lightmaps[i];
c = 0;
for (t = 0; t <= l.texsize[1]; t++)
@ -567,4 +545,3 @@ LightFace (int surfnum)
}
}
}

View file

@ -36,7 +36,6 @@ static const char rcsid[] =
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <getopt.h>
#include <errno.h>
#include <stdlib.h>
@ -77,16 +76,17 @@ usage (int status)
{
printf ("%s - QuakeForge light tool\n", this_program);
printf ("Usage: %s [options] bspfile\n", this_program);
printf ("Options:\n"
" -q, --quiet Inhibit usual output\n"
" -v, --verbose Display more output than usual\n"
" -h, --help Display this help and exit\n"
" -V, --version Output version information and exit\n"
" -t, --threads [num] Number of threads to use\n"
" -e, --extra Apply extra sampling\n"
" -d, --distance [scale] Scale distance\n"
" -r, --range [scale] Scale range\n"
" -f, --file [bspfile] BSP file\n\n");
printf (
"Options:\n"
" -q, --quiet Inhibit usual output\n"
" -v, --verbose Display more output than usual\n"
" -h, --help Display this help and exit\n"
" -V, --version Output version information and exit\n"
" -t, --threads [num] Number of threads to use\n"
" -e, --extra Apply extra sampling\n"
" -d, --distance [scale] Scale distance\n"
" -r, --range [scale] Scale range\n"
" -f, --file [bspfile] BSP file\n\n");
exit (status);
}

View file

@ -30,7 +30,6 @@ static const char rcsid[] =
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@ -80,25 +79,24 @@ float minlights[MAX_MAP_FACES];
byte *
GetFileSpace (int size)
{
byte *buf;
byte *buf;
LOCK;
file_p = (byte *) (((long) file_p + 3) & ~3);
buf = file_p;
file_p += size;
UNLOCK;
if (file_p > file_end)
LOCK;
file_p = (byte *) (((long) file_p + 3) & ~3);
buf = file_p;
file_p += size;
UNLOCK;
if (file_p > file_end)
fprintf (stderr, "GetFileSpace: overrun");
return buf;
return buf;
}
void
LightThread (void *junk)
{
int i;
int i;
while (1) {
while (1) {
LOCK;
i = bspfileface++;
UNLOCK;
@ -106,18 +104,18 @@ LightThread (void *junk)
return;
LightFace (i);
}
}
}
void
LightWorld (void)
{
filebase = file_p = dlightdata;
file_end = filebase + MAX_MAP_LIGHTING;
filebase = file_p = dlightdata;
file_end = filebase + MAX_MAP_LIGHTING;
RunThreadsOn (LightThread);
RunThreadsOn (LightThread);
lightdatasize = file_p - filebase;
lightdatasize = file_p - filebase;
if (options.verbosity >= 0)
printf ("lightdatasize: %i\n", lightdatasize);
@ -126,38 +124,38 @@ LightWorld (void)
int
main (int argc, char **argv)
{
double start, stop;
double start, stop;
start = Sys_DoubleTime ();
this_program = argv[0];
DecodeArgs (argc, argv);
if (!bspfile) {
fprintf (stderr, "%s: no bsp file specified.\n", this_program);
usage (1);
}
InitThreads ();
COM_StripExtension (bspfile, bspfile);
COM_DefaultExtension (bspfile, ".bsp");
LoadBSPFile (bspfile);
LoadEntities ();
MakeTnodes (&dmodels[0]);
LoadBSPFile (bspfile);
LoadEntities ();
LightWorld ();
MakeTnodes (&dmodels[0]);
WriteEntitiesToString ();
WriteBSPFile (bspfile);
LightWorld ();
WriteEntitiesToString ();
WriteBSPFile (bspfile);
stop = Sys_DoubleTime ();
if (options.verbosity >= 0)
printf ("%5.1f seconds elapsed\n", stop - start);
return 0;
return 0;
}

View file

@ -30,7 +30,6 @@ static const char rcsid[] =
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@ -59,14 +58,14 @@ void
InitThreads (void)
{
#ifdef __alpha
pthread_mutexattr_t mattrib;
pthread_mutexattr_t mattrib;
my_mutex = malloc (sizeof (*my_mutex));
if (pthread_mutexattr_create (&mattrib) == -1)
my_mutex = malloc (sizeof (*my_mutex));
if (pthread_mutexattr_create (&mattrib) == -1)
fprintf (stderr, "pthread_mutex_attr_create failed");
if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
if (pthread_mutexattr_setkind_np (&mattrib, MUTEX_FAST_NP) == -1)
fprintf (stderr, "pthread_mutexattr_setkind_np failed");
if (pthread_mutex_init (my_mutex, mattrib) == -1)
if (pthread_mutex_init (my_mutex, mattrib) == -1)
fprintf (stderr, "pthread_mutex_init failed");
#endif
}
@ -75,32 +74,33 @@ void
RunThreadsOn (threadfunc_t func)
{
#ifdef __alpha
pthread_t work_threads[256];
pthread_addr_t status;
pthread_attr_t attrib;
int i;
pthread_t work_threads[256];
pthread_addr_t status;
pthread_attr_t attrib;
int i;
if (numthreads == 1) {
if (numthreads == 1) {
func (NULL);
return;
}
}
if (pthread_attr_create (&attrib) == -1)
if (pthread_attr_create (&attrib) == -1)
fprintf (stderr, "pthread_attr_create failed");
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
if (pthread_attr_setstacksize (&attrib, 0x100000) == -1)
fprintf (stderr, "pthread_attr_setstacksize failed");
for (i = 0; i < numthreads; i++) {
if (pthread_create (&work_threads[i], attrib, (pthread_startroutine_t) func, (pthread_addr_t) i) == -1)
for (i = 0; i < numthreads; i++) {
if (pthread_create (&work_threads[i], attrib,
(pthread_startroutine_t) func,
(pthread_addr_t) i) == -1)
fprintf (stderr, "pthread_create failed");
}
}
for (i = 0; i < numthreads; i++) {
for (i = 0; i < numthreads; i++) {
if (pthread_join (work_threads[i], &status) == -1)
fprintf (stderr, "pthread_join failed");
}
}
#else
func (NULL);
func (NULL);
#endif
}

View file

@ -30,7 +30,6 @@ static const char rcsid[] =
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@ -54,17 +53,17 @@ static const char rcsid[] =
#include "light.h"
typedef struct {
int type;
vec3_t normal;
float dist;
int children[2];
int pad;
int type;
vec3_t normal;
float dist;
int children[2];
int pad;
} tnode_t;
typedef struct {
vec3_t backpt;
int side;
int node;
vec3_t backpt;
int side;
int node;
} tracestack_t;
tnode_t *tnodes, *tnode_p;
@ -85,29 +84,28 @@ by recursive subdivision of the line by the BSP tree.
void
MakeTnode (int nodenum)
{
tnode_t *t;
dplane_t *plane;
int i;
dnode_t *node;
dnode_t *node;
dplane_t *plane;
int i;
tnode_t *t;
t = tnode_p++;
t = tnode_p++;
node = dnodes + nodenum;
plane = dplanes + node->planenum;
node = dnodes + nodenum;
plane = dplanes + node->planenum;
t->type = plane->type;
VectorCopy (plane->normal, t->normal);
t->dist = plane->dist;
t->type = plane->type;
VectorCopy (plane->normal, t->normal);
t->dist = plane->dist;
for (i = 0; i < 2; i++) {
for (i = 0; i < 2; i++) {
if (node->children[i] < 0)
t->children[i] = dleafs[-node->children[i] - 1].contents;
else {
t->children[i] = tnode_p - tnodes;
MakeTnode (node->children[i]);
}
}
}
}
/*
@ -118,34 +116,31 @@ MakeTnode (int nodenum)
void
MakeTnodes (dmodel_t *bm)
{
tnode_p = tnodes = malloc (numnodes * sizeof (tnode_t));
tnode_p = tnodes = malloc (numnodes * sizeof (tnode_t));
MakeTnode (0);
MakeTnode (0);
}
qboolean
TestLine (vec3_t start, vec3_t stop)
{
int node;
float front, back;
tracestack_t *tstack_p;
int side;
float frontx, fronty, frontz, backx, backy, backz;
tracestack_t tracestack[64];
tnode_t *tnode;
float front, back, frontx, fronty, frontz, backx, backy, backz;
int node, side;
tracestack_t *tstack_p;
tracestack_t tracestack[64];
tnode_t *tnode;
frontx = start[0];
fronty = start[1];
frontz = start[2];
backx = stop[0];
backy = stop[1];
backz = stop[2];
frontx = start[0];
fronty = start[1];
frontz = start[2];
backx = stop[0];
backy = stop[1];
backz = stop[2];
tstack_p = tracestack;
node = 0;
tstack_p = tracestack;
node = 0;
while (1) {
while (1) {
while (node < 0 && node != CONTENTS_SOLID) {
// pop up the stack for a back side
tstack_p--;
@ -194,19 +189,17 @@ TestLine (vec3_t start, vec3_t stop)
break;
}
if (front > -ON_EPSILON && back > -ON_EPSILON)
// if (front > 0 && back > 0)
{
node = tnode->children[0];
continue;
}
if (front > -ON_EPSILON && back > -ON_EPSILON) {
// if (front > 0 && back > 0) {
node = tnode->children[0];
continue;
}
if (front < ON_EPSILON && back < ON_EPSILON)
// if (front <= 0 && back <= 0)
{
node = tnode->children[1];
continue;
}
if (front < ON_EPSILON && back < ON_EPSILON) {
// if (front <= 0 && back <= 0) {
node = tnode->children[1];
continue;
}
side = front < 0;
@ -225,6 +218,5 @@ TestLine (vec3_t start, vec3_t stop)
backz = frontz + front * (backz - frontz);
node = tnode->children[side];
}
}
}

View file

@ -51,9 +51,9 @@ typedef struct {
} plane_t;
typedef struct {
qboolean original; // don't free, it's part of the portal
int numpoints;
vec3_t points[8]; // variable sized
qboolean original; // don't free, it's part of the portal
int numpoints;
vec3_t points[8]; // variable sized
} winding_t;
typedef enum {
@ -65,44 +65,44 @@ typedef enum {
typedef struct {
plane_t plane; // normal pointing into neighbor
int leaf; // neighbor
winding_t *winding;
vstatus_t status;
byte *visbits;
byte *mightsee;
int nummightsee;
int numcansee;
winding_t *winding;
vstatus_t status;
byte *visbits;
byte *mightsee;
int nummightsee;
int numcansee;
} portal_t;
typedef struct seperating_plane_s {
struct seperating_plane_s *next;
plane_t plane; // from portal is on positive side
struct seperating_plane_s *next;
plane_t plane; // from portal is on positive side
} sep_t;
typedef struct passage_s {
struct passage_s *next;
int from, to; // leaf numbers
sep_t *planes;
struct passage_s *next;
int from, to; // leaf numbers
sep_t *planes;
} passage_t;
typedef struct leaf_s {
int numportals;
passage_t *passages;
portal_t *portals[MAX_PORTALS_ON_LEAF];
int numportals;
passage_t *passages;
portal_t *portals[MAX_PORTALS_ON_LEAF];
} leaf_t;
typedef struct pstack_s {
struct pstack_s *next;
leaf_t *leaf;
portal_t *portal; // portal exiting
winding_t *source, *pass;
plane_t portalplane;
byte *mightsee; // bit string
struct pstack_s *next;
leaf_t *leaf;
portal_t *portal; // portal exiting
winding_t *source, *pass;
plane_t portalplane;
byte *mightsee; // bit string
} pstack_t;
typedef struct {
byte *leafvis; // bit string
portal_t *base;
pstack_t pstack_head;
byte *leafvis; // bit string
portal_t *base;
pstack_t pstack_head;
} threaddata_t;
extern int numportals;
@ -134,4 +134,3 @@ void PortalFlow (portal_t *portal);
void CalcAmbientSounds (void);
#endif// __vis_h

View file

@ -73,7 +73,6 @@ CheckStack (leaf_t *leaf, threaddata_t *thread)
{
pstack_t *p;
for (p = thread->pstack_head.next; p; p = p->next)
if (p->leaf == leaf)
fprintf (stderr, "CheckStack: leaf recursion");
@ -95,23 +94,22 @@ CheckStack (leaf_t *leaf, threaddata_t *thread)
*/
winding_t *
ClipToSeperators (winding_t *source, winding_t *pass, winding_t *target,
qboolean flipclip)
qboolean flipclip)
{
int i, j, k, l;
plane_t plane;
vec3_t v1, v2;
float d;
vec_t length;
int i, j, k, l;
int counts[3];
qboolean fliptest;
plane_t plane;
vec3_t v1, v2;
vec_t length;
// check all combinations
for (i = 0; i < source->numpoints; i++) {
l = (i + 1) % source->numpoints;
VectorSubtract (source->points[l], source->points[i], v1);
// fing a vertex of pass that makes a plane that puts all of the
// 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
for (j = 0; j < pass->numpoints; j++) {
@ -212,15 +210,14 @@ void
RecursiveLeafFlow (int leafnum, threaddata_t *thread, pstack_t *prevstack)
{
int i, j;
leaf_t *leaf;
long *test, *might, *vis;
qboolean more;
pstack_t stack;
portal_t *p;
plane_t backplane;
winding_t *source, *target;
leaf_t *leaf;
long *test, *might, *vis;
qboolean more;
c_chains++;
leaf = &leafs[leafnum];
@ -360,7 +357,6 @@ void
PortalFlow (portal_t *p)
{
threaddata_t data;
if (p->status != stat_working)
fprintf (stderr, "PortalFlow: reflowed");
@ -393,7 +389,6 @@ SimpleFlood (portal_t *srcportal, int leafnum)
int i;
leaf_t *leaf;
portal_t *p;
if (srcportal->mightsee[leafnum >> 3] & (1 << (leafnum & 7)))
return;
@ -417,7 +412,6 @@ BasePortalVis (void)
float d;
portal_t *tp, *p;
winding_t *winding;
for (i = 0, p = portals; i < numportals * 2; i++, p++) {
p->mightsee = malloc (bitbytes);
@ -429,7 +423,7 @@ BasePortalVis (void)
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],
@ -459,4 +453,3 @@ BasePortalVis (void)
p->nummightsee = c_leafsee;
}
}

View file

@ -30,7 +30,6 @@ static const char rcsid[] =
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#endif
@ -68,22 +67,22 @@ static const char *short_options =
"f:" // file
;
void
usage (int status)
{
printf ("%s - QuakeForge PVS/PHS generation tool\n", this_program);
printf ("Usage: %s [options]\n", this_program);
printf (
"Options:\n"
" -q, --quiet Inhibit usual output\n"
" -v, --verbose Display more output than usual\n"
" -h, --help Display this help and exit\n"
" -V, --version Output version information and exit\n"
" -t, --threads [num] Number of threads to use\n"
" -m, --minimal Perform minimal vis'ing\n"
" -l, --level [level] Vis level to perform\n"
" -f, --file [bspfile] BSP file to vis\n\n"
);
"Options:\n"
" -q, --quiet Inhibit usual output\n"
" -v, --verbose Display more output than usual\n"
" -h, --help Display this help and exit\n"
" -V, --version Output version information and exit\n"
" -t, --threads [num] Number of threads to use\n"
" -m, --minimal Perform minimal vis'ing\n"
" -l, --level [level] Vis level to perform\n"
" -f, --file [bspfile] BSP file to vis\n\n");
exit (status);
}

View file

@ -30,7 +30,6 @@ static const char rcsid[] =
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
@ -92,87 +91,84 @@ byte *uncompressed; // [bitbytes * portalleafs]
void
NormalizePlane (plane_t *dp)
{
vec_t ax, ay, az;
vec_t ax, ay, az;
if (dp->normal[0] == -1.0) {
if (dp->normal[0] == -1.0) {
dp->normal[0] = 1.0;
dp->dist = -dp->dist;
return;
}
if (dp->normal[1] == -1.0) {
}
if (dp->normal[1] == -1.0) {
dp->normal[1] = 1.0;
dp->dist = -dp->dist;
return;
}
if (dp->normal[2] == -1.0) {
}
if (dp->normal[2] == -1.0) {
dp->normal[2] = 1.0;
dp->dist = -dp->dist;
return;
}
}
ax = fabs (dp->normal[0]);
ay = fabs (dp->normal[1]);
az = fabs (dp->normal[2]);
ax = fabs (dp->normal[0]);
ay = fabs (dp->normal[1]);
az = fabs (dp->normal[2]);
if (ax >= ay && ax >= az) {
if (ax >= ay && ax >= az) {
if (dp->normal[0] < 0) {
VectorSubtract (vec3_origin, dp->normal, dp->normal);
dp->dist = -dp->dist;
}
return;
}
}
if (ay >= ax && ay >= az) {
if (ay >= ax && ay >= az) {
if (dp->normal[1] < 0) {
VectorSubtract (vec3_origin, dp->normal, dp->normal);
dp->dist = -dp->dist;
}
return;
}
}
if (dp->normal[2] < 0) {
if (dp->normal[2] < 0) {
VectorSubtract (vec3_origin, dp->normal, dp->normal);
dp->dist = -dp->dist;
}
}
}
#endif
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);
VectorSubtract (winding->points[0], winding->points[1], v2);
CrossProduct (v2, v1, plane->normal);
VectorNormalize (plane->normal);
plane->dist = DotProduct (winding->points[0], plane->normal);
VectorSubtract (winding->points[2], winding->points[1], v1);
VectorSubtract (winding->points[0], winding->points[1], v2);
CrossProduct (v2, v1, plane->normal);
VectorNormalize (plane->normal);
plane->dist = DotProduct (winding->points[0], plane->normal);
}
winding_t *
NewWinding (int points)
{
winding_t *winding;
int size;
winding_t *winding;
int size;
if (points > MAX_POINTS_ON_WINDING)
if (points > MAX_POINTS_ON_WINDING)
fprintf (stderr, "NewWinding: %i points\n", points);
size = (int) ((winding_t *) 0)->points[points];
winding = malloc (size);
memset (winding, 0, size);
size = (int) ((winding_t *) 0)->points[points];
winding = malloc (size);
memset (winding, 0, size);
return winding;
return winding;
}
void
FreeWinding (winding_t *winding)
{
if (!winding->original)
if (!winding->original)
free (winding);
}
@ -180,46 +176,44 @@ FreeWinding (winding_t *winding)
void
pw (winding_t *winding)
{
int i;
int i;
for (i = 0; i < winding->numpoints; i++)
for (i = 0; i < winding->numpoints; i++)
printf ("(%5.1f, %5.1f, %5.1f)\n", winding->points[i][0],
winding->points[i][1],
winding->points[i][2]);
winding->points[i][1],
winding->points[i][2]);
}
// FIXME: currently unused
void
prl (leaf_t *leaf)
{
int i;
portal_t *portal;
plane_t plane;
int i;
portal_t *portal;
plane_t plane;
for (i = 0; i < leaf->numportals; i++) {
for (i = 0; i < leaf->numportals; i++) {
portal = leaf->portals[i];
plane = portal->plane;
printf ("portal %4i to leaf %4i : %7.1f : (%4.1f, %4.1f, %4.1f)\n",
(int) (portal - portals),
portal->leaf, plane.dist,
plane.normal[0], plane.normal[1], plane.normal[2]);
}
(int) (portal - portals),
portal->leaf, plane.dist,
plane.normal[0], plane.normal[1], plane.normal[2]);
}
}
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);
memcpy (copy, winding, size);
copy->original = false;
return copy;
size = (int) ((winding_t *) 0)->points[winding->numpoints];
copy = malloc (size);
memcpy (copy, winding, size);
copy->original = false;
return copy;
}
/*
@ -236,21 +230,19 @@ CopyWinding (winding_t *winding)
winding_t *
ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
{
int i, j;
vec_t dists[MAX_POINTS_ON_WINDING];
int sides[MAX_POINTS_ON_WINDING];
int counts[3];
vec_t dot;
vec_t *p1, *p2;
vec3_t mid;
winding_t *neww;
int maxpts;
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;
counts[0] = counts[1] = counts[2] = 0;
// determine sides for each point
for (i = 0; i < in->numpoints; i++) {
for (i = 0; i < in->numpoints; i++) {
dot = DotProduct (in->points[i], split->normal);
dot -= split->dist;
dists[i] = dot;
@ -262,25 +254,25 @@ ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
sides[i] = SIDE_ON;
}
counts[sides[i]]++;
}
sides[i] = sides[0];
dists[i] = dists[0];
}
sides[i] = sides[0];
dists[i] = dists[0];
if (keepon && !counts[0] && !counts[1])
if (keepon && !counts[0] && !counts[1])
return in;
if (!counts[0]) {
if (!counts[0]) {
FreeWinding (in);
return NULL;
}
if (!counts[1])
}
if (!counts[1])
return in;
maxpts = in->numpoints + 4; // can't use counts[0] + 2 because
maxpts = in->numpoints + 4; // can't use counts[0] + 2 because
// of fp grouping errors
neww = NewWinding (maxpts);
neww = NewWinding (maxpts);
for (i = 0; i < in->numpoints; i++) {
for (i = 0; i < in->numpoints; i++) {
p1 = in->points[i];
if (sides[i] == SIDE_ON) {
@ -313,14 +305,14 @@ ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
VectorCopy (mid, neww->points[neww->numpoints]);
neww->numpoints++;
}
}
if (neww->numpoints > maxpts)
if (neww->numpoints > maxpts)
fprintf (stderr, "ClipWinding: points exceeded estimate\n");
// free the original winding
FreeWinding (in);
FreeWinding (in);
return neww;
return neww;
}
/*
@ -333,37 +325,36 @@ ClipWinding (winding_t *in, plane_t *split, qboolean keepon)
portal_t *
GetNextPortal (void)
{
int j;
portal_t *p, *tp;
int min;
int j;
portal_t *p, *tp;
int min;
LOCK;
LOCK;
min = 99999;
p = NULL;
min = 99999;
p = NULL;
for (j = 0, tp = portals; j < numportals * 2; j++, tp++) {
for (j = 0, tp = portals; j < numportals * 2; j++, tp++) {
if (tp->nummightsee < min && tp->status == stat_none) {
min = tp->nummightsee;
p = tp;
}
}
}
if (p)
if (p)
p->status = stat_working;
UNLOCK;
UNLOCK;
return p;
return p;
}
void *LeafThread (void *thread)
void *
LeafThread (void *thread)
{
portal_t *portal;
portal_t *portal;
do {
do {
portal = GetNextPortal ();
if (!portal)
break;
@ -375,24 +366,23 @@ void *LeafThread (void *thread)
(int) (portal - portals),
portal->nummightsee,
portal->numcansee);
} while (1);
} while (1);
return NULL;
return NULL;
}
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;
dest_p = dest;
visrow = (portalleafs + 7) >> 3;
for (j = 0; j < visrow; j++) {
for (j = 0; j < visrow; j++) {
*dest_p++ = vis[j];
if (vis[j])
continue;
@ -405,9 +395,9 @@ CompressRow (byte *vis, byte *dest)
rep++;
*dest_p++ = rep;
j--;
}
}
return dest_p - dest;
return dest_p - dest;
}
/*
@ -418,55 +408,53 @@ CompressRow (byte *vis, byte *dest)
void
LeafFlow (int leafnum)
{
int i, j;
leaf_t *leaf;
byte *outbuffer;
byte compressed[MAX_MAP_LEAFS / 8];
int numvis;
byte *dest;
portal_t *portal;
byte *dest, *outbuffer;
byte compressed[MAX_MAP_LEAFS / 8];
int numbvis, i, j;
leaf_t *leaf;
portal_t *portal;
// flow through all portals, collecting visible bits
outbuffer = uncompressed + leafnum * bitbytes;
leaf = &leafs[leafnum];
for (i = 0; i < leaf->numportals; i++) {
outbuffer = uncompressed + leafnum * bitbytes;
leaf = &leafs[leafnum];
for (i = 0; i < leaf->numportals; i++) {
portal = leaf->portals[i];
if (portal->status != stat_done)
fprintf (stderr, "portal not done\n");
for (j = 0; j < bitbytes; j++)
outbuffer[j] |= portal->visbits[j];
}
}
if (outbuffer[leafnum >> 3] & (1 << (leafnum & 7)))
if (outbuffer[leafnum >> 3] & (1 << (leafnum & 7)))
fprintf (stderr, "Leaf portals saw into leaf\n");
outbuffer[leafnum >> 3] |= (1 << (leafnum & 7));
outbuffer[leafnum >> 3] |= (1 << (leafnum & 7));
numvis = 0;
for (i = 0; i < portalleafs; i++)
numvis = 0;
for (i = 0; i < portalleafs; i++)
if (outbuffer[i >> 3] & (1 << (i & 3)))
numvis++;
// compress the bit string
if (options.verbosity > 0)
if (options.verbosity > 0)
printf ("leaf %4i : %4i visible\n", leafnum, numvis);
totalvis += numvis;
totalvis += numvis;
#if 0
i = (portalleafs + 7) >> 3;
memcpy (compressed, outbuffer, i);
i = (portalleafs + 7) >> 3;
memcpy (compressed, outbuffer, i);
#else
i = CompressRow (outbuffer, compressed);
i = CompressRow (outbuffer, compressed);
#endif
dest = vismap_p;
vismap_p += i;
dest = vismap_p;
vismap_p += i;
if (vismap_p > vismap_end) {
if (vismap_p > vismap_end) {
int d = dest - dvisdata;
int p = vismap_p - dvisdata;
int e = vismap_end - dvisdata;
visdatasize = p;
vismap = dvisdata = realloc (dvisdata, visdatasize);
dest = dvisdata + d;
@ -475,40 +463,40 @@ LeafFlow (int leafnum)
fprintf (stderr, "Vismap grown\n");
}
dleafs[leafnum + 1].visofs = dest - vismap; // leaf 0 is a common solid
dleafs[leafnum + 1].visofs = dest - vismap; // leaf 0 is a common solid
memcpy (dest, compressed, i);
memcpy (dest, compressed, i);
}
void
CalcPortalVis (void)
{
int i;
int i;
// fastvis just uses mightsee for a very loose bound
if (options.minimal) {
if (options.minimal) {
for (i = 0; i < numportals * 2; i++) {
portals[i].visbits = portals[i].mightsee;
portals[i].status = stat_done;
}
return;
}
}
leafon = 0;
leafon = 0;
#ifdef HAVE_PTHREAD_H
{
pthread_t work_threads[MAX_THREADS];
void *status;
pthread_attr_t attrib;
pthread_mutexattr_t mattrib;
{
pthread_t work_threads[MAX_THREADS];
void *status;
pthread_attr_t attrib;
pthread_mutexattr_t mattrib;
my_mutex = malloc (sizeof (*my_mutex));
if (pthread_mutexattr_init (&mattrib) == -1)
fprintf (stderr, "pthread_mutex_attr_create failed\n");
//if (pthread_mutexattr_settype (&mattrib, PTHREAD_MUTEX_ADAPTIVE_NP) == -1)
// fprintf (stderr, "pthread_mutexattr_setkind_np failed\n");
my_mutex = malloc (sizeof (*my_mutex));
if (pthread_mutexattr_init (&mattrib) == -1)
fprintf (stderr, "pthread_mutex_attr_create failed\n");
// if (pthread_mutexattr_settype (&mattrib, PTHREAD_MUTEX_ADAPTIVE_NP)
// == -1)
// fprintf (stderr, "pthread_mutexattr_setkind_np failed\n");
if (pthread_mutex_init (my_mutex, &mattrib) == -1)
fprintf (stderr, "pthread_mutex_init failed\n");
if (pthread_attr_init (&attrib) == -1)
@ -533,26 +521,23 @@ CalcPortalVis (void)
LeafThread (0);
#endif
if (options.verbosity > 0) {
if (options.verbosity > 0) {
printf ("portalcheck: %i portaltest: %i portalpass: %i\n",
c_portalcheck, c_portaltest, c_portalpass);
printf ("c_vistest: %i c_mighttest: %i\n", c_vistest, c_mighttest);
}
}
}
void
CalcVis (void)
{
int i;
int i;
BasePortalVis ();
CalcPortalVis ();
BasePortalVis ();
CalcPortalVis ();
// assemble the leaf vis lists by oring and compressing the portal lists
for (i = 0; i < portalleafs; i++)
for (i = 0; i < portalleafs; i++)
LeafFlow (i);
if (options.verbosity >= 0)
@ -562,40 +547,38 @@ CalcVis (void)
qboolean
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;
for (i = 0; i < 3; i++)
for (i = 0; i < 3; i++)
if (fabs (p1->normal[i] - p2->normal[i]) > 0.001)
return false;
return true;
return true;
}
sep_t *
Findpassages (winding_t *source, winding_t *pass)
{
int i, j, k, l;
plane_t plane;
vec3_t v1, v2;
float d;
double length;
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;
list = NULL;
// check all combinations
for (i = 0; i < source->numpoints; i++) {
for (i = 0; i < source->numpoints; i++) {
l = (i + 1) % source->numpoints;
VectorSubtract (source->points[l], source->points[i], v1);
// fing a vertex of pass that makes a plane that puts all of the
// 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
for (j = 0; j < pass->numpoints; j++) {
@ -677,26 +660,24 @@ Findpassages (winding_t *source, winding_t *pass)
list = sep;
sep->plane = plane;
}
}
return list;
}
return list;
}
void
CalcPassages (void)
{
int i, j, k;
int count, count2;
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");
count = count2 = 0;
for (i = 0; i < portalleafs; i++) {
count = count2 = 0;
for (i = 0; i < portalleafs; i++) {
leaf = &leafs[i];
for (j = 0; j < leaf->numportals; j++) {
@ -729,7 +710,7 @@ CalcPassages (void)
leaf->passages = passages;
}
}
}
}
if (options.verbosity >= 0) {
printf ("numpassages: %i (%i)\n", count2, count);
@ -740,31 +721,29 @@ CalcPassages (void)
void
LoadPortals (char *name)
{
int i, j;
portal_t *portal;
leaf_t *leaf;
winding_t *winding;
char magic[80];
FILE *f;
int leafnums[2];
int numpoints, i, j;
leaf_t *leaf;
plane_t plane;
char magic[80];
FILE *f;
int numpoints;
int leafnums[2];
portal_t *portal;
winding_t *winding;
if (!strcmp (name, "-"))
if (!strcmp (name, "-"))
f = stdin;
else {
else {
f = fopen (name, "r");
if (!f) {
printf ("LoadPortals: couldn't read %s\n", name);
printf ("No vising performed.\n");
exit (1);
}
}
}
if (fscanf (f, "%79s\n%i\n%i\n", magic, &portalleafs, &numportals) != 3)
if (fscanf (f, "%79s\n%i\n%i\n", magic, &portalleafs, &numportals) != 3)
fprintf (stderr, "LoadPortals: failed to read header\n");
if (strcmp (magic, PORTALFILE))
if (strcmp (magic, PORTALFILE))
fprintf (stderr, "LoadPortals: not a portal file\n");
if (options.verbosity >= 0) {
@ -772,27 +751,28 @@ LoadPortals (char *name)
printf ("%4i numportals\n", numportals);
}
bitbytes = ((portalleafs + 63) & ~63) >> 3;
bitlongs = bitbytes / sizeof (long);
bitbytes = ((portalleafs + 63) & ~63) >> 3;
bitlongs = bitbytes / sizeof (long);
// each file portal is split into two memory portals
portals = malloc (2 * numportals * sizeof (portal_t));
memset (portals, 0, 2 * numportals * sizeof (portal_t));
portals = malloc (2 * numportals * sizeof (portal_t));
memset (portals, 0, 2 * numportals * sizeof (portal_t));
leafs = malloc (portalleafs * sizeof (leaf_t));
memset (leafs, 0, portalleafs * sizeof (leaf_t));
leafs = malloc (portalleafs * sizeof (leaf_t));
memset (leafs, 0, portalleafs * sizeof (leaf_t));
originalvismapsize = portalleafs * ((portalleafs + 7) / 8);
originalvismapsize = portalleafs * ((portalleafs + 7) / 8);
vismap = vismap_p = dvisdata;
vismap_end = vismap + visdatasize;
vismap = vismap_p = dvisdata;
vismap_end = vismap + visdatasize;
for (i = 0, portal = portals; i < numportals; i++) {
for (i = 0, portal = portals; i < numportals; i++) {
if (fscanf (f, "%i %i %i ", &numpoints, &leafnums[0],
&leafnums[1]) != 3)
fprintf (stderr, "LoadPortals: reading portal %i\n", i);
if (numpoints > MAX_POINTS_ON_WINDING)
fprintf (stderr, "LoadPortals: portal %i has too many points\n", i);
fprintf (stderr, "LoadPortals: portal %i has too many points\n",
i);
if ((unsigned) leafnums[0] > portalleafs
|| (unsigned) leafnums[1] > portalleafs)
fprintf (stderr, "LoadPortals: reading portal %i\n", i);
@ -802,7 +782,6 @@ LoadPortals (char *name)
winding->numpoints = numpoints;
for (j = 0; j < numpoints; j++) {
double v[3];
int k;
@ -843,8 +822,8 @@ LoadPortals (char *name)
portal->plane = plane;
portal->leaf = leafnums[0];
portal++;
}
fclose (f);
}
fclose (f);
}
int
@ -854,7 +833,7 @@ main (int argc, char **argv)
dstring_t *portalfile = dstring_new ();
start = Sys_DoubleTime ();
this_program = argv[0];
DecodeArgs (argc, argv);
@ -863,12 +842,11 @@ main (int argc, char **argv)
fprintf (stderr, "%s: no bsp file specified.\n", this_program);
usage (1);
}
COM_StripExtension (options.bspfile, options.bspfile);
COM_DefaultExtension (options.bspfile, ".bsp");
LoadBSPFile (options.bspfile);
LoadBSPFile (options.bspfile);
portalfile->size = strlen (options.bspfile) + 1;
dstring_adjust (portalfile);
@ -884,19 +862,19 @@ main (int argc, char **argv)
if (options.verbosity >= 0)
printf ("c_chains: %i\n", c_chains);
visdatasize = vismap_p - dvisdata;
visdatasize = vismap_p - dvisdata;
if (options.verbosity >= 0)
printf ("visdatasize:%i compressed from %i\n", visdatasize,
originalvismapsize);
CalcAmbientSounds ();
CalcAmbientSounds ();
WriteBSPFile (options.bspfile);
WriteBSPFile (options.bspfile);
stop = Sys_DoubleTime ();
if (options.verbosity >= 0)
printf ("%5.1f seconds elapsed\n", stop - start);
return 0;
return 0;
}

View file

@ -30,7 +30,6 @@ static const char rcsid[] =
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <getopt.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
@ -69,15 +68,13 @@ static const char rcsid[] =
void
SurfaceBBox (dface_t *s, vec3_t mins, vec3_t maxs)
{
int i, j;
int e;
int vi;
float *v;
int vi, e, i, j;
float *v;
mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999;
mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999;
for (i = 0; i < s->numedges; i++) {
for (i = 0; i < s->numedges; i++) {
e = dsurfedges[s->firstedge + i];
if (e >= 0)
vi = dedges[e].v[0];
@ -91,26 +88,23 @@ SurfaceBBox (dface_t *s, vec3_t mins, vec3_t maxs)
if (v[j] > maxs[j])
maxs[j] = v[j];
}
}
}
}
void
CalcAmbientSounds (void)
{
int i, j, k, l;
dleaf_t *leaf, *hit;
byte *vis;
dface_t *surf;
vec3_t mins, maxs;
float d, maxd;
int ambient_type;
texinfo_t *info;
miptex_t *miptex;
int ofs;
float dists[NUM_AMBIENTS];
float vol;
byte *vis;
dface_t *surf;
dleaf_t *leaf, *hit;
float maxd, vol, d;
float dists[NUM_AMBIENTS];
int ambient_type, ofs, i, j, k, l;
vec3_t mins, maxs;
texinfo_t *info;
miptex_t *miptex;
for (i = 0; i < portalleafs; i++) {
for (i = 0; i < portalleafs; i++) {
leaf = &dleafs[i + 1];
// clear ambients
@ -122,7 +116,7 @@ CalcAmbientSounds (void)
for (j = 0; j < portalleafs; j++) {
if (!(vis[j >> 3] & (1 << (j & 7))))
continue;
// check this leaf for sound textures
hit = &dleafs[j + 1];
@ -175,5 +169,5 @@ CalcAmbientSounds (void)
}
leaf->ambient_level[j] = vol * 255;
}
}
}
}