1
0

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
This commit is contained in:
Tycho 2014-02-03 12:26:17 -08:00
parent 2450d0467f
commit 80807eec2c
9 changed files with 32 additions and 17 deletions

View File

@ -78,7 +78,7 @@ bool cBiomeRenderer::Render(cPixmap & a_Pixmap)
{ {
for (int i = 0; i < ARRAYCOUNT(CurBiomes); i++) for (int i = 0; i < ARRAYCOUNT(CurBiomes); i++)
{ {
CurBiomes[i] = (EMCSBiome)-1; CurBiomes[i] = EMCSBiome::biInvalidBiome;
} }
break; break;
} }

View File

@ -13,9 +13,17 @@ EMCSBiome StringToBiome(const AString & a_BiomeString)
int res = atoi(a_BiomeString.c_str()); int res = atoi(a_BiomeString.c_str());
if ((res != 0) || (a_BiomeString.compare("0") == 0)) if ((res != 0) || (a_BiomeString.compare("0") == 0))
{ {
// It was a valid number if(res >= biFirstBiome && res < biNumBiomes)
{
return (EMCSBiome)res; 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: // Convert using the built-in map:
static struct { static struct {
@ -100,7 +108,7 @@ EMCSBiome StringToBiome(const AString & a_BiomeString)
return BiomeMap[i].m_Biome; return BiomeMap[i].m_Biome;
} }
} // for i - BiomeMap[] } // for i - BiomeMap[]
return (EMCSBiome)-1; return biInvalidBiome;
} }

View File

@ -20,6 +20,9 @@ BiomeIDs over 255 are used by MCServer internally and are translated to MC biome
*/ */
enum EMCSBiome enum EMCSBiome
{ {
biInvalidBiome = -1,
biFirstBiome = 0,
biOcean = 0, biOcean = 0,
biPlains = 1, biPlains = 1,
biDesert = 2, biDesert = 2,
@ -74,6 +77,7 @@ enum EMCSBiome
biVariant = 128, biVariant = 128,
// Release 1.7 biome variants: // Release 1.7 biome variants:
biFirstVarientBiome = 129,
biSunflowerPlains = 129, biSunflowerPlains = 129,
biDesertM = 130, biDesertM = 130,
biExtremeHillsM = 131, biExtremeHillsM = 131,
@ -95,9 +99,12 @@ enum EMCSBiome
biMesaBryce = 165, biMesaBryce = 165,
biMesaPlateauFM = 166, biMesaPlateauFM = 166,
biMesaPlateauM = 167, 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); extern EMCSBiome StringToBiome(const AString & a_BiomeString);
/// Returns true if the biome has no downfall - deserts and savannas /// Returns true if the biome has no downfall - deserts and savannas

View File

@ -97,7 +97,7 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile)
{ {
AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "Plains"); AString Biome = a_IniFile.GetValueSet("Generator", "ConstantBiome", "Plains");
m_Biome = StringToBiome(Biome); 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()); LOGWARN("[Generator]::ConstantBiome value \"%s\" not recognized, using \"Plains\".", Biome.c_str());
m_Biome = biPlains; m_Biome = biPlains;
@ -233,7 +233,7 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes)
} }
} }
EMCSBiome Biome = StringToBiome(Split2[0]); EMCSBiome Biome = StringToBiome(Split2[0]);
if (Biome != -1) if (Biome != EMCSBiome::biInvalidBiome)
{ {
for (int i = 0; i < Count; i++) 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; int OffsetZ = (m_Noise4.IntNoise3DInt(RealCellX, 32 * RealCellX - 16 * RealCellZ, RealCellZ) / 8) % m_OceanCellSize;
SeedX[xc][zc] = CellBlockX + OffsetX; SeedX[xc][zc] = CellBlockX + OffsetX;
SeedZ[xc][zc] = CellBlockZ + OffsetZ; 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 z
} // for x } // 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; float NoiseCoordZ = (float)(a_ChunkZ * cChunkDef::Width + z) / m_RiverCellSize;
for (int x = 0; x < cChunkDef::Width; x++) 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 // Biome already set, skip this column
continue; continue;
@ -693,7 +693,7 @@ void cBioGenMultiStepMap::DecideLandBiomes(cChunkDef::BiomeMap & a_BiomeMap, con
int idxZ = 17 * z; int idxZ = 17 * z;
for (int x = 0; x < cChunkDef::Width; x++) 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 // Already set before
continue; continue;

View File

@ -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);
} }

View File

@ -53,7 +53,7 @@ public:
void SetBlockMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_BlockMeta); 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); 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); EMCSBiome GetBiome(int a_RelX, int a_RelZ);
// These operate on the heightmap, so they could get out of sync with the data // These operate on the heightmap, so they could get out of sync with the data

View File

@ -29,7 +29,7 @@ void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk) void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk)
{ {
super::Tick(a_Dt, 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); TakeDamage(*this);
} }

View File

@ -1222,7 +1222,7 @@ void cWorld::GrowTreeByBiome(int a_X, int a_Y, int a_Z)
{ {
cNoise Noise(m_Generator.GetSeed()); cNoise Noise(m_Generator.GetSeed());
sSetBlockVector Logs, Other; 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()); Other.insert(Other.begin(), Logs.begin(), Logs.end());
Logs.clear(); Logs.clear();
GrowTreeImage(Other); 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); return m_ChunkMap->GetBiomeAt(a_BlockX, a_BlockZ);
} }

View File

@ -526,7 +526,7 @@ public:
void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow); 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 */ /** 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 */ /** Returns the name of the world */
const AString & GetName(void) const { return m_WorldName; } const AString & GetName(void) const { return m_WorldName; }