From 014770b212a4705e83254440547c4e7d8b1a7213 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sun, 2 Jul 2017 17:18:19 -0600 Subject: [PATCH] qbsp: refactor GrowNodeRegion --- qbsp/surfaces.cc | 140 ++++++++++++++++++----------------------------- 1 file changed, 53 insertions(+), 87 deletions(-) diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index a9a8edc1..ab1a85c8 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -442,20 +442,60 @@ MakeFaceEdges_r(mapentity_t *entity, node_t *node, int progress) return progress; } +/* +============== +EmitFace +============== +*/ +template +static void +EmitFace(mapentity_t *entity, face_t *face) +{ + struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES]; + struct lumpdata *faces = &entity->lumps[LUMP_FACES]; + struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT]; + DFACE *out; + int i; + + if (map.mtexinfos.at(face->texinfo).flags & (TEX_SKIP | TEX_HINT)) + return; + + // emit a region + face->outputnumber = map.cTotal[LUMP_FACES]; + if (lmshifts->data) + ((unsigned char*)lmshifts->data)[faces->index] = face->lmshift[1]; + out = (DFACE *)faces->data + faces->index; + out->planenum = ExportMapPlane(face->planenum); + out->side = face->planeside; + out->texinfo = face->texinfo; + for (i = 0; i < MAXLIGHTMAPS; i++) + out->styles[i] = 255; + out->lightofs = -1; + + out->firstedge = map.cTotal[LUMP_SURFEDGES]; + for (i = 0; i < face->w.numpoints; i++) { + ((int *)surfedges->data)[surfedges->index] = face->edges[i]; + surfedges->index++; + map.cTotal[LUMP_SURFEDGES]++; + } + FreeMem(face->edges, OTHER, face->w.numpoints * sizeof(int)); + + out->numedges = map.cTotal[LUMP_SURFEDGES] - out->firstedge; + + map.cTotal[LUMP_FACES]++; + faces->index++; +} + /* ============== GrowNodeRegion ============== */ +template static void -GrowNodeRegion_BSP29(mapentity_t *entity, node_t *node) +GrowNodeRegion(mapentity_t *entity, node_t *node) { - struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES]; - struct lumpdata *faces = &entity->lumps[LUMP_FACES]; - struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT]; - bsp29_dface_t *out; face_t *face; - int i; if (node->planenum == PLANENUM_LEAF) return; @@ -463,90 +503,16 @@ GrowNodeRegion_BSP29(mapentity_t *entity, node_t *node) node->firstface = map.cTotal[LUMP_FACES]; for (face = node->faces; face; face = face->next) { - if (map.mtexinfos.at(face->texinfo).flags & (TEX_SKIP | TEX_HINT)) - continue; - + Q_assert(face->planenum == node->planenum); + // emit a region - face->outputnumber = map.cTotal[LUMP_FACES]; - if (lmshifts->data) - ((unsigned char*)lmshifts->data)[faces->index] = face->lmshift[1]; - out = (bsp29_dface_t *)faces->data + faces->index; - out->planenum = ExportMapPlane(node->planenum); - out->side = face->planeside; - out->texinfo = face->texinfo; - for (i = 0; i < MAXLIGHTMAPS; i++) - out->styles[i] = 255; - out->lightofs = -1; - - out->firstedge = map.cTotal[LUMP_SURFEDGES]; - for (i = 0; i < face->w.numpoints; i++) { - ((int *)surfedges->data)[surfedges->index] = face->edges[i]; - surfedges->index++; - map.cTotal[LUMP_SURFEDGES]++; - } - FreeMem(face->edges, OTHER, face->w.numpoints * sizeof(int)); - - out->numedges = map.cTotal[LUMP_SURFEDGES] - out->firstedge; - - map.cTotal[LUMP_FACES]++; - faces->index++; + EmitFace(entity, face); } node->numfaces = map.cTotal[LUMP_FACES] - node->firstface; - GrowNodeRegion_BSP29(entity, node->children[0]); - GrowNodeRegion_BSP29(entity, node->children[1]); -} - -static void -GrowNodeRegion_BSP2(mapentity_t *entity, node_t *node) -{ - struct lumpdata *surfedges = &entity->lumps[LUMP_SURFEDGES]; - struct lumpdata *faces = &entity->lumps[LUMP_FACES]; - struct lumpdata *lmshifts = &entity->lumps[BSPX_LMSHIFT]; - bsp2_dface_t *out; - face_t *face; - int i; - - if (node->planenum == PLANENUM_LEAF) - return; - - node->firstface = map.cTotal[LUMP_FACES]; - - for (face = node->faces; face; face = face->next) { - if (map.mtexinfos.at(face->texinfo).flags & (TEX_SKIP | TEX_HINT)) - continue; - - // emit a region - face->outputnumber = map.cTotal[LUMP_FACES]; - if (lmshifts->data) - ((unsigned char*)lmshifts->data)[faces->index] = face->lmshift[1]; - out = (bsp2_dface_t *)faces->data + faces->index; - out->planenum = ExportMapPlane(node->planenum); - out->side = face->planeside; - out->texinfo = face->texinfo; - for (i = 0; i < MAXLIGHTMAPS; i++) - out->styles[i] = 255; - out->lightofs = -1; - - out->firstedge = map.cTotal[LUMP_SURFEDGES]; - for (i = 0; i < face->w.numpoints; i++) { - ((int *)surfedges->data)[surfedges->index] = face->edges[i]; - surfedges->index++; - map.cTotal[LUMP_SURFEDGES]++; - } - FreeMem(face->edges, OTHER, face->w.numpoints * sizeof(int)); - - out->numedges = map.cTotal[LUMP_SURFEDGES] - out->firstedge; - - map.cTotal[LUMP_FACES]++; - faces->index++; - } - - node->numfaces = map.cTotal[LUMP_FACES] - node->firstface; - - GrowNodeRegion_BSP2(entity, node->children[0]); - GrowNodeRegion_BSP2(entity, node->children[1]); + GrowNodeRegion(entity, node->children[0]); + GrowNodeRegion(entity, node->children[1]); } /* @@ -656,9 +622,9 @@ MakeFaceEdges(mapentity_t *entity, node_t *headnode) Message(msgProgress, "GrowRegions"); if (options.BSPVersion == BSPVERSION) - GrowNodeRegion_BSP29(entity, headnode); + GrowNodeRegion(entity, headnode); else - GrowNodeRegion_BSP2(entity, headnode); + GrowNodeRegion(entity, headnode); return firstface; }