From 7608a78b44052b751792a987e1ae0167ba2b5c0d Mon Sep 17 00:00:00 2001 From: Eric Wasylishen Date: Mon, 7 Aug 2023 15:42:29 -0600 Subject: [PATCH] style: use std::min/std::max/std::clamp and remove using --- bsputil/bsputil.cc | 2 +- common/bspfile.cc | 2 +- common/bspinfo.cc | 6 +++--- common/mathlib.cc | 4 ++-- common/settings.cc | 2 +- include/common/aabb.hh | 16 ++++++++-------- include/common/mathlib.hh | 2 -- include/common/polylib.hh | 10 +++++----- include/common/qvec.hh | 14 +++++++------- light/entities.cc | 4 ++-- light/lightgrid.cc | 4 ++-- light/ltface.cc | 26 +++++++++++++------------- light/phong.cc | 4 ++-- light/trace_embree.cc | 2 +- lightpreview/glview.cpp | 4 ++-- qbsp/brush.cc | 8 ++++---- qbsp/brushbsp.cc | 4 ++-- qbsp/csg.cc | 2 +- qbsp/faces.cc | 2 +- qbsp/map.cc | 22 +++++++++++----------- vis/vis.cc | 4 ++-- 21 files changed, 71 insertions(+), 73 deletions(-) diff --git a/bsputil/bsputil.cc b/bsputil/bsputil.cc index d83204cb..4bfc4738 100644 --- a/bsputil/bsputil.cc +++ b/bsputil/bsputil.cc @@ -153,7 +153,7 @@ static int Node_Height(const mbsp_t *bsp, const bsp2_dnode_t *node, std::map(lumps[i].fileofs + lumps[i].filelen)); + bspxofs = std::max(bspxofs, static_cast(lumps[i].fileofs + lumps[i].filelen)); } bspxofs = (bspxofs + 3) & ~3; diff --git a/common/bspinfo.cc b/common/bspinfo.cc index 7525c64b..6fc71100 100644 --- a/common/bspinfo.cc +++ b/common/bspinfo.cc @@ -340,7 +340,7 @@ full_atlas_t build_lightmap_atlas(const mbsp_t &bsp, const bspxentries_t &bspx, continue; } - atl.tallest = max(atl.tallest, (size_t)rect.extents.height()); + atl.tallest = std::max(atl.tallest, (size_t)rect.extents.height()); rect.x = atl.current_x; rect.y = atl.current_y; rect.atlas = current_atlas; @@ -363,8 +363,8 @@ full_atlas_t build_lightmap_atlas(const mbsp_t &bsp, const bspxentries_t &bspx, if (rect.atlas == i) { rect.x += atlas_x; rect.y += atlas_y; - trimmed_width = max(trimmed_width, rect.x + rect.extents.width()); - trimmed_height = max(trimmed_height, rect.y + rect.extents.height()); + trimmed_width = std::max(trimmed_width, rect.x + rect.extents.width()); + trimmed_height = std::max(trimmed_height, rect.y + rect.extents.height()); } #if 0 for (size_t x = 0; x < rect.texture->width; x++) { diff --git a/common/mathlib.cc b/common/mathlib.cc index 4ff9c2cd..299aeec1 100644 --- a/common/mathlib.cc +++ b/common/mathlib.cc @@ -80,7 +80,7 @@ qmat3x3f RotateFromUpToSurfaceNormal(const qvec3f &surfaceNormal) // get angle away from Z axis float cosangleFromUp = qv::dot(up, surfaceNormal); - cosangleFromUp = min(max(-1.0f, cosangleFromUp), 1.0f); + cosangleFromUp = std::min(std::max(-1.0f, cosangleFromUp), 1.0f); float radiansFromUp = acosf(cosangleFromUp); const qmat3x3d rotations = RotateAboutZ(theta) * RotateAboutY(radiansFromUp); @@ -496,7 +496,7 @@ qvec3f ClosestPointOnLineSegment(const qvec3f &v, const qvec3f &w, const qvec3f /// Returns degrees of clockwise rotation from start to end, assuming `normal` is pointing towards the viewer float SignedDegreesBetweenUnitVectors(const qvec3f &start, const qvec3f &end, const qvec3f &normal) { - const float cosangle = max(-1.0f, min(1.0f, qv::dot(start, end))); + const float cosangle = std::max(-1.0f, std::min(1.0f, qv::dot(start, end))); const float unsigned_degrees = acos(cosangle) * (360.0 / (2.0 * Q_PI)); // get a normal for the rotation plane using the right-hand rule diff --git a/common/settings.cc b/common/settings.cc index 099380da..f1840c9d 100644 --- a/common/settings.cc +++ b/common/settings.cc @@ -544,7 +544,7 @@ void setting_container::print_help() } for (auto setting : grouped.second) { - size_t numPadding = max(static_cast(0), 28 - (setting->primary_name().size() + 4)); + size_t numPadding = std::max(static_cast(0), 28 - (setting->primary_name().size() + 4)); fmt::print( " -{} {:{}} {}\n", setting->primary_name(), setting->format(), numPadding, setting->description()); diff --git a/include/common/aabb.hh b/include/common/aabb.hh index 3144a814..ce294930 100644 --- a/include/common/aabb.hh +++ b/include/common/aabb.hh @@ -159,8 +159,8 @@ public: { auto corners = m_corners; for (size_t i = 0; i < N; i++) { - corners[0][i] = min(corners[0][i], pt[i]); - corners[1][i] = max(corners[1][i], pt[i]); + corners[0][i] = std::min(corners[0][i], pt[i]); + corners[1][i] = std::max(corners[1][i], pt[i]); } return {corners[0], corners[1]}; } @@ -176,8 +176,8 @@ public: constexpr aabb &expand_in_place(const value_type &pt) { for (size_t i = 0; i < N; i++) { - m_corners[0][i] = min(m_corners[0][i], pt[i]); - m_corners[1][i] = max(m_corners[1][i], pt[i]); + m_corners[0][i] = std::min(m_corners[0][i], pt[i]); + m_corners[1][i] = std::max(m_corners[1][i], pt[i]); } return *this; @@ -190,8 +190,8 @@ public: constexpr aabb &unionWith_in_place(const aabb &other) { for (size_t i = 0; i < N; i++) { - m_corners[0][i] = min({m_corners[0][i], other.mins()[i], other.maxs()[i]}); - m_corners[1][i] = max({m_corners[1][i], other.mins()[i], other.maxs()[i]}); + m_corners[0][i] = std::min({m_corners[0][i], other.mins()[i], other.maxs()[i]}); + m_corners[1][i] = std::max({m_corners[1][i], other.mins()[i], other.maxs()[i]}); } return *this; @@ -201,8 +201,8 @@ public: { auto corners = m_corners; for (size_t i = 0; i < N; i++) { - corners[0][i] = max(corners[0][i], other.mins()[i]); - corners[1][i] = min(corners[1][i], other.maxs()[i]); + corners[0][i] = std::max(corners[0][i], other.mins()[i]); + corners[1][i] = std::min(corners[1][i], other.maxs()[i]); if (corners[0][i] > corners[1][i]) { // empty intersection return {}; diff --git a/include/common/mathlib.hh b/include/common/mathlib.hh index 4351c4bb..c8b59503 100644 --- a/include/common/mathlib.hh +++ b/include/common/mathlib.hh @@ -24,8 +24,6 @@ #include #include -using std::max, std::min, std::clamp; - // Calculate average of inputs template constexpr auto avg(T &&...args) diff --git a/include/common/polylib.hh b/include/common/polylib.hh index feca0218..6aeda536 100644 --- a/include/common/polylib.hh +++ b/include/common/polylib.hh @@ -400,7 +400,7 @@ public: : winding_storage_hybrid_t(end - begin) { // copy the array range - std::copy_n(begin, min(count, N), array.begin()); + std::copy_n(begin, std::min(count, N), array.begin()); // copy the vector range, if required if (count > N) { @@ -414,7 +414,7 @@ public: : winding_storage_hybrid_t(copy.size()) { // copy array range - memcpy(&array.front(), ©.array.front(), min(count, N) * sizeof(qvec3d)); + memcpy(&array.front(), ©.array.front(), std::min(count, N) * sizeof(qvec3d)); // copy vector range, if required if (count > N) { @@ -429,7 +429,7 @@ public: count = move.count; // blit over array data - memcpy(&array.front(), &move.array.front(), min(count, N) * sizeof(qvec3d)); + memcpy(&array.front(), &move.array.front(), std::min(count, N) * sizeof(qvec3d)); // move vector data, if available if (count > N) { @@ -445,7 +445,7 @@ public: count = copy.count; // copy array range - memcpy(&array.front(), ©.array.front(), min(count, N) * sizeof(qvec3d)); + memcpy(&array.front(), ©.array.front(), std::min(count, N) * sizeof(qvec3d)); // copy vector range, if required if (count > N) { @@ -463,7 +463,7 @@ public: count = move.count; // blit over array data - memcpy(&array.front(), &move.array.front(), min(count, N) * sizeof(qvec3d)); + memcpy(&array.front(), &move.array.front(), std::min(count, N) * sizeof(qvec3d)); // move vector data, if available if (count > N) { diff --git a/include/common/qvec.hh b/include/common/qvec.hh index 207be1b4..dfb7c571 100644 --- a/include/common/qvec.hh +++ b/include/common/qvec.hh @@ -64,7 +64,7 @@ public: // multiple arguments; copy up to min(N, `count`), // leave `count` -> N as zeroes else { - constexpr size_t copy_size = min(N, count); + constexpr size_t copy_size = std::min(N, count); size_t i = 0; ((i++ < copy_size ? (v[i - 1] = a, true) : false), ...); } @@ -106,7 +106,7 @@ public: template constexpr qvec(const qvec &other) { - constexpr size_t minSize = min(N, N2); + constexpr size_t minSize = std::min(N, N2); // truncates if `other` is longer than `this` for (size_t i = 0; i < minSize; i++) @@ -359,7 +359,7 @@ template { T res = std::numeric_limits::largest(); for (auto &c : v) { - res = ::min(c, res); + res = std::min(c, res); } return res; } @@ -369,7 +369,7 @@ template { T res = std::numeric_limits::lowest(); for (auto &c : v) { - res = ::max(c, res); + res = std::max(c, res); } return res; } @@ -389,7 +389,7 @@ template { qvec res; for (size_t i = 0; i < N; i++) { - res[i] = ::min(v1[i], v2[i]); + res[i] = std::min(v1[i], v2[i]); } return res; } @@ -399,7 +399,7 @@ template { qvec res; for (size_t i = 0; i < N; i++) { - res[i] = ::max(v1[i], v2[i]); + res[i] = std::max(v1[i], v2[i]); } return res; } @@ -708,7 +708,7 @@ inline qvec mangle_from_vec(const qvec &v) // get angle away from Z axis T cosangleFromUp = qv::dot(up, v); - cosangleFromUp = ::min(::max(static_cast(-1.0), cosangleFromUp), static_cast(1.0)); + cosangleFromUp = std::min(std::max(static_cast(-1.0), cosangleFromUp), static_cast(1.0)); T radiansFromUp = acosf(cosangleFromUp); return qvec{theta, -(radiansFromUp - Q_PI / 2.0), 0} * static_cast(180.0 / Q_PI); diff --git a/light/entities.cc b/light/entities.cc index 1a52504b..c8a4160c 100644 --- a/light/entities.cc +++ b/light/entities.cc @@ -522,7 +522,7 @@ static void SetupSkyDome(const settings::worldspawn_keys &cfg, vec_t upperLight, /* pick a value for 'iterations' so that 'numSuns' will be close to 'sunsamples' */ iterations = rint(sqrt((light_options.sunsamples.value() - 1) / 4)) + 1; - iterations = max(iterations, 2); + iterations = std::max(iterations, 2); /* dummy check */ if (upperLight <= 0.0f && lowerLight <= 0.0f) { @@ -971,7 +971,7 @@ void LoadEntities(const settings::worldspawn_keys &cfg, const mbsp_t *bsp) const auto anglescale = entdict.find("_anglescale"); if (anglescale != entdict.end()) { // Convert from 0..2 to 0..1 range... - const vec_t val = min(1.0, max(0.0, entdict.get_float("_anglescale") * 0.5)); + const vec_t val = std::min(1.0, std::max(0.0, entdict.get_float("_anglescale") * 0.5)); entdict.set("_anglescale", std::to_string(val)); } } diff --git a/light/lightgrid.cc b/light/lightgrid.cc index fa2ca123..240e0f10 100644 --- a/light/lightgrid.cc +++ b/light/lightgrid.cc @@ -372,7 +372,7 @@ static aabb3f MakeCube(const aabb3f &input) { qvec3f centroid = input.centroid(); - const float new_size = max(max(input.size()[0], input.size()[1]), input.size()[2]); + const float new_size = std::max(std::max(input.size()[0], input.size()[1]), input.size()[2]); return aabb3f(centroid - qvec3f(new_size / 2), centroid + qvec3f(new_size / 2)); } @@ -452,7 +452,7 @@ void LightGrid(bspdata_t *bspdata) data.num_styles = [&]() { int result = 0; for (auto &samples : data.grid_result) { - result = max(result, samples.used_styles()); + result = std::max(result, samples.used_styles()); } return result; }(); diff --git a/light/ltface.cc b/light/ltface.cc index 1bc9ddf2..e7d5fde1 100644 --- a/light/ltface.cc +++ b/light/ltface.cc @@ -1411,7 +1411,7 @@ static void LightFace_Sky(const mbsp_t *bsp, const sun_t *sun, lightsurf_t *ligh } } - angle = max(0.0, angle); + angle = std::max(0.0, angle); angle = (1.0 - sun->anglescale) + sun->anglescale * angle; vec_t value = angle * sun->sunlight; @@ -1503,7 +1503,7 @@ static void LightPoint_Sky(const mbsp_t *bsp, raystream_intersection_t &rs, cons cube_normal[axis] = sign; vec_t angle = qv::dot(incoming, cube_normal); - angle = max(0.0, angle); + angle = std::max(0.0, angle); angle = (1.0 - sun->anglescale) + sun->anglescale * angle; float value = angle * sun->sunlight; @@ -1904,7 +1904,7 @@ constexpr qvec3f SurfaceLight_ColorAtDist(const settings::worldspawn_keys &cfg, const float &intensity, const qvec3d &color, const float &dist, const float &hotspot_clamp) { // Exponential falloff - const float d = max(dist, hotspot_clamp); // Clamp away hotspots, also avoid division by 0... + const float d = std::max(dist, hotspot_clamp); // Clamp away hotspots, also avoid division by 0... const float scaledintensity = intensity * surf_scale; const float scale = (1.0f / (d * d)); @@ -1942,7 +1942,7 @@ inline qvec3f GetSurfaceLighting(const settings::worldspawn_keys &cfg, const sur dotProductFactor = dp2; } - dotProductFactor = max(0.0f, dotProductFactor); + dotProductFactor = std::max(0.0f, dotProductFactor); // Get light contribution result = SurfaceLight_ColorAtDist(cfg, vpl_settings.omnidirectional ? sky_scale : standard_scale, @@ -2384,7 +2384,7 @@ static void LightFace_CalculateDirt(lightsurf_t *lightsurf) const int i = rs.getPushedRayPointIndex(k); if (rs.getPushedRayHitType(k) == hittype_t::SOLID) { vec_t dist = rs.getPushedRayHitDist(k); - lightsurf->samples[i].occlusion += min(cfg.dirtdepth.value(), dist); + lightsurf->samples[i].occlusion += std::min(cfg.dirtdepth.value(), dist); } else { lightsurf->samples[i].occlusion += cfg.dirtdepth.value(); } @@ -2789,8 +2789,8 @@ static std::vector BoxBlurImage(const std::vector &input, int w, for (int y0 = -radius; y0 <= radius; y0++) { for (int x0 = -radius; x0 <= radius; x0++) { - const int x1 = clamp(x + x0, 0, w - 1); - const int y1 = clamp(y + y0, 0, h - 1); + const int x1 = std::clamp(x + x0, 0, w - 1); + const int y1 = std::clamp(y + y0, 0, h - 1); // check if the kernel goes outside of the source image @@ -2932,7 +2932,7 @@ static void WriteSingleLightmap(const mbsp_t *bsp, const mface_t *face, const li This must be max(), see LightNormalize in MarkV 1036. */ - float light = max({color[0], color[1], color[2]}); + float light = std::max({color[0], color[1], color[2]}); if (light < 0) light = 0; if (light > 255) @@ -2979,8 +2979,8 @@ static void WriteSingleLightmap_FromDecoupled(const mbsp_t *bsp, const mface_t * // samples the "decoupled" lightmap at an integer coordinate, with clamping auto tex = [&lightsurf, &fullres](int x, int y) -> qvec4f { - const int x_clamped = clamp(x, 0, lightsurf->width - 1); - const int y_clamped = clamp(y, 0, lightsurf->height - 1); + const int x_clamped = std::clamp(x, 0, lightsurf->width - 1); + const int y_clamped = std::clamp(y, 0, lightsurf->height - 1); const int sampleindex = (y_clamped * lightsurf->width) + x_clamped; assert(sampleindex >= 0); @@ -3087,7 +3087,7 @@ void SaveLightmapSurface(const mbsp_t *bsp, mface_t *face, facesup_t *facesup, return; } - size_t maxfstyles = min((size_t)light_options.facestyles.value(), facesup ? MAXLIGHTMAPSSUP : MAXLIGHTMAPS); + size_t maxfstyles = std::min((size_t)light_options.facestyles.value(), facesup ? MAXLIGHTMAPSSUP : MAXLIGHTMAPS); int maxstyle = facesup ? INVALID_LIGHTSTYLE : INVALID_LIGHTSTYLE_OLD; // intermediate collection for sorting lightmaps @@ -3535,8 +3535,8 @@ void lightgrid_samples_t::add(const qvec3d &color, int style) qvec3b lightgrid_sample_t::round_to_int() const { - return qvec3b{ - clamp((int)round(color[0]), 0, 255), clamp((int)round(color[1]), 0, 255), clamp((int)round(color[2]), 0, 255)}; + return qvec3b{std::clamp((int)round(color[0]), 0, 255), std::clamp((int)round(color[1]), 0, 255), + std::clamp((int)round(color[2]), 0, 255)}; } float lightgrid_sample_t::brightness() const diff --git a/light/phong.cc b/light/phong.cc index 3a0efec1..41f7e07a 100644 --- a/light/phong.cc +++ b/light/phong.cc @@ -434,7 +434,7 @@ void CalculateVertexNormals(const mbsp_t *bsp) // support on func_detail/func_group for (size_t i = 0; i < bsp->dmodels.size(); i++) { const modelinfo_t *info = ModelInfoForModel(bsp, i); - const uint8_t phongangle_byte = (uint8_t)clamp((int)rint(info->getResolvedPhongAngle()), 0, 255); + const uint8_t phongangle_byte = (uint8_t)std::clamp((int)rint(info->getResolvedPhongAngle()), 0, 255); if (!phongangle_byte) continue; @@ -529,7 +529,7 @@ void CalculateVertexNormals(const mbsp_t *bsp) const bool concave = f_plane.dist_above(f2_centroid) > 0.1; const vec_t f_threshold = concave ? f_phong_angle_concave : f_phong_angle; const vec_t f2_threshold = concave ? f2_phong_angle_concave : f2_phong_angle; - const vec_t min_threshold = min(f_threshold, f2_threshold); + const vec_t min_threshold = std::min(f_threshold, f2_threshold); const vec_t cosmaxangle = cos(DEG2RAD(min_threshold)); if (f_phongValue != f2_phongValue) { diff --git a/light/trace_embree.cc b/light/trace_embree.cc index 14ad78de..32d9d9db 100644 --- a/light/trace_embree.cc +++ b/light/trace_embree.cc @@ -694,7 +694,7 @@ static void AddGlassToRay(RTCIntersectContext *context, unsigned rayIndex, float } // clamp opacity - opacity = clamp(opacity, 0.0f, 1.0f); + opacity = std::clamp(opacity, 0.0f, 1.0f); Q_assert(rayIndex < rs->_numrays); diff --git a/lightpreview/glview.cpp b/lightpreview/glview.cpp index dd36698b..71f29d72 100644 --- a/lightpreview/glview.cpp +++ b/lightpreview/glview.cpp @@ -935,7 +935,7 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries int32_t highest_depth = 0; for (auto &style : lightmap.style_to_lightmap_atlas) { - highest_depth = max(highest_depth, style.first); + highest_depth = std::max(highest_depth, style.first); } // upload lightmap atlases @@ -1506,7 +1506,7 @@ void GLView::wheelEvent(QWheelEvent *event) double delta = event->angleDelta().y(); m_moveSpeed += delta; - m_moveSpeed = clamp(m_moveSpeed, 10.0f, 5000.0f); + m_moveSpeed = std::clamp(m_moveSpeed, 10.0f, 5000.0f); } void GLView::mousePressEvent(QMouseEvent *event) diff --git a/qbsp/brush.cc b/qbsp/brush.cc index e1350218..6acfd724 100644 --- a/qbsp/brush.cc +++ b/qbsp/brush.cc @@ -661,12 +661,12 @@ std::optional LoadBrush(const mapentity_t &src, mapbrush_t &mapbrush vec_t max = -std::numeric_limits::infinity(), min = std::numeric_limits::infinity(); for (auto &v : brush.bounds.mins()) { - min = ::min(min, v); - max = ::max(max, v); + min = std::min(min, v); + max = std::max(max, v); } for (auto &v : brush.bounds.maxs()) { - min = ::min(min, v); - max = ::max(max, v); + min = std::min(min, v); + max = std::max(max, v); } vec_t delta = std::max(fabs(max), fabs(min)); diff --git a/qbsp/brushbsp.cc b/qbsp/brushbsp.cc index 462a5bd8..32511030 100644 --- a/qbsp/brushbsp.cc +++ b/qbsp/brushbsp.cc @@ -816,8 +816,8 @@ inline void DivideBounds(const aabb3d &in_bounds, const qbsp_plane_t &split, aab mid *= (dist1 / (dist1 - dist2)); mid += in_bounds[0][a]; - split_mins = max(min(mid, split_mins), in_bounds.mins()[a]); - split_maxs = min(max(mid, split_maxs), in_bounds.maxs()[a]); + split_mins = std::max(std::min(mid, split_mins), in_bounds.mins()[a]); + split_maxs = std::min(std::max(mid, split_maxs), in_bounds.maxs()[a]); } } if (split.get_normal()[a] > 0) { diff --git a/qbsp/csg.cc b/qbsp/csg.cc index 2091dc5f..68777a61 100644 --- a/qbsp/csg.cc +++ b/qbsp/csg.cc @@ -73,7 +73,7 @@ void UpdateFaceSphere(face_t *in) in->origin = in->w.center(); in->radius = 0; for (size_t i = 0; i < in->w.size(); i++) { - in->radius = max(in->radius, qv::distance2(in->w[i], in->origin)); + in->radius = std::max(in->radius, qv::distance2(in->w[i], in->origin)); } in->radius = sqrt(in->radius); } diff --git a/qbsp/faces.cc b/qbsp/faces.cc index 38a6fb7d..a1ddbfda 100644 --- a/qbsp/faces.cc +++ b/qbsp/faces.cc @@ -366,7 +366,7 @@ static std::list> SubdivideFace(std::unique_ptr // legacy engines support 18*18 max blocks (at 1:16 scale). // the 18*18 limit can be relaxed in certain engines, and doing so will generally give a performance boost. - subdiv = min(qbsp_options.subdivide.value(), 255 << lmshift); + subdiv = std::min(qbsp_options.subdivide.value(), 255 << lmshift); // subdiv += 8; diff --git a/qbsp/map.cc b/qbsp/map.cc index fb333101..3443b8c5 100644 --- a/qbsp/map.cc +++ b/qbsp/map.cc @@ -751,11 +751,11 @@ static surfflags_t SurfFlagsForEntity( } if (phongangle) { - flags.phong_angle = clamp(phongangle, 0.0, 360.0); + flags.phong_angle = std::clamp(phongangle, 0.0, 360.0); } const vec_t phong_angle_concave = entity.epairs.get_float("_phong_angle_concave"); - flags.phong_angle_concave = clamp(phong_angle_concave, 0.0, 360.0); + flags.phong_angle_concave = std::clamp(phong_angle_concave, 0.0, 360.0); flags.phong_group = entity.epairs.get_int("_phong_group"); @@ -763,7 +763,7 @@ static surfflags_t SurfFlagsForEntity( if (entity.epairs.has("_minlight")) { const vec_t minlight = entity.epairs.get_float("_minlight"); // handle -1 as an alias for 0 (same with other negative values). - flags.minlight = max(0., minlight); + flags.minlight = std::max(0., minlight); } // handle "_maxlight" @@ -771,14 +771,14 @@ static surfflags_t SurfFlagsForEntity( if (maxlight > 0) { // CHECK: allow > 510 now that we're float? or is it not worth it since it will // be beyond max? - flags.maxlight = clamp(maxlight, 0.0, 510.0); + flags.maxlight = std::clamp(maxlight, 0.0, 510.0); } // handle "_lightcolorscale" if (entity.epairs.has("_lightcolorscale")) { const vec_t lightcolorscale = entity.epairs.get_float("_lightcolorscale"); if (lightcolorscale != 1.0) { - flags.lightcolorscale = clamp(lightcolorscale, 0.0, 1.0); + flags.lightcolorscale = std::clamp(lightcolorscale, 0.0, 1.0); } } @@ -810,7 +810,7 @@ static surfflags_t SurfFlagsForEntity( mincolor = qv::normalize_color_format(mincolor); if (!qv::epsilonEmpty(mincolor, QBSP_EQUAL_EPSILON)) { for (int32_t i = 0; i < 3; i++) { - flags.minlight_color[i] = clamp(mincolor[i], 0.0, 255.0); + flags.minlight_color[i] = std::clamp(mincolor[i], 0.0, 255.0); } } } @@ -818,7 +818,7 @@ static surfflags_t SurfFlagsForEntity( // handle "_light_alpha" if (entity.epairs.has("_light_alpha")) { const vec_t lightalpha = entity.epairs.get_float("_light_alpha"); - flags.light_alpha = clamp(lightalpha, 0.0, 1.0); + flags.light_alpha = std::clamp(lightalpha, 0.0, 1.0); } return flags; @@ -1129,7 +1129,7 @@ float clockwiseDegreesBetween(qvec2f start, qvec2f end) start = qv::normalize(start); end = qv::normalize(end); - const float cosAngle = max(-1.0f, min(1.0f, qv::dot(start, end))); + const float cosAngle = std::max(-1.0f, std::min(1.0f, qv::dot(start, end))); const float unsigned_degrees = acos(cosAngle) * (360.0 / (2.0 * Q_PI)); if (unsigned_degrees < ANGLEEPSILON) @@ -3712,7 +3712,7 @@ inline vec_t GetBrushExtents(const mapbrush_t &hullbrush) if (legal) { for (auto &p : *vertex) { - extents = max(extents, fabs(p)); + extents = std::max(extents, fabs(p)); } } } @@ -3735,7 +3735,7 @@ void CalculateWorldExtent(void) tbb::parallel_for_each(map.entities, [&](const mapentity_t &entity) { tbb::parallel_for_each(entity.mapbrushes, [&](const mapbrush_t &mapbrush) { - const vec_t brushExtents = max(extents.load(), GetBrushExtents(mapbrush)); + const vec_t brushExtents = std::max(extents.load(), GetBrushExtents(mapbrush)); vec_t currentExtents = extents; while (currentExtents < brushExtents && !extents.compare_exchange_weak(currentExtents, brushExtents)) ; @@ -3746,7 +3746,7 @@ void CalculateWorldExtent(void) for (auto &hull : qbsp_options.target_game->get_hull_sizes()) { for (auto &v : hull.size()) { - hull_extents = max(hull_extents, fabs(v)); + hull_extents = std::max(hull_extents, fabs(v)); } } diff --git a/vis/vis.cc b/vis/vis.cc index 00398d98..44910852 100644 --- a/vis/vis.cc +++ b/vis/vis.cc @@ -592,9 +592,9 @@ static void LoadPortals(const fs::path &name, mbsp_t *bsp) /* Allocate for worst case where RLE might grow the data (unlikely) */ if (bsp->loadversion->game->id == GAME_QUAKE_II) { - compressed.reserve(max(1, (portalleafs * 2) / 8)); + compressed.reserve(std::max(1, (portalleafs * 2) / 8)); } else { - compressed.reserve(max(1, (portalleafs_real * 2) / 8)); + compressed.reserve(std::max(1, (portalleafs_real * 2) / 8)); } numportals = prtfile.portals.size();