From 050f1dc8dfcdd4f6b6f111c67177db6c85f4c0b4 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Wed, 18 Sep 2019 08:34:36 +0000 Subject: [PATCH] Removes usages of duplication of Clamp function in graphics. Refs D1763. This was SVN commit r22925. --- source/graphics/Camera.cpp | 8 +-- source/graphics/Color.cpp | 8 +-- source/graphics/Decal.cpp | 10 +-- source/graphics/HFTracer.cpp | 6 +- source/graphics/HeightMipmap.cpp | 30 ++++----- source/graphics/LightEnv.h | 2 +- source/graphics/MaterialManager.cpp | 2 +- source/graphics/ObjectBase.cpp | 6 +- source/graphics/ParticleEmitterType.cpp | 4 +- source/graphics/Terrain.cpp | 82 ++++++++++++------------- 10 files changed, 79 insertions(+), 79 deletions(-) diff --git a/source/graphics/Camera.cpp b/source/graphics/Camera.cpp index 5b6462a1e4..86ee8cf38d 100644 --- a/source/graphics/Camera.cpp +++ b/source/graphics/Camera.cpp @@ -231,8 +231,8 @@ CVector3D CCamera::GetWorldCoordinates(int px, int py, bool aboveWater) const ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); if (gotWater) { - waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); - waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); + waterPoint.X = Clamp(waterPoint.X, 0.f, static_cast((mapSize - 1) * TERRAIN_TILE_SIZE)); + waterPoint.Z = Clamp(waterPoint.Z, 0.f, static_cast((mapSize - 1) * TERRAIN_TILE_SIZE)); } if (gotTerrain) @@ -309,8 +309,8 @@ CVector3D CCamera::GetFocus() const ssize_t mapSize = g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide(); if (gotWater) { - waterPoint.X = clamp(waterPoint.X, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); - waterPoint.Z = clamp(waterPoint.Z, 0.f, (float)((mapSize-1)*TERRAIN_TILE_SIZE)); + waterPoint.X = Clamp(waterPoint.X, 0.f, static_cast((mapSize - 1) * TERRAIN_TILE_SIZE)); + waterPoint.Z = Clamp(waterPoint.Z, 0.f, static_cast((mapSize - 1) * TERRAIN_TILE_SIZE)); } if (gotTerrain) diff --git a/source/graphics/Color.cpp b/source/graphics/Color.cpp index b4ed365751..4c2fc454c2 100644 --- a/source/graphics/Color.cpp +++ b/source/graphics/Color.cpp @@ -32,9 +32,9 @@ static SColor4ub fallback_ConvertRGBColorTo4ub(const RGBColor& src) { SColor4ub result; - result.R = clamp(static_cast(src.X * 255), 0, 255); - result.G = clamp(static_cast(src.Y * 255), 0, 255); - result.B = clamp(static_cast(src.Z * 255), 0, 255); + result.R = Clamp(static_cast(src.X * 255), 0, 255); + result.G = Clamp(static_cast(src.Y * 255), 0, 255); + result.B = Clamp(static_cast(src.Z * 255), 0, 255); result.A = 255; return result; } @@ -53,7 +53,7 @@ static SColor4ub sse_ConvertRGBColorTo4ub(const RGBColor& src) __m128 g = _mm_load_ss(&src.Y); __m128 b = _mm_load_ss(&src.Z); - // C = min(255, 255*max(C, 0)) ( == clamp(255*C, 0, 255) ) + // C = min(255, 255*max(C, 0)) ( == Clamp(255*C, 0, 255) ) r = _mm_max_ss(r, zero); g = _mm_max_ss(g, zero); b = _mm_max_ss(b, zero); diff --git a/source/graphics/Decal.cpp b/source/graphics/Decal.cpp index 17660d3dd0..f8b513da98 100644 --- a/source/graphics/Decal.cpp +++ b/source/graphics/Decal.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2013 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -45,10 +45,10 @@ void CModelDecal::CalcVertexExtents(ssize_t& i0, ssize_t& j0, ssize_t& i1, ssize i1 = ceil(std::max(std::max(corner0.X, corner1.X), std::max(corner2.X, corner3.X)) / TERRAIN_TILE_SIZE); j1 = ceil(std::max(std::max(corner0.Z, corner1.Z), std::max(corner2.Z, corner3.Z)) / TERRAIN_TILE_SIZE); - i0 = clamp(i0, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1); - j0 = clamp(j0, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1); - i1 = clamp(i1, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1); - j1 = clamp(j1, (ssize_t)0, m_Terrain->GetVerticesPerSide()-1); + i0 = Clamp(i0, static_cast(0), m_Terrain->GetVerticesPerSide() - 1); + j0 = Clamp(j0, static_cast(0), m_Terrain->GetVerticesPerSide() - 1); + i1 = Clamp(i1, static_cast(0), m_Terrain->GetVerticesPerSide() - 1); + j1 = Clamp(j1, static_cast(0), m_Terrain->GetVerticesPerSide() - 1); } void CModelDecal::CalcBounds() diff --git a/source/graphics/HFTracer.cpp b/source/graphics/HFTracer.cpp index df4c6fbb53..c0c7418ae1 100644 --- a/source/graphics/HFTracer.cpp +++ b/source/graphics/HFTracer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2014 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -323,8 +323,8 @@ bool CHFTracer::PatchRayIntersect(CPatch* patch, const CVector3D& origin, const // should be extremely rare, and it's safe and simple).) // Work out which tile we're starting in - int i = clamp((int)(entryPatch.X / TERRAIN_TILE_SIZE), 0, (int)PATCH_SIZE-1); - int j = clamp((int)(entryPatch.Z / TERRAIN_TILE_SIZE), 0, (int)PATCH_SIZE-1); + int i = Clamp(static_cast(entryPatch.X / TERRAIN_TILE_SIZE), 0, static_cast(PATCH_SIZE) - 1); + int j = Clamp(static_cast(entryPatch.Z / TERRAIN_TILE_SIZE), 0, static_cast(PATCH_SIZE) - 1); // Work out which direction the ray is going in int di = (dir.X >= 0 ? 1 : 0); diff --git a/source/graphics/HeightMipmap.cpp b/source/graphics/HeightMipmap.cpp index 92b1da3909..d665300d42 100644 --- a/source/graphics/HeightMipmap.cpp +++ b/source/graphics/HeightMipmap.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2012 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -63,11 +63,11 @@ void CHeightMipmap::Update(const u16* ptr, size_t left, size_t bottom, size_t ri for (size_t i = 0; i < m_Mipmap.size(); ++i) { // update window - left = clamp((size_t)floorf((float)left / mapSize * m_Mipmap[i].m_MapSize), 0, m_Mipmap[i].m_MapSize - 1); - bottom = clamp((size_t)floorf((float)bottom / mapSize * m_Mipmap[i].m_MapSize), 0, m_Mipmap[i].m_MapSize - 1); + left = Clamp(floorf(static_cast(left) / mapSize * m_Mipmap[i].m_MapSize), 0, m_Mipmap[i].m_MapSize - 1); + bottom = Clamp(floorf(static_cast(bottom) / mapSize * m_Mipmap[i].m_MapSize), 0, m_Mipmap[i].m_MapSize - 1); - right = clamp((size_t)ceilf((float)right / mapSize * m_Mipmap[i].m_MapSize), 0, m_Mipmap[i].m_MapSize); - top = clamp((size_t)ceilf((float)top / mapSize * m_Mipmap[i].m_MapSize), 0, m_Mipmap[i].m_MapSize); + right = Clamp(ceilf(static_cast(right) / mapSize * m_Mipmap[i].m_MapSize), 0, m_Mipmap[i].m_MapSize); + top = Clamp(ceilf(static_cast(top) / mapSize * m_Mipmap[i].m_MapSize), 0, m_Mipmap[i].m_MapSize); // TODO: should verify that the bounds calculations are actually correct @@ -104,9 +104,9 @@ float CHeightMipmap::GetTrilinearGroundLevel(float x, float z, float radius) con if (radius <= 0.0f) // avoid logf of non-positive value y = 0.0f; else - y = clamp(logf(radius * m_Mipmap[0].m_MapSize) / logf(2), 0, m_Mipmap.size()); + y = Clamp(logf(radius * m_Mipmap[0].m_MapSize) / logf(2), 0.0f, m_Mipmap.size()); - const size_t iy = (size_t)clamp((ssize_t)floorf(y), 0, m_Mipmap.size() - 2); + const size_t iy = static_cast(Clamp(floorf(y), 0, m_Mipmap.size() - 2)); const float fy = y - iy; @@ -121,11 +121,11 @@ float CHeightMipmap::BilinearFilter(const SMipmap &mipmap, float x, float z) con x *= mipmap.m_MapSize; z *= mipmap.m_MapSize; - const size_t xi = (size_t)clamp((ssize_t)floor(x), 0, mipmap.m_MapSize - 2); - const size_t zi = (size_t)clamp((ssize_t)floor(z), 0, mipmap.m_MapSize - 2); + const size_t xi = static_cast(Clamp(floor(x), 0, mipmap.m_MapSize - 2)); + const size_t zi = static_cast(Clamp(floor(z), 0, mipmap.m_MapSize - 2)); - const float xf = clamp(x-xi, 0.0f, 1.0f); - const float zf = clamp(z-zi, 0.0f, 1.0f); + const float xf = Clamp(x-xi, 0.0f, 1.0f); + const float zf = Clamp(z-zi, 0.0f, 1.0f); const float h00 = mipmap.m_Heightmap[zi*mipmap.m_MapSize + xi]; const float h01 = mipmap.m_Heightmap[(zi+1)*mipmap.m_MapSize + xi]; @@ -198,11 +198,11 @@ void CHeightMipmap::BilinearUpdate(SMipmap &out_mipmap, size_t mapSize, const u1 const float x = ((float)dstX / (float)out_mipmap.m_MapSize) * mapSize; const float z = ((float)dstZ / (float)out_mipmap.m_MapSize) * mapSize; - const size_t srcX = clamp((size_t)x, 0, mapSize - 2); - const size_t srcZ = clamp((size_t)z, 0, mapSize - 2); + const size_t srcX = Clamp(x, 0, mapSize - 2); + const size_t srcZ = Clamp(z, 0, mapSize - 2); - const float fx = clamp(x - srcX, 0.0f, 1.0f); - const float fz = clamp(z - srcZ, 0.0f, 1.0f); + const float fx = Clamp(x - srcX, 0.0f, 1.0f); + const float fz = Clamp(z - srcZ, 0.0f, 1.0f); const float h00 = ptr[srcX + 0 + srcZ * mapSize]; const float h10 = ptr[srcX + 1 + srcZ * mapSize]; diff --git a/source/graphics/LightEnv.h b/source/graphics/LightEnv.h index fce44cebf0..bcc79fbca1 100644 --- a/source/graphics/LightEnv.h +++ b/source/graphics/LightEnv.h @@ -94,7 +94,7 @@ public: SColor4ub EvaluateTerrainDiffuseFactor(const CVector3D& normal) const { float dot = -normal.Dot(m_SunDir); - u8 c = static_cast(clamp(dot * 255.f, 0.f, 255.f)); + u8 c = static_cast(Clamp(dot * 255.f, 0.f, 255.f)); return SColor4ub(c, c, c, 255); } diff --git a/source/graphics/MaterialManager.cpp b/source/graphics/MaterialManager.cpp index c41a1c65e6..617ef81b1c 100644 --- a/source/graphics/MaterialManager.cpp +++ b/source/graphics/MaterialManager.cpp @@ -35,7 +35,7 @@ CMaterialManager::CMaterialManager() { qualityLevel = 5.0; CFG_GET_VAL("materialmgr.quality", qualityLevel); - qualityLevel = clamp(qualityLevel, 0.0f, 10.0f); + qualityLevel = Clamp(qualityLevel, 0.0f, 10.0f); if (VfsDirectoryExists(L"art/materials/") && !CXeromyces::AddValidator(g_VFS, "material", "art/materials/material.rng")) LOGERROR("CMaterialManager: failed to load grammar file 'art/materials/material.rng'"); diff --git a/source/graphics/ObjectBase.cpp b/source/graphics/ObjectBase.cpp index 7b55c0d2bc..837bb82a21 100644 --- a/source/graphics/ObjectBase.cpp +++ b/source/graphics/ObjectBase.cpp @@ -173,11 +173,11 @@ void CObjectBase::LoadVariant(const CXeromyces& XeroFile, const XMBElement& vari else if (ae.Name == at_speed) anim.m_Speed = ae.Value.ToInt() > 0 ? ae.Value.ToInt() / 100.f : 1.f; else if (ae.Name == at_event) - anim.m_ActionPos = clamp(ae.Value.ToFloat(), 0.f, 1.f); + anim.m_ActionPos = Clamp(ae.Value.ToFloat(), 0.f, 1.f); else if (ae.Name == at_load) - anim.m_ActionPos2 = clamp(ae.Value.ToFloat(), 0.f, 1.f); + anim.m_ActionPos2 = Clamp(ae.Value.ToFloat(), 0.f, 1.f); else if (ae.Name == at_sound) - anim.m_SoundPos = clamp(ae.Value.ToFloat(), 0.f, 1.f); + anim.m_SoundPos = Clamp(ae.Value.ToFloat(), 0.f, 1.f); } currentVariant.m_Anims.push_back(anim); } diff --git a/source/graphics/ParticleEmitterType.cpp b/source/graphics/ParticleEmitterType.cpp index 46a540d732..7a29f26c77 100644 --- a/source/graphics/ParticleEmitterType.cpp +++ b/source/graphics/ParticleEmitterType.cpp @@ -587,8 +587,8 @@ void CParticleEmitterType::UpdateEmitterStep(CParticleEmitter& emitter, float dt // TODO: this should probably be done as a variable or something, // instead of hardcoding float ageFrac = p.age / p.maxAge; - float a = std::min(1.f-ageFrac, 5.f*ageFrac); - p.color.A = clamp((int)(a*255.f), 0, 255); + float a = std::min(1.f - ageFrac, 5.f * ageFrac); + p.color.A = Clamp(static_cast(a * 255.f), 0, 255); } for (size_t i = 0; i < m_Effectors.size(); ++i) diff --git a/source/graphics/Terrain.cpp b/source/graphics/Terrain.cpp index 28c180ed7f..da95c2352a 100644 --- a/source/graphics/Terrain.cpp +++ b/source/graphics/Terrain.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2015 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -118,8 +118,8 @@ CStr8 CTerrain::GetMovementClass(ssize_t i, ssize_t j) const // outwards to infinity void CTerrain::CalcPosition(ssize_t i, ssize_t j, CVector3D& pos) const { - ssize_t hi = clamp(i, (ssize_t)0, m_MapSize-1); - ssize_t hj = clamp(j, (ssize_t)0, m_MapSize-1); + ssize_t hi = Clamp(i, static_cast(0), m_MapSize - 1); + ssize_t hj = Clamp(j, static_cast(0), m_MapSize - 1); u16 height = m_Heightmap[hj*m_MapSize + hi]; pos.X = float(i*TERRAIN_TILE_SIZE); pos.Y = float(height*HEIGHT_SCALE); @@ -130,8 +130,8 @@ void CTerrain::CalcPosition(ssize_t i, ssize_t j, CVector3D& pos) const // CalcPositionFixed: calculate the world space position of the vertex at (i,j) void CTerrain::CalcPositionFixed(ssize_t i, ssize_t j, CFixedVector3D& pos) const { - ssize_t hi = clamp(i, (ssize_t)0, m_MapSize-1); - ssize_t hj = clamp(j, (ssize_t)0, m_MapSize-1); + ssize_t hi = Clamp(i, static_cast(0), m_MapSize - 1); + ssize_t hj = Clamp(j, static_cast(0), m_MapSize - 1); u16 height = m_Heightmap[hj*m_MapSize + hi]; pos.X = fixed::FromInt(i) * (int)TERRAIN_TILE_SIZE; // fixed max value is 32767, but height is a u16, so divide by two to avoid overflow @@ -236,11 +236,11 @@ void CTerrain::CalcNormalFixed(ssize_t i, ssize_t j, CFixedVector3D& normal) con CVector3D CTerrain::CalcExactNormal(float x, float z) const { // Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) - const ssize_t xi = clamp((ssize_t)floor(x/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); - const ssize_t zi = clamp((ssize_t)floor(z/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); + const ssize_t xi = Clamp(static_cast(floor(x / TERRAIN_TILE_SIZE)), static_cast(0), m_MapSize - 2); + const ssize_t zi = Clamp(static_cast(floor(z / TERRAIN_TILE_SIZE)), static_cast(0), m_MapSize - 2); - const float xf = clamp(x/TERRAIN_TILE_SIZE-xi, 0.0f, 1.0f); - const float zf = clamp(z/TERRAIN_TILE_SIZE-zi, 0.0f, 1.0f); + const float xf = Clamp(x / TERRAIN_TILE_SIZE-xi, 0.0f, 1.0f); + const float zf = Clamp(z / TERRAIN_TILE_SIZE-zi, 0.0f, 1.0f); float h00 = m_Heightmap[zi*m_MapSize + xi]; float h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; @@ -308,15 +308,15 @@ CMiniPatch* CTerrain::GetTile(ssize_t i, ssize_t j) const float CTerrain::GetVertexGroundLevel(ssize_t i, ssize_t j) const { - i = clamp(i, (ssize_t)0, m_MapSize-1); - j = clamp(j, (ssize_t)0, m_MapSize-1); + i = Clamp(i, static_cast(0), m_MapSize - 1); + j = Clamp(j, static_cast(0), m_MapSize - 1); return HEIGHT_SCALE * m_Heightmap[j*m_MapSize + i]; } fixed CTerrain::GetVertexGroundLevelFixed(ssize_t i, ssize_t j) const { - i = clamp(i, (ssize_t)0, m_MapSize-1); - j = clamp(j, (ssize_t)0, m_MapSize-1); + i = Clamp(i, static_cast(0), m_MapSize - 1); + j = Clamp(j, static_cast(0), m_MapSize - 1); // Convert to fixed metres (being careful to avoid intermediate overflows) return fixed::FromInt(m_Heightmap[j*m_MapSize + i] / 2) / (int)(HEIGHT_UNITS_PER_METRE / 2); } @@ -324,8 +324,8 @@ fixed CTerrain::GetVertexGroundLevelFixed(ssize_t i, ssize_t j) const fixed CTerrain::GetSlopeFixed(ssize_t i, ssize_t j) const { // Clamp to size-2 so we can use the tiles (i,j)-(i+1,j+1) - i = clamp(i, (ssize_t)0, m_MapSize-2); - j = clamp(j, (ssize_t)0, m_MapSize-2); + i = Clamp(i, static_cast(0), m_MapSize - 2); + j = Clamp(j, static_cast(0), m_MapSize - 2); u16 h00 = m_Heightmap[j*m_MapSize + i]; u16 h01 = m_Heightmap[(j+1)*m_MapSize + i]; @@ -343,13 +343,13 @@ fixed CTerrain::GetSlopeFixed(ssize_t i, ssize_t j) const fixed CTerrain::GetExactSlopeFixed(fixed x, fixed z) const { // Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) - const ssize_t xi = clamp((ssize_t)(x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); - const ssize_t zi = clamp((ssize_t)(z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); + const ssize_t xi = Clamp((x / static_cast(TERRAIN_TILE_SIZE)).ToInt_RoundToZero(), 0, m_MapSize - 2); + const ssize_t zi = Clamp((z / static_cast(TERRAIN_TILE_SIZE)).ToInt_RoundToZero(), 0, m_MapSize - 2); const fixed one = fixed::FromInt(1); - const fixed xf = clamp((x / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(xi), fixed::Zero(), one); - const fixed zf = clamp((z / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(zi), fixed::Zero(), one); + const fixed xf = Clamp((x / static_cast(TERRAIN_TILE_SIZE)) - fixed::FromInt(xi), fixed::Zero(), one); + const fixed zf = Clamp((z / static_cast(TERRAIN_TILE_SIZE)) - fixed::FromInt(zi), fixed::Zero(), one); u16 h00 = m_Heightmap[zi*m_MapSize + xi]; u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; @@ -406,11 +406,11 @@ float CTerrain::GetFilteredGroundLevel(float x, float z, float radius) const float CTerrain::GetExactGroundLevel(float x, float z) const { // Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) - const ssize_t xi = clamp((ssize_t)floor(x/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); - const ssize_t zi = clamp((ssize_t)floor(z/TERRAIN_TILE_SIZE), (ssize_t)0, m_MapSize-2); + const ssize_t xi = Clamp(floor(x / TERRAIN_TILE_SIZE), 0, m_MapSize - 2); + const ssize_t zi = Clamp(floor(z / TERRAIN_TILE_SIZE), 0, m_MapSize - 2); - const float xf = clamp(x/TERRAIN_TILE_SIZE-xi, 0.0f, 1.0f); - const float zf = clamp(z/TERRAIN_TILE_SIZE-zi, 0.0f, 1.0f); + const float xf = Clamp(x / TERRAIN_TILE_SIZE - xi, 0.0f, 1.0f); + const float zf = Clamp(z / TERRAIN_TILE_SIZE - zi, 0.0f, 1.0f); float h00 = m_Heightmap[zi*m_MapSize + xi]; float h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; @@ -451,13 +451,13 @@ float CTerrain::GetExactGroundLevel(float x, float z) const fixed CTerrain::GetExactGroundLevelFixed(fixed x, fixed z) const { // Clamp to size-2 so we can use the tiles (xi,zi)-(xi+1,zi+1) - const ssize_t xi = clamp((ssize_t)(x / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); - const ssize_t zi = clamp((ssize_t)(z / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), (ssize_t)0, m_MapSize-2); + const ssize_t xi = Clamp((x / static_cast(TERRAIN_TILE_SIZE)).ToInt_RoundToZero(), 0, m_MapSize - 2); + const ssize_t zi = Clamp((z / static_cast(TERRAIN_TILE_SIZE)).ToInt_RoundToZero(), 0, m_MapSize - 2); const fixed one = fixed::FromInt(1); - const fixed xf = clamp((x / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(xi), fixed::Zero(), one); - const fixed zf = clamp((z / (int)TERRAIN_TILE_SIZE) - fixed::FromInt(zi), fixed::Zero(), one); + const fixed xf = Clamp((x / static_cast(TERRAIN_TILE_SIZE)) - fixed::FromInt(xi), fixed::Zero(), one); + const fixed zf = Clamp((z / static_cast(TERRAIN_TILE_SIZE)) - fixed::FromInt(zi), fixed::Zero(), one); u16 h00 = m_Heightmap[zi*m_MapSize + xi]; u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; @@ -480,8 +480,8 @@ fixed CTerrain::GetExactGroundLevelFixed(fixed x, fixed z) const bool CTerrain::GetTriangulationDir(ssize_t i, ssize_t j) const { // Clamp to size-2 so we can use the tiles (i,j)-(i+1,j+1) - i = clamp(i, (ssize_t)0, m_MapSize-2); - j = clamp(j, (ssize_t)0, m_MapSize-2); + i = Clamp(i, static_cast(0), m_MapSize - 2); + j = Clamp(j, static_cast(0), m_MapSize - 2); int h00 = m_Heightmap[j*m_MapSize + i]; int h01 = m_Heightmap[(j+1)*m_MapSize + i]; @@ -651,10 +651,10 @@ void CTerrain::SetHeightMap(u16* heightmap) void CTerrain::MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dirtyFlags) { // Finds the inclusive limits of the patches that include the specified range of tiles - ssize_t pi0 = clamp( i0 /PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1); - ssize_t pi1 = clamp((i1-1)/PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1); - ssize_t pj0 = clamp( j0 /PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1); - ssize_t pj1 = clamp((j1-1)/PATCH_SIZE, (ssize_t)0, m_MapSizePatches-1); + ssize_t pi0 = Clamp( i0 /PATCH_SIZE, static_cast(0), m_MapSizePatches-1); + ssize_t pi1 = Clamp((i1-1)/PATCH_SIZE, static_cast(0), m_MapSizePatches-1); + ssize_t pj0 = Clamp( j0 /PATCH_SIZE, static_cast(0), m_MapSizePatches-1); + ssize_t pj1 = Clamp((j1-1)/PATCH_SIZE, static_cast(0), m_MapSizePatches-1); for (ssize_t j = pj0; j <= pj1; j++) { @@ -670,10 +670,10 @@ void CTerrain::MakeDirty(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1, int dir if (m_Heightmap) { m_HeightMipmap.Update(m_Heightmap, - clamp(i0, (ssize_t)0, m_MapSize-1), - clamp(j0, (ssize_t)0, m_MapSize-1), - clamp(i1, (ssize_t)1, m_MapSize), - clamp(j1, (ssize_t)1, m_MapSize) + Clamp(i0, static_cast(0), m_MapSize - 1), + Clamp(j0, static_cast(0), m_MapSize - 1), + Clamp(i1, static_cast(1), m_MapSize), + Clamp(j1, static_cast(1), m_MapSize) ); } } @@ -697,10 +697,10 @@ void CTerrain::MakeDirty(int dirtyFlags) CBoundingBoxAligned CTerrain::GetVertexesBound(ssize_t i0, ssize_t j0, ssize_t i1, ssize_t j1) { - i0 = clamp(i0, (ssize_t)0, m_MapSize-1); - j0 = clamp(j0, (ssize_t)0, m_MapSize-1); - i1 = clamp(i1, (ssize_t)0, m_MapSize-1); - j1 = clamp(j1, (ssize_t)0, m_MapSize-1); + i0 = Clamp(i0, static_cast(0), m_MapSize - 1); + j0 = Clamp(j0, static_cast(0), m_MapSize - 1); + i1 = Clamp(i1, static_cast(0), m_MapSize - 1); + j1 = Clamp(j1, static_cast(0), m_MapSize - 1); u16 minH = 65535; u16 maxH = 0;