From 54799a11fc11880e636d0c709312928c5f77f968 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Sat, 4 Sep 2021 11:47:33 -0600 Subject: [PATCH] qbsp: restore bspx brushes writing --- include/qbsp/map.hh | 8 +++----- qbsp/qbsp.cc | 31 +++++++++++++++---------------- qbsp/writebsp.cc | 3 +++ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 3e87b930..36d24d1e 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -173,6 +173,7 @@ typedef struct mapdata_s { // bspx data std::vector exported_lmshifts; bool needslmshifts = false; + std::vector exported_bspxbrushes; // helpers std::string texinfoTextureName(int texinfo) const { @@ -222,11 +223,8 @@ int MakeFaceEdges(mapentity_t *entity, node_t *headnode); void ExportClipNodes(mapentity_t *entity, node_t *headnode, const int hullnum); void ExportDrawNodes(mapentity_t *entity, node_t *headnode, int firstface); -struct bspxbrushes_s -{ - uint8_t *lumpinfo; - size_t lumpsize; - size_t lumpmaxsize; +struct bspxbrushes_s { + std::vector lumpdata; }; void BSPX_Brushes_Finalize(struct bspxbrushes_s *ctx); void BSPX_Brushes_Init(struct bspxbrushes_s *ctx); diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 1ac89c8a..812db5d6 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -316,14 +316,21 @@ This lump replaces the clipnodes stuff for custom collision sizes. */ void BSPX_Brushes_Finalize(struct bspxbrushes_s *ctx) { - //BSPX_AddLump("BRUSHLIST", ctx->lumpinfo, ctx->lumpsize); // FIXME: fix bspx - -// free(ctx->lumpinfo); + // Actually written in WriteBSPFile() + map.exported_bspxbrushes = std::move(ctx->lumpdata); } void BSPX_Brushes_Init(struct bspxbrushes_s *ctx) { - memset(ctx, 0, sizeof(*ctx)); + ctx->lumpdata.clear(); } + +static void +vec_push_bytes(std::vector& vec, const void* data, size_t count) { + const uint8_t* bytes = static_cast(data); + + vec.insert(vec.end(), bytes, bytes + count); +} + /* WriteBrushes Generates a submodel's direct brush information to a separate file, so the engine doesn't need to depend upon specific hull sizes @@ -372,18 +379,11 @@ void BSPX_Brushes_AddModel(struct bspxbrushes_s *ctx, int modelnum, brush_t *bru } } - if (ctx->lumpmaxsize < ctx->lumpsize + sizeof(permodel) + permodel.numbrushes*sizeof(perbrush) + permodel.numfaces*sizeof(perface)) - { - ctx->lumpmaxsize = (ctx->lumpsize + sizeof(permodel) + permodel.numbrushes*sizeof(perbrush) + permodel.numfaces*sizeof(perface))*2; - ctx->lumpinfo = (uint8_t *) realloc(ctx->lumpinfo, ctx->lumpmaxsize); - } - permodel.ver = LittleLong(1); permodel.modelnum = LittleLong(modelnum); permodel.numbrushes = LittleLong(permodel.numbrushes); permodel.numfaces = LittleLong(permodel.numfaces); - memcpy(ctx->lumpinfo+ctx->lumpsize, &permodel, sizeof(permodel)); - ctx->lumpsize += sizeof(permodel); + vec_push_bytes(ctx->lumpdata, &permodel, sizeof(permodel)); for (b = brushes; b; b = b->next) { @@ -428,8 +428,7 @@ void BSPX_Brushes_AddModel(struct bspxbrushes_s *ctx, int modelnum, brush_t *bru } perbrush.contents = LittleShort(perbrush.contents); perbrush.numfaces = LittleShort(perbrush.numfaces); - memcpy(ctx->lumpinfo+ctx->lumpsize, &perbrush, sizeof(perbrush)); - ctx->lumpsize += sizeof(perbrush); + vec_push_bytes(ctx->lumpdata, &perbrush, sizeof(perbrush)); for (f = b->faces; f; f = f->next) { @@ -454,11 +453,11 @@ void BSPX_Brushes_AddModel(struct bspxbrushes_s *ctx, int modelnum, brush_t *bru perface.dist = map.planes[f->planenum].dist; } - memcpy(ctx->lumpinfo+ctx->lumpsize, &perface, sizeof(perface)); - ctx->lumpsize += sizeof(perface); + vec_push_bytes(ctx->lumpdata, &perface, sizeof(perface)); } } } + /* for generating BRUSHLIST bspx lump */ static void BSPX_CreateBrushList(void) { diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index 5f5b65cb..e24ede16 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -441,6 +441,9 @@ WriteBSPFile() if (map.needslmshifts) { BSPX_AddLump(&bspdata, "LMSHIFT", map.exported_lmshifts.data(), map.exported_lmshifts.size()); } + if (!map.exported_bspxbrushes.empty()) { + BSPX_AddLump(&bspdata, "BRUSHLIST", map.exported_bspxbrushes.data(), map.exported_bspxbrushes.size()); + } ConvertBSPFormat(&bspdata, options.target_version);