Index: source/graphics/Camera.cpp =================================================================== --- source/graphics/Camera.cpp +++ source/graphics/Camera.cpp @@ -224,8 +224,8 @@ 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) @@ -302,8 +302,8 @@ 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) Index: source/graphics/Color.cpp =================================================================== --- source/graphics/Color.cpp +++ 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; } Index: source/graphics/Decal.cpp =================================================================== --- source/graphics/Decal.cpp +++ 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 @@ 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() Index: source/graphics/HFTracer.cpp =================================================================== --- source/graphics/HFTracer.cpp +++ 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 @@ // 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); Index: source/graphics/HeightMipmap.cpp =================================================================== --- source/graphics/HeightMipmap.cpp +++ 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 @@ 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 @@ 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, 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 @@ 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 @@ 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((size_t)x, 0, mapSize - 2); + const size_t srcZ = Clamp((size_t)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]; Index: source/graphics/LightEnv.h =================================================================== --- source/graphics/LightEnv.h +++ source/graphics/LightEnv.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 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 @@ -128,7 +128,7 @@ 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); } Index: source/graphics/MapIO.cpp =================================================================== --- source/graphics/MapIO.cpp +++ source/graphics/MapIO.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 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 @@ -89,7 +89,7 @@ u16 value = std::max({mapdata[offset], mapdata[offset + bytesPP], mapdata[offset + bytesPP * 2]}); value = mapdata[offset]; - heightmap[(tileSize - y) * (tileSize + 1) + x] = clamp(value * 256, 0, 65535); + heightmap[(tileSize - y) * (tileSize + 1) + x] = Clamp(value * 256, 0, 65535); } return INFO::OK; Index: source/graphics/MaterialManager.cpp =================================================================== --- source/graphics/MaterialManager.cpp +++ source/graphics/MaterialManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 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 @@ -35,7 +35,7 @@ { 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'"); Index: source/graphics/ObjectBase.cpp =================================================================== --- source/graphics/ObjectBase.cpp +++ source/graphics/ObjectBase.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 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 @@ -173,11 +173,11 @@ 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); } Index: source/graphics/ParticleEmitterType.cpp =================================================================== --- source/graphics/ParticleEmitterType.cpp +++ source/graphics/ParticleEmitterType.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 @@ -587,8 +587,8 @@ // 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) Index: source/graphics/Terrain.cpp =================================================================== --- source/graphics/Terrain.cpp +++ 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 @@ // 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 @@ // 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 @@ 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(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]; @@ -308,15 +308,15 @@ 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::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::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::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 @@ 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 / (int)TERRAIN_TILE_SIZE).ToInt_RoundToZero(), 0, m_MapSize-2); + const ssize_t zi = Clamp((z / (int)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 / (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); u16 h00 = m_Heightmap[zi*m_MapSize + xi]; u16 h01 = m_Heightmap[(zi+1)*m_MapSize + xi]; @@ -480,8 +480,8 @@ 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::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 @@ 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 @@ 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; Index: source/gui/CSlider.cpp =================================================================== --- source/gui/CSlider.cpp +++ source/gui/CSlider.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 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 @@ -19,6 +19,7 @@ #include "CSlider.h" #include "GUI.h" #include "lib/ogl.h" +#include "maths/MathUtil.h" #include "ps/CLogger.h" Index: source/gui/IGUIScrollBar.cpp =================================================================== --- source/gui/IGUIScrollBar.cpp +++ source/gui/IGUIScrollBar.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 @@ -58,7 +58,7 @@ max = length; // Clamp size to not exceed a minimum or maximum. - m_BarSize = clamp(length * std::min((float)m_ScrollSpace / (float)m_ScrollRange, 1.f), min, max); + m_BarSize = Clamp(length * std::min(m_ScrollSpace / m_ScrollRange, 1.f), min, max); } const SGUIScrollBarStyle* IGUIScrollBar::GetStyle() const Index: source/lib/lib.h =================================================================== --- source/lib/lib.h +++ source/lib/lib.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -63,14 +63,6 @@ #include // fabsf #include // numeric_limits #include // out_of_range -#include // min, max - -template -T Clamp(T val, T min, T max) -{ - ASSERT(min <= max); - return std::max(min, std::min(val, max)); -} template T DivideRoundUp(T dividend, T divisor) Index: source/maths/MathUtil.h =================================================================== --- source/maths/MathUtil.h +++ source/maths/MathUtil.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 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 @@ -23,17 +23,20 @@ #define SQR(x) ((x) * (x)) template -inline T Interpolate(const T& a, const T& b, float l) +inline T Interpolate(T a, T b, float t) { - return a + (b - a) * l; + return a + (b - a) * t; } template -inline T clamp(T value, T min, T max) +inline T Clamp(T value, T min, T max) { - if (value <= min) return min; - else if (value >= max) return max; - else return value; + ASSERT(min <= max); + if (value < min) + return min; + else if (value > max) + return max; + return value; } inline float sgn(float a) Index: source/ps/CConsole.cpp =================================================================== --- source/ps/CConsole.cpp +++ source/ps/CConsole.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 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 @@ -384,7 +384,7 @@ CScopeLock lock(m_Mutex); // needed for safe access to m_deqMsgHistory int linesShown = (int)m_fHeight/m_iFontHeight - 4; - m_iMsgHistPos = clamp((int)m_deqMsgHistory.size() - linesShown, 1, (int)m_deqMsgHistory.size()); + m_iMsgHistPos = Clamp(static_cast(m_deqMsgHistory.size()) - linesShown, 1, static_cast(m_deqMsgHistory.size())); } else { Index: source/renderer/SilhouetteRenderer.cpp =================================================================== --- source/renderer/SilhouetteRenderer.cpp +++ source/renderer/SilhouetteRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 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 @@ -189,10 +189,10 @@ // TODO: there must be a quicker way to do this than to test every vertex, // given the symmetry of the bounding box - occluder.x0 = clamp(x0, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); - occluder.y0 = clamp(y0, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); - occluder.x1 = clamp(x1, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); - occluder.y1 = clamp(y1, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); + occluder.x0 = Clamp(x0, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); + occluder.y0 = Clamp(y0, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); + occluder.x1 = Clamp(x1, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); + occluder.y1 = Clamp(y1, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); occluder.z = z0; } @@ -201,8 +201,8 @@ CVector4D svec = proj.Transform(CVector4D(pos.X, pos.Y, pos.Z, 1.0f)); u16 x = g_HalfMaxCoord + static_cast(g_HalfMaxCoord * svec.X / svec.W); u16 y = g_HalfMaxCoord + static_cast(g_HalfMaxCoord * svec.Y / svec.W); - caster.x = clamp(x, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); - caster.y = clamp(y, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); + caster.x = Clamp(x, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); + caster.y = Clamp(y, std::numeric_limits::min(), static_cast(g_MaxCoord - 1)); caster.z = svec.Z / svec.W; } Index: source/renderer/TerrainOverlay.cpp =================================================================== --- source/renderer/TerrainOverlay.cpp +++ source/renderer/TerrainOverlay.cpp @@ -134,10 +134,10 @@ // Clamp the min to 0, but the max to -1 - so tile -1 can never be rendered, // but if unclamped_max<0 then no tiles at all will be rendered. And the same // for the upper limit. - min_i = clamp(min_i, ssize_t(0), m_Terrain->GetTilesPerSide()); - min_j = clamp(min_j, ssize_t(0), m_Terrain->GetTilesPerSide()); - max_i = clamp(max_i, ssize_t(-1), m_Terrain->GetTilesPerSide()-1); - max_j = clamp(max_j, ssize_t(-1), m_Terrain->GetTilesPerSide()-1); + min_i = Clamp(min_i, static_cast(0), m_Terrain->GetTilesPerSide()); + min_j = Clamp(min_j, static_cast(0), m_Terrain->GetTilesPerSide()); + max_i = Clamp(max_i, static_cast(-1), m_Terrain->GetTilesPerSide() - 1); + max_j = Clamp(max_j, static_cast(-1), m_Terrain->GetTilesPerSide() - 1); for (m_j = min_j; m_j <= max_j; ++m_j) for (m_i = min_i; m_i <= max_i; ++m_i) Index: source/renderer/TerrainRenderer.cpp =================================================================== --- source/renderer/TerrainRenderer.cpp +++ source/renderer/TerrainRenderer.cpp @@ -284,7 +284,7 @@ glEnableClientState(GL_COLOR_ARRAY); // diffuse lighting colors // The vertex color is scaled by 0.5 to permit overbrightness without clamping. - // We therefore need to draw clamp((texture*lighting)*2.0), where 'texture' + // We therefore need to draw Clamp((texture*lighting)*2.0), where 'texture' // is what previous passes drew onto the framebuffer, and 'lighting' is the // color computed by this pass. // We can do that with blending by getting it to draw dst*src + src*dst: @@ -622,8 +622,8 @@ continue; scissor += screenBounds; } - return CBoundingBoxAligned(CVector3D(clamp(scissor[0].X, -1.0f, 1.0f), clamp(scissor[0].Y, -1.0f, 1.0f), -1.0f), - CVector3D(clamp(scissor[1].X, -1.0f, 1.0f), clamp(scissor[1].Y, -1.0f, 1.0f), 1.0f)); + return CBoundingBoxAligned(CVector3D(Clamp(scissor[0].X, -1.0f, 1.0f), Clamp(scissor[0].Y, -1.0f, 1.0f), -1.0f), + CVector3D(Clamp(scissor[1].X, -1.0f, 1.0f), Clamp(scissor[1].Y, -1.0f, 1.0f), 1.0f)); } // Render fancy water Index: source/renderer/TexturedLineRData.cpp =================================================================== --- source/renderer/TexturedLineRData.cpp +++ source/renderer/TexturedLineRData.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 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 @@ -392,7 +392,7 @@ // Let v range from 0 to 1 as we move along the semi-circle, keep u fixed at 0 (i.e. curve the left vertical edge // of the texture around the edge of the semicircle) float u = 0.f; - float v = clamp((i/(float)(roundCapPoints-1)), 0.f, 1.f); // pos, u, v + float v = Clamp((i / static_cast(roundCapPoints - 1)), 0.f, 1.f); // pos, u, v verticesOut.push_back(SVertex(worldPos3D, u, v)); } Index: source/renderer/WaterManager.cpp =================================================================== --- source/renderer/WaterManager.cpp +++ source/renderer/WaterManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 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 @@ -777,8 +777,8 @@ float baseHeight = 0.04f; - float halfWidth = (width-1.0f)/2.0f; - float sideNess = sqrtf(clamp( (halfWidth - fabsf(a-halfWidth))/3.0f, 0.0f,1.0f)); + float halfWidth = (width - 1.0f) / 2.0f; + float sideNess = sqrtf(Clamp((halfWidth - fabsf(a - halfWidth)) / 3.0f, 0.0f, 1.0f)); point[0].m_UV[0] = a; point[0].m_UV[1] = 8; point[1].m_UV[0] = a; point[1].m_UV[1] = 7; @@ -1077,14 +1077,14 @@ baseLevel *= baseLevel; tendency /= 15.0f; baseLevel -= tendency; // if the terrain was sloping downwards, increase baselevel. Otherwise reduce. - baseLevel = clamp(baseLevel,0.0f,1.0f); + baseLevel = Clamp(baseLevel, 0.0f, 1.0f); // Draw on map. This is pretty slow. float length = 35.0f * (1.0f-baseLevel/1.8f); for (float y = 0; y < length; y += 0.6f) { - int xx = clamp(i - y * windDir.X,0.0f,(float)(m_MapSize-1)); - int yy = clamp(j - y * windDir.Y,0.0f,(float)(m_MapSize-1)); + int xx = Clamp(i - y * windDir.X, 0.0f, static_cast(m_MapSize-1)); + int yy = Clamp(j - y * windDir.Y, 0.0f, static_cast(m_MapSize-1)); Temp[yy*m_MapSize + xx] = Temp[yy*m_MapSize + xx] < (0.0f+baseLevel/1.5f) * (1.0f-y/length) + y/length * 1.0f ? Temp[yy*m_MapSize + xx] : (0.0f+baseLevel/1.5f) * (1.0f-y/length) + y/length * 1.0f; } Index: source/simulation2/components/CCmpPathfinder_Vertex.cpp =================================================================== --- source/simulation2/components/CCmpPathfinder_Vertex.cpp +++ source/simulation2/components/CCmpPathfinder_Vertex.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 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 @@ -264,10 +264,10 @@ // won't have a boundary with any passable navcells. TODO: is that definitely // safe enough?) - i0 = clamp(i0, 1, grid.m_W-2); - j0 = clamp(j0, 1, grid.m_H-2); - i1 = clamp(i1, 1, grid.m_W-2); - j1 = clamp(j1, 1, grid.m_H-2); + i0 = Clamp(i0, 1, grid.m_W-2); + j0 = Clamp(j0, 1, grid.m_H-2); + i1 = Clamp(i1, 1, grid.m_W-2); + j1 = Clamp(j1, 1, grid.m_H-2); for (int j = j0; j <= j1; ++j) { @@ -823,8 +823,8 @@ // To prevent integer overflows later on, we need to ensure all vertexes are // 'close' to the source. The goal might be far away (not a good idea but // sometimes it happens), so clamp it to the current search range - npos.X = clamp(npos.X, rangeXMin, rangeXMax); - npos.Y = clamp(npos.Y, rangeZMin, rangeZMax); + npos.X = Clamp(npos.X, rangeXMin, rangeXMax); + npos.Y = Clamp(npos.Y, rangeZMin, rangeZMax); } else npos = vertexes[n].p; Index: source/simulation2/components/CCmpPosition.cpp =================================================================== --- source/simulation2/components/CCmpPosition.cpp +++ source/simulation2/components/CCmpPosition.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 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 @@ -786,7 +786,7 @@ if (delta < 0) delta += 2*(float)M_PI; // range 0..2PI delta -= (float)M_PI; // range -M_PI..M_PI // Clamp to max rate - float deltaClamped = clamp(delta, -m_RotYSpeed*msgData.deltaSimTime, +m_RotYSpeed*msgData.deltaSimTime); + float deltaClamped = Clamp(delta, -m_RotYSpeed*msgData.deltaSimTime, +m_RotYSpeed*msgData.deltaSimTime); // Calculate new orientation, in a peculiar way in order to make sure the // result gets close to m_orientation (rather than being n*2*M_PI out) m_InterpolatedRotY = rotY + deltaClamped - delta; Index: source/simulation2/components/CCmpTerritoryManager.cpp =================================================================== --- source/simulation2/components/CCmpTerritoryManager.cpp +++ source/simulation2/components/CCmpTerritoryManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 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 @@ -362,8 +362,8 @@ static void NearestTerritoryTile(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u16 h) { entity_pos_t scale = Pathfinding::NAVCELL_SIZE * ICmpTerritoryManager::NAVCELLS_PER_TERRITORY_TILE; - i = clamp((x / scale).ToInt_RoundToNegInfinity(), 0, w - 1); - j = clamp((z / scale).ToInt_RoundToNegInfinity(), 0, h - 1); + i = Clamp((x / scale).ToInt_RoundToNegInfinity(), 0, w - 1); + j = Clamp((z / scale).ToInt_RoundToNegInfinity(), 0, h - 1); } void CCmpTerritoryManager::CalculateCostGrid() Index: source/simulation2/helpers/Pathfinding.h =================================================================== --- source/simulation2/helpers/Pathfinding.h +++ source/simulation2/helpers/Pathfinding.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2016 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 @@ -145,8 +145,8 @@ inline void NearestNavcell(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u16 h) { // Use NAVCELL_SIZE_INT to save the cost of dividing by a fixed - i = (u16)clamp((x / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, w - 1); - j = (u16)clamp((z / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, h - 1); + i = static_cast(Clamp((x / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, w - 1)); + j = static_cast(Clamp((z / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, h - 1)); } /** Index: source/simulation2/helpers/Render.cpp =================================================================== --- source/simulation2/helpers/Render.cpp +++ source/simulation2/helpers/Render.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 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 @@ -88,7 +88,7 @@ } // Adapt the circle resolution to look reasonable for small and largeish radiuses - size_t numPoints = clamp((size_t)(radius*(end-start)), (size_t)12, (size_t)48); + size_t numPoints = Clamp(radius * (end - start), 12, 48); if (!isCircle) overlay.m_Coords.reserve((numPoints + 1 + 2) * 3); Index: source/simulation2/system/TurnManager.cpp =================================================================== --- source/simulation2/system/TurnManager.cpp +++ source/simulation2/system/TurnManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 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 @@ -214,7 +214,7 @@ // TODO: using m_TurnLength might be a bit dodgy when length changes - maybe // we need to save the previous turn length? - float offset = clamp(m_DeltaSimTime / (m_TurnLength / 1000.f) + 1.0, 0.0, 1.0); + float offset = Clamp(m_DeltaSimTime / (m_TurnLength / 1000.f) + 1.0, 0.0, 1.0); // Stop animations while still updating the selection highlight if (m_CurrentTurn > m_FinalTurn) Index: source/soundmanager/data/ogg.cpp =================================================================== --- source/soundmanager/data/ogg.cpp +++ source/soundmanager/data/ogg.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 @@ -22,12 +22,11 @@ #include "lib/external_libraries/openal.h" #include "lib/external_libraries/vorbis.h" - #include "lib/byte_order.h" #include "lib/file/io/io.h" #include "lib/file/file_system.h" - #include "lib/file/vfs/vfs_util.h" +#include "maths/MathUtil.h" #include "ps/CLogger.h" #include "ps/Filesystem.h" Index: source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/ElevationHandlers.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 @@ -33,6 +33,8 @@ #include "../Brushes.h" #include "../DeltaArray.h" +#include + namespace AtlasMessage { class TerrainArray : public DeltaArray2D @@ -50,7 +52,7 @@ if (size_t(x) >= size_t(m_VertsPerSide) || size_t(y) >= size_t(m_VertsPerSide)) return; - set(x,y, (u16)clamp(get(x,y) + amount, 0, 65535)); + set(x,y, static_cast(Clamp(get(x,y) + amount, 0, std::numeric_limits::max()))); } void MoveVertexTowards(ssize_t x, ssize_t y, int target, int amount) @@ -66,7 +68,7 @@ else return; - set(x,y, (u16)clamp(h, 0, 65535)); + set(x, y, static_cast(Clamp(h, 0, std::numeric_limits::max()))); } void SetVertex(ssize_t x, ssize_t y, u16 value) @@ -79,7 +81,7 @@ u16 GetVertex(ssize_t x, ssize_t y) { - return get(clamp(x, ssize_t(0), ssize_t(m_VertsPerSide-1)), clamp(y, ssize_t(0), ssize_t(m_VertsPerSide-1))); + return get(Clamp(x, static_cast(0), ssize_t(m_VertsPerSide - 1)), Clamp(y, static_cast(0), ssize_t(m_VertsPerSide - 1))); } protected: @@ -415,7 +417,7 @@ { float x = (float)dx - ((float)g_CurrentBrush.m_H - 1) / 2.f; float y = (float)dy - ((float)g_CurrentBrush.m_W - 1) / 2.f; - float distance = clamp(1 - (float)sqrt(x * x + y * y) / h, 0.01f, 1.0f); + float distance = Clamp(1.0f - sqrtf(x * x + y * y) / h, 0.01f, 1.0f); distance *= distance; m_TerrainDelta.RaiseVertex(x0 + dx, y0 + dy, (int)(amount * distance)); } Index: source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 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 @@ -173,8 +173,8 @@ ev.ev.button.clicks = msg->clicks; float x, y; msg->pos->GetScreenSpace(x, y); - ev.ev.button.x = (u16)clamp((int)x, 0, g_xres); - ev.ev.button.y = (u16)clamp((int)y, 0, g_yres); + ev.ev.button.x = static_cast(Clamp(static_cast(x), 0, g_xres)); + ev.ev.button.y = static_cast(Clamp(static_cast(y), 0, g_yres)); in_dispatch_event(&ev); } @@ -184,8 +184,8 @@ ev.ev.type = SDL_MOUSEMOTION; float x, y; msg->pos->GetScreenSpace(x, y); - ev.ev.motion.x = (u16)clamp((int)x, 0, g_xres); - ev.ev.motion.y = (u16)clamp((int)y, 0, g_yres); + ev.ev.motion.x = static_cast(Clamp(static_cast(x), 0, g_xres)); + ev.ev.motion.y = static_cast(Clamp(static_cast(y), 0, g_yres)); in_dispatch_event(&ev); } Index: source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp =================================================================== --- source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -377,14 +377,14 @@ // Clamp the position to the edges of the world: - // Use 'clamp' with a value slightly less than the width, so that converting + // Use 'Clamp' with a value slightly less than the width, so that converting // to integer (rounding towards zero) will put it on the tile inside the edge // instead of just outside float mapWidth = (g_Game->GetWorld()->GetTerrain()->GetVerticesPerSide()-1)*TERRAIN_TILE_SIZE; float delta = 1e-6f; // fraction of map width - must be > FLT_EPSILON - float xOnMap = clamp(vec.X, 0.f, mapWidth * (1.f - delta)); - float zOnMap = clamp(vec.Z, 0.f, mapWidth * (1.f - delta)); + float xOnMap = Clamp(vec.X, 0.f, mapWidth * (1.f - delta)); + float zOnMap = Clamp(vec.Z, 0.f, mapWidth * (1.f - delta)); // Don't waste time with GetExactGroundLevel unless we've changed if (xOnMap != vec.X || zOnMap != vec.Z)