style: use std::min/std::max/std::clamp and remove using
This commit is contained in:
parent
a2ea5d8217
commit
7608a78b44
|
|
@ -153,7 +153,7 @@ static int Node_Height(const mbsp_t *bsp, const bsp2_dnode_t *node, std::map<con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int height = max(child_heights[0], child_heights[1]) + 1;
|
const int height = std::max(child_heights[0], child_heights[1]) + 1;
|
||||||
if (cache)
|
if (cache)
|
||||||
(*cache)[node] = height;
|
(*cache)[node] = height;
|
||||||
return height;
|
return height;
|
||||||
|
|
|
||||||
|
|
@ -2543,7 +2543,7 @@ void LoadBSPFile(fs::path &filename, bspdata_t *bspdata)
|
||||||
// detect BSPX
|
// detect BSPX
|
||||||
/*bspx header is positioned exactly+4align at the end of the last lump position (regardless of order)*/
|
/*bspx header is positioned exactly+4align at the end of the last lump position (regardless of order)*/
|
||||||
for (i = 0, bspxofs = 0; i < lumps.size(); i++) {
|
for (i = 0, bspxofs = 0; i < lumps.size(); i++) {
|
||||||
bspxofs = max(bspxofs, static_cast<size_t>(lumps[i].fileofs + lumps[i].filelen));
|
bspxofs = std::max(bspxofs, static_cast<size_t>(lumps[i].fileofs + lumps[i].filelen));
|
||||||
}
|
}
|
||||||
|
|
||||||
bspxofs = (bspxofs + 3) & ~3;
|
bspxofs = (bspxofs + 3) & ~3;
|
||||||
|
|
|
||||||
|
|
@ -340,7 +340,7 @@ full_atlas_t build_lightmap_atlas(const mbsp_t &bsp, const bspxentries_t &bspx,
|
||||||
continue;
|
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.x = atl.current_x;
|
||||||
rect.y = atl.current_y;
|
rect.y = atl.current_y;
|
||||||
rect.atlas = current_atlas;
|
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) {
|
if (rect.atlas == i) {
|
||||||
rect.x += atlas_x;
|
rect.x += atlas_x;
|
||||||
rect.y += atlas_y;
|
rect.y += atlas_y;
|
||||||
trimmed_width = max(trimmed_width, rect.x + rect.extents.width());
|
trimmed_width = std::max(trimmed_width, rect.x + rect.extents.width());
|
||||||
trimmed_height = max(trimmed_height, rect.y + rect.extents.height());
|
trimmed_height = std::max(trimmed_height, rect.y + rect.extents.height());
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
for (size_t x = 0; x < rect.texture->width; x++) {
|
for (size_t x = 0; x < rect.texture->width; x++) {
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ qmat3x3f RotateFromUpToSurfaceNormal(const qvec3f &surfaceNormal)
|
||||||
|
|
||||||
// get angle away from Z axis
|
// get angle away from Z axis
|
||||||
float cosangleFromUp = qv::dot(up, surfaceNormal);
|
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);
|
float radiansFromUp = acosf(cosangleFromUp);
|
||||||
|
|
||||||
const qmat3x3d rotations = RotateAboutZ(theta) * RotateAboutY(radiansFromUp);
|
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
|
/// 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)
|
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));
|
const float unsigned_degrees = acos(cosangle) * (360.0 / (2.0 * Q_PI));
|
||||||
|
|
||||||
// get a normal for the rotation plane using the right-hand rule
|
// get a normal for the rotation plane using the right-hand rule
|
||||||
|
|
|
||||||
|
|
@ -544,7 +544,7 @@ void setting_container::print_help()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto setting : grouped.second) {
|
for (auto setting : grouped.second) {
|
||||||
size_t numPadding = max(static_cast<size_t>(0), 28 - (setting->primary_name().size() + 4));
|
size_t numPadding = std::max(static_cast<size_t>(0), 28 - (setting->primary_name().size() + 4));
|
||||||
fmt::print(
|
fmt::print(
|
||||||
" -{} {:{}} {}\n", setting->primary_name(), setting->format(), numPadding, setting->description());
|
" -{} {:{}} {}\n", setting->primary_name(), setting->format(), numPadding, setting->description());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,8 @@ public:
|
||||||
{
|
{
|
||||||
auto corners = m_corners;
|
auto corners = m_corners;
|
||||||
for (size_t i = 0; i < N; i++) {
|
for (size_t i = 0; i < N; i++) {
|
||||||
corners[0][i] = min(corners[0][i], pt[i]);
|
corners[0][i] = std::min(corners[0][i], pt[i]);
|
||||||
corners[1][i] = max(corners[1][i], pt[i]);
|
corners[1][i] = std::max(corners[1][i], pt[i]);
|
||||||
}
|
}
|
||||||
return {corners[0], corners[1]};
|
return {corners[0], corners[1]};
|
||||||
}
|
}
|
||||||
|
|
@ -176,8 +176,8 @@ public:
|
||||||
constexpr aabb &expand_in_place(const value_type &pt)
|
constexpr aabb &expand_in_place(const value_type &pt)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < N; i++) {
|
for (size_t i = 0; i < N; i++) {
|
||||||
m_corners[0][i] = min(m_corners[0][i], pt[i]);
|
m_corners[0][i] = std::min(m_corners[0][i], pt[i]);
|
||||||
m_corners[1][i] = max(m_corners[1][i], pt[i]);
|
m_corners[1][i] = std::max(m_corners[1][i], pt[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -190,8 +190,8 @@ public:
|
||||||
constexpr aabb &unionWith_in_place(const aabb &other)
|
constexpr aabb &unionWith_in_place(const aabb &other)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < N; i++) {
|
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[0][i] = std::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[1][i] = std::max({m_corners[1][i], other.mins()[i], other.maxs()[i]});
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
@ -201,8 +201,8 @@ public:
|
||||||
{
|
{
|
||||||
auto corners = m_corners;
|
auto corners = m_corners;
|
||||||
for (size_t i = 0; i < N; i++) {
|
for (size_t i = 0; i < N; i++) {
|
||||||
corners[0][i] = max(corners[0][i], other.mins()[i]);
|
corners[0][i] = std::max(corners[0][i], other.mins()[i]);
|
||||||
corners[1][i] = min(corners[1][i], other.maxs()[i]);
|
corners[1][i] = std::min(corners[1][i], other.maxs()[i]);
|
||||||
if (corners[0][i] > corners[1][i]) {
|
if (corners[0][i] > corners[1][i]) {
|
||||||
// empty intersection
|
// empty intersection
|
||||||
return {};
|
return {};
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
using std::max, std::min, std::clamp;
|
|
||||||
|
|
||||||
// Calculate average of inputs
|
// Calculate average of inputs
|
||||||
template<typename... T>
|
template<typename... T>
|
||||||
constexpr auto avg(T &&...args)
|
constexpr auto avg(T &&...args)
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ public:
|
||||||
: winding_storage_hybrid_t(end - begin)
|
: winding_storage_hybrid_t(end - begin)
|
||||||
{
|
{
|
||||||
// copy the array range
|
// 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
|
// copy the vector range, if required
|
||||||
if (count > N) {
|
if (count > N) {
|
||||||
|
|
@ -414,7 +414,7 @@ public:
|
||||||
: winding_storage_hybrid_t(copy.size())
|
: winding_storage_hybrid_t(copy.size())
|
||||||
{
|
{
|
||||||
// copy array range
|
// 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
|
// copy vector range, if required
|
||||||
if (count > N) {
|
if (count > N) {
|
||||||
|
|
@ -429,7 +429,7 @@ public:
|
||||||
count = move.count;
|
count = move.count;
|
||||||
|
|
||||||
// blit over array data
|
// 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
|
// move vector data, if available
|
||||||
if (count > N) {
|
if (count > N) {
|
||||||
|
|
@ -445,7 +445,7 @@ public:
|
||||||
count = copy.count;
|
count = copy.count;
|
||||||
|
|
||||||
// copy array range
|
// 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
|
// copy vector range, if required
|
||||||
if (count > N) {
|
if (count > N) {
|
||||||
|
|
@ -463,7 +463,7 @@ public:
|
||||||
count = move.count;
|
count = move.count;
|
||||||
|
|
||||||
// blit over array data
|
// 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
|
// move vector data, if available
|
||||||
if (count > N) {
|
if (count > N) {
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ public:
|
||||||
// multiple arguments; copy up to min(N, `count`),
|
// multiple arguments; copy up to min(N, `count`),
|
||||||
// leave `count` -> N as zeroes
|
// leave `count` -> N as zeroes
|
||||||
else {
|
else {
|
||||||
constexpr size_t copy_size = min(N, count);
|
constexpr size_t copy_size = std::min(N, count);
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
((i++ < copy_size ? (v[i - 1] = a, true) : false), ...);
|
((i++ < copy_size ? (v[i - 1] = a, true) : false), ...);
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ public:
|
||||||
template<size_t N2>
|
template<size_t N2>
|
||||||
constexpr qvec(const qvec<T, N2> &other)
|
constexpr qvec(const qvec<T, N2> &other)
|
||||||
{
|
{
|
||||||
constexpr size_t minSize = min(N, N2);
|
constexpr size_t minSize = std::min(N, N2);
|
||||||
|
|
||||||
// truncates if `other` is longer than `this`
|
// truncates if `other` is longer than `this`
|
||||||
for (size_t i = 0; i < minSize; i++)
|
for (size_t i = 0; i < minSize; i++)
|
||||||
|
|
@ -359,7 +359,7 @@ template<size_t N, class T>
|
||||||
{
|
{
|
||||||
T res = std::numeric_limits<T>::largest();
|
T res = std::numeric_limits<T>::largest();
|
||||||
for (auto &c : v) {
|
for (auto &c : v) {
|
||||||
res = ::min(c, res);
|
res = std::min(c, res);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -369,7 +369,7 @@ template<size_t N, class T>
|
||||||
{
|
{
|
||||||
T res = std::numeric_limits<T>::lowest();
|
T res = std::numeric_limits<T>::lowest();
|
||||||
for (auto &c : v) {
|
for (auto &c : v) {
|
||||||
res = ::max(c, res);
|
res = std::max(c, res);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -389,7 +389,7 @@ template<size_t N, class T>
|
||||||
{
|
{
|
||||||
qvec<T, N> res;
|
qvec<T, N> res;
|
||||||
for (size_t i = 0; i < N; i++) {
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -399,7 +399,7 @@ template<size_t N, class T>
|
||||||
{
|
{
|
||||||
qvec<T, N> res;
|
qvec<T, N> res;
|
||||||
for (size_t i = 0; i < N; i++) {
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -708,7 +708,7 @@ inline qvec<T, 3> mangle_from_vec(const qvec<T, 3> &v)
|
||||||
|
|
||||||
// get angle away from Z axis
|
// get angle away from Z axis
|
||||||
T cosangleFromUp = qv::dot(up, v);
|
T cosangleFromUp = qv::dot(up, v);
|
||||||
cosangleFromUp = ::min(::max(static_cast<T>(-1.0), cosangleFromUp), static_cast<T>(1.0));
|
cosangleFromUp = std::min(std::max(static_cast<T>(-1.0), cosangleFromUp), static_cast<T>(1.0));
|
||||||
T radiansFromUp = acosf(cosangleFromUp);
|
T radiansFromUp = acosf(cosangleFromUp);
|
||||||
|
|
||||||
return qvec<T, 3>{theta, -(radiansFromUp - Q_PI / 2.0), 0} * static_cast<T>(180.0 / Q_PI);
|
return qvec<T, 3>{theta, -(radiansFromUp - Q_PI / 2.0), 0} * static_cast<T>(180.0 / Q_PI);
|
||||||
|
|
|
||||||
|
|
@ -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' */
|
/* pick a value for 'iterations' so that 'numSuns' will be close to 'sunsamples' */
|
||||||
iterations = rint(sqrt((light_options.sunsamples.value() - 1) / 4)) + 1;
|
iterations = rint(sqrt((light_options.sunsamples.value() - 1) / 4)) + 1;
|
||||||
iterations = max(iterations, 2);
|
iterations = std::max(iterations, 2);
|
||||||
|
|
||||||
/* dummy check */
|
/* dummy check */
|
||||||
if (upperLight <= 0.0f && lowerLight <= 0.0f) {
|
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");
|
const auto anglescale = entdict.find("_anglescale");
|
||||||
if (anglescale != entdict.end()) {
|
if (anglescale != entdict.end()) {
|
||||||
// Convert from 0..2 to 0..1 range...
|
// 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));
|
entdict.set("_anglescale", std::to_string(val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -372,7 +372,7 @@ static aabb3f MakeCube(const aabb3f &input)
|
||||||
{
|
{
|
||||||
qvec3f centroid = input.centroid();
|
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));
|
return aabb3f(centroid - qvec3f(new_size / 2), centroid + qvec3f(new_size / 2));
|
||||||
}
|
}
|
||||||
|
|
@ -452,7 +452,7 @@ void LightGrid(bspdata_t *bspdata)
|
||||||
data.num_styles = [&]() {
|
data.num_styles = [&]() {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (auto &samples : data.grid_result) {
|
for (auto &samples : data.grid_result) {
|
||||||
result = max(result, samples.used_styles());
|
result = std::max(result, samples.used_styles());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}();
|
}();
|
||||||
|
|
|
||||||
|
|
@ -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;
|
angle = (1.0 - sun->anglescale) + sun->anglescale * angle;
|
||||||
vec_t value = angle * sun->sunlight;
|
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;
|
cube_normal[axis] = sign;
|
||||||
|
|
||||||
vec_t angle = qv::dot(incoming, cube_normal);
|
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;
|
angle = (1.0 - sun->anglescale) + sun->anglescale * angle;
|
||||||
|
|
||||||
float value = angle * sun->sunlight;
|
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)
|
const float &intensity, const qvec3d &color, const float &dist, const float &hotspot_clamp)
|
||||||
{
|
{
|
||||||
// Exponential falloff
|
// 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 scaledintensity = intensity * surf_scale;
|
||||||
const float scale = (1.0f / (d * d));
|
const float scale = (1.0f / (d * d));
|
||||||
|
|
||||||
|
|
@ -1942,7 +1942,7 @@ inline qvec3f GetSurfaceLighting(const settings::worldspawn_keys &cfg, const sur
|
||||||
dotProductFactor = dp2;
|
dotProductFactor = dp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
dotProductFactor = max(0.0f, dotProductFactor);
|
dotProductFactor = std::max(0.0f, dotProductFactor);
|
||||||
|
|
||||||
// Get light contribution
|
// Get light contribution
|
||||||
result = SurfaceLight_ColorAtDist(cfg, vpl_settings.omnidirectional ? sky_scale : standard_scale,
|
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);
|
const int i = rs.getPushedRayPointIndex(k);
|
||||||
if (rs.getPushedRayHitType(k) == hittype_t::SOLID) {
|
if (rs.getPushedRayHitType(k) == hittype_t::SOLID) {
|
||||||
vec_t dist = rs.getPushedRayHitDist(k);
|
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 {
|
} else {
|
||||||
lightsurf->samples[i].occlusion += cfg.dirtdepth.value();
|
lightsurf->samples[i].occlusion += cfg.dirtdepth.value();
|
||||||
}
|
}
|
||||||
|
|
@ -2789,8 +2789,8 @@ static std::vector<qvec4f> BoxBlurImage(const std::vector<qvec4f> &input, int w,
|
||||||
|
|
||||||
for (int y0 = -radius; y0 <= radius; y0++) {
|
for (int y0 = -radius; y0 <= radius; y0++) {
|
||||||
for (int x0 = -radius; x0 <= radius; x0++) {
|
for (int x0 = -radius; x0 <= radius; x0++) {
|
||||||
const int x1 = clamp(x + x0, 0, w - 1);
|
const int x1 = std::clamp(x + x0, 0, w - 1);
|
||||||
const int y1 = clamp(y + y0, 0, h - 1);
|
const int y1 = std::clamp(y + y0, 0, h - 1);
|
||||||
|
|
||||||
// check if the kernel goes outside of the source image
|
// 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.
|
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)
|
if (light < 0)
|
||||||
light = 0;
|
light = 0;
|
||||||
if (light > 255)
|
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
|
// samples the "decoupled" lightmap at an integer coordinate, with clamping
|
||||||
auto tex = [&lightsurf, &fullres](int x, int y) -> qvec4f {
|
auto tex = [&lightsurf, &fullres](int x, int y) -> qvec4f {
|
||||||
const int x_clamped = clamp(x, 0, lightsurf->width - 1);
|
const int x_clamped = std::clamp(x, 0, lightsurf->width - 1);
|
||||||
const int y_clamped = clamp(y, 0, lightsurf->height - 1);
|
const int y_clamped = std::clamp(y, 0, lightsurf->height - 1);
|
||||||
|
|
||||||
const int sampleindex = (y_clamped * lightsurf->width) + x_clamped;
|
const int sampleindex = (y_clamped * lightsurf->width) + x_clamped;
|
||||||
assert(sampleindex >= 0);
|
assert(sampleindex >= 0);
|
||||||
|
|
@ -3087,7 +3087,7 @@ void SaveLightmapSurface(const mbsp_t *bsp, mface_t *face, facesup_t *facesup,
|
||||||
return;
|
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;
|
int maxstyle = facesup ? INVALID_LIGHTSTYLE : INVALID_LIGHTSTYLE_OLD;
|
||||||
|
|
||||||
// intermediate collection for sorting lightmaps
|
// 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
|
qvec3b lightgrid_sample_t::round_to_int() const
|
||||||
{
|
{
|
||||||
return qvec3b{
|
return qvec3b{std::clamp((int)round(color[0]), 0, 255), std::clamp((int)round(color[1]), 0, 255),
|
||||||
clamp((int)round(color[0]), 0, 255), clamp((int)round(color[1]), 0, 255), clamp((int)round(color[2]), 0, 255)};
|
std::clamp((int)round(color[2]), 0, 255)};
|
||||||
}
|
}
|
||||||
|
|
||||||
float lightgrid_sample_t::brightness() const
|
float lightgrid_sample_t::brightness() const
|
||||||
|
|
|
||||||
|
|
@ -434,7 +434,7 @@ void CalculateVertexNormals(const mbsp_t *bsp)
|
||||||
// support on func_detail/func_group
|
// support on func_detail/func_group
|
||||||
for (size_t i = 0; i < bsp->dmodels.size(); i++) {
|
for (size_t i = 0; i < bsp->dmodels.size(); i++) {
|
||||||
const modelinfo_t *info = ModelInfoForModel(bsp, 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)
|
if (!phongangle_byte)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -529,7 +529,7 @@ void CalculateVertexNormals(const mbsp_t *bsp)
|
||||||
const bool concave = f_plane.dist_above(f2_centroid) > 0.1;
|
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 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 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));
|
const vec_t cosmaxangle = cos(DEG2RAD(min_threshold));
|
||||||
|
|
||||||
if (f_phongValue != f2_phongValue) {
|
if (f_phongValue != f2_phongValue) {
|
||||||
|
|
|
||||||
|
|
@ -694,7 +694,7 @@ static void AddGlassToRay(RTCIntersectContext *context, unsigned rayIndex, float
|
||||||
}
|
}
|
||||||
|
|
||||||
// clamp opacity
|
// clamp opacity
|
||||||
opacity = clamp(opacity, 0.0f, 1.0f);
|
opacity = std::clamp(opacity, 0.0f, 1.0f);
|
||||||
|
|
||||||
Q_assert(rayIndex < rs->_numrays);
|
Q_assert(rayIndex < rs->_numrays);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -935,7 +935,7 @@ void GLView::renderBSP(const QString &file, const mbsp_t &bsp, const bspxentries
|
||||||
int32_t highest_depth = 0;
|
int32_t highest_depth = 0;
|
||||||
|
|
||||||
for (auto &style : lightmap.style_to_lightmap_atlas) {
|
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
|
// upload lightmap atlases
|
||||||
|
|
@ -1506,7 +1506,7 @@ void GLView::wheelEvent(QWheelEvent *event)
|
||||||
double delta = event->angleDelta().y();
|
double delta = event->angleDelta().y();
|
||||||
|
|
||||||
m_moveSpeed += delta;
|
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)
|
void GLView::mousePressEvent(QMouseEvent *event)
|
||||||
|
|
|
||||||
|
|
@ -661,12 +661,12 @@ std::optional<bspbrush_t> LoadBrush(const mapentity_t &src, mapbrush_t &mapbrush
|
||||||
vec_t max = -std::numeric_limits<vec_t>::infinity(), min = std::numeric_limits<vec_t>::infinity();
|
vec_t max = -std::numeric_limits<vec_t>::infinity(), min = std::numeric_limits<vec_t>::infinity();
|
||||||
|
|
||||||
for (auto &v : brush.bounds.mins()) {
|
for (auto &v : brush.bounds.mins()) {
|
||||||
min = ::min(min, v);
|
min = std::min(min, v);
|
||||||
max = ::max(max, v);
|
max = std::max(max, v);
|
||||||
}
|
}
|
||||||
for (auto &v : brush.bounds.maxs()) {
|
for (auto &v : brush.bounds.maxs()) {
|
||||||
min = ::min(min, v);
|
min = std::min(min, v);
|
||||||
max = ::max(max, v);
|
max = std::max(max, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec_t delta = std::max(fabs(max), fabs(min));
|
vec_t delta = std::max(fabs(max), fabs(min));
|
||||||
|
|
|
||||||
|
|
@ -816,8 +816,8 @@ inline void DivideBounds(const aabb3d &in_bounds, const qbsp_plane_t &split, aab
|
||||||
mid *= (dist1 / (dist1 - dist2));
|
mid *= (dist1 / (dist1 - dist2));
|
||||||
mid += in_bounds[0][a];
|
mid += in_bounds[0][a];
|
||||||
|
|
||||||
split_mins = max(min(mid, split_mins), in_bounds.mins()[a]);
|
split_mins = std::max(std::min(mid, split_mins), in_bounds.mins()[a]);
|
||||||
split_maxs = min(max(mid, split_maxs), in_bounds.maxs()[a]);
|
split_maxs = std::min(std::max(mid, split_maxs), in_bounds.maxs()[a]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (split.get_normal()[a] > 0) {
|
if (split.get_normal()[a] > 0) {
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ void UpdateFaceSphere(face_t *in)
|
||||||
in->origin = in->w.center();
|
in->origin = in->w.center();
|
||||||
in->radius = 0;
|
in->radius = 0;
|
||||||
for (size_t i = 0; i < in->w.size(); i++) {
|
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);
|
in->radius = sqrt(in->radius);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -366,7 +366,7 @@ static std::list<std::unique_ptr<face_t>> SubdivideFace(std::unique_ptr<face_t>
|
||||||
|
|
||||||
// legacy engines support 18*18 max blocks (at 1:16 scale).
|
// 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.
|
// 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;
|
// subdiv += 8;
|
||||||
|
|
||||||
|
|
|
||||||
22
qbsp/map.cc
22
qbsp/map.cc
|
|
@ -751,11 +751,11 @@ static surfflags_t SurfFlagsForEntity(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (phongangle) {
|
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");
|
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");
|
flags.phong_group = entity.epairs.get_int("_phong_group");
|
||||||
|
|
||||||
|
|
@ -763,7 +763,7 @@ static surfflags_t SurfFlagsForEntity(
|
||||||
if (entity.epairs.has("_minlight")) {
|
if (entity.epairs.has("_minlight")) {
|
||||||
const vec_t minlight = entity.epairs.get_float("_minlight");
|
const vec_t minlight = entity.epairs.get_float("_minlight");
|
||||||
// handle -1 as an alias for 0 (same with other negative values).
|
// 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"
|
// handle "_maxlight"
|
||||||
|
|
@ -771,14 +771,14 @@ static surfflags_t SurfFlagsForEntity(
|
||||||
if (maxlight > 0) {
|
if (maxlight > 0) {
|
||||||
// CHECK: allow > 510 now that we're float? or is it not worth it since it will
|
// CHECK: allow > 510 now that we're float? or is it not worth it since it will
|
||||||
// be beyond max?
|
// be beyond max?
|
||||||
flags.maxlight = clamp(maxlight, 0.0, 510.0);
|
flags.maxlight = std::clamp(maxlight, 0.0, 510.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle "_lightcolorscale"
|
// handle "_lightcolorscale"
|
||||||
if (entity.epairs.has("_lightcolorscale")) {
|
if (entity.epairs.has("_lightcolorscale")) {
|
||||||
const vec_t lightcolorscale = entity.epairs.get_float("_lightcolorscale");
|
const vec_t lightcolorscale = entity.epairs.get_float("_lightcolorscale");
|
||||||
if (lightcolorscale != 1.0) {
|
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);
|
mincolor = qv::normalize_color_format(mincolor);
|
||||||
if (!qv::epsilonEmpty(mincolor, QBSP_EQUAL_EPSILON)) {
|
if (!qv::epsilonEmpty(mincolor, QBSP_EQUAL_EPSILON)) {
|
||||||
for (int32_t i = 0; i < 3; i++) {
|
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"
|
// handle "_light_alpha"
|
||||||
if (entity.epairs.has("_light_alpha")) {
|
if (entity.epairs.has("_light_alpha")) {
|
||||||
const vec_t lightalpha = entity.epairs.get_float("_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;
|
return flags;
|
||||||
|
|
@ -1129,7 +1129,7 @@ float clockwiseDegreesBetween(qvec2f start, qvec2f end)
|
||||||
start = qv::normalize(start);
|
start = qv::normalize(start);
|
||||||
end = qv::normalize(end);
|
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));
|
const float unsigned_degrees = acos(cosAngle) * (360.0 / (2.0 * Q_PI));
|
||||||
|
|
||||||
if (unsigned_degrees < ANGLEEPSILON)
|
if (unsigned_degrees < ANGLEEPSILON)
|
||||||
|
|
@ -3712,7 +3712,7 @@ inline vec_t GetBrushExtents(const mapbrush_t &hullbrush)
|
||||||
if (legal) {
|
if (legal) {
|
||||||
|
|
||||||
for (auto &p : *vertex) {
|
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(map.entities, [&](const mapentity_t &entity) {
|
||||||
tbb::parallel_for_each(entity.mapbrushes, [&](const mapbrush_t &mapbrush) {
|
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;
|
vec_t currentExtents = extents;
|
||||||
while (currentExtents < brushExtents && !extents.compare_exchange_weak(currentExtents, brushExtents))
|
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 &hull : qbsp_options.target_game->get_hull_sizes()) {
|
||||||
for (auto &v : hull.size()) {
|
for (auto &v : hull.size()) {
|
||||||
hull_extents = max(hull_extents, fabs(v));
|
hull_extents = std::max(hull_extents, fabs(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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) */
|
/* Allocate for worst case where RLE might grow the data (unlikely) */
|
||||||
if (bsp->loadversion->game->id == GAME_QUAKE_II) {
|
if (bsp->loadversion->game->id == GAME_QUAKE_II) {
|
||||||
compressed.reserve(max(1, (portalleafs * 2) / 8));
|
compressed.reserve(std::max(1, (portalleafs * 2) / 8));
|
||||||
} else {
|
} else {
|
||||||
compressed.reserve(max(1, (portalleafs_real * 2) / 8));
|
compressed.reserve(std::max(1, (portalleafs_real * 2) / 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
numportals = prtfile.portals.size();
|
numportals = prtfile.portals.size();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue