From 7985ea4b8ea3c5361c413de0f214873499987486 Mon Sep 17 00:00:00 2001 From: vladislavbelov Date: Wed, 18 Sep 2019 15:02:36 +0000 Subject: [PATCH] Removes usages of duplication of Clamp function in simulation and atlas. Refs D1763. This was SVN commit r22927. --- source/simulation2/components/CCmpPosition.cpp | 4 ++-- .../simulation2/components/CCmpTerritoryManager.cpp | 6 +++--- source/simulation2/helpers/Pathfinding.h | 4 ++-- source/simulation2/helpers/Render.cpp | 4 ++-- source/simulation2/helpers/VertexPathfinder.cpp | 12 ++++++------ source/simulation2/system/TurnManager.cpp | 2 +- .../GameInterface/Handlers/ElevationHandlers.cpp | 10 +++++----- .../atlas/GameInterface/Handlers/MiscHandlers.cpp | 10 +++++----- .../atlas/GameInterface/Handlers/ObjectHandlers.cpp | 6 +++--- 9 files changed, 29 insertions(+), 29 deletions(-) diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp index 6460b4a2d5..cd272e8902 100644 --- a/source/simulation2/components/CCmpPosition.cpp +++ b/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 @@ public: 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; diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index 9659f395f4..36c1800c00 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/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 @@ struct Tile 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() diff --git a/source/simulation2/helpers/Pathfinding.h b/source/simulation2/helpers/Pathfinding.h index 9359deca2c..8b1e74811e 100644 --- a/source/simulation2/helpers/Pathfinding.h +++ b/source/simulation2/helpers/Pathfinding.h @@ -161,8 +161,8 @@ namespace Pathfinding 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)); } /** diff --git a/source/simulation2/helpers/Render.cpp b/source/simulation2/helpers/Render.cpp index 952df3e8c8..e5d6db66d3 100644 --- a/source/simulation2/helpers/Render.cpp +++ b/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 @@ -86,7 +86,7 @@ static void ConstructCircleOrClosedArc( } // 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); diff --git a/source/simulation2/helpers/VertexPathfinder.cpp b/source/simulation2/helpers/VertexPathfinder.cpp index 9dfd1f4e26..bd70bde08e 100644 --- a/source/simulation2/helpers/VertexPathfinder.cpp +++ b/source/simulation2/helpers/VertexPathfinder.cpp @@ -265,10 +265,10 @@ static void AddTerrainEdges(std::vector& edges, std::vector& verte // 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) { @@ -750,8 +750,8 @@ WaypointPath VertexPathfinder::ComputeShortPath(const ShortPathRequest& request, // 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 + EDGE_EXPAND_DELTA, rangeXMax - EDGE_EXPAND_DELTA); - npos.Y = clamp(npos.Y, rangeZMin + EDGE_EXPAND_DELTA, rangeZMax - EDGE_EXPAND_DELTA); + npos.X = Clamp(npos.X, rangeXMin + EDGE_EXPAND_DELTA, rangeXMax - EDGE_EXPAND_DELTA); + npos.Y = Clamp(npos.Y, rangeZMin + EDGE_EXPAND_DELTA, rangeZMax - EDGE_EXPAND_DELTA); } else npos = m_Vertexes[n].p; diff --git a/source/simulation2/system/TurnManager.cpp b/source/simulation2/system/TurnManager.cpp index c9965ad7f7..c2c7040e62 100644 --- a/source/simulation2/system/TurnManager.cpp +++ b/source/simulation2/system/TurnManager.cpp @@ -217,7 +217,7 @@ void CTurnManager::Interpolate(float simFrameLength, float realFrameLength) // 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) diff --git a/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp index d75d0f24f0..30e7090cbc 100644 --- a/source/tools/atlas/GameInterface/Handlers/ElevationHandlers.cpp +++ b/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 @@ -50,7 +50,7 @@ public: 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, 65535))); } void MoveVertexTowards(ssize_t x, ssize_t y, int target, int amount) @@ -66,7 +66,7 @@ public: else return; - set(x,y, (u16)clamp(h, 0, 65535)); + set(x, y, static_cast(Clamp(h, 0, 65535))); } void SetVertex(ssize_t x, ssize_t y, u16 value) @@ -79,7 +79,7 @@ public: 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, 0, m_VertsPerSide - 1), Clamp(y, 0, m_VertsPerSide - 1)); } protected: @@ -415,7 +415,7 @@ BEGIN_COMMAND(PikeElevation) { 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 - static_cast(sqrt(x * x + y * y)) / h, 0.01f, 1.0f); distance *= distance; m_TerrainDelta.RaiseVertex(x0 + dx, y0 + dy, (int)(amount * distance)); } diff --git a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp index 567587a6da..80b7385396 100644 --- a/source/tools/atlas/GameInterface/Handlers/MiscHandlers.cpp +++ b/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 @@ MESSAGEHANDLER(GuiMouseButtonEvent) 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(x, 0, g_xres)); + ev.ev.button.y = static_cast(Clamp(y, 0, g_yres)); in_dispatch_event(&ev); } @@ -184,8 +184,8 @@ MESSAGEHANDLER(GuiMouseMotionEvent) 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(x, 0, g_xres)); + ev.ev.motion.y = static_cast(Clamp(y, 0, g_yres)); in_dispatch_event(&ev); } diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index 2d9cabed69..2dfd5ecf3d 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -378,14 +378,14 @@ static CVector3D GetUnitPos(const Position& pos, bool floating) // 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)