From b20294604c5a64a39b3c5f4491b653e4cf2a3c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matti=20H=C3=A4nninen?= Date: Wed, 5 Aug 2015 01:24:59 +0300 Subject: Fix old style casts and implicit conversions --- src/Map.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/Map.cpp') diff --git a/src/Map.cpp b/src/Map.cpp index d55642a5a..a79a6bd0c 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -67,20 +67,20 @@ void cMap::Tick() void cMap::UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius) { - int PixelRadius = a_Radius / GetPixelWidth(); + int PixelRadius = static_cast(a_Radius / GetPixelWidth()); - unsigned int StartX = Clamp(a_PixelX - PixelRadius, 0, (int)m_Width); - unsigned int StartZ = Clamp(a_PixelZ - PixelRadius, 0, (int)m_Height); + unsigned int StartX = static_cast(Clamp(a_PixelX - PixelRadius, 0, static_cast(m_Width))); + unsigned int StartZ = static_cast(Clamp(a_PixelZ - PixelRadius, 0, static_cast(m_Height))); - unsigned int EndX = Clamp(a_PixelX + PixelRadius, 0, (int)m_Width); - unsigned int EndZ = Clamp(a_PixelZ + PixelRadius, 0, (int)m_Height); + unsigned int EndX = static_cast(Clamp(a_PixelX + PixelRadius, 0, static_cast(m_Width))); + unsigned int EndZ = static_cast(Clamp(a_PixelZ + PixelRadius, 0, static_cast(m_Height))); for (unsigned int X = StartX; X < EndX; ++X) { for (unsigned int Z = StartZ; Z < EndZ; ++Z) { - int dX = X - a_PixelX; - int dZ = Z - a_PixelZ; + int dX = static_cast(X) - a_PixelX; + int dZ = static_cast(Z) - a_PixelZ; if ((dX * dX) + (dZ * dZ) < (PixelRadius * PixelRadius)) { @@ -96,10 +96,10 @@ void cMap::UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius) void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius) { - unsigned int PixelWidth = GetPixelWidth(); + int PixelWidth = static_cast(GetPixelWidth()); - int PixelX = (int) (a_Player.GetPosX() - m_CenterX) / PixelWidth + (m_Width / 2); - int PixelZ = (int) (a_Player.GetPosZ() - m_CenterZ) / PixelWidth + (m_Height / 2); + int PixelX = static_cast(a_Player.GetPosX() - m_CenterX) / PixelWidth + static_cast(m_Width / 2); + int PixelZ = static_cast(a_Player.GetPosZ() - m_CenterZ) / PixelWidth + static_cast(m_Height / 2); UpdateRadius(PixelX, PixelZ, a_Radius); } @@ -110,10 +110,8 @@ void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius) bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) { - unsigned int PixelWidth = GetPixelWidth(); - - int BlockX = m_CenterX + ((a_X - (m_Width / 2)) * PixelWidth); - int BlockZ = m_CenterZ + ((a_Z - (m_Height / 2)) * PixelWidth); + int BlockX = m_CenterX + static_cast((a_X - m_Width / 2) * GetPixelWidth()); + int BlockZ = m_CenterZ + static_cast((a_Z - m_Height / 2) * GetPixelWidth()); int ChunkX, ChunkZ; cChunkDef::BlockToChunk(BlockX, BlockZ, ChunkX, ChunkZ); @@ -174,7 +172,8 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z) } // Multiply base color ID by 4 and add brightness ID - m_PixelData = ColourID * 4 + BrightnessID[Clamp(static_cast(Height / (ChunkHeight / BrightnessID.size())), 0, BrightnessID.size() - 1)]; + const int BrightnessIDSize = static_cast(BrightnessID.size()); + m_PixelData = ColourID * 4 + BrightnessID[static_cast(Clamp((BrightnessIDSize * Height) / ChunkHeight, 0, BrightnessIDSize - 1))]; return false; } @@ -294,8 +293,8 @@ const cMapDecorator cMap::CreateDecorator(const cEntity * a_TrackedEntity) int InsideHeight = (GetHeight() / 2) - 1; // Center of pixel - int PixelX = (int)(a_TrackedEntity->GetPosX() - GetCenterX()) / GetPixelWidth(); - int PixelZ = (int)(a_TrackedEntity->GetPosZ() - GetCenterZ()) / GetPixelWidth(); + int PixelX = static_cast(a_TrackedEntity->GetPosX() - GetCenterX()) / static_cast(GetPixelWidth()); + int PixelZ = static_cast(a_TrackedEntity->GetPosZ() - GetCenterZ()) / static_cast(GetPixelWidth()); cMapDecorator::eType Type; int Rot; @@ -347,7 +346,7 @@ const cMapDecorator cMap::CreateDecorator(const cEntity * a_TrackedEntity) } } - return {Type, (unsigned)(2 * PixelX + 1), (unsigned)(2 * PixelZ + 1), Rot}; + return {Type, static_cast(2 * PixelX + 1), static_cast(2 * PixelZ + 1), Rot}; } @@ -355,7 +354,7 @@ const cMapDecorator cMap::CreateDecorator(const cEntity * a_TrackedEntity) unsigned int cMap::GetPixelWidth(void) const { - return (int) pow(2.0, (double) m_Scale); + return static_cast(pow(2.0, static_cast(m_Scale))); } -- cgit v1.2.3