diff options
-rw-r--r-- | src/Endianness.h | 4 | ||||
-rw-r--r-- | src/Generating/BioGen.cpp | 84 | ||||
-rw-r--r-- | src/Generating/IntGen.h | 4 | ||||
-rw-r--r-- | src/LinearUpscale.h | 10 | ||||
-rw-r--r-- | src/Protocol/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/WorldStorage/FastNBT.h | 60 | ||||
-rwxr-xr-x | src/WorldStorage/WSSAnvil.cpp | 12 |
7 files changed, 88 insertions, 88 deletions
diff --git a/src/Endianness.h b/src/Endianness.h index a415903a5..0e8bc8e99 100644 --- a/src/Endianness.h +++ b/src/Endianness.h @@ -2,7 +2,7 @@ #pragma once #undef ntohll -#define ntohll(x) ((((UInt64)ntohl((UInt32)x)) << 32) + ntohl(x >> 32)) +#define ntohll(x) (((static_cast<UInt64>(ntohl(static_cast<UInt32>(x)))) << 32) + ntohl(x >> 32)) @@ -13,7 +13,7 @@ inline UInt64 HostToNetwork8(const void * a_Value) { UInt64 buf; memcpy( &buf, a_Value, sizeof( buf)); - buf = (( ( (UInt64)htonl((UInt32)buf)) << 32) + htonl(buf >> 32)); + buf = (( ( static_cast<UInt64>(htonl(static_cast<UInt32>(buf)))) << 32) + htonl(buf >> 32)); return buf; } diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index ee8368b36..6c929f4cb 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -166,7 +166,7 @@ cBioGenMulticache::cBioGenMulticache(cBiomeGenPtr a_BioGenToCache, size_t a_SubC void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) { const size_t coefficient = 3; - const size_t cacheIdx = ((size_t)a_ChunkX + coefficient * (size_t)a_ChunkZ) % m_NumSubCaches; + const size_t cacheIdx = (static_cast<size_t>(a_ChunkX) + coefficient * static_cast<size_t>(a_ChunkZ)) % m_NumSubCaches; m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); } @@ -226,7 +226,7 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) } // for itr - Split[] if (!m_Biomes.empty()) { - m_BiomesCount = (int)m_Biomes.size(); + m_BiomesCount = static_cast<int>(m_Biomes.size()); return; } @@ -260,7 +260,7 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) { m_Biomes.push_back(Biomes[i]); } - m_BiomesCount = (int)m_Biomes.size(); + m_BiomesCount = static_cast<int>(m_Biomes.size()); } @@ -385,15 +385,15 @@ void cBioGenDistortedVoronoi::InitializeBiomeGen(cIniFile & a_IniFile) void cBioGenDistortedVoronoi::Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ) { - double NoiseX = m_Noise.CubicNoise3D((float)a_BlockX / m_CellSize, (float)a_BlockZ / m_CellSize, 1000); - NoiseX += 0.5 * m_Noise.CubicNoise3D(2 * (float)a_BlockX / m_CellSize, 2 * (float)a_BlockZ / m_CellSize, 2000); - NoiseX += 0.08 * m_Noise.CubicNoise3D(16 * (float)a_BlockX / m_CellSize, 16 * (float)a_BlockZ / m_CellSize, 3000); - double NoiseZ = m_Noise.CubicNoise3D((float)a_BlockX / m_CellSize, (float)a_BlockZ / m_CellSize, 4000); - NoiseZ += 0.5 * m_Noise.CubicNoise3D(2 * (float)a_BlockX / m_CellSize, 2 * (float)a_BlockZ / m_CellSize, 5000); - NoiseZ += 0.08 * m_Noise.CubicNoise3D(16 * (float)a_BlockX / m_CellSize, 16 * (float)a_BlockZ / m_CellSize, 6000); + double NoiseX = m_Noise.CubicNoise3D(static_cast<float>(a_BlockX / m_CellSize), static_cast<float>(a_BlockZ / m_CellSize), 1000); + NoiseX += 0.5 * m_Noise.CubicNoise3D(2 * static_cast<float>(a_BlockX / m_CellSize), 2 * static_cast<float>(a_BlockZ / m_CellSize), 2000); + NoiseX += 0.08 * m_Noise.CubicNoise3D(16 * static_cast<float>(a_BlockX / m_CellSize), 16 * static_cast<float>(a_BlockZ / m_CellSize), 3000); + double NoiseZ = m_Noise.CubicNoise3D(static_cast<float>(a_BlockX / m_CellSize), static_cast<float>(a_BlockZ / m_CellSize), 4000); + NoiseZ += 0.5 * m_Noise.CubicNoise3D(2 * static_cast<float>(a_BlockX / m_CellSize), 2 * static_cast<float>(a_BlockZ / m_CellSize), 5000); + NoiseZ += 0.08 * m_Noise.CubicNoise3D(16 * static_cast<float>(a_BlockX / m_CellSize), 16 * static_cast<float>(a_BlockZ / m_CellSize), 6000); - a_DistortedX = a_BlockX + (int)(m_CellSize * 0.5 * NoiseX); - a_DistortedZ = a_BlockZ + (int)(m_CellSize * 0.5 * NoiseZ); + a_DistortedX = a_BlockX + static_cast<int>(m_CellSize * 0.5 * NoiseX); + a_DistortedZ = a_BlockZ + static_cast<int>(m_CellSize * 0.5 * NoiseZ); } @@ -429,7 +429,7 @@ void cBioGenMultiStepMap::InitializeBiomeGen(cIniFile & a_IniFile) m_MushroomIslandSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapMushroomIslandSize", m_MushroomIslandSize); m_RiverCellSize = a_IniFile.GetValueSetI("Generator", "MultiStepMapRiverCellSize", m_RiverCellSize); m_RiverWidthThreshold = a_IniFile.GetValueSetF("Generator", "MultiStepMapRiverWidth", m_RiverWidthThreshold); - m_LandBiomesSize = (float)a_IniFile.GetValueSetI("Generator", "MultiStepMapLandBiomeSize", (int)m_LandBiomesSize); + m_LandBiomesSize = static_cast<float>(a_IniFile.GetValueSetI("Generator", "MultiStepMapLandBiomeSize", static_cast<int>(m_LandBiomesSize))); } @@ -554,7 +554,7 @@ void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome { for (int z = 0; z < cChunkDef::Width; z++) { - float NoiseCoordZ = (float)(a_ChunkZ * cChunkDef::Width + z) / m_RiverCellSize; + float NoiseCoordZ = static_cast<float>(a_ChunkZ * cChunkDef::Width + z / m_RiverCellSize); for (int x = 0; x < cChunkDef::Width; x++) { if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biInvalidBiome) @@ -563,7 +563,7 @@ void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome continue; } - float NoiseCoordX = (float)(a_ChunkX * cChunkDef::Width + x) / m_RiverCellSize; + float NoiseCoordX = static_cast<float>(a_ChunkX * cChunkDef::Width + x / m_RiverCellSize); double Noise = m_Noise1.CubicNoise2D( NoiseCoordX, NoiseCoordZ); Noise += 0.5 * m_Noise3.CubicNoise2D(2 * NoiseCoordX, 2 * NoiseCoordZ); @@ -597,15 +597,15 @@ void cBioGenMultiStepMap::ApplyTemperatureHumidity(int a_ChunkX, int a_ChunkZ, c void cBioGenMultiStepMap::Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX, int & a_DistortedZ, int a_CellSize) { - double NoiseX = m_Noise3.CubicNoise2D( (float)a_BlockX / a_CellSize, (float)a_BlockZ / a_CellSize); - NoiseX += 0.5 * m_Noise2.CubicNoise2D(2 * (float)a_BlockX / a_CellSize, 2 * (float)a_BlockZ / a_CellSize); - NoiseX += 0.1 * m_Noise1.CubicNoise2D(16 * (float)a_BlockX / a_CellSize, 16 * (float)a_BlockZ / a_CellSize); - double NoiseZ = m_Noise6.CubicNoise2D( (float)a_BlockX / a_CellSize, (float)a_BlockZ / a_CellSize); - NoiseZ += 0.5 * m_Noise5.CubicNoise2D(2 * (float)a_BlockX / a_CellSize, 2 * (float)a_BlockZ / a_CellSize); - NoiseZ += 0.1 * m_Noise4.CubicNoise2D(16 * (float)a_BlockX / a_CellSize, 16 * (float)a_BlockZ / a_CellSize); + double NoiseX = m_Noise3.CubicNoise2D( static_cast<float>(a_BlockX / a_CellSize), static_cast<float>(a_BlockZ / a_CellSize)); + NoiseX += 0.5 * m_Noise2.CubicNoise2D(2 * static_cast<float>(a_BlockX / a_CellSize), 2 * static_cast<float>(a_BlockZ / a_CellSize)); + NoiseX += 0.1 * m_Noise1.CubicNoise2D(16 * static_cast<float>(a_BlockX / a_CellSize), 16 * static_cast<float>(a_BlockZ / a_CellSize)); + double NoiseZ = m_Noise6.CubicNoise2D( static_cast<float>(a_BlockX / a_CellSize), static_cast<float>(a_BlockZ / a_CellSize)); + NoiseZ += 0.5 * m_Noise5.CubicNoise2D(2 * static_cast<float>(a_BlockX / a_CellSize), 2 * static_cast<float>(a_BlockZ / a_CellSize)); + NoiseZ += 0.1 * m_Noise4.CubicNoise2D(16 * static_cast<float>(a_BlockX / a_CellSize), 16 * static_cast<float>(a_BlockZ / a_CellSize)); - a_DistortedX = a_BlockX + (int)(a_CellSize * 0.5 * NoiseX); - a_DistortedZ = a_BlockZ + (int)(a_CellSize * 0.5 * NoiseZ); + a_DistortedX = a_BlockX + static_cast<int>(a_CellSize * 0.5 * NoiseX); + a_DistortedZ = a_BlockZ + static_cast<int>(a_CellSize * 0.5 * NoiseZ); } @@ -619,10 +619,10 @@ void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(int a_ChunkX, int a_Chunk DblMap HumidityMap; for (int z = 0; z < 17; z += 8) { - float NoiseCoordZ = (float)(a_ChunkZ * cChunkDef::Width + z) / m_LandBiomesSize; + float NoiseCoordZ = static_cast<float>(a_ChunkZ * cChunkDef::Width + z) / m_LandBiomesSize; for (int x = 0; x < 17; x += 8) { - float NoiseCoordX = (float)(a_ChunkX * cChunkDef::Width + x) / m_LandBiomesSize; + float NoiseCoordX = static_cast<float>(a_ChunkX * cChunkDef::Width + x) / m_LandBiomesSize; double NoiseT = m_Noise1.CubicNoise2D( NoiseCoordX, NoiseCoordZ); NoiseT += 0.5 * m_Noise2.CubicNoise2D(2 * NoiseCoordX, 2 * NoiseCoordZ); @@ -641,8 +641,8 @@ void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(int a_ChunkX, int a_Chunk // Re-map into integral values in [0 .. 255] range: for (size_t idx = 0; idx < ARRAYCOUNT(a_TemperatureMap); idx++) { - a_TemperatureMap[idx] = std::max(0, std::min(255, (int)(128 + TemperatureMap[idx] * 128))); - a_HumidityMap[idx] = std::max(0, std::min(255, (int)(128 + HumidityMap[idx] * 128))); + a_TemperatureMap[idx] = std::max(0, std::min(255, static_cast<int>(128 + TemperatureMap[idx] * 128))); + a_HumidityMap[idx] = std::max(0, std::min(255, static_cast<int>(128 + HumidityMap[idx] * 128))); } } @@ -771,8 +771,8 @@ void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap NoiseZ += m_AmpZ2 * m_Noise5.CubicNoise2D(BlockX * m_FreqZ2, BlockZ * m_FreqZ2); NoiseZ += m_AmpZ3 * m_Noise6.CubicNoise2D(BlockX * m_FreqZ3, BlockZ * m_FreqZ3); - DistortX[4 * x][4 * z] = (int)(BlockX + NoiseX); - DistortZ[4 * x][4 * z] = (int)(BlockZ + NoiseZ); + DistortX[4 * x][4 * z] = static_cast<int>(BlockX + NoiseX); + DistortZ[4 * x][4 * z] = static_cast<int>(BlockZ + NoiseZ); } LinearUpscale2DArrayInPlace<cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4>(&DistortX[0][0]); @@ -913,18 +913,18 @@ void cBioGenTwoLevel::InitializeBiomeGen(cIniFile & a_IniFile) { m_VoronoiLarge.SetCellSize(a_IniFile.GetValueSetI("Generator", "TwoLevelLargeCellSize", 1024)); m_VoronoiSmall.SetCellSize(a_IniFile.GetValueSetI("Generator", "TwoLevelSmallCellSize", 128)); - m_FreqX1 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave1Freq", 0.01); - m_AmpX1 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave1Amp", 80); - m_FreqX2 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave2Freq", 0.05); - m_AmpX2 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave2Amp", 20); - m_FreqX3 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave3Freq", 0.1), - m_AmpX3 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave3Amp", 8); - m_FreqZ1 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave1Freq", 0.01); - m_AmpZ1 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave1Amp", 80); - m_FreqZ2 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave2Freq", 0.05); - m_AmpZ2 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave2Amp", 20); - m_FreqZ3 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave3Freq", 0.1); - m_AmpZ3 = (float)a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave3Amp", 8); + m_FreqX1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave1Freq", 0.01)); + m_AmpX1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave1Amp", 80)); + m_FreqX2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave2Freq", 0.05)); + m_AmpX2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave2Amp", 20)); + m_FreqX3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave3Freq", 0.1)), + m_AmpX3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortXOctave3Amp", 8)); + m_FreqZ1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave1Freq", 0.01)); + m_AmpZ1 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave1Amp", 80)); + m_FreqZ2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave2Freq", 0.05)); + m_AmpZ2 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave2Amp", 20)); + m_FreqZ3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave3Freq", 0.1)); + m_AmpZ3 = static_cast<float>(a_IniFile.GetValueSetF("Generator", "TwoLevelDistortZOctave3Amp", 8)); } @@ -1022,7 +1022,7 @@ public: { for (int x = 0; x < cChunkDef::Width; x++) { - cChunkDef::SetBiome(a_Biomes, x, z, (EMCSBiome)vals[x + cChunkDef::Width * z]); + cChunkDef::SetBiome(a_Biomes, x, z, static_cast<EMCSBiome>(vals[x + cChunkDef::Width * z])); } } } @@ -1126,7 +1126,7 @@ public: { for (int x = 0; x < cChunkDef::Width; x++) { - cChunkDef::SetBiome(a_Biomes, x, z, (EMCSBiome)vals[x + cChunkDef::Width * z]); + cChunkDef::SetBiome(a_Biomes, x, z, static_cast<EMCSBiome>(vals[x + cChunkDef::Width * z])); } } } diff --git a/src/Generating/IntGen.h b/src/Generating/IntGen.h index 9cc881639..3f94ec3d0 100644 --- a/src/Generating/IntGen.h +++ b/src/Generating/IntGen.h @@ -754,7 +754,7 @@ public: int IdxZ = z * SizeX; for (int x = 0; x < SizeX; x++) { - size_t val = (size_t)a_Values[x + IdxZ]; + size_t val = static_cast<size_t>(a_Values[x + IdxZ]); const cBiomesInGroups & Biomes = (val > bgfRare) ? rareBiomesInGroups[(val & (bgfRare - 1)) % ARRAYCOUNT(rareBiomesInGroups)] : biomesInGroups[val % ARRAYCOUNT(biomesInGroups)]; @@ -891,7 +891,7 @@ public: } // There's a river, change the output to a river or a frozen river, based on the original biome: - if (IsBiomeVeryCold((EMCSBiome)a_Values[idx])) + if (IsBiomeVeryCold(static_cast<EMCSBiome>(a_Values[idx]))) { a_Values[idx] = biFrozenRiver; } diff --git a/src/LinearUpscale.h b/src/LinearUpscale.h index 1b0fbd89a..d4e9da82a 100644 --- a/src/LinearUpscale.h +++ b/src/LinearUpscale.h @@ -109,11 +109,11 @@ template <typename TYPE> void LinearUpscale2DArray( TYPE RatioY[MAX_UPSCALE_Y]; for (int x = 0; x <= a_UpscaleX; x++) { - RatioX[x] = (TYPE)x / a_UpscaleX; + RatioX[x] = static_cast<TYPE>(x) / a_UpscaleX; } for (int y = 0; y <= a_UpscaleY; y++) { - RatioY[y] = (TYPE)y / a_UpscaleY; + RatioY[y] = static_cast<TYPE>(y) / a_UpscaleY; } // Interpolate each XY cell: @@ -184,15 +184,15 @@ template <typename TYPE> void LinearUpscale3DArray( TYPE RatioZ[MAX_UPSCALE_Z]; for (int x = 0; x <= a_UpscaleX; x++) { - RatioX[x] = (TYPE)x / a_UpscaleX; + RatioX[x] = static_cast<TYPE>(x / a_UpscaleX); } for (int y = 0; y <= a_UpscaleY; y++) { - RatioY[y] = (TYPE)y / a_UpscaleY; + RatioY[y] = static_cast<TYPE>(y / a_UpscaleY); } for (int z = 0; z <= a_UpscaleZ; z++) { - RatioZ[z] = (TYPE)z / a_UpscaleZ; + RatioZ[z] = static_cast<TYPE>(z / a_UpscaleZ); } // Interpolate each XYZ cell: diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index 5adf6bd5e..42a7d5a9d 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -29,7 +29,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set_source_files_properties(ChunkDataSerializer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(MojangAPI.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") set_source_files_properties(Packetizer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") - set_source_files_properties(Protocol18x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum -Wno-error=switch") + set_source_files_properties(Protocol18x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast -Wno-error=sign-conversion -Wno-error=conversion -Wno-error=switch-enum -Wno-error=switch") set_source_files_properties(Protocol17x.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=switch-enum -Wno-error=old-style-cast") set_source_files_properties(ProtocolRecognizer.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") endif() diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index 35e47c8e4..a23dc7af2 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -126,33 +126,33 @@ public: int GetRoot(void) const {return 0; } /** Returns the first child of the specified tag, or -1 if none / not applicable. */ - int GetFirstChild (int a_Tag) const { return m_Tags[(size_t)a_Tag].m_FirstChild; } + int GetFirstChild (int a_Tag) const { return m_Tags[static_cast<size_t>(a_Tag)].m_FirstChild; } /** Returns the last child of the specified tag, or -1 if none / not applicable. */ - int GetLastChild (int a_Tag) const { return m_Tags[(size_t)a_Tag].m_LastChild; } + int GetLastChild (int a_Tag) const { return m_Tags[static_cast<size_t>(a_Tag)].m_LastChild; } /** Returns the next sibling of the specified tag, or -1 if none. */ - int GetNextSibling(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_NextSibling; } + int GetNextSibling(int a_Tag) const { return m_Tags[static_cast<size_t>(a_Tag)].m_NextSibling; } /** Returns the previous sibling of the specified tag, or -1 if none. */ - int GetPrevSibling(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_PrevSibling; } + int GetPrevSibling(int a_Tag) const { return m_Tags[static_cast<size_t>(a_Tag)].m_PrevSibling; } /** Returns the length of the tag's data, in bytes. Not valid for Compound or List tags! */ size_t GetDataLength (int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_List); - ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_Compound); - return m_Tags[(size_t)a_Tag].m_DataLength; + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type != TAG_List); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type != TAG_Compound); + return m_Tags[static_cast<size_t>(a_Tag)].m_DataLength; } /** Returns the data stored in this tag. Not valid for Compound or List tags! */ const char * GetData(int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_List); - ASSERT(m_Tags[(size_t)a_Tag].m_Type != TAG_Compound); - return m_Data + m_Tags[(size_t)a_Tag].m_DataStart; + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type != TAG_List); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type != TAG_Compound); + return m_Data + m_Tags[static_cast<size_t>(a_Tag)].m_DataStart; } /** Returns the direct child tag of the specified name, or -1 if no such tag. */ @@ -167,47 +167,47 @@ public: /** Returns the child tag of the specified path (Name1 / Name2 / Name3...), or -1 if no such tag. */ int FindTagByPath(int a_Tag, const AString & a_Path) const; - eTagType GetType(int a_Tag) const { return m_Tags[(size_t)a_Tag].m_Type; } + eTagType GetType(int a_Tag) const { return m_Tags[static_cast<size_t>(a_Tag)].m_Type; } /** Returns the children type for a List tag; undefined on other tags. If list empty, returns TAG_End. */ eTagType GetChildrenType(int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_List); - return (m_Tags[(size_t)a_Tag].m_FirstChild < 0) ? TAG_End : m_Tags[(size_t)m_Tags[(size_t)a_Tag].m_FirstChild].m_Type; + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type == TAG_List); + return (m_Tags[static_cast<size_t>(a_Tag)].m_FirstChild < 0) ? TAG_End : m_Tags[static_cast<size_t>(m_Tags[static_cast<size_t>(a_Tag)].m_FirstChild)].m_Type; } /** Returns the value stored in a Byte tag. Not valid for any other tag type. */ inline unsigned char GetByte(int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Byte); - return (unsigned char)(m_Data[(size_t)m_Tags[(size_t)a_Tag].m_DataStart]); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type == TAG_Byte); + return static_cast<unsigned char>(m_Data[static_cast<size_t>(m_Tags[static_cast<size_t>(a_Tag)].m_DataStart)]); } /** Returns the value stored in a Short tag. Not valid for any other tag type. */ inline Int16 GetShort(int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Short); - return GetBEShort(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type == TAG_Short); + return GetBEShort(m_Data + m_Tags[static_cast<size_t>(a_Tag)].m_DataStart); } /** Returns the value stored in an Int tag. Not valid for any other tag type. */ inline Int32 GetInt(int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Int); - return GetBEInt(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type == TAG_Int); + return GetBEInt(m_Data + m_Tags[static_cast<size_t>(a_Tag)].m_DataStart); } /** Returns the value stored in a Long tag. Not valid for any other tag type. */ inline Int64 GetLong(int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Long); - return NetworkToHostLong8(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type == TAG_Long); + return NetworkToHostLong8(m_Data + m_Tags[static_cast<size_t>(a_Tag)].m_DataStart); } /** Returns the value stored in a Float tag. Not valid for any other tag type. */ inline float GetFloat(int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Float); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type == TAG_Float); // Cause a compile-time error if sizeof(float) != 4 // If your platform produces a compiler error here, you'll need to add code that manually decodes 32-bit floats @@ -216,7 +216,7 @@ public: UNUSED_VAR(Check1); UNUSED_VAR(Check2); - Int32 i = GetBEInt(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); + Int32 i = GetBEInt(m_Data + m_Tags[static_cast<size_t>(a_Tag)].m_DataStart); float f; memcpy(&f, &i, sizeof(f)); return f; @@ -232,16 +232,16 @@ public: UNUSED_VAR(Check1); UNUSED_VAR(Check2); - ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_Double); - return NetworkToHostDouble8(m_Data + m_Tags[(size_t)a_Tag].m_DataStart); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type == TAG_Double); + return NetworkToHostDouble8(m_Data + m_Tags[static_cast<size_t>(a_Tag)].m_DataStart); } /** Returns the value stored in a String tag. Not valid for any other tag type. */ inline AString GetString(int a_Tag) const { - ASSERT(m_Tags[(size_t)a_Tag].m_Type == TAG_String); + ASSERT(m_Tags[static_cast<size_t>(a_Tag)].m_Type == TAG_String); AString res; - res.assign(m_Data + m_Tags[(size_t)a_Tag].m_DataStart, (size_t)m_Tags[(size_t)a_Tag].m_DataLength); + res.assign(m_Data + m_Tags[static_cast<size_t>(a_Tag)].m_DataStart, static_cast<size_t>(m_Tags[static_cast<size_t>(a_Tag)].m_DataLength)); return res; } @@ -249,7 +249,7 @@ public: inline AString GetName(int a_Tag) const { AString res; - res.assign(m_Data + m_Tags[(size_t)a_Tag].m_NameStart, (size_t)m_Tags[(size_t)a_Tag].m_NameLength); + res.assign(m_Data + m_Tags[static_cast<size_t>(a_Tag)].m_NameStart, static_cast<size_t>(m_Tags[static_cast<size_t>(a_Tag)].m_NameLength)); return res; } @@ -333,8 +333,8 @@ protected: if (IsStackTopCompound()) { // Compound: add the type and name: - m_Result.push_back((char)a_Type); - WriteString(a_Name.c_str(), (UInt16)a_Name.length()); + m_Result.push_back(static_cast<char>(a_Type)); + WriteString(a_Name.c_str(), static_cast<UInt16>(a_Name.length())); } else { diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index 8ca49c2c0..4912d20f6 100755 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -130,7 +130,7 @@ cWSSAnvil::cWSSAnvil(cWorld * a_World, int a_CompressionFactor) : gzFile gz = gzopen((FILE_IO_PREFIX + fnam).c_str(), "wb"); if (gz != nullptr) { - gzwrite(gz, Writer.GetResult().data(), (unsigned)Writer.GetResult().size()); + gzwrite(gz, Writer.GetResult().data(), static_cast<unsigned>(Writer.GetResult().size())); } gzclose(gz); } @@ -497,7 +497,7 @@ bool cWSSAnvil::SaveChunkToNBT(const cChunkCoords & a_Chunk, cFastNBTWriter & a_ a_Writer.AddByteArray("Data", BlockMetas + Y * SliceSizeNibble, SliceSizeNibble); a_Writer.AddByteArray("SkyLight", BlockSkyLight + Y * SliceSizeNibble, SliceSizeNibble); a_Writer.AddByteArray("BlockLight", BlockLight + Y * SliceSizeNibble, SliceSizeNibble); - a_Writer.AddByte("Y", (unsigned char)Y); + a_Writer.AddByte("Y", static_cast<unsigned char>(Y)); a_Writer.EndCompound(); } a_Writer.EndList(); // "Sections" @@ -3070,7 +3070,7 @@ bool cWSSAnvil::cMCAFile::GetChunkData(const cChunkCoords & a_Chunk, AString & a LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); return false; } - ChunkSize = ntohl((u_long)ChunkSize); + ChunkSize = ntohl(static_cast<u_long>(ChunkSize)); char CompressionType = 0; if (m_File.Read(&CompressionType, 1) != 1) { @@ -3122,7 +3122,7 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri // Store the chunk data: m_File.Seek(ChunkSector * 4096); - u_long ChunkSize = htonl((u_long)a_Data.size() + 1); + u_long ChunkSize = htonl(static_cast<u_long>(a_Data.size()) + 1); if (m_File.Write(&ChunkSize, 4) != 4) { LOGWARNING("Cannot save chunk [%d, %d], writing(1) data to file \"%s\" failed", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, GetFileName().c_str()); @@ -3149,11 +3149,11 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri } // Store the header: - ChunkSize = ((u_long)a_Data.size() + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size up to nearest 4KB sector, make it a sector number + ChunkSize = (static_cast<u_long>(a_Data.size()) + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size up to nearest 4KB sector, make it a sector number if (ChunkSize > 255) { LOGWARNING("Cannot save chunk [%d, %d], the data is too large (%u KiB, maximum is 1024 KiB). Remove some entities and retry.", - a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, (unsigned)(ChunkSize * 4) + a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, static_cast<unsigned>(ChunkSize * 4) ); return false; } |