From fd18fc154c3b26d22eb31122ed8a1b2458441903 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 12 Oct 2021 14:39:15 -0400 Subject: [PATCH] Fix various warnings by testing a clang-cl compile --- common/bspfile.cc | 16 ++++++++-------- common/cmdlib.cc | 2 -- include/common/bspfile.hh | 13 +++++++++---- include/light/settings.hh | 4 ++-- include/vis/vis.hh | 4 ++-- light/light.cc | 19 ++++++------------- light/ltface.cc | 8 ++++++-- light/phong.cc | 2 +- light/trace_embree.cc | 1 - qbsp/map.cc | 3 ++- qbsp/qbsp.cc | 2 ++ qbsp/surfaces.cc | 2 +- qbsp/writebsp.cc | 10 ---------- vis/soundpvs.cc | 2 +- 14 files changed, 40 insertions(+), 48 deletions(-) diff --git a/common/bspfile.cc b/common/bspfile.cc index 83441b79..02c9351f 100644 --- a/common/bspfile.cc +++ b/common/bspfile.cc @@ -850,15 +850,15 @@ bool ConvertBSPFormat(bspdata_t *bspdata, const bspversion_t *to_version) try { if (to_version == &bspver_q1 || to_version == &bspver_h2 || to_version == &bspver_hl) { - bspdata->bsp = std::move(ConvertGenericToQ1BSP(mbsp, to_version)); + bspdata->bsp = ConvertGenericToQ1BSP(mbsp, to_version); } else if (to_version == &bspver_q2) { - bspdata->bsp = std::move(ConvertGenericToQ2BSP(mbsp, to_version)); + bspdata->bsp = ConvertGenericToQ2BSP(mbsp, to_version); } else if (to_version == &bspver_qbism) { - bspdata->bsp = std::move(ConvertGenericToQ2BSP(mbsp, to_version)); + bspdata->bsp = ConvertGenericToQ2BSP(mbsp, to_version); } else if (to_version == &bspver_bsp2rmq || to_version == &bspver_h2bsp2rmq) { - bspdata->bsp = std::move(ConvertGenericToQ1BSP(mbsp, to_version)); + bspdata->bsp = ConvertGenericToQ1BSP(mbsp, to_version); } else if (to_version == &bspver_bsp2 || to_version == &bspver_h2bsp2) { - bspdata->bsp = std::move(ConvertGenericToQ1BSP(mbsp, to_version)); + bspdata->bsp = ConvertGenericToQ1BSP(mbsp, to_version); } else { return false; } @@ -1273,12 +1273,12 @@ public: write_lump(LUMP_MARKSURFACES, bsp.dmarksurfaces); write_lump(LUMP_SURFEDGES, bsp.dsurfedges); write_lump(LUMP_EDGES, bsp.dedges); - std::visit([this](auto&& arg) { write_lump(LUMP_MODELS, arg); }, bsp.dmodels); + std::visit([this](auto&& arg) { this->write_lump(LUMP_MODELS, arg); }, bsp.dmodels); write_lump(LUMP_LIGHTING, bsp.dlightdata); write_lump(LUMP_VISIBILITY, bsp.dvisdata); write_lump(LUMP_ENTITIES, bsp.dentdata); - std::visit([this](auto&& arg) { write_lump(LUMP_TEXTURES, arg); }, bsp.dtex); + std::visit([this](auto&& arg) { this->write_lump(LUMP_TEXTURES, arg); }, bsp.dtex); } template, int> = 0> @@ -1318,7 +1318,7 @@ public: auto bspxheader = stream.tellp(); // write dummy lump headers - for (auto &x : bspdata.bspx.entries) { + for ([[maybe_unused]] auto &_ : bspdata.bspx.entries) { stream <= bspx_lump_t{}; } diff --git a/common/cmdlib.cc b/common/cmdlib.cc index 0e571ad6..3f0b0171 100644 --- a/common/cmdlib.cc +++ b/common/cmdlib.cc @@ -39,8 +39,6 @@ #include -constexpr char PATHSEPERATOR = '/'; - /* set these before calling CheckParm */ int myargc; char **myargv; diff --git a/include/common/bspfile.hh b/include/common/bspfile.hh index b682acf4..0be17d49 100644 --- a/include/common/bspfile.hh +++ b/include/common/bspfile.hh @@ -272,6 +272,11 @@ struct miptex_t std::string name; uint32_t width, height; std::array, MIPLEVELS> data; + + miptex_t() = default; + miptex_t(miptex_t &&) = default; + + virtual ~miptex_t() { } virtual void stream_read(std::istream &stream) { @@ -827,8 +832,8 @@ struct texvec : qmat template constexpr qvec uvs(const qvec &pos) const { - return {(pos[0] * at(0, 0) + pos[1] * at(0, 1) + pos[2] * at(0, 2) + at(0, 3)), - (pos[0] * at(1, 0) + pos[1] * at(1, 1) + pos[2] * at(1, 2) + at(1, 3))}; + return {(pos[0] * this->at(0, 0) + pos[1] * this->at(0, 1) + pos[2] * this->at(0, 2) + this->at(0, 3)), + (pos[0] * this->at(1, 0) + pos[1] * this->at(1, 1) + pos[2] * this->at(1, 2) + this->at(1, 3))}; } template @@ -844,7 +849,7 @@ struct texvec : qmat { for (size_t i = 0; i < 2; i++) for (size_t x = 0; x < 4; x++) { - stream >= at(i, x); + stream >= this->at(i, x); } } @@ -852,7 +857,7 @@ struct texvec : qmat { for (size_t i = 0; i < 2; i++) for (size_t x = 0; x < 4; x++) { - stream <= at(i, x); + stream <= this->at(i, x); } } }; diff --git a/include/light/settings.hh b/include/light/settings.hh index f3e5a449..0bce1bed 100644 --- a/include/light/settings.hh +++ b/include/light/settings.hh @@ -124,7 +124,7 @@ public: class lockable_bool_t : public lockable_setting_t { private: - bool _default, _value; + [[maybe_unused]] bool _default, _value; void setBoolValueInternal(bool f, setting_source_t newsource) { @@ -161,7 +161,7 @@ public: class lockable_vec_t : public lockable_setting_t { private: - vec_t _default, _value, _min, _max; + [[maybe_unused]] vec_t _default, _value, _min, _max; inline void setFloatInternal(vec_t f, setting_source_t newsource) { diff --git a/include/vis/vis.hh b/include/vis/vis.hh index 83dea543..3dbcaa54 100644 --- a/include/vis/vis.hh +++ b/include/vis/vis.hh @@ -60,10 +60,10 @@ struct winding_t : polylib::winding_base_t using winding_base_t::winding_base_t; // copy constructor - winding_t(const winding_t ©) : origin(copy.origin), radius(copy.radius), winding_base_t(copy) { } + winding_t(const winding_t ©) : winding_base_t(copy), origin(copy.origin), radius(copy.radius) { } // move constructor - winding_t(winding_t &&move) : origin(move.origin), radius(move.radius), winding_base_t(move) { } + winding_t(winding_t &&move) : winding_base_t(move), origin(move.origin), radius(move.radius) { } // assignment copy inline winding_t &operator=(const winding_t ©) diff --git a/light/light.cc b/light/light.cc index 62f6f5bb..5e41b465 100644 --- a/light/light.cc +++ b/light/light.cc @@ -521,19 +521,6 @@ static void LoadExtendedTexinfoFlags(const std::filesystem::path &sourcefilename // obj -static qfile_t InitObjFile(const std::filesystem::path &filename) -{ - std::filesystem::path objfilename(filename); - objfilename.replace_extension("obj"); - - qfile_t objfile = SafeOpenWrite(objfilename); - - if (!objfile) - FError("Failed to open {}: {}", objfilename, strerror(errno)); - - return objfile; -} - static void ExportObjFace(std::ofstream &f, const mbsp_t *bsp, const mface_t *face, int *vertcount) { // export the vertices and uvs @@ -697,6 +684,7 @@ static void CheckLitNeeded(const globalconfig_t &cfg) } } +#if 0 static void PrintLight(const light_t &light) { bool first = true; @@ -726,6 +714,7 @@ static void PrintLights(void) PrintLight(light); } } +#endif static void PrintUsage() { @@ -846,6 +835,7 @@ static bool ParseIntOptional(int *result, int *i_inout, int argc, const char **a } } +#if 0 static const char *ParseStringOptional(int *i_inout, int argc, const char **argv) { if ((*i_inout + 1) < argc) { @@ -854,6 +844,7 @@ static const char *ParseStringOptional(int *i_inout, int argc, const char **argv return NULL; } } +#endif static void ParseVec3(vec3_t vec3_out, int *i_inout, int argc, const char **argv) { @@ -887,6 +878,7 @@ static int ParseInt(int *i_inout, int argc, const char **argv) return result; } +#if 0 static const char *ParseString(int *i_inout, int argc, const char **argv) { const char *result = NULL; @@ -895,6 +887,7 @@ static const char *ParseString(int *i_inout, int argc, const char **argv) } return result; } +#endif static inline void WriteNormals(const mbsp_t &bsp, bspdata_t &bspdata) { diff --git a/light/ltface.cc b/light/ltface.cc index 6fbda310..47631453 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -818,6 +818,7 @@ static void Lightmap_AllocOrClear(lightmap_t *lightmap, const lightsurf_t *light } } +#if 0 static const lightmap_t *Lightmap_ForStyle_ReadOnly(const lightsurf_t *lightsurf, const int style) { for (const auto &lm : lightsurf->lightmapsByStyle) { @@ -826,6 +827,7 @@ static const lightmap_t *Lightmap_ForStyle_ReadOnly(const lightsurf_t *lightsurf } return nullptr; } +#endif /* * Lightmap_ForStyle @@ -2278,8 +2280,6 @@ static void LightFace_DebugNeighbours(lightsurf_t *lightsurf, lightmapdict_t *li /* use a style 0 light map */ lightmap_t *lightmap = Lightmap_ForStyle(lightmaps, 0, lightsurf); - const int fnum = Face_GetNum(lightsurf->bsp, lightsurf->face); - // std::vector neighbours = NeighbouringFaces_new(lightsurf->bsp, BSP_GetFace(lightsurf->bsp, // dump_facenum)); bool found = false; for (auto &f : neighbours) { // if (f.face == lightsurf->face) @@ -2611,6 +2611,7 @@ static float Lightmap_MaxBrightness(const lightmap_t *lm, const lightsurf_t *lig return maxb; } +#if 0 static void WritePPM(const std::filesystem::path &fname, int width, int height, const uint8_t *rgbdata) { qfile_t file = SafeOpenWrite(fname); @@ -2675,6 +2676,7 @@ static void DumpDownscaledLightmap(const mbsp_t *bsp, const mface_t *face, int w WritePPM(fmt::format("face-small{:04}.ppm", fnum), w, h, rgbdata.data()); } +#endif static std::vector LightmapColorsToGLMVector(const lightsurf_t *lightsurf, const lightmap_t *lm) { @@ -2698,6 +2700,7 @@ static std::vector LightmapNormalsToGLMVector(const lightsurf_t *lightsu return res; } +#if 0 static std::vector LightmapToGLMVector(const mbsp_t *bsp, const lightsurf_t *lightsurf) { const lightmap_t *lm = Lightmap_ForStyle_ReadOnly(lightsurf, 0); @@ -2706,6 +2709,7 @@ static std::vector LightmapToGLMVector(const mbsp_t *bsp, const lightsur } return std::vector(); } +#endif static qvec3f LinearToGamma22(const qvec3f &c) { diff --git a/light/phong.cc b/light/phong.cc index f6dc077f..edf58e22 100644 --- a/light/phong.cc +++ b/light/phong.cc @@ -614,13 +614,13 @@ void CalculateVertexNormals(const mbsp_t *bsp) // normalize vertex normals (NOTE: updates smoothedNormals map) for (auto &pair : smoothedNormals) { - const int vertIndex = pair.first; face_normal_t &vertNormal = pair.second; if (0 == qv::length(vertNormal.normal)) { // this happens when there are colinear vertices, which give zero-area triangles, // so there is no contribution to the normal of the triangle in the middle of the // line. Not really an error, just set it to use the face normal. #if 0 + const int vertIndex = pair.first; LogPrint("Failed to calculate normal for vertex {} at ({} {} {})\n", vertIndex, bsp->dvertexes[vertIndex].point[0], diff --git a/light/trace_embree.cc b/light/trace_embree.cc index f9adb35b..53372293 100644 --- a/light/trace_embree.cc +++ b/light/trace_embree.cc @@ -290,7 +290,6 @@ template static void Embree_FilterFuncN(const struct RTCFilterFunctionNArguments *args) { int *const valid = args->valid; - void *const userDataPtr = args->geometryUserPtr; RTCIntersectContext *const context = args->context; struct RTCRayN *const ray = args->ray; struct RTCHitN *const potentialHit = args->hit; diff --git a/qbsp/map.cc b/qbsp/map.cc index 55431476..43a1d86d 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -1445,6 +1445,8 @@ static void ParseTextureDef(parser_t &parser, mapface_t &mapface, const mapbrush tx_type = TX_QUAKED; } } + } else { + FError("Bad brush format"); } // If we're not Q2 but we're loading a Q2 map, just remove the extra @@ -1455,7 +1457,6 @@ static void ParseTextureDef(parser_t &parser, mapface_t &mapface, const mapbrush tx->miptex = FindMiptex(mapface.texname.c_str(), extinfo.info); - const auto &miptex = map.miptex[tx->miptex]; mapface.contents = extinfo.info->contents; tx->flags = mapface.flags = {extinfo.info->flags}; tx->value = mapface.value = extinfo.info->value; diff --git a/qbsp/qbsp.cc b/qbsp/qbsp.cc index 94a8b752..3d2613be 100644 --- a/qbsp/qbsp.cc +++ b/qbsp/qbsp.cc @@ -298,6 +298,7 @@ FLOOD AREAS ========================================================= */ +#if 0 int32_t c_areas; /* @@ -491,6 +492,7 @@ static void EmitAreaPortals(node_t *headnode) LogPrint(LOG_STAT, "{:5} numareas\n", map.bsp.dareas.size()); LogPrint(LOG_STAT, "{:5} numareaportals\n", map.bsp.dareaportals.size()); } +#endif winding_t BaseWindingForPlane(const qbsp_plane_t *p) { diff --git a/qbsp/surfaces.cc b/qbsp/surfaces.cc index 36f2d423..1cb073bd 100644 --- a/qbsp/surfaces.cc +++ b/qbsp/surfaces.cc @@ -285,7 +285,7 @@ inline size_t GetEdge(mapentity_t *entity, const qvec3d &p1, const qvec3d &p2, c /* emit an edge */ size_t i = map.bsp.dedges.size(); - auto &edge = map.bsp.dedges.emplace_back(bsp2_dedge_t{static_cast(v1), static_cast(v2)}); + map.bsp.dedges.emplace_back(bsp2_dedge_t{static_cast(v1), static_cast(v2)}); AddHashEdge(v1, v2, i); diff --git a/qbsp/writebsp.cc b/qbsp/writebsp.cc index 32098641..37653be9 100644 --- a/qbsp/writebsp.cc +++ b/qbsp/writebsp.cc @@ -365,16 +365,6 @@ static void CopyVector(const std::vector &vec, int *elementCountOut, C **arra *arrayCopyOut = (C *)data; } -static void CopyString(const std::string &string, bool addNullTermination, int *elementCountOut, void **arrayCopyOut) -{ - const size_t numBytes = addNullTermination ? string.size() + 1 : string.size(); - void *data = new uint8_t[numBytes]; - memcpy(data, string.data(), numBytes); // std::string::data() has null termination, so it's safe to copy it - - *elementCountOut = numBytes; - *arrayCopyOut = data; -} - /* ============= WriteBSPFile diff --git a/vis/soundpvs.cc b/vis/soundpvs.cc index 8a6d7db1..db75aa20 100644 --- a/vis/soundpvs.cc +++ b/vis/soundpvs.cc @@ -192,7 +192,7 @@ void CalcPHS(mbsp_t *bsp) const long *src = (long *)uncompressed_2; long *dest = (long *)uncompressed; for (int32_t l = 0; l < leaflongs; l++) - ((long *)uncompressed)[l] |= src[l]; + dest[l] |= src[l]; } } for (int32_t j = 0; j < portalleafs; j++)