qbsp: misc local variable naming changes for writebsp.c

Shouldn't be any functional changes to the code.

Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
Kevin Shanahan 2013-03-05 14:53:54 +10:30
parent fe89facbd0
commit 6dd0fbd085
1 changed files with 116 additions and 114 deletions

View File

@ -29,11 +29,10 @@ static int *planemapping;
static void static void
ExportNodePlanes_r(node_t *node) ExportNodePlanes_r(node_t *node)
{ {
struct lumpdata *planes = &pWorldEnt->lumps[BSPPLANE];
plane_t *plane; plane_t *plane;
dplane_t *dplane; dplane_t *dplane;
int i; int i;
vec3_t tmp;
struct lumpdata *planes = &pWorldEnt->lumps[BSPPLANE];
if (node->planenum == -1) if (node->planenum == -1)
return; return;
@ -43,10 +42,11 @@ ExportNodePlanes_r(node_t *node)
// search for an equivalent plane // search for an equivalent plane
for (i = 0; i < planes->index; i++, dplane++) { for (i = 0; i < planes->index; i++, dplane++) {
tmp[0] = dplane->normal[0]; vec3_t normal;
tmp[1] = dplane->normal[1]; normal[0] = dplane->normal[0];
tmp[2] = dplane->normal[2]; normal[1] = dplane->normal[1];
if (DotProduct(tmp, plane->normal) > 1 - 0.00001 && normal[2] = dplane->normal[2];
if (DotProduct(normal, plane->normal) > 1 - 0.00001 &&
fabs(dplane->dist - plane->dist) < 0.01 && fabs(dplane->dist - plane->dist) < 0.01 &&
dplane->type == plane->type) dplane->type == plane->type)
break; break;
@ -109,15 +109,15 @@ CountClipNodes_r
================== ==================
*/ */
static void static void
CountClipNodes_r(mapentity_t *ent, node_t *node) CountClipNodes_r(mapentity_t *entity, node_t *node)
{ {
if (node->planenum == -1) if (node->planenum == -1)
return; return;
ent->lumps[BSPCLIPNODE].count++; entity->lumps[BSPCLIPNODE].count++;
CountClipNodes_r(ent, node->children[0]); CountClipNodes_r(entity, node->children[0]);
CountClipNodes_r(ent, node->children[1]); CountClipNodes_r(entity, node->children[1]);
} }
/* /*
@ -126,36 +126,38 @@ ExportClipNodes_r
================== ==================
*/ */
static int static int
ExportClipNodes_r(mapentity_t *ent, node_t *node) ExportClipNodes_r(mapentity_t *entity, node_t *node)
{ {
int i, c; int i, nodenum;
dclipnode_t *cn; dclipnode_t *clipnode;
face_t *f, *next; face_t *face, *next;
struct lumpdata *clipnodes = &ent->lumps[BSPCLIPNODE]; struct lumpdata *clipnodes = &entity->lumps[BSPCLIPNODE];
// FIXME: free more stuff? // FIXME: free more stuff?
if (node->planenum == -1) { if (node->planenum == -1) {
c = node->contents; int contents = node->contents;
FreeMem(node, NODE, 1); FreeMem(node, NODE, 1);
return c; return contents;
} }
// emit a clipnode
c = map.cTotal[BSPCLIPNODE]; /* emit a clipnode */
cn = (dclipnode_t *)clipnodes->data + clipnodes->index; clipnode = (dclipnode_t *)clipnodes->data + clipnodes->index;
clipnodes->index++; clipnodes->index++;
nodenum = map.cTotal[BSPCLIPNODE];
map.cTotal[BSPCLIPNODE]++; map.cTotal[BSPCLIPNODE]++;
cn->planenum = node->outputplanenum; clipnode->planenum = node->outputplanenum;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
cn->children[i] = ExportClipNodes_r(ent, node->children[i]); clipnode->children[i] = ExportClipNodes_r(entity, node->children[i]);
for (f = node->faces; f; f = next) { for (face = node->faces; face; face = next) {
next = f->next; next = face->next;
memset(f, 0, sizeof(face_t)); memset(face, 0, sizeof(face_t));
FreeMem(f, FACE, 1); FreeMem(face, FACE, 1);
} }
FreeMem(node, NODE, 1); FreeMem(node, NODE, 1);
return c;
return nodenum;
} }
/* /*
@ -171,47 +173,47 @@ accomodate new data interleaved with old.
================== ==================
*/ */
void void
ExportClipNodes(mapentity_t *ent, node_t *nodes, const int hullnum) ExportClipNodes(mapentity_t *entity, node_t *nodes, const int hullnum)
{ {
int oldcount, i, diff; int oldcount, i, diff;
int clipcount = 0; int clipcount = 0;
dclipnode_t *pTemp; dclipnode_t *olddata, *clipnode;
struct lumpdata *clipnodes = &ent->lumps[BSPCLIPNODE]; struct lumpdata *clipnodes = &entity->lumps[BSPCLIPNODE];
dmodel_t *model = (dmodel_t *)ent->lumps[BSPMODEL].data; dmodel_t *model = (dmodel_t *)entity->lumps[BSPMODEL].data;
oldcount = clipnodes->count; oldcount = clipnodes->count;
/* Count nodes before this one */ /* Count nodes before this one */
for (i = 0; i < ent - map.entities; i++) for (i = 0; i < entity - map.entities; i++)
clipcount += map.entities[i].lumps[BSPCLIPNODE].count; clipcount += map.entities[i].lumps[BSPCLIPNODE].count;
model->headnode[hullnum] = clipcount + oldcount; model->headnode[hullnum] = clipcount + oldcount;
CountClipNodes_r(ent, nodes); CountClipNodes_r(entity, nodes);
if (clipnodes->count > MAX_BSP_CLIPNODES) if (clipnodes->count > MAX_BSP_CLIPNODES)
Error(errTooManyClipnodes); Error(errTooManyClipnodes);
pTemp = clipnodes->data; olddata = clipnodes->data;
clipnodes->data = AllocMem(BSPCLIPNODE, clipnodes->count, true); clipnodes->data = AllocMem(BSPCLIPNODE, clipnodes->count, true);
if (pTemp) { if (olddata) {
memcpy(clipnodes->data, pTemp, oldcount * rgcMemSize[BSPCLIPNODE]); memcpy(clipnodes->data, olddata, oldcount * rgcMemSize[BSPCLIPNODE]);
FreeMem(pTemp, BSPCLIPNODE, oldcount); FreeMem(olddata, BSPCLIPNODE, oldcount);
/* Worth special-casing for entity 0 (no modification needed) */ /* Worth special-casing for entity 0 (no modification needed) */
diff = clipcount - model->headnode[1]; diff = clipcount - model->headnode[1];
if (diff != 0) { if (diff != 0) {
model->headnode[1] += diff; model->headnode[1] += diff;
for (i = 0; i < oldcount; i++) { clipnode = clipnodes->data;
pTemp = (dclipnode_t *)clipnodes->data + i; for (i = 0; i < oldcount; i++, clipnode++) {
if (pTemp->children[0] < MAX_BSP_CLIPNODES) if (clipnode->children[0] < MAX_BSP_CLIPNODES)
pTemp->children[0] += diff; clipnode->children[0] += diff;
if (pTemp->children[1] < MAX_BSP_CLIPNODES) if (clipnode->children[1] < MAX_BSP_CLIPNODES)
pTemp->children[1] += diff; clipnode->children[1] += diff;
} }
} }
} }
map.cTotal[BSPCLIPNODE] = clipcount + oldcount; map.cTotal[BSPCLIPNODE] = clipcount + oldcount;
ExportClipNodes_r(ent, nodes); ExportClipNodes_r(entity, nodes);
} }
//=========================================================================== //===========================================================================
@ -223,17 +225,17 @@ CountLeaves
================== ==================
*/ */
static void static void
CountLeaves(mapentity_t *ent, node_t *node) CountLeaves(mapentity_t *entity, node_t *node)
{ {
face_t **fp, *f; face_t **markfaces, *face;
const texinfo_t *texinfo = pWorldEnt->lumps[BSPTEXINFO].data; const texinfo_t *texinfo = pWorldEnt->lumps[BSPTEXINFO].data;
ent->lumps[BSPLEAF].count++; entity->lumps[BSPLEAF].count++;
for (fp = node->markfaces; *fp; fp++) { for (markfaces = node->markfaces; *markfaces; markfaces++) {
if (texinfo[(*fp)->texinfo].flags & TEX_SKIP) if (texinfo[(*markfaces)->texinfo].flags & TEX_SKIP)
continue; continue;
for (f = *fp; f; f = f->original) for (face = *markfaces; face; face = face->original)
ent->lumps[BSPMARKSURF].count++; entity->lumps[BSPMARKSURF].count++;
} }
} }
@ -243,18 +245,18 @@ CountNodes_r
================== ==================
*/ */
static void static void
CountNodes_r(mapentity_t *ent, node_t *node) CountNodes_r(mapentity_t *entity, node_t *node)
{ {
int i; int i;
ent->lumps[BSPNODE].count++; entity->lumps[BSPNODE].count++;
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (node->children[i]->planenum == -1) { if (node->children[i]->planenum == -1) {
if (node->children[i]->contents != CONTENTS_SOLID) if (node->children[i]->contents != CONTENTS_SOLID)
CountLeaves(ent, node->children[i]); CountLeaves(entity, node->children[i]);
} else } else
CountNodes_r(ent, node->children[i]); CountNodes_r(entity, node->children[i]);
} }
} }
@ -264,12 +266,12 @@ CountNodes
================== ==================
*/ */
static void static void
CountNodes(mapentity_t *ent, node_t *headnode) CountNodes(mapentity_t *entity, node_t *headnode)
{ {
if (headnode->contents < 0) if (headnode->contents < 0)
CountLeaves(ent, headnode); CountLeaves(entity, headnode);
else else
CountNodes_r(ent, headnode); CountNodes_r(entity, headnode);
} }
/* /*
@ -278,14 +280,14 @@ ExportLeaf
================== ==================
*/ */
static void static void
ExportLeaf(mapentity_t *ent, node_t *node) ExportLeaf(mapentity_t *entity, node_t *node)
{ {
face_t **fp, *f;
dleaf_t *dleaf;
const texinfo_t *texinfo = pWorldEnt->lumps[BSPTEXINFO].data; const texinfo_t *texinfo = pWorldEnt->lumps[BSPTEXINFO].data;
struct lumpdata *leaves = &ent->lumps[BSPLEAF]; struct lumpdata *leaves = &entity->lumps[BSPLEAF];
struct lumpdata *marksurfs = &ent->lumps[BSPMARKSURF]; struct lumpdata *marksurfs = &entity->lumps[BSPMARKSURF];
unsigned short *marksurfnums = marksurfs->data; unsigned short *marksurfnums = marksurfs->data;
face_t **markfaces, *face;
dleaf_t *dleaf;
// ptr arithmetic to get correct leaf in memory // ptr arithmetic to get correct leaf in memory
dleaf = (dleaf_t *)leaves->data + leaves->index; dleaf = (dleaf_t *)leaves->data + leaves->index;
@ -294,10 +296,10 @@ ExportLeaf(mapentity_t *ent, node_t *node)
dleaf->contents = node->contents; dleaf->contents = node->contents;
// /*
// write bounding box info * write bounding box info
// * (VectorCopy doesn't work since dest are shorts)
// VectorCopy don't work since dest are shorts */
dleaf->mins[0] = (short)node->mins[0]; dleaf->mins[0] = (short)node->mins[0];
dleaf->mins[1] = (short)node->mins[1]; dleaf->mins[1] = (short)node->mins[1];
dleaf->mins[2] = (short)node->mins[2]; dleaf->mins[2] = (short)node->mins[2];
@ -310,18 +312,18 @@ ExportLeaf(mapentity_t *ent, node_t *node)
// write the marksurfaces // write the marksurfaces
dleaf->firstmarksurface = map.cTotal[BSPMARKSURF]; dleaf->firstmarksurface = map.cTotal[BSPMARKSURF];
for (fp = node->markfaces; *fp; fp++) { for (markfaces = node->markfaces; *markfaces; markfaces++) {
f = *fp; face = *markfaces;
if (texinfo[f->texinfo].flags & TEX_SKIP) if (texinfo[face->texinfo].flags & TEX_SKIP)
continue; continue;
/* emit a marksurface */ /* emit a marksurface */
do { do {
marksurfnums[marksurfs->index] = f->outputnumber; marksurfnums[marksurfs->index] = face->outputnumber;
marksurfs->index++; marksurfs->index++;
map.cTotal[BSPMARKSURF]++; map.cTotal[BSPMARKSURF]++;
f = f->original; /* grab tjunction split faces */ face = face->original; /* grab tjunction split faces */
} while (f); } while (face);
} }
dleaf->nummarksurfaces = map.cTotal[BSPMARKSURF] - dleaf->firstmarksurface; dleaf->nummarksurfaces = map.cTotal[BSPMARKSURF] - dleaf->firstmarksurface;
} }
@ -333,41 +335,40 @@ ExportDrawNodes_r
================== ==================
*/ */
static void static void
ExportDrawNodes_r(mapentity_t *ent, node_t *node) ExportDrawNodes_r(mapentity_t *entity, node_t *node)
{ {
dnode_t *n; struct lumpdata *nodes = &entity->lumps[BSPNODE];
dnode_t *dnode;
int i; int i;
struct lumpdata *nodes = &ent->lumps[BSPNODE];
// ptr arithmetic to get correct node in memory dnode = (dnode_t *)nodes->data + nodes->index;
n = (dnode_t *)nodes->data + nodes->index;
nodes->index++; nodes->index++;
map.cTotal[BSPNODE]++; map.cTotal[BSPNODE]++;
// VectorCopy doesn't work since dest are shorts // VectorCopy doesn't work since dest are shorts
n->mins[0] = (short)node->mins[0]; dnode->mins[0] = (short)node->mins[0];
n->mins[1] = (short)node->mins[1]; dnode->mins[1] = (short)node->mins[1];
n->mins[2] = (short)node->mins[2]; dnode->mins[2] = (short)node->mins[2];
n->maxs[0] = (short)node->maxs[0]; dnode->maxs[0] = (short)node->maxs[0];
n->maxs[1] = (short)node->maxs[1]; dnode->maxs[1] = (short)node->maxs[1];
n->maxs[2] = (short)node->maxs[2]; dnode->maxs[2] = (short)node->maxs[2];
n->planenum = node->outputplanenum; dnode->planenum = node->outputplanenum;
n->firstface = node->firstface; dnode->firstface = node->firstface;
n->numfaces = node->numfaces; dnode->numfaces = node->numfaces;
// recursively output the other nodes // recursively output the other nodes
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
if (node->children[i]->planenum == -1) { if (node->children[i]->planenum == -1) {
if (node->children[i]->contents == CONTENTS_SOLID) if (node->children[i]->contents == CONTENTS_SOLID)
n->children[i] = -1; dnode->children[i] = -1;
else { else {
n->children[i] = -(map.cTotal[BSPLEAF] + 1); dnode->children[i] = -(map.cTotal[BSPLEAF] + 1);
ExportLeaf(ent, node->children[i]); ExportLeaf(entity, node->children[i]);
} }
} else { } else {
n->children[i] = map.cTotal[BSPNODE]; dnode->children[i] = map.cTotal[BSPNODE];
ExportDrawNodes_r(ent, node->children[i]); ExportDrawNodes_r(entity, node->children[i]);
} }
} }
} }
@ -378,16 +379,16 @@ ExportDrawNodes
================== ==================
*/ */
void void
ExportDrawNodes(mapentity_t *ent, node_t *headnode) ExportDrawNodes(mapentity_t *entity, node_t *headnode)
{ {
int i; int i;
dmodel_t *bm; dmodel_t *dmodel;
struct lumpdata *nodes = &ent->lumps[BSPNODE]; struct lumpdata *nodes = &entity->lumps[BSPNODE];
struct lumpdata *leaves = &ent->lumps[BSPLEAF]; struct lumpdata *leaves = &entity->lumps[BSPLEAF];
struct lumpdata *marksurfs = &ent->lumps[BSPMARKSURF]; struct lumpdata *marksurfs = &entity->lumps[BSPMARKSURF];
// Get a feel for how many of these things there are. // Get a feel for how many of these things there are.
CountNodes(ent, headnode); CountNodes(entity, headnode);
// emit a model // emit a model
nodes->data = AllocMem(BSPNODE, nodes->count, true); nodes->data = AllocMem(BSPNODE, nodes->count, true);
@ -400,25 +401,26 @@ ExportDrawNodes(mapentity_t *ent, node_t *headnode)
*/ */
((dleaf_t *)pWorldEnt->lumps[BSPLEAF].data)->contents = CONTENTS_SOLID; ((dleaf_t *)pWorldEnt->lumps[BSPLEAF].data)->contents = CONTENTS_SOLID;
bm = (dmodel_t *)ent->lumps[BSPMODEL].data; dmodel = (dmodel_t *)entity->lumps[BSPMODEL].data;
bm->headnode[0] = map.cTotal[BSPNODE]; dmodel->headnode[0] = map.cTotal[BSPNODE];
bm->firstface = firstface; dmodel->firstface = firstface;
bm->numfaces = map.cTotal[BSPFACE] - firstface; dmodel->numfaces = map.cTotal[BSPFACE] - firstface;
firstface = map.cTotal[BSPFACE]; firstface = map.cTotal[BSPFACE];
if (headnode->contents < 0) if (headnode->contents < 0)
ExportLeaf(ent, headnode); ExportLeaf(entity, headnode);
else else
ExportDrawNodes_r(ent, headnode); ExportDrawNodes_r(entity, headnode);
// Not counting initial vis leaf /* Not counting initial vis leaf */
bm->visleafs = leaves->count; dmodel->visleafs = leaves->count;
if (ent == pWorldEnt) if (entity == pWorldEnt)
bm->visleafs--; dmodel->visleafs--;
/* remove the headnode padding */
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
bm->mins[i] = headnode->mins[i] + SIDESPACE + 1; // remove the padding dmodel->mins[i] = headnode->mins[i] + SIDESPACE + 1;
bm->maxs[i] = headnode->maxs[i] - SIDESPACE - 1; dmodel->maxs[i] = headnode->maxs[i] - SIDESPACE - 1;
} }
} }
@ -468,17 +470,17 @@ FinishBSPFile
void void
FinishBSPFile(void) FinishBSPFile(void)
{ {
dplane_t *pTemp;
struct lumpdata *planes = &pWorldEnt->lumps[BSPPLANE]; struct lumpdata *planes = &pWorldEnt->lumps[BSPPLANE];
dplane_t *newdata;
options.fVerbose = true; options.fVerbose = true;
Message(msgProgress, "WriteBSPFile"); Message(msgProgress, "WriteBSPFile");
// TODO: Fix this somewhere else? // TODO: Fix this somewhere else?
pTemp = AllocMem(BSPPLANE, map.cTotal[BSPPLANE], true); newdata = AllocMem(BSPPLANE, map.cTotal[BSPPLANE], true);
memcpy(pTemp, planes->data, map.cTotal[BSPPLANE] * rgcMemSize[BSPPLANE]); memcpy(newdata, planes->data, map.cTotal[BSPPLANE] * rgcMemSize[BSPPLANE]);
FreeMem(planes->data, BSPPLANE, planes->count); FreeMem(planes->data, BSPPLANE, planes->count);
planes->data = pTemp; planes->data = newdata;
planes->count = map.cTotal[BSPPLANE]; planes->count = map.cTotal[BSPPLANE];
PrintBSPFileSizes(); PrintBSPFileSizes();