From 80807eec2cc1c497c4766a0c7cddb9c3ddc29e45 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 3 Feb 2014 12:26:17 -0800 Subject: Increased Type safety of Biomes Changed a number of funcictions from using integers to store biomes to using EMCSBiome Note that switching from an int to an Enum is a non-breaking chang to the lua bindings --- src/BiomeDef.cpp | 14 +++++++++++--- src/BiomeDef.h | 9 ++++++++- src/Generating/BioGen.cpp | 10 +++++----- src/Generating/ChunkDesc.cpp | 4 ++-- src/Generating/ChunkDesc.h | 2 +- src/Mobs/SnowGolem.cpp | 2 +- src/World.cpp | 4 ++-- src/World.h | 2 +- 8 files changed, 31 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index 89a1cdefb..5c1156484 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -13,8 +13,16 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) int res = atoi(a_BiomeString.c_str()); if ((res != 0) || (a_BiomeString.compare("0") == 0)) { - // It was a valid number - return (EMCSBiome)res; + if(res >= biFirstBiome && res < biNumBiomes) + { + return (EMCSBiome)res; + } + else if(res >= biFirstVarientBiome && res < biNumVarientBiomes) + { + return (EMCSBiome)res; + } + // It was an invalid number + return biInvalidBiome; } // Convert using the built-in map: @@ -100,7 +108,7 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) return BiomeMap[i].m_Biome; } } // for i - BiomeMap[] - return (EMCSBiome)-1; + return biInvalidBiome; } diff --git a/src/BiomeDef.h b/src/BiomeDef.h index df1e387f0..f015dd836 100644 --- a/src/BiomeDef.h +++ b/src/BiomeDef.h @@ -20,6 +20,9 @@ BiomeIDs over 255 are used by MCServer internally and are translated to MC biome */ enum EMCSBiome { + biInvalidBiome = -1, + + biFirstBiome = 0, biOcean = 0, biPlains = 1, biDesert = 2, @@ -74,6 +77,7 @@ enum EMCSBiome biVariant = 128, // Release 1.7 biome variants: + biFirstVarientBiome = 129, biSunflowerPlains = 129, biDesertM = 130, biExtremeHillsM = 131, @@ -95,9 +99,12 @@ enum EMCSBiome biMesaBryce = 165, biMesaPlateauFM = 166, biMesaPlateauM = 167, + // Automatically capture the maximum consecutive biome value into biVarientMaxBiome: + biNumVarientBiomes, // True number of biomes, since they are zero-based + biMaxVarientBiome = biNumVarientBiomes - 1, // The maximum biome value } ; -/// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns -1 on failure. +/// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns biInvalidBiome on failure. extern EMCSBiome StringToBiome(const AString & a_BiomeString); /// Returns true if the biome has no downfall - deserts and savannas diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index f89b1800d..1a18f53f1 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -97,7 +97,7 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) { AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "Plains"); m_Biome = StringToBiome(Biome); - if (m_Biome == -1) + if (m_Biome == EMCSBiome::biInvalidBiome) { LOGWARN("[Generator]::ConstantBiome value \"%s\" not recognized, using \"Plains\".", Biome.c_str()); m_Biome = biPlains; @@ -233,7 +233,7 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) } } EMCSBiome Biome = StringToBiome(Split2[0]); - if (Biome != -1) + if (Biome != EMCSBiome::biInvalidBiome) { for (int i = 0; i < Count; i++) { @@ -500,7 +500,7 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cC int OffsetZ = (m_Noise4.IntNoise3DInt(RealCellX, 32 * RealCellX - 16 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize; SeedX[xc][zc] = CellBlockX + OffsetX; SeedZ[xc][zc] = CellBlockZ + OffsetZ; - SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : ((EMCSBiome)(-1)); + SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : (EMCSBiome::biInvalidBiome); } // for z } // for x @@ -573,7 +573,7 @@ void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome float NoiseCoordZ = (float)(a_ChunkZ * cChunkDef::Width + z) / m_RiverCellSize; for (int x = 0; x < cChunkDef::Width; x++) { - if (cChunkDef::GetBiome(a_BiomeMap, x, z) != -1) + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != EMCSBiome::biInvalidBiome) { // Biome already set, skip this column continue; @@ -693,7 +693,7 @@ void cBioGenMultiStepMap::DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, con int idxZ = 17 * z; for (int x = 0; x < cChunkDef::Width; x++) { - if (cChunkDef::GetBiome(a_BiomeMap, x, z) != -1) + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != EMCSBiome::biInvalidBiome) { // Already set before continue; diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp index 87566aa78..d9529b4b0 100644 --- a/src/Generating/ChunkDesc.cpp +++ b/src/Generating/ChunkDesc.cpp @@ -118,9 +118,9 @@ void cChunkDesc::SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_B -void cChunkDesc::SetBiome(int a_RelX, int a_RelZ, int a_BiomeID) +void cChunkDesc::SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID) { - cChunkDef::SetBiome(m_BiomeMap, a_RelX, a_RelZ, (EMCSBiome)a_BiomeID); + cChunkDef::SetBiome(m_BiomeMap, a_RelX, a_RelZ, a_BiomeID); } diff --git a/src/Generating/ChunkDesc.h b/src/Generating/ChunkDesc.h index e258383d5..8edc2800b 100644 --- a/src/Generating/ChunkDesc.h +++ b/src/Generating/ChunkDesc.h @@ -53,7 +53,7 @@ public: void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta); NIBBLETYPE GetBlockMeta(int a_RelX, int a_RelY, int a_RelZ); - void SetBiome(int a_RelX, int a_RelZ, int a_BiomeID); + void SetBiome(int a_RelX, int a_RelZ, EMCSBiome a_BiomeID); EMCSBiome GetBiome(int a_RelX, int a_RelZ); // These operate on the heightmap, so they could get out of sync with the data diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 06021cca5..c60103055 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -29,7 +29,7 @@ void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - if (IsBiomeNoDownfall((EMCSBiome) m_World->GetBiomeAt((int) floor(GetPosX()), (int) floor(GetPosZ())) )) + if (IsBiomeNoDownfall(m_World->GetBiomeAt((int) floor(GetPosX()), (int) floor(GetPosZ())) )) { TakeDamage(*this); } diff --git a/src/World.cpp b/src/World.cpp index de2002b84..f9a6e7776 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -1222,7 +1222,7 @@ void cWorld::GrowTreeByBiome(int a_X, int a_Y, int a_Z) { cNoise Noise(m_Generator.GetSeed()); sSetBlockVector Logs, Other; - GetTreeImageByBiome(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), (EMCSBiome)GetBiomeAt(a_X, a_Z), Logs, Other); + GetTreeImageByBiome(a_X, a_Y, a_Z, Noise, (int)(m_WorldAge & 0xffffffff), GetBiomeAt(a_X, a_Z), Logs, Other); Other.insert(Other.begin(), Logs.begin(), Logs.end()); Logs.clear(); GrowTreeImage(Other); @@ -1475,7 +1475,7 @@ void cWorld::GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBl -int cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) +EMCSBiome cWorld::GetBiomeAt (int a_BlockX, int a_BlockZ) { return m_ChunkMap->GetBiomeAt(a_BlockX, a_BlockZ); } diff --git a/src/World.h b/src/World.h index bf6a4ba28..afdc09788 100644 --- a/src/World.h +++ b/src/World.h @@ -526,7 +526,7 @@ public: void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); /** Returns the biome at the specified coords. Reads the biome from the chunk, if loaded, otherwise uses the world generator to provide the biome value */ - int GetBiomeAt(int a_BlockX, int a_BlockZ); + EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ); /** Returns the name of the world */ const AString & GetName(void) const { return m_WorldName; } -- cgit v1.2.3 From f8881622a4000d769af700396f772bae21d1d117 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 3 Feb 2014 12:31:18 -0800 Subject: Removed unused lookups --- src/Simulator/FluidSimulator.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/Simulator/FluidSimulator.cpp b/src/Simulator/FluidSimulator.cpp index 72b2eb628..61c93ed73 100644 --- a/src/Simulator/FluidSimulator.cpp +++ b/src/Simulator/FluidSimulator.cpp @@ -166,14 +166,12 @@ Direction cFluidSimulator::GetFlowingDirection(int a_X, int a_Y, int a_Z, bool a { LowestPoint = Meta; X = Pos->x; - Pos->y; //Remove if no side effects Z = Pos->z; } }else if(BlockID == E_BLOCK_AIR) { LowestPoint = 9; //This always dominates X = Pos->x; - Pos->y; //Remove if no side effects Z = Pos->z; } -- cgit v1.2.3 From d9fb83300cf831ea31a74d509f9be9f2ed4f1189 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 3 Feb 2014 13:01:12 -0800 Subject: Fixed Compile errors c++11 introduces scoped enums, so the code didn't fail in clang --- src/BiomeDef.cpp | 4 ++-- src/BiomeDef.h | 6 +++--- src/Generating/BioGen.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/BiomeDef.cpp b/src/BiomeDef.cpp index 5c1156484..3fba93e8a 100644 --- a/src/BiomeDef.cpp +++ b/src/BiomeDef.cpp @@ -13,11 +13,11 @@ EMCSBiome StringToBiome(const AString & a_BiomeString) int res = atoi(a_BiomeString.c_str()); if ((res != 0) || (a_BiomeString.compare("0") == 0)) { - if(res >= biFirstBiome && res < biNumBiomes) + if ((res >= biFirstBiome) && (res < biNumBiomes)) { return (EMCSBiome)res; } - else if(res >= biFirstVarientBiome && res < biNumVarientBiomes) + else if ((res >= biFirstVariantBiome) && (res < biNumVariantBiomes)) { return (EMCSBiome)res; } diff --git a/src/BiomeDef.h b/src/BiomeDef.h index f015dd836..474d4df76 100644 --- a/src/BiomeDef.h +++ b/src/BiomeDef.h @@ -77,7 +77,7 @@ enum EMCSBiome biVariant = 128, // Release 1.7 biome variants: - biFirstVarientBiome = 129, + biFirstVariantBiome = 129, biSunflowerPlains = 129, biDesertM = 130, biExtremeHillsM = 131, @@ -100,8 +100,8 @@ enum EMCSBiome biMesaPlateauFM = 166, biMesaPlateauM = 167, // Automatically capture the maximum consecutive biome value into biVarientMaxBiome: - biNumVarientBiomes, // True number of biomes, since they are zero-based - biMaxVarientBiome = biNumVarientBiomes - 1, // The maximum biome value + biNumVariantBiomes, // True number of biomes, since they are zero-based + biMaxVariantBiome = biNumVariantBiomes - 1, // The maximum biome value } ; /// Translates a biome string to biome enum. Takes either a number or a biome alias (built-in). Returns biInvalidBiome on failure. diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 1a18f53f1..20f269fc8 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -97,7 +97,7 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) { AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "Plains"); m_Biome = StringToBiome(Biome); - if (m_Biome == EMCSBiome::biInvalidBiome) + if (m_Biome == biInvalidBiome) { LOGWARN("[Generator]::ConstantBiome value \"%s\" not recognized, using \"Plains\".", Biome.c_str()); m_Biome = biPlains; -- cgit v1.2.3 From 4b1924730502c26519202c9fa8ea9e77976475e5 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 3 Feb 2014 13:07:38 -0800 Subject: Fogot to save Biogen --- src/Generating/BioGen.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 20f269fc8..967deba6a 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -233,7 +233,7 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) } } EMCSBiome Biome = StringToBiome(Split2[0]); - if (Biome != EMCSBiome::biInvalidBiome) + if (Biome != biInvalidBiome) { for (int i = 0; i < Count; i++) { @@ -500,7 +500,7 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cC int OffsetZ = (m_Noise4.IntNoise3DInt(RealCellX, 32 * RealCellX - 16 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize; SeedX[xc][zc] = CellBlockX + OffsetX; SeedZ[xc][zc] = CellBlockZ + OffsetZ; - SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : (EMCSBiome::biInvalidBiome); + SeedV[xc][zc] = (((m_Noise6.IntNoise3DInt(RealCellX, RealCellX - RealCellZ + 1000, RealCellZ) / 11) % 256) > 90) ? biOcean : (biInvalidBiome); } // for z } // for x @@ -573,7 +573,7 @@ void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome float NoiseCoordZ = (float)(a_ChunkZ * cChunkDef::Width + z) / m_RiverCellSize; for (int x = 0; x < cChunkDef::Width; x++) { - if (cChunkDef::GetBiome(a_BiomeMap, x, z) != EMCSBiome::biInvalidBiome) + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biInvalidBiome) { // Biome already set, skip this column continue; @@ -693,7 +693,7 @@ void cBioGenMultiStepMap::DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, con int idxZ = 17 * z; for (int x = 0; x < cChunkDef::Width; x++) { - if (cChunkDef::GetBiome(a_BiomeMap, x, z) != EMCSBiome::biInvalidBiome) + if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biInvalidBiome) { // Already set before continue; -- cgit v1.2.3