diff options
Diffstat (limited to '')
-rw-r--r-- | src/Generating/BioGen.cpp | 101 |
1 files changed, 42 insertions, 59 deletions
diff --git a/src/Generating/BioGen.cpp b/src/Generating/BioGen.cpp index 4439fd901..c84cb559d 100644 --- a/src/Generating/BioGen.cpp +++ b/src/Generating/BioGen.cpp @@ -18,8 +18,9 @@ //////////////////////////////////////////////////////////////////////////////// // cBioGenConstant: -void cBioGenConstant::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenConstant::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { + UNUSED(a_ChunkCoords); for (size_t i = 0; i < ARRAYCOUNT(a_BiomeMap); i++) { a_BiomeMap[i] = m_Biome; @@ -59,17 +60,15 @@ void cBioGenConstant::InitializeBiomeGen(cIniFile & a_IniFile) cBioGenCache::cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize) : m_BioGenToCache(a_BioGenToCache), m_CacheSize(a_CacheSize), - m_CacheOrder(new size_t[a_CacheSize]), - m_CacheData(new sCacheData[a_CacheSize]), m_NumHits(0), m_NumMisses(0), m_TotalChain(0) { + m_CacheData.resize(m_CacheSize); + m_CacheOrder.resize(m_CacheSize); for (size_t i = 0; i < m_CacheSize; i++) { m_CacheOrder[i] = i; - m_CacheData[i].m_ChunkX = 0x7fffffff; - m_CacheData[i].m_ChunkZ = 0x7fffffff; } } @@ -77,19 +76,7 @@ cBioGenCache::cBioGenCache(cBiomeGenPtr a_BioGenToCache, size_t a_CacheSize) : -cBioGenCache::~cBioGenCache() -{ - delete[] m_CacheData; - m_CacheData = nullptr; - delete[] m_CacheOrder; - m_CacheOrder = nullptr; -} - - - - - -void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenCache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { if (((m_NumHits + m_NumMisses) % 1024) == 10) { @@ -99,10 +86,7 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a for (size_t i = 0; i < m_CacheSize; i++) { - if ( - (m_CacheData[m_CacheOrder[i]].m_ChunkX != a_ChunkX) || - (m_CacheData[m_CacheOrder[i]].m_ChunkZ != a_ChunkZ) - ) + if (m_CacheData[m_CacheOrder[i]].m_Coords != a_ChunkCoords) { continue; } @@ -126,7 +110,7 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a // Not in the cache: m_NumMisses++; - m_BioGenToCache->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); + m_BioGenToCache->GenBiomes(a_ChunkCoords, a_BiomeMap); // Insert it as the first item in the MRU order: size_t Idx = m_CacheOrder[m_CacheSize - 1]; @@ -136,8 +120,7 @@ void cBioGenCache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a } // for i - m_CacheOrder[] m_CacheOrder[0] = Idx; memcpy(m_CacheData[Idx].m_BiomeMap, a_BiomeMap, sizeof(a_BiomeMap)); - m_CacheData[Idx].m_ChunkX = a_ChunkX; - m_CacheData[Idx].m_ChunkZ = a_ChunkZ; + m_CacheData[Idx].m_Coords = a_ChunkCoords; } @@ -170,12 +153,12 @@ cBioGenMulticache::cBioGenMulticache(cBiomeGenPtr a_BioGenToCache, size_t a_SubC -void cBioGenMulticache::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenMulticache::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { const size_t coefficient = 3; - const size_t cacheIdx = (static_cast<size_t>(a_ChunkX) + coefficient * static_cast<size_t>(a_ChunkZ)) % m_NumSubCaches; + const size_t cacheIdx = (static_cast<size_t>(a_ChunkCoords.m_ChunkX) + coefficient * static_cast<size_t>(a_ChunkCoords.m_ChunkZ)) % m_NumSubCaches; - m_Caches[cacheIdx]->GenBiomes(a_ChunkX, a_ChunkZ, a_BiomeMap); + m_Caches[cacheIdx]->GenBiomes(a_ChunkCoords, a_BiomeMap); } @@ -277,14 +260,14 @@ void cBiomeGenList::InitializeBiomes(const AString & a_Biomes) //////////////////////////////////////////////////////////////////////////////// // cBioGenCheckerboard: -void cBioGenCheckerboard::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenCheckerboard::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { for (int z = 0; z < cChunkDef::Width; z++) { - int Base = (cChunkDef::Width * a_ChunkZ + z) / m_BiomeSize; + int Base = (cChunkDef::Width * a_ChunkCoords.m_ChunkZ + z) / m_BiomeSize; for (int x = 0; x < cChunkDef::Width; x++) { - int Add = cChunkDef::Width * a_ChunkX + x; + int Add = cChunkDef::Width * a_ChunkCoords.m_ChunkX + x; size_t BiomeIdx = static_cast<size_t>((((Base + Add / m_BiomeSize) % m_BiomesCount) + m_BiomesCount) % m_BiomesCount); // Need to add and modulo twice because of negative numbers a_BiomeMap[x + cChunkDef::Width * z] = m_Biomes[BiomeIdx]; } @@ -311,10 +294,10 @@ void cBioGenCheckerboard::InitializeBiomeGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cBioGenVoronoi : -void cBioGenVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenVoronoi::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { - int BaseZ = cChunkDef::Width * a_ChunkZ; - int BaseX = cChunkDef::Width * a_ChunkX; + int BaseZ = cChunkDef::Width * a_ChunkCoords.m_ChunkZ; + int BaseX = cChunkDef::Width * a_ChunkCoords.m_ChunkX; for (int z = 0; z < cChunkDef::Width; z++) { int AbsoluteZ = BaseZ + z; @@ -349,10 +332,10 @@ void cBioGenVoronoi::InitializeBiomeGen(cIniFile & a_IniFile) //////////////////////////////////////////////////////////////////////////////// // cBioGenDistortedVoronoi: -void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenDistortedVoronoi::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { - int BaseZ = cChunkDef::Width * a_ChunkZ; - int BaseX = cChunkDef::Width * a_ChunkX; + int BaseZ = cChunkDef::Width * a_ChunkCoords.m_ChunkZ; + int BaseX = cChunkDef::Width * a_ChunkCoords.m_ChunkX; // Distortions for linear interpolation: int DistortX[cChunkDef::Width + 1][cChunkDef::Width + 1]; @@ -444,24 +427,24 @@ void cBioGenMultiStepMap::InitializeBiomeGen(cIniFile & a_IniFile) -void cBioGenMultiStepMap::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenMultiStepMap::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { - DecideOceanLandMushroom(a_ChunkX, a_ChunkZ, a_BiomeMap); - AddRivers(a_ChunkX, a_ChunkZ, a_BiomeMap); - ApplyTemperatureHumidity(a_ChunkX, a_ChunkZ, a_BiomeMap); + DecideOceanLandMushroom(a_ChunkCoords, a_BiomeMap); + AddRivers(a_ChunkCoords, a_BiomeMap); + ApplyTemperatureHumidity(a_ChunkCoords, a_BiomeMap); } -void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenMultiStepMap::DecideOceanLandMushroom(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { // Distorted Voronoi over 3 biomes, with mushroom having only a special occurence. // Prepare a distortion lookup table, by distorting a 5x5 area and using that as 1:4 zoom (linear interpolate): - int BaseZ = cChunkDef::Width * a_ChunkZ; - int BaseX = cChunkDef::Width * a_ChunkX; + int BaseZ = cChunkDef::Width * a_ChunkCoords.m_ChunkZ; + int BaseX = cChunkDef::Width * a_ChunkCoords.m_ChunkX; int DistortX[cChunkDef::Width + 1][cChunkDef::Width + 1]; int DistortZ[cChunkDef::Width + 1][cChunkDef::Width + 1]; int DistortSize = m_OceanCellSize / 2; @@ -558,11 +541,11 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cC -void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenMultiStepMap::AddRivers(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { for (int z = 0; z < cChunkDef::Width; z++) { - float NoiseCoordZ = static_cast<float>(a_ChunkZ * cChunkDef::Width + z) / m_RiverCellSize; + float NoiseCoordZ = static_cast<float>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width + z) / m_RiverCellSize; for (int x = 0; x < cChunkDef::Width; x++) { if (cChunkDef::GetBiome(a_BiomeMap, x, z) != biInvalidBiome) @@ -571,7 +554,7 @@ void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome continue; } - float NoiseCoordX = static_cast<float>(a_ChunkX * cChunkDef::Width + x) / m_RiverCellSize; + float NoiseCoordX = static_cast<float>(a_ChunkCoords.m_ChunkX * cChunkDef::Width + x) / m_RiverCellSize; double Noise = m_Noise1.CubicNoise2D( NoiseCoordX, NoiseCoordZ); Noise += 0.5 * m_Noise3.CubicNoise2D(2 * NoiseCoordX, 2 * NoiseCoordZ); @@ -589,11 +572,11 @@ void cBioGenMultiStepMap::AddRivers(int a_ChunkX, int a_ChunkZ, cChunkDef::Biome -void cBioGenMultiStepMap::ApplyTemperatureHumidity(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenMultiStepMap::ApplyTemperatureHumidity(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { IntMap TemperatureMap; IntMap HumidityMap; - BuildTemperatureHumidityMaps(a_ChunkX, a_ChunkZ, TemperatureMap, HumidityMap); + BuildTemperatureHumidityMaps(a_ChunkCoords, TemperatureMap, HumidityMap); FreezeWaterBiomes(a_BiomeMap, TemperatureMap); DecideLandBiomes(a_BiomeMap, TemperatureMap, HumidityMap); @@ -620,17 +603,17 @@ void cBioGenMultiStepMap::Distort(int a_BlockX, int a_BlockZ, int & a_DistortedX -void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(int a_ChunkX, int a_ChunkZ, IntMap & a_TemperatureMap, IntMap & a_HumidityMap) +void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(cChunkCoords a_ChunkCoords, IntMap & a_TemperatureMap, IntMap & a_HumidityMap) { // Linear interpolation over 8x8 blocks; use double for better precision: DblMap TemperatureMap; DblMap HumidityMap; for (int z = 0; z < 17; z += 8) { - float NoiseCoordZ = static_cast<float>(a_ChunkZ * cChunkDef::Width + z) / m_LandBiomesSize; + float NoiseCoordZ = static_cast<float>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width + z) / m_LandBiomesSize; for (int x = 0; x < 17; x += 8) { - float NoiseCoordX = static_cast<float>(a_ChunkX * cChunkDef::Width + x) / m_LandBiomesSize; + float NoiseCoordX = static_cast<float>(a_ChunkCoords.m_ChunkX * cChunkDef::Width + x) / m_LandBiomesSize; double NoiseT = m_Noise1.CubicNoise2D( NoiseCoordX, NoiseCoordZ); NoiseT += 0.5 * m_Noise2.CubicNoise2D(2 * NoiseCoordX, 2 * NoiseCoordZ); @@ -760,10 +743,10 @@ cBioGenTwoLevel::cBioGenTwoLevel(int a_Seed) : -void cBioGenTwoLevel::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) +void cBioGenTwoLevel::GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) { - int BaseZ = cChunkDef::Width * a_ChunkZ; - int BaseX = cChunkDef::Width * a_ChunkX; + int BaseZ = cChunkDef::Width * a_ChunkCoords.m_ChunkZ; + int BaseX = cChunkDef::Width * a_ChunkCoords.m_ChunkX; // Distortions for linear interpolation: int DistortX[cChunkDef::Width + 1][cChunkDef::Width + 1]; @@ -1022,10 +1005,10 @@ public: ))))); } - virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) override + virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_Biomes) override { cIntGen<16, 16>::Values vals; - m_Gen->GetInts(a_ChunkX * cChunkDef::Width, a_ChunkZ * cChunkDef::Width, vals); + m_Gen->GetInts(a_ChunkCoords.m_ChunkX * cChunkDef::Width, a_ChunkCoords.m_ChunkZ * cChunkDef::Width, vals); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) @@ -1126,10 +1109,10 @@ public: ))))); } - virtual void GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_Biomes) override + virtual void GenBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_Biomes) override { int vals[16 * 16]; - m_Gen->GetInts(a_ChunkX * cChunkDef::Width, a_ChunkZ * cChunkDef::Width, 16, 16, vals); + m_Gen->GetInts(a_ChunkCoords.m_ChunkX * cChunkDef::Width, a_ChunkCoords.m_ChunkZ * cChunkDef::Width, 16, 16, vals); for (int z = 0; z < cChunkDef::Width; z++) { for (int x = 0; x < cChunkDef::Width; x++) |