From ee596f3ff16e9a8ef660267b68e71565f443a5f3 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 23 Jun 2022 16:18:52 -0400 Subject: [PATCH] use vector for vis state set autoclean default to true, make it invertable --- include/vis/vis.hh | 2 +- qbsp/map.cc | 2 +- qbsp/tjunc.cc | 19 +++++++++---------- vis/state.cc | 17 ++++++----------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/include/vis/vis.hh b/include/vis/vis.hh index dc6ceee1..cf2d9c23 100644 --- a/include/vis/vis.hh +++ b/include/vis/vis.hh @@ -229,7 +229,7 @@ public: this, "visdist", 0.0, &advanced_group, "control the distance required for a portal to be considered seen"}; setting_bool nostate{this, "nostate", false, &advanced_group, "ignore saved state files, for forced re-runs"}; setting_bool phsonly{this, "phsonly", false, &advanced_group, "re-calculate the PHS of a Quake II BSP without touching the PVS"}; - setting_bool autoclean{this, "autoclean", false, &output_group, "remove any extra files on successful completion"}; + setting_invertible_bool autoclean{this, "autoclean", true, &output_group, "remove any extra files on successful completion"}; fs::path sourceMap; diff --git a/qbsp/map.cc b/qbsp/map.cc index 25f3fe75..b46db3ca 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -1511,7 +1511,7 @@ static std::unique_ptr ParseBrushFace(parser_t &parser, const mapbrus bool normal_ok; maptexinfo_t tx; int i, j; - std::unique_ptr face{new mapface_t}; + std::unique_ptr face = std::make_unique(); face->linenum = parser.linenum; ParsePlaneDef(parser, planepts); diff --git a/qbsp/tjunc.cc b/qbsp/tjunc.cc index d53a972c..05ac55dd 100644 --- a/qbsp/tjunc.cc +++ b/qbsp/tjunc.cc @@ -46,8 +46,8 @@ static int tjuncfaces; static int cWVerts; static int cWEdges; -static wvert_t *pWVerts; -static wedge_t *pWEdges; +static std::vector pWVerts; +static std::vector pWEdges; //============================================================================ @@ -155,7 +155,7 @@ static wedge_t *FindEdge(const qvec3d &p1, const qvec3d &p2, vec_t &t1, vec_t &t if (numwedges >= cWEdges) FError("Internal error: didn't allocate enough edges for tjuncs?"); - edge = pWEdges + numwedges; + edge = &pWEdges[numwedges]; numwedges++; edge->next = wedge_hash[h]; @@ -192,7 +192,7 @@ static void AddVert(wedge_t *edge, vec_t t) if (numwverts >= cWVerts) FError("Internal error: didn't allocate enough vertices for tjuncs?"); - newv = pWVerts + numwverts; + newv = &pWVerts[numwverts]; numwverts++; newv->t = t; @@ -418,9 +418,11 @@ void TJunc(const mapentity_t *entity, node_t *headnode) tjunc_count_r(headnode); cWEdges = cWVerts; cWVerts *= 2; - - pWVerts = new wvert_t[cWVerts]{}; - pWEdges = new wedge_t[cWEdges]{}; + + pWVerts.clear(); + pWEdges.clear(); + pWVerts.resize(cWVerts); + pWEdges.resize(cWEdges); qvec3d maxs; /* @@ -448,9 +450,6 @@ void TJunc(const mapentity_t *entity, node_t *headnode) tjuncs = tjuncfaces = 0; tjunc_fix_r(headnode); - delete[] pWVerts; - delete[] pWEdges; - logging::print(logging::flag::STAT, " {:8} edges added by tjunctions\n", tjuncs); logging::print(logging::flag::STAT, " {:8} faces added by tjunctions\n", tjuncfaces); } diff --git a/vis/state.cc b/vis/state.cc index 02fd9330..69e30e06 100644 --- a/vis/state.cc +++ b/vis/state.cc @@ -136,8 +136,6 @@ void SaveVisState(void) const portal_t *p; dvisstate_t state; dportal_t pstate; - uint8_t *vis; - uint8_t *might; std::ofstream out(statetmpfile, std::ios_base::out | std::ios_base::binary); out << endianness; @@ -152,13 +150,13 @@ void SaveVisState(void) out <= state; /* Allocate memory for compressed bitstrings */ - might = new uint8_t[(portalleafs + 7) >> 3]; - vis = new uint8_t[(portalleafs + 7) >> 3]; + std::vector might((portalleafs + 7) >> 3); + std::vector vis((portalleafs + 7) >> 3); for (i = 0, p = portals; i < numportals * 2; i++, p++) { - might_len = CompressBits(might, p->mightsee); + might_len = CompressBits(might.data(), p->mightsee); if (p->status == pstat_done) - vis_len = CompressBits(vis, p->visbits); + vis_len = CompressBits(vis.data(), p->visbits); else vis_len = 0; @@ -169,16 +167,13 @@ void SaveVisState(void) pstate.numcansee = p->numcansee; out <= pstate; - out.write((const char *) might, might_len); + out.write((const char *) might.data(), might_len); if (vis_len) - out.write((const char *) vis, vis_len); + out.write((const char *) vis.data(), vis_len); } out.close(); - delete[] might; - delete[] vis; - std::error_code ec; fs::remove(statefile, ec);