From 8a71b372bd9141b20e607c77dcfced17e62760b5 Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Fri, 15 Apr 2022 00:25:29 -0600 Subject: [PATCH] qbsp: remove unnecessary num*() helpers from mapdata_t --- include/qbsp/map.hh | 12 ++---------- qbsp/brush.cc | 2 +- qbsp/map.cc | 18 +++++++++--------- qbsp/outside.cc | 2 +- qbsp/qbsp.cc | 21 +++++++++------------ qbsp/wad.cc | 10 +++++----- 6 files changed, 27 insertions(+), 38 deletions(-) diff --git a/include/qbsp/map.hh b/include/qbsp/map.hh index 23e58885..03eb6e1f 100644 --- a/include/qbsp/map.hh +++ b/include/qbsp/map.hh @@ -132,16 +132,8 @@ struct mapdata_t /* map from plane hash code to list of indicies in `planes` vector */ std::unordered_map> planehash; - /* Number of items currently used */ - int numfaces() const { return faces.size(); }; - int numbrushes() const { return brushes.size(); }; - int numentities() const { return entities.size(); }; - int numplanes() const { return planes.size(); }; - int nummiptex() const { return miptex.size(); }; - int numtexinfo() const { return mtexinfos.size(); }; - /* Misc other global state for the compile process */ - bool leakfile; /* Flag once we've written a leak (.por/.pts) file */ + bool leakfile = false; /* Flag once we've written a leak (.por/.pts) file */ // Final, exported BSP mbsp_t bsp; @@ -152,7 +144,7 @@ struct mapdata_t std::vector exported_bspxbrushes; // Q2 stuff - int32_t numareaportals; + int32_t numareaportals = 0; // misc int start_spots = 0; diff --git a/qbsp/brush.cc b/qbsp/brush.cc index 9a741d94..4f12d925 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -995,7 +995,7 @@ brush_stats_t Brush_LoadEntity(mapentity_t *entity, const int hullnum) * We no longer care about the order of adding func_detail and func_group, * Entity_SortBrushes will sort the brushes */ - for (int i = 1; i < map.numentities(); i++) { + for (int i = 1; i < map.entities.size(); i++) { mapentity_t *source = &map.entities.at(i); /* Load external .map and change the classname, if needed */ diff --git a/qbsp/map.cc b/qbsp/map.cc index 63bb8ab3..a2e741e5 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -122,11 +122,11 @@ static void AddAnimTex(const char *name) snprintf(framename, sizeof(framename), "%s", name); for (i = 0; i < frame; i++) { framename[1] = basechar + i; - for (j = 0; j < map.nummiptex(); j++) { + for (j = 0; j < map.miptex.size(); j++) { if (!Q_strcasecmp(framename, map.miptex.at(j).name.c_str())) break; } - if (j < map.nummiptex()) + if (j < map.miptex.size()) continue; map.miptex.push_back({framename}); @@ -171,7 +171,7 @@ int FindMiptex(const char *name, std::optional &extended_inf extended_info = extended_texinfo_t{}; } - for (i = 0; i < map.nummiptex(); i++) { + for (i = 0; i < map.miptex.size(); i++) { const texdata_t &tex = map.miptex.at(i); if (!Q_strcasecmp(name, tex.name.c_str())) { @@ -198,7 +198,7 @@ int FindMiptex(const char *name, std::optional &extended_inf extended_info = extended_texinfo_t{}; } - for (i = 0; i < map.nummiptex(); i++) { + for (i = 0; i < map.miptex.size(); i++) { const texdata_t &tex = map.miptex.at(i); if (!Q_strcasecmp(name, tex.name.c_str()) && tex.flags.native == extended_info->flags.native && @@ -1899,11 +1899,11 @@ void LoadMapFile(void) // if (!(map.start_spots & info_player_coop)) // logging::print("WARNING: No info_player_coop entities in level\n"); - logging::print(logging::flag::STAT, " {:8} faces\n", map.numfaces()); - logging::print(logging::flag::STAT, " {:8} brushes\n", map.numbrushes()); - logging::print(logging::flag::STAT, " {:8} entities\n", map.numentities()); - logging::print(logging::flag::STAT, " {:8} unique texnames\n", map.nummiptex()); - logging::print(logging::flag::STAT, " {:8} texinfo\n", map.numtexinfo()); + logging::print(logging::flag::STAT, " {:8} faces\n", map.faces.size()); + logging::print(logging::flag::STAT, " {:8} brushes\n", map.brushes.size()); + logging::print(logging::flag::STAT, " {:8} entities\n", map.entities.size()); + logging::print(logging::flag::STAT, " {:8} unique texnames\n", map.miptex.size()); + logging::print(logging::flag::STAT, " {:8} texinfo\n", map.mtexinfos.size()); logging::print(logging::flag::STAT, "\n"); if (options.expand.value()) { diff --git a/qbsp/outside.cc b/qbsp/outside.cc index 126252ad..65b3d9ca 100644 --- a/qbsp/outside.cc +++ b/qbsp/outside.cc @@ -298,7 +298,7 @@ std::vector FindOccupiedClusters(node_t *headnode) { std::vector result; - for (int i = 1; i < map.numentities(); i++) { + for (int i = 1; i < map.entities.size(); i++) { mapentity_t *entity = &map.entities.at(i); /* skip entities at (0 0 0) (bmodels) */ diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index b1ef3de8..a02c9994 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -648,7 +648,7 @@ static void ProcessEntity(mapentity_t *entity, const int hullnum) logging::print(logging::flag::STAT, " {:8} liquid brushes\n", stats.liquid); } - logging::print(logging::flag::STAT, " {:8} planes\n", map.numplanes()); + logging::print(logging::flag::STAT, " {:8} planes\n", map.planes.size()); if (hullnum > 0) { nodes = SolidBSP(entity, true); @@ -757,14 +757,14 @@ UpdateEntLump */ static void UpdateEntLump(void) { - int modnum, i; + int modnum; char modname[10]; mapentity_t *entity; logging::print(logging::flag::STAT, " Updating entities lump...\n"); modnum = 1; - for (i = 1; i < map.numentities(); i++) { + for (int i = 1; i < map.entities.size(); i++) { entity = &map.entities.at(i); /* Special handling for misc_external_map. @@ -922,10 +922,6 @@ static void BSPX_Brushes_AddModel(struct bspxbrushes_s *ctx, int modelnum, std:: /* for generating BRUSHLIST bspx lump */ static void BSPX_CreateBrushList(void) { - mapentity_t *ent; - int entnum; - int modelnum; - const char *mod; struct bspxbrushes_s ctx; if (!options.wrbrushes.value()) @@ -933,12 +929,13 @@ static void BSPX_CreateBrushList(void) BSPX_Brushes_Init(&ctx); - for (entnum = 0; entnum < map.numentities(); entnum++) { - ent = &map.entities.at(entnum); - if (ent == map.world_entity()) + for (int entnum = 0; entnum < map.entities.size(); ++entnum) { + mapentity_t *ent = &map.entities.at(entnum); + int modelnum; + if (ent == map.world_entity()) { modelnum = 0; - else { - mod = ValueForKey(ent, "model"); + } else { + const char *mod = ValueForKey(ent, "model"); if (*mod != '*') continue; modelnum = atoi(mod + 1); diff --git a/qbsp/wad.cc b/qbsp/wad.cc index 18661025..5c74bd22 100644 --- a/qbsp/wad.cc +++ b/qbsp/wad.cc @@ -264,7 +264,7 @@ static bool WAD_LoadLump(const wad_t &wad, const char *name, miptexhl_t &dest) static void WADList_LoadTextures() { - for (size_t i = 0; i < map.nummiptex(); i++) { + for (size_t i = 0; i < map.miptex.size(); i++) { // already loaded? if (map.bsp.dtex.textures[i].data[0]) continue; @@ -278,7 +278,7 @@ static void WADList_LoadTextures() static void WADList_AddAnimationFrames() { - size_t oldcount = map.nummiptex(); + size_t oldcount = map.miptex.size(); for (size_t i = 0; i < oldcount; i++) { const std::string &existing_name = map.miptexTextureName(i); @@ -294,7 +294,7 @@ static void WADList_AddAnimationFrames() } } - logging::print(logging::flag::STAT, " {:8} texture frames added\n", map.nummiptex() - oldcount); + logging::print(logging::flag::STAT, " {:8} texture frames added\n", map.miptex.size() - oldcount); } void WADList_Process() @@ -307,12 +307,12 @@ void WADList_Process() } /* Default texture data to store in worldmodel */ - map.bsp.dtex.textures.resize(map.nummiptex()); + map.bsp.dtex.textures.resize(map.miptex.size()); WADList_LoadTextures(); /* Last pass, mark unfound textures as such */ - for (size_t i = 0; i < map.nummiptex(); i++) { + for (size_t i = 0; i < map.miptex.size(); i++) { if (!map.bsp.dtex.textures[i].data[0]) { logging::print("WARNING: Texture {} not found\n", map.miptexTextureName(i)); }