diff --git a/include/QF/darray.h b/include/QF/darray.h index e41cd5edb..47f887db3 100644 --- a/include/QF/darray.h +++ b/include/QF/darray.h @@ -31,6 +31,8 @@ #ifndef __QF_darray_h #define __QF_darray_h +#include + #include "QF/sys.h" /** \defgroup darray Dynamic Arrays diff --git a/tools/qfbsp/include/brush.h b/tools/qfbsp/include/brush.h index 345b14747..83c9528bb 100644 --- a/tools/qfbsp/include/brush.h +++ b/tools/qfbsp/include/brush.h @@ -22,6 +22,7 @@ #ifndef qfbsp_brush_h #define qfbsp_brush_h +#include "QF/darray.h" #include "QF/mathlib.h" #include "bsp5.h" @@ -48,8 +49,8 @@ typedef struct brushset_s { brush_t *brushes; // NULL terminated list } brushset_t; -extern int numbrushplanes; -extern plane_t planes[MAX_MAP_PLANES]; +typedef struct DARRAY_TYPE (plane_t) planeset_t; +extern planeset_t planes; /** Allocate a new brush. diff --git a/tools/qfbsp/include/csg4.h b/tools/qfbsp/include/csg4.h index e6ff8b4a3..fbe44cbd6 100644 --- a/tools/qfbsp/include/csg4.h +++ b/tools/qfbsp/include/csg4.h @@ -23,6 +23,7 @@ #define qfbsp_csg4_h #include "QF/bspfile.h" +#include "QF/darray.h" /** \defgroup qfbsp_csg4 CSG Functions \ingroup qfbsp @@ -34,7 +35,8 @@ struct visfacet_s; struct brushset_s; struct surface_s; -extern struct visfacet_s *validfaces[MAX_MAP_PLANES]; +typedef struct DARRAY_TYPE (struct visfacet_s *) visfacetset_t; +extern visfacetset_t validfaces; /** Build the surface lists for the brushset. diff --git a/tools/qfbsp/source/brush.c b/tools/qfbsp/source/brush.c index e0b05f2d9..39fabf726 100644 --- a/tools/qfbsp/source/brush.c +++ b/tools/qfbsp/source/brush.c @@ -42,8 +42,7 @@ */ //@{ -int numbrushplanes; -plane_t planes[MAX_MAP_PLANES]; +planeset_t planes = DARRAY_STATIC_INIT (1024); int numbrushfaces; mface_t faces[MAX_FACES]; // beveled clipping hull can generate many extra @@ -78,7 +77,7 @@ CheckFace (const face_t *f) if (f->points->numpoints < 3) Sys_Error ("CheckFace: %i points", f->points->numpoints); - VectorCopy (planes[f->planenum].normal, facenormal); + VectorCopy (planes.a[f->planenum].normal, facenormal); if (f->planeside) VectorNegate (facenormal, facenormal); @@ -92,14 +91,14 @@ CheckFace (const face_t *f) j = i + 1 == f->points->numpoints ? 0 : i + 1; // check the point is on the face plane - d = PlaneDiff (p1, &planes[f->planenum]); + d = PlaneDiff (p1, &planes.a[f->planenum]); // point off plane autofix if (d < -ON_EPSILON || d > ON_EPSILON) if (options.verbosity > 1) printf ("CheckFace: point off plane: %g @ (%g %g %g)\n", d, p1[0], p1[1], p1[2]); - VectorMultSub (p1, d, planes[f->planenum].normal, p1); + VectorMultSub (p1, d, planes.a[f->planenum].normal, p1); // check the edge isn't degenerate p2 = f->points->points[j]; @@ -257,7 +256,6 @@ NormalizePlane (plane_t *dp) int FindPlane (const plane_t *dplane, int *side) { - int i; plane_t *dp, pl; vec_t dot; @@ -272,8 +270,8 @@ FindPlane (const plane_t *dplane, int *side) else *side = 1; - dp = planes; - for (i = 0; i < numbrushplanes; i++, dp++) { + dp = planes.a; + for (size_t i = 0; i < planes.size; i++, dp++) { dot = DotProduct (dp->normal, pl.normal); if (dot > 1.0 - ANGLEEPSILON && fabs(dp->dist - pl.dist) < DISTEPSILON) { // regular match @@ -281,14 +279,9 @@ FindPlane (const plane_t *dplane, int *side) } } - if (numbrushplanes == MAX_MAP_PLANES) - Sys_Error ("numbrushplanes == MAX_MAP_PLANES"); + DARRAY_APPEND (&planes, pl); - planes[numbrushplanes] = pl; - - numbrushplanes++; - - return numbrushplanes - 1; + return planes.size - 1; } /* diff --git a/tools/qfbsp/source/csg4.c b/tools/qfbsp/source/csg4.c index 76d11e2d1..05c1b8034 100644 --- a/tools/qfbsp/source/csg4.c +++ b/tools/qfbsp/source/csg4.c @@ -46,7 +46,7 @@ tjunction */ -face_t *validfaces[MAX_MAP_PLANES]; +visfacetset_t validfaces = DARRAY_STATIC_INIT (1024); face_t *inside, *outside; int brushfaces; int csgfaces; @@ -134,7 +134,7 @@ ClipInside (int splitplane, int frontside, qboolean precedence) face_t *frags[2]; plane_t *split; - split = &planes[splitplane]; + split = &planes.a[splitplane]; insidelist = NULL; for (f = inside; f; f = next) { @@ -195,12 +195,12 @@ SaveOutside (qboolean mirror) newf->contents[0] = f->contents[1]; newf->contents[1] = f->contents[0]; - validfaces[planenum] = MergeFaceToList (newf, - validfaces[planenum]); + validfaces.a[planenum] = MergeFaceToList (newf, + validfaces.a[planenum]); } - validfaces[planenum] = MergeFaceToList (f, validfaces[planenum]); - validfaces[planenum] = FreeMergeListScraps (validfaces[planenum]); + validfaces.a[planenum] = MergeFaceToList (f, validfaces.a[planenum]); + validfaces.a[planenum] = FreeMergeListScraps (validfaces.a[planenum]); } } @@ -234,13 +234,12 @@ BuildSurfaces (void) { face_t *count; face_t **f; - int i; surface_t *surfhead, *s; surfhead = NULL; - f = validfaces; - for (i = 0; i < numbrushplanes; i++, f++) { + f = validfaces.a; + for (size_t i = 0; i < planes.size; i++, f++) { if (!*f) continue; // nothing left on this plane @@ -304,7 +303,8 @@ CSGFaces (brushset_t *bs) qprintf ("---- CSGFaces ----\n"); - memset (validfaces, 0, sizeof (validfaces)); + DARRAY_RESIZE (&validfaces, planes.size); + memset (validfaces.a, 0, validfaces.size * sizeof (validfaces.a[0])); csgfaces = brushfaces = csgmergefaces = 0; diff --git a/tools/qfbsp/source/info.c b/tools/qfbsp/source/info.c index ca4b16df7..fb2a6dc0c 100644 --- a/tools/qfbsp/source/info.c +++ b/tools/qfbsp/source/info.c @@ -41,7 +41,7 @@ static lumpinfo_t lump_info[] = { void bspinfo () { - printf ("version: %d\n", bsp->header->version); + printf ("version: %x\n", bsp->header->version); for (int i = 0; i < HEADER_LUMPS; i++) { lump_t *lump = &bsp->header->lumps[i]; lumpinfo_t *info = &lump_info[i]; diff --git a/tools/qfbsp/source/merge.c b/tools/qfbsp/source/merge.c index 480af3896..325353f19 100644 --- a/tools/qfbsp/source/merge.c +++ b/tools/qfbsp/source/merge.c @@ -96,7 +96,7 @@ TryMerge (const face_t *f1, const face_t *f2) found_edge: // check slope of connected lines // if the slopes are colinear, the point can be removed - plane = &planes[f1->planenum]; + plane = &planes.a[f1->planenum]; VectorCopy (plane->normal, planenormal); if (f1->planeside) VectorNegate (planenormal, planenormal); diff --git a/tools/qfbsp/source/outside.c b/tools/qfbsp/source/outside.c index d7ba0d142..81b8b0e30 100644 --- a/tools/qfbsp/source/outside.c +++ b/tools/qfbsp/source/outside.c @@ -47,8 +47,8 @@ PointInLeaf (node_t *node, const vec3_t point) vec_t d; while (!node->contents) { - d = DotProduct (planes[node->planenum].normal, point); - node = node->children[d <= planes[node->planenum].dist]; + d = DotProduct (planes.a[node->planenum].normal, point); + node = node->children[d <= planes.a[node->planenum].dist]; } return node; } diff --git a/tools/qfbsp/source/portals.c b/tools/qfbsp/source/portals.c index cbc128f1e..56c665e3f 100644 --- a/tools/qfbsp/source/portals.c +++ b/tools/qfbsp/source/portals.c @@ -271,7 +271,7 @@ CutNodePortals_r (node_t *node) return; } - plane = &planes[node->planenum]; + plane = &planes.a[node->planenum]; f = node->children[0]; b = node->children[1]; @@ -281,7 +281,7 @@ CutNodePortals_r (node_t *node) /// portals on the node. w = BaseWindingForPlane (plane); for (p = node->portals; p; p = p->next[side]) { - clipplane = planes[p->planenum]; // copy the plane + clipplane = planes.a[p->planenum]; // copy the plane if (p->nodes[0] == node) side = 0; else if (p->nodes[1] == node) { @@ -511,7 +511,7 @@ WritePortalFile_r (const node_t *node) // sometimes planes get turned around when they are very near the // changeover point between different axis. interpret the plane // the same way vis will, and flip the side orders if needed - pl = &planes[p->planenum]; + pl = &planes.a[p->planenum]; PlaneFromWinding (w, &plane2); if (DotProduct (pl->normal, plane2.normal) < 0.99) { // backwards.. fprintf (pf, "%i %i %i ", w->numpoints, diff --git a/tools/qfbsp/source/qfbsp.c b/tools/qfbsp/source/qfbsp.c index a73e6b0af..19a0d5023 100644 --- a/tools/qfbsp/source/qfbsp.c +++ b/tools/qfbsp/source/qfbsp.c @@ -296,8 +296,6 @@ ReadClipHull (int hullnum) firstclipnode = bsp->numclipnodes; for (i = 0; i < n; i++) { - if (bsp->numclipnodes == MAX_MAP_CLIPNODES) - Sys_Error ("ReadClipHull: MAX_MAP_CLIPNODES"); if (fscanf (f, "%d : %f %f %f %f : %d %d\n", &junk, &f1, &f2, &f3, &f4, &c1, &c2) != 7) Sys_Error ("Error parsing %s", options.hullfile); diff --git a/tools/qfbsp/source/readbsp.c b/tools/qfbsp/source/readbsp.c index c554755c5..c71d74b5f 100644 --- a/tools/qfbsp/source/readbsp.c +++ b/tools/qfbsp/source/readbsp.c @@ -101,16 +101,17 @@ static void load_planes (void) { const dplane_t *p; + plane_t tp = { }; int i; - memset (planes, 0, sizeof (planes)); + planes.size = 0; for (i = 0; i < bsp->numplanes; i++) { p = bsp->planes + i; - VectorCopy (p->normal, planes[i].normal); - planes[i].dist = p->dist; - planes[i].type = p->type; + VectorCopy (p->normal, tp.normal); + tp.dist = p->dist; + tp.type = p->type; + DARRAY_APPEND (&planes, tp); } - numbrushplanes = bsp->numplanes; } static void diff --git a/tools/qfbsp/source/region.c b/tools/qfbsp/source/region.c index 03dfd2efd..acb8e5da1 100644 --- a/tools/qfbsp/source/region.c +++ b/tools/qfbsp/source/region.c @@ -160,13 +160,6 @@ RecursiveGrowRegion (dface_t *r, face_t *f) } */ -typedef struct { - int numedges; - int edges[2]; -} checkpoint_t; - -checkpoint_t checkpoints[MAX_MAP_VERTS]; - static void CountRealNumbers (void) { @@ -207,8 +200,6 @@ GrowNodeRegion_r (node_t * node) // continue; // allready grown into an earlier region // emit a region - if (bsp->numfaces == MAX_MAP_FACES) - Sys_Error ("MAX_MAP_FACES"); f->outputnumber = bsp->numfaces; r.planenum = node->outputplanenum; diff --git a/tools/qfbsp/source/solidbsp.c b/tools/qfbsp/source/solidbsp.c index c49422c20..a06ad512a 100644 --- a/tools/qfbsp/source/solidbsp.c +++ b/tools/qfbsp/source/solidbsp.c @@ -138,7 +138,7 @@ ChooseMidPlaneFromList (surface_t *surfaces, if (p->onnode) continue; - plane = &planes[p->planenum]; + plane = &planes.a[p->planenum]; // check for axis aligned surfaces l = plane->type; @@ -215,7 +215,7 @@ ChoosePlaneFromList (surface_t *surfaces, const vec3_t mins, const vec3_t maxs, if (!p->has_struct && !usedetail) continue; - plane = &planes[p->planenum]; + plane = &planes.a[p->planenum]; k = 0; if (!usefloors && plane->normal[2] == 1) @@ -393,7 +393,7 @@ DividePlane (surface_t *in, plane_t *split, surface_t **front, int have[2][2]; // [front|back][detail|struct] - inplane = &planes[in->planenum]; + inplane = &planes.a[in->planenum]; // parallel case is easy if (_VectorCompare (inplane->normal, split->normal)) { @@ -638,7 +638,7 @@ PartitionSurfaces (surface_t *surfaces, node_t *node) node->children[1] = AllocNode (); node->planenum = split->planenum; - splitplane = &planes[split->planenum]; + splitplane = &planes.a[split->planenum]; // multiple surfaces, so split all the polysurfaces into front and back // lists diff --git a/tools/qfbsp/source/surfaces.c b/tools/qfbsp/source/surfaces.c index 2c9c08897..c99b4fb40 100644 --- a/tools/qfbsp/source/surfaces.c +++ b/tools/qfbsp/source/surfaces.c @@ -26,9 +26,11 @@ #endif #include +#include "QF/progs.h" // for PR_RESMAP #include "QF/sys.h" #include "tools/qfbsp/include/bsp5.h" +#include "tools/qfbsp/include/brush.h" #include "tools/qfbsp/include/csg4.h" #include "tools/qfbsp/include/options.h" #include "tools/qfbsp/include/region.h" @@ -162,8 +164,8 @@ GatherNodeFaces_r (node_t *node) if (!f->points) { // face was removed outside FreeFace (f); } else { - f->next = validfaces[f->planenum]; - validfaces[f->planenum] = f; + f->next = validfaces.a[f->planenum]; + validfaces.a[f->planenum] = f; } } @@ -180,7 +182,8 @@ GatherNodeFaces_r (node_t *node) surface_t * GatherNodeFaces (node_t *headnode) { - memset (validfaces, 0, sizeof (validfaces)); + DARRAY_RESIZE (&validfaces, planes.size); + memset (validfaces.a, 0, validfaces.size * sizeof (validfaces.a[0])); GatherNodeFaces_r (headnode); return BuildSurfaces (); } @@ -198,8 +201,7 @@ typedef struct hashvert_s { int c_cornerverts; -hashvert_t hvertex[MAX_MAP_VERTS]; -hashvert_t *hvert_p; +static PR_RESMAP (hashvert_t) hvertex; #define EDGEFACE_CHUNK 4096 int numedgefaces = 0; @@ -241,7 +243,7 @@ InitHash (void) hash_scale[1] = newsize[1] / size[1]; hash_scale[2] = newsize[1]; - hvert_p = hvertex; + PR_RESRESET (hvertex); } /** Calulate the hash value of a vector. @@ -302,7 +304,7 @@ GetVertex (const vec3_t in, int planenum) } } - hv = hvert_p; + hv = PR_RESNEW (hvertex); hv->numedges = 1; hv->numplanes = 1; hv->planenums[0] = planenum; @@ -310,14 +312,8 @@ GetVertex (const vec3_t in, int planenum) hashverts[h] = hv; VectorCopy (vert, hv->point); hv->num = bsp->numvertexes; - if (hv->num == MAX_MAP_VERTS) - Sys_Error ("GetVertex: MAX_MAP_VERTS"); - hvert_p++; // emit a vertex - if (bsp->numvertexes == MAX_MAP_VERTS) - Sys_Error ("numvertexes == MAX_MAP_VERTS"); - v.point[0] = vert[0]; v.point[1] = vert[1]; v.point[2] = vert[2]; diff --git a/tools/qfbsp/source/writebsp.c b/tools/qfbsp/source/writebsp.c index 9001b92dc..28943c145 100644 --- a/tools/qfbsp/source/writebsp.c +++ b/tools/qfbsp/source/writebsp.c @@ -67,14 +67,12 @@ FindFinalPlane (const dplane_t *p) } // new plane - if (bsp->numplanes == MAX_MAP_PLANES) - Sys_Error ("numplanes == MAX_MAP_PLANES"); BSP_AddPlane (bsp, p); return bsp->numplanes - 1; } -int planemapping[MAX_MAP_PLANES]; +static struct DARRAY_TYPE(int) planemapping = DARRAY_STATIC_INIT (1024); /** Recursively write the nodes' planes to the bsp file. @@ -91,10 +89,10 @@ WriteNodePlanes_r (node_t *node) if (node->planenum == -1) return; - if (planemapping[node->planenum] == -1) { // a new plane - planemapping[node->planenum] = bsp->numplanes; + if (planemapping.a[node->planenum] == -1) { // a new plane + planemapping.a[node->planenum] = bsp->numplanes; - plane = &planes[node->planenum]; + plane = &planes.a[node->planenum]; VectorCopy (plane->normal, dplane.normal); dplane.dist = plane->dist; @@ -102,7 +100,7 @@ WriteNodePlanes_r (node_t *node) BSP_AddPlane (bsp, &dplane); } - node->outputplanenum = planemapping[node->planenum]; + node->outputplanenum = planemapping.a[node->planenum]; WriteNodePlanes_r (node->children[0]); WriteNodePlanes_r (node->children[1]); @@ -111,7 +109,8 @@ WriteNodePlanes_r (node_t *node) void WriteNodePlanes (node_t *nodes) { - memset (planemapping, -1, sizeof (planemapping)); + DARRAY_RESIZE (&planemapping, planes.size); + memset (planemapping.a, -1, planemapping.size * sizeof (planemapping.a[0])); WriteNodePlanes_r (nodes); } @@ -176,8 +175,6 @@ WriteLeaf (const node_t *node) for (fp = node->markfaces; *fp; fp++) { // emit a marksurface - if (bsp->nummarksurfaces == MAX_MAP_MARKSURFACES) - Sys_Error ("nummarksurfaces == MAX_MAP_MARKSURFACES"); f = *fp; if (f->texturenum < 0) continue; @@ -206,8 +203,6 @@ WriteDrawNodes_r (const node_t *node) int nodenum = bsp->numnodes; // emit a node - if (bsp->numnodes == MAX_MAP_NODES) - Sys_Error ("numnodes == MAX_MAP_NODES"); BSP_AddNode (bsp, &dummy); n = &bsp->nodes[nodenum];