From f2689c4887e6bd66af34de81cd793322f1dd57c4 Mon Sep 17 00:00:00 2001 From: tycho Date: Tue, 19 May 2015 11:50:59 +0100 Subject: Fixed a lot of warnings --- src/Generating/FinishGen.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Generating/FinishGen.cpp') diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 00b34bddd..af4056e8c 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -260,13 +260,13 @@ void cFinishGenGlowStone::TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX for (int j = 0; j < a_Size; j++) { - Vector3i Direction = AvailableDirections[m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i, CurrentPos.z) % ARRAYCOUNT(AvailableDirections)]; + Vector3i Direction = AvailableDirections[static_cast(m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i, CurrentPos.z)) % ARRAYCOUNT(AvailableDirections)]; int Attempts = 2; // multiply by 1 would make no difference, so multiply by 2 instead while (Direction.Equals(PreviousDirection)) { // To make the glowstone branches look better we want to make the direction change every time. - Direction = AvailableDirections[m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i * Attempts, CurrentPos.z) % ARRAYCOUNT(AvailableDirections)]; + Direction = AvailableDirections[static_cast(m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i * Attempts, CurrentPos.z)) % ARRAYCOUNT(AvailableDirections)]; Attempts++; } @@ -438,7 +438,7 @@ void cFinishGenVines::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - NIBBLETYPE Meta = Places[m_Noise.IntNoise3DInt(xx, y, zz) % Places.size()]; + NIBBLETYPE Meta = Places[static_cast(m_Noise.IntNoise3DInt(xx, y, zz)) % Places.size()]; a_ChunkDesc.SetBlockTypeMeta(x, y, z, E_BLOCK_VINES, Meta); } } @@ -515,7 +515,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) { continue; } - int Top = a_ChunkDesc.GetHeight(x, z); + HEIGHTTYPE Top = a_ChunkDesc.GetHeight(x, z); if (Top > 250) { // Nothing grows above Y=250 @@ -676,7 +676,7 @@ void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc) { for (int x = 0; x < cChunkDef::Width; x++) { - int Height = a_ChunkDesc.GetHeight(x, z); + HEIGHTTYPE Height = a_ChunkDesc.GetHeight(x, z); if (GetSnowStartHeight(a_ChunkDesc.GetBiome(x, z)) > Height) { // Height isn't high enough for snow to start forming. @@ -775,7 +775,7 @@ void cFinishGenSingleTopBlock::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - int Height = a_ChunkDesc.GetHeight(x, z); + HEIGHTTYPE Height = a_ChunkDesc.GetHeight(x, z); if (Height >= cChunkDef::Height - 1) { // Too high up @@ -918,7 +918,7 @@ void cFinishGenPreSimulator::CollapseSandGravel( } } // switch (GetBlock) } // for y - cChunkDef::SetHeight(a_HeightMap, x, z, HeightY); + cChunkDef::SetHeight(a_HeightMap, x, z, static_cast(HeightY)); } // for x } // for z } @@ -1374,7 +1374,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) return mtInvalidType; } - int RandMob = (m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size(); + size_t RandMob = static_cast((m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7)) % ListOfSpawnables.size(); auto MobIter = ListOfSpawnables.begin(); std::advance(MobIter, RandMob); -- cgit v1.2.3 From 45012b72e7af975421fb40f9aa8ff5b9ffc30f5a Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sun, 24 May 2015 07:28:17 +0100 Subject: Wolves don't spawn in rivers. --- src/Generating/FinishGen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Generating/FinishGen.cpp') diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index e96d959f9..c988224e6 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1259,7 +1259,7 @@ bool cFinishGenPassiveMobs::TrySpawnAnimals(cChunkDesc & a_ChunkDesc, int a_RelX } if ( (BlockUnderFeet != E_BLOCK_GRASS) && - ((AnimalToSpawn == mtRabbit) || (AnimalToSpawn == mtCow) || (AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig)) + ((AnimalToSpawn == mtWolf) || (AnimalToSpawn == mtRabbit) || (AnimalToSpawn == mtCow) || (AnimalToSpawn == mtSheep) || (AnimalToSpawn == mtChicken) || (AnimalToSpawn == mtPig)) ) { return false; -- cgit v1.2.3 From dae9e5792a4f030ae9e748548a16a89790fbd311 Mon Sep 17 00:00:00 2001 From: tycho Date: Sun, 24 May 2015 12:56:56 +0100 Subject: Made -Weverything an error. --- src/Generating/FinishGen.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/Generating/FinishGen.cpp') diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index e0349f012..1c48fdee4 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -69,7 +69,7 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc) } // Choose what block to use. - NOISE_DATATYPE BlockType = m_Noise.IntNoise3D((int) ChunkX, y, (int) ChunkZ); + NOISE_DATATYPE BlockType = m_Noise.IntNoise3D(static_cast(ChunkX), y, static_cast(ChunkZ)); if (BlockType < -0.7) { TryPlaceClump(a_ChunkDesc, PosX, y, PosZ, E_BLOCK_BROWN_MUSHROOM); @@ -507,7 +507,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) for (int z = 0; z < cChunkDef::Width; z++) { int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width + z; - const float zz = (float)BlockZ; + const float zz = static_cast(BlockZ); for (int x = 0; x < cChunkDef::Width; x++) { int BlockX = a_ChunkDesc.GetChunkX() * cChunkDef::Width + x; @@ -528,7 +528,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - const float xx = (float)BlockX; + const float xx = static_cast(BlockX); float val1 = m_Noise.CubicNoise2D(xx * 0.1f, zz * 0.1f); float val2 = m_Noise.CubicNoise2D(xx * 0.01f, zz * 0.01f); switch (a_ChunkDesc.GetBlockType(x, Top, z)) @@ -563,7 +563,7 @@ void cFinishGenSprinkleFoliage::GenFinish(cChunkDesc & a_ChunkDesc) } else if ((val1 > 0.5) && (val2 < -0.5)) { - a_ChunkDesc.SetBlockTypeMeta(x, ++Top, z, E_BLOCK_PUMPKIN, (int)(val3 * 8) % 4); + a_ChunkDesc.SetBlockTypeMeta(x, ++Top, z, E_BLOCK_PUMPKIN, static_cast(val3 * 8) % 4); } break; } // case E_BLOCK_GRASS @@ -650,9 +650,9 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc) continue; } - NOISE_DATATYPE NoiseX = ((NOISE_DATATYPE)(xx)) / 32; - NOISE_DATATYPE NoiseY = ((NOISE_DATATYPE)(zz)) / 32; - NOISE_DATATYPE CompBlock = m_Noise.CubicNoise3D(NoiseX, (float) (y) / 4, NoiseY); + NOISE_DATATYPE NoiseX = (static_cast(xx)) / 32; + NOISE_DATATYPE NoiseY = (static_cast(zz)) / 32; + NOISE_DATATYPE CompBlock = m_Noise.CubicNoise3D(NoiseX, static_cast(y) / 4, NoiseY); if (CompBlock < 0) { a_ChunkDesc.SetBlockType(x, y, z, E_BLOCK_SOULSAND); -- cgit v1.2.3 From ee34e7131a5a7a308fe431c44741d68a10bb2625 Mon Sep 17 00:00:00 2001 From: linnemannr Date: Sat, 30 May 2015 02:23:57 -0600 Subject: Fix FreeBSD/clang errors caused by -Werror With FreeBSD/clang, -Werror combined with the configured warning flags yields some fatal errors, specifically related to signed conversion, 64 to 32 bit conversion, and tautological compares. CONTRIBUTORS Add myself to the contributor list src/Generating/FinishGen.cpp In cFinishGenPassiveMobs::GetRandomMob(), change the type of RandMob from size_t to the difference_type of the ListOfSpawnables iterator MobIter. Using size_t triggers a 64 bit to 32 bit conversion if the difference_type of the iterator class is 64 bit Also explicitly cast the noise expression to unsigned long so we don't get a signed conversion warning from the modulo against ListOfSpawnables.size() src/OSSupport/StackTrace.cpp FreeBSD 10 and above includes a non glibc implementation of benchmark() for which size_t, not int, is the return type. To account for this and prevent a signed conversion warning, abstract the type for numItems with a macro btsize src/StringUtils.h In StringToInteger(), correct a tautological compare warning for unsigned types with the template. If T is unsigned, comparing std::numeric_limits::min() to the unsigned result is always false. That control can enter this branch in an evaluated template with an unsigned type T may also permit a signed number to be parsed and erroneously stripped of its signedness at runtime. To guard against this and avoid the warning in the case that the number parsed from the string is non-positive, return false and don't try to parse if T is unsigned and control enters the non-positive branch --- src/Generating/FinishGen.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/Generating/FinishGen.cpp') diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 5540f80d4..656dc95db 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1375,8 +1375,12 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) return mtInvalidType; } - size_t RandMob = static_cast((m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7)) % ListOfSpawnables.size(); auto MobIter = ListOfSpawnables.begin(); + using diff_type = + std::iterator_traits::difference_type; + diff_type RandMob = static_cast + ((unsigned long)(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) + % ListOfSpawnables.size()); std::advance(MobIter, RandMob); return *MobIter; -- cgit v1.2.3 From bca13d918770d28dda143931bbac4d594a327fac Mon Sep 17 00:00:00 2001 From: tycho Date: Sat, 30 May 2015 12:31:05 +0100 Subject: Fixed minor cast warning --- src/Generating/FinishGen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Generating/FinishGen.cpp') diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 656dc95db..59af0fd63 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -1379,7 +1379,7 @@ eMonsterType cFinishGenPassiveMobs::GetRandomMob(cChunkDesc & a_ChunkDesc) using diff_type = std::iterator_traits::difference_type; diff_type RandMob = static_cast - ((unsigned long)(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) + (static_cast(m_Noise.IntNoise2DInt(chunkX - chunkZ + 2, chunkX + 5) / 7) % ListOfSpawnables.size()); std::advance(MobIter, RandMob); -- cgit v1.2.3