forked from 0ad/0ad
Removes usages of duplication of Clamp function in simulation and atlas. Refs D1763.
This was SVN commit r22927.
This commit is contained in:
parent
f1de8eb4ba
commit
7985ea4b8e
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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<u16>(Clamp((x / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, w - 1));
|
||||
j = static_cast<u16>(Clamp((z / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, h - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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<size_t>(radius * (end - start), 12, 48);
|
||||
|
||||
if (!isCircle)
|
||||
overlay.m_Coords.reserve((numPoints + 1 + 2) * 3);
|
||||
|
@ -265,10 +265,10 @@ static void AddTerrainEdges(std::vector<Edge>& edges, std::vector<Vertex>& 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;
|
||||
|
@ -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)
|
||||
|
@ -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<u16>(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<u16>(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<ssize_t>(x, 0, m_VertsPerSide - 1), Clamp<ssize_t>(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<float>(sqrt(x * x + y * y)) / h, 0.01f, 1.0f);
|
||||
distance *= distance;
|
||||
m_TerrainDelta.RaiseVertex(x0 + dx, y0 + dy, (int)(amount * distance));
|
||||
}
|
||||
|
@ -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<u16>(Clamp<int>(x, 0, g_xres));
|
||||
ev.ev.button.y = static_cast<u16>(Clamp<int>(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<u16>(Clamp<int>(x, 0, g_xres));
|
||||
ev.ev.motion.y = static_cast<u16>(Clamp<int>(y, 0, g_yres));
|
||||
in_dispatch_event(&ev);
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user