From 4e8b4981d877b28e0784f294341072fa3f279fb4 Mon Sep 17 00:00:00 2001 From: Woazboat Date: Tue, 28 Apr 2015 02:26:25 +0200 Subject: convert c style casts to c++ static casts --- src/SetChunkData.cpp | 2 +- src/Tracer.cpp | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/SetChunkData.cpp b/src/SetChunkData.cpp index e5afd96ed..7549b0dbf 100644 --- a/src/SetChunkData.cpp +++ b/src/SetChunkData.cpp @@ -103,7 +103,7 @@ void cSetChunkData::CalculateHeightMap(void) int index = cChunkDef::MakeIndexNoCheck(x, y, z); if (m_BlockTypes[index] != E_BLOCK_AIR) { - m_HeightMap[x + z * cChunkDef::Width] = (HEIGHTTYPE)y; + m_HeightMap[x + z * cChunkDef::Width] = static_cast(y); break; } } // for y diff --git a/src/Tracer.cpp b/src/Tracer.cpp index e604f4a5b..3f9501e1f 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -98,37 +98,38 @@ void cTracer::SetValues(const Vector3f & a_Start, const Vector3f & a_Direction) tDelta.z = 0; } + // start voxel coordinates - pos.x = (int)floorf(a_Start.x); - pos.y = (int)floorf(a_Start.y); - pos.z = (int)floorf(a_Start.z); + pos.x = static_cast(floorf(a_Start.x)); + pos.y = static_cast(floorf(a_Start.y)); + pos.z = static_cast(floorf(a_Start.z)); // calculate distance to first intersection in the voxel we start from if (dir.x < 0) { - tMax.x = ((float)pos.x - a_Start.x) / dir.x; + tMax.x = (static_cast(pos.x) - a_Start.x) / dir.x; } else { - tMax.x = (((float)pos.x + 1) - a_Start.x) / dir.x; + tMax.x = (static_cast(pos.x + 1) - a_Start.x) / dir.x; //TODO: Possible division by zero } if (dir.y < 0) { - tMax.y = ((float)pos.y - a_Start.y) / dir.y; + tMax.y = (static_cast(pos.y) - a_Start.y) / dir.y; } else { - tMax.y = (((float)pos.y + 1) - a_Start.y) / dir.y; + tMax.y = (static_cast(pos.y + 1) - a_Start.y) / dir.y; //TODO: Possible division by zero } if (dir.z < 0) { - tMax.z = ((float)pos.z - a_Start.z) / dir.z; + tMax.z = (static_cast(pos.z) - a_Start.z) / dir.z; } else { - tMax.z = (((float)pos.z + 1) - a_Start.z) / dir.z; + tMax.z = (static_cast(pos.z + 1) - a_Start.z) / dir.z; //TODO: Possible division by zero } } @@ -146,18 +147,18 @@ bool cTracer::Trace(const Vector3f & a_Start, const Vector3f & a_Direction, int SetValues(a_Start, a_Direction); - Vector3f End = a_Start + (dir * (float)a_Distance); + Vector3f End = a_Start + (dir * static_cast(a_Distance)); if (End.y < 0) { - float dist = -a_Start.y / dir.y; + float dist = -a_Start.y / dir.y; // No division by 0 possible End = a_Start + (dir * dist); } // end voxel coordinates - end1.x = (int)floorf(End.x); - end1.y = (int)floorf(End.y); - end1.z = (int)floorf(End.z); + end1.x = static_cast(floorf(End.x)); + end1.y = static_cast(floorf(End.y)); + end1.z = static_cast(floorf(End.z)); // check if first is occupied if (pos.Equals(end1)) -- cgit v1.2.3