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 #define DEFAULTLIGHTLEVEL 300
typedef struct epair_s { typedef struct epair_s {
struct epair_s *next; struct epair_s *next;
char key[MAX_KEY]; char key[MAX_KEY];
char value[MAX_VALUE]; char value[MAX_VALUE];
} epair_t; } epair_t;
typedef struct entity_s { typedef struct entity_s {
char classname[64]; char classname[64];
vec3_t origin; vec3_t origin;
float angle; float angle;
int light; int light;
int style; int style;
char target[32]; char target[32];
char targetname[32]; char targetname[32];
struct epair_s *epairs; struct epair_s *epairs;
struct entity_s *targetent; struct entity_s *targetent;
} entity_t; } entity_t;
extern entity_t entities[MAX_MAP_ENTITIES]; 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); void RotateSample (vec3_t in, vec3_t out);
#endif// __light_h #endif// __light_h

View file

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

View file

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

View file

@ -30,7 +30,6 @@ static const char rcsid[] =
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
@ -80,25 +79,24 @@ float minlights[MAX_MAP_FACES];
byte * byte *
GetFileSpace (int size) GetFileSpace (int size)
{ {
byte *buf; byte *buf;
LOCK; LOCK;
file_p = (byte *) (((long) file_p + 3) & ~3); file_p = (byte *) (((long) file_p + 3) & ~3);
buf = file_p; buf = file_p;
file_p += size; file_p += size;
UNLOCK; UNLOCK;
if (file_p > file_end) if (file_p > file_end)
fprintf (stderr, "GetFileSpace: overrun"); fprintf (stderr, "GetFileSpace: overrun");
return buf; return buf;
} }
void void
LightThread (void *junk) LightThread (void *junk)
{ {
int i; int i;
while (1) { while (1) {
LOCK; LOCK;
i = bspfileface++; i = bspfileface++;
UNLOCK; UNLOCK;
@ -106,18 +104,18 @@ LightThread (void *junk)
return; return;
LightFace (i); LightFace (i);
} }
} }
void void
LightWorld (void) LightWorld (void)
{ {
filebase = file_p = dlightdata; filebase = file_p = dlightdata;
file_end = filebase + MAX_MAP_LIGHTING; file_end = filebase + MAX_MAP_LIGHTING;
RunThreadsOn (LightThread); RunThreadsOn (LightThread);
lightdatasize = file_p - filebase; lightdatasize = file_p - filebase;
if (options.verbosity >= 0) if (options.verbosity >= 0)
printf ("lightdatasize: %i\n", lightdatasize); printf ("lightdatasize: %i\n", lightdatasize);
@ -126,38 +124,38 @@ LightWorld (void)
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
double start, stop; double start, stop;
start = Sys_DoubleTime (); start = Sys_DoubleTime ();
this_program = argv[0]; this_program = argv[0];
DecodeArgs (argc, argv); DecodeArgs (argc, argv);
if (!bspfile) { if (!bspfile) {
fprintf (stderr, "%s: no bsp file specified.\n", this_program); fprintf (stderr, "%s: no bsp file specified.\n", this_program);
usage (1); usage (1);
} }
InitThreads (); InitThreads ();
COM_StripExtension (bspfile, bspfile); COM_StripExtension (bspfile, bspfile);
COM_DefaultExtension (bspfile, ".bsp"); COM_DefaultExtension (bspfile, ".bsp");
LoadBSPFile (bspfile);
LoadEntities ();
MakeTnodes (&dmodels[0]); LoadBSPFile (bspfile);
LoadEntities ();
LightWorld (); MakeTnodes (&dmodels[0]);
WriteEntitiesToString (); LightWorld ();
WriteBSPFile (bspfile);
WriteEntitiesToString ();
WriteBSPFile (bspfile);
stop = Sys_DoubleTime (); stop = Sys_DoubleTime ();
if (options.verbosity >= 0) if (options.verbosity >= 0)
printf ("%5.1f seconds elapsed\n", stop - start); 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 #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
#endif #endif
@ -59,14 +58,14 @@ void
InitThreads (void) InitThreads (void)
{ {
#ifdef __alpha #ifdef __alpha
pthread_mutexattr_t mattrib; pthread_mutexattr_t mattrib;
my_mutex = malloc (sizeof (*my_mutex)); my_mutex = malloc (sizeof (*my_mutex));
if (pthread_mutexattr_create (&mattrib) == -1) if (pthread_mutexattr_create (&mattrib) == -1)
fprintf (stderr, "pthread_mutex_attr_create failed"); 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"); 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"); fprintf (stderr, "pthread_mutex_init failed");
#endif #endif
} }
@ -75,32 +74,33 @@ void
RunThreadsOn (threadfunc_t func) RunThreadsOn (threadfunc_t func)
{ {
#ifdef __alpha #ifdef __alpha
pthread_t work_threads[256]; pthread_t work_threads[256];
pthread_addr_t status; pthread_addr_t status;
pthread_attr_t attrib; pthread_attr_t attrib;
int i; int i;
if (numthreads == 1) { if (numthreads == 1) {
func (NULL); func (NULL);
return; return;
} }
if (pthread_attr_create (&attrib) == -1) if (pthread_attr_create (&attrib) == -1)
fprintf (stderr, "pthread_attr_create failed"); 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"); fprintf (stderr, "pthread_attr_setstacksize failed");
for (i = 0; i < numthreads; i++) { for (i = 0; i < numthreads; i++) {
if (pthread_create (&work_threads[i], attrib, (pthread_startroutine_t) func, (pthread_addr_t) i) == -1) if (pthread_create (&work_threads[i], attrib,
(pthread_startroutine_t) func,
(pthread_addr_t) i) == -1)
fprintf (stderr, "pthread_create failed"); 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) if (pthread_join (work_threads[i], &status) == -1)
fprintf (stderr, "pthread_join failed"); fprintf (stderr, "pthread_join failed");
} }
#else #else
func (NULL); func (NULL);
#endif #endif
} }

View file

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

View file

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

View file

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

View file

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

View file

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