ChunkGenerator: Changed to use cChunkCoords.
This commit is contained in:
parent
5f4df3e87d
commit
ad24702b4e
@ -99,7 +99,7 @@ void cChunkGeneratorThread::GenerateBiomes(cChunkCoords a_Coords, cChunkDef::Bio
|
||||
{
|
||||
if (m_Generator != nullptr)
|
||||
{
|
||||
m_Generator->GenerateBiomes(a_Coords.m_ChunkX, a_Coords.m_ChunkZ, a_BiomeMap);
|
||||
m_Generator->GenerateBiomes(a_Coords, a_BiomeMap);
|
||||
}
|
||||
}
|
||||
|
||||
@ -247,7 +247,7 @@ void cChunkGeneratorThread::DoGenerate(cChunkCoords a_Coords)
|
||||
|
||||
cChunkDesc ChunkDesc(a_Coords);
|
||||
m_PluginInterface->CallHookChunkGenerating(ChunkDesc);
|
||||
m_Generator->Generate(a_Coords.m_ChunkX, a_Coords.m_ChunkZ, ChunkDesc);
|
||||
m_Generator->Generate(ChunkDesc);
|
||||
m_PluginInterface->CallHookChunkGenerated(ChunkDesc);
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
@ -71,7 +71,7 @@ EMCSBiome cChunkGenerator::GetBiomeAt(int a_BlockX, int a_BlockZ)
|
||||
int Y = 0;
|
||||
int ChunkX, ChunkZ;
|
||||
cChunkDef::AbsoluteToRelative(a_BlockX, Y, a_BlockZ, ChunkX, ChunkZ);
|
||||
GenerateBiomes(ChunkX, ChunkZ, Biomes);
|
||||
GenerateBiomes({ChunkX, ChunkZ}, Biomes);
|
||||
return cChunkDef::GetBiome(Biomes, a_BlockX, a_BlockZ);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
/** Generates the biomes for the specified chunk.
|
||||
Used by the world loader if biomes failed loading. */
|
||||
virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) = 0;
|
||||
virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) = 0;
|
||||
|
||||
/** Returns the biome at the specified coords.
|
||||
Used by ChunkMap if an invalid chunk is queried for biome.
|
||||
@ -36,7 +36,7 @@ public:
|
||||
|
||||
/** Does the actual chunk generation.
|
||||
Descendants need to override this and generate into a_ChunkDesc. */
|
||||
virtual void Generate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc) = 0;
|
||||
virtual void Generate(cChunkDesc & a_ChunkDesc) = 0;
|
||||
|
||||
/** Returns the seed that was read from the INI file. */
|
||||
int GetSeed(void) const { return m_Seed; }
|
||||
|
@ -141,11 +141,11 @@ void cComposableGenerator::Initialize(cIniFile & a_IniFile)
|
||||
|
||||
|
||||
|
||||
void cComposableGenerator::GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap)
|
||||
void cComposableGenerator::GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap)
|
||||
{
|
||||
if (m_BiomeGen != nullptr) // Quick fix for generator deinitializing before the world storage finishes loading
|
||||
{
|
||||
m_BiomeGen->GenBiomes({a_ChunkX, a_ChunkZ}, a_BiomeMap);
|
||||
m_BiomeGen->GenBiomes(a_ChunkCoords, a_BiomeMap);
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ void cComposableGenerator::GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef:
|
||||
|
||||
|
||||
|
||||
void cComposableGenerator::Generate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc)
|
||||
void cComposableGenerator::Generate(cChunkDesc & a_ChunkDesc)
|
||||
{
|
||||
if (a_ChunkDesc.IsUsingDefaultBiomes())
|
||||
{
|
||||
|
@ -210,8 +210,8 @@ public:
|
||||
|
||||
// cChunkGenerator::cGenerator overrides:
|
||||
virtual void Initialize(cIniFile & a_IniFile) override;
|
||||
virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
||||
virtual void Generate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc) override;
|
||||
virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
|
||||
virtual void Generate(cChunkDesc & a_ChunkDesc) override;
|
||||
|
||||
/** If there's no particular sub-generator set in the INI file,
|
||||
adds the default one, based on the dimension. */
|
||||
|
@ -195,8 +195,9 @@ void cNoise3DGenerator::Initialize(cIniFile & a_IniFile)
|
||||
|
||||
|
||||
|
||||
void cNoise3DGenerator::GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap)
|
||||
void cNoise3DGenerator::GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap)
|
||||
{
|
||||
UNUSED(a_ChunkCoords);
|
||||
for (size_t i = 0; i < ARRAYCOUNT(a_BiomeMap); i++)
|
||||
{
|
||||
a_BiomeMap[i] = biExtremeHills;
|
||||
@ -207,10 +208,10 @@ void cNoise3DGenerator::GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::Bi
|
||||
|
||||
|
||||
|
||||
void cNoise3DGenerator::Generate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc)
|
||||
void cNoise3DGenerator::Generate(cChunkDesc & a_ChunkDesc)
|
||||
{
|
||||
NOISE_DATATYPE Noise[17 * 257 * 17];
|
||||
GenerateNoiseArray(a_ChunkX, a_ChunkZ, Noise);
|
||||
GenerateNoiseArray(a_ChunkDesc.GetChunkCoords(), Noise);
|
||||
|
||||
// Output noise into chunk:
|
||||
for (int z = 0; z < cChunkDef::Width; z++)
|
||||
@ -243,23 +244,21 @@ void cNoise3DGenerator::Generate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_Chun
|
||||
|
||||
|
||||
|
||||
void cNoise3DGenerator::GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DATATYPE * a_OutNoise)
|
||||
void cNoise3DGenerator::GenerateNoiseArray(cChunkCoords a_ChunkCoords, NOISE_DATATYPE * a_OutNoise)
|
||||
{
|
||||
NOISE_DATATYPE NoiseO[DIM_X * DIM_Y * DIM_Z]; // Output for the Perlin noise
|
||||
NOISE_DATATYPE NoiseW[DIM_X * DIM_Y * DIM_Z]; // Workspace that the noise calculation can use and trash
|
||||
|
||||
// Our noise array has different layout, XZY, instead of regular chunk's XYZ, that's why the coords are "renamed"
|
||||
NOISE_DATATYPE StartX = static_cast<NOISE_DATATYPE>(a_ChunkX * cChunkDef::Width) / m_FrequencyX;
|
||||
NOISE_DATATYPE EndX = static_cast<NOISE_DATATYPE>((a_ChunkX + 1) * cChunkDef::Width) / m_FrequencyX;
|
||||
NOISE_DATATYPE StartZ = static_cast<NOISE_DATATYPE>(a_ChunkZ * cChunkDef::Width) / m_FrequencyZ;
|
||||
NOISE_DATATYPE EndZ = static_cast<NOISE_DATATYPE>((a_ChunkZ + 1) * cChunkDef::Width) / m_FrequencyZ;
|
||||
NOISE_DATATYPE StartX = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkX * cChunkDef::Width) / m_FrequencyX;
|
||||
NOISE_DATATYPE EndX = static_cast<NOISE_DATATYPE>((a_ChunkCoords.m_ChunkX + 1) * cChunkDef::Width) / m_FrequencyX;
|
||||
NOISE_DATATYPE StartZ = static_cast<NOISE_DATATYPE>(a_ChunkCoords.m_ChunkZ * cChunkDef::Width) / m_FrequencyZ;
|
||||
NOISE_DATATYPE EndZ = static_cast<NOISE_DATATYPE>((a_ChunkCoords.m_ChunkZ + 1) * cChunkDef::Width) / m_FrequencyZ;
|
||||
NOISE_DATATYPE StartY = 0;
|
||||
NOISE_DATATYPE EndY = static_cast<NOISE_DATATYPE>(256) / m_FrequencyY;
|
||||
|
||||
m_Perlin.Generate3D(NoiseO, DIM_X, DIM_Y, DIM_Z, StartX, EndX, StartY, EndY, StartZ, EndZ, NoiseW);
|
||||
|
||||
// DEBUG: Debug3DNoise(NoiseO, DIM_X, DIM_Y, DIM_Z, Printf("Chunk_%d_%d_orig", a_ChunkX, a_ChunkZ));
|
||||
|
||||
// Precalculate a "height" array:
|
||||
NOISE_DATATYPE Height[DIM_X * DIM_Z]; // Output for the cubic noise heightmap ("source")
|
||||
m_Cubic.Generate2D(Height, DIM_X, DIM_Z, StartX / 5, EndX / 5, StartZ / 5, EndZ / 5);
|
||||
@ -283,15 +282,11 @@ void cNoise3DGenerator::GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DAT
|
||||
}
|
||||
}
|
||||
|
||||
// DEBUG: Debug3DNoise(NoiseO, DIM_X, DIM_Y, DIM_Z, Printf("Chunk_%d_%d_hei", a_ChunkX, a_ChunkZ));
|
||||
|
||||
// Upscale the Perlin noise into full-blown chunk dimensions:
|
||||
LinearUpscale3DArray(
|
||||
NoiseO, DIM_X, DIM_Y, DIM_Z,
|
||||
a_OutNoise, UPSCALE_X, UPSCALE_Y, UPSCALE_Z
|
||||
);
|
||||
|
||||
// DEBUG: Debug3DNoise(a_OutNoise, 17, 257, 17, Printf("Chunk_%d_%d_lerp", a_ChunkX, a_ChunkZ));
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,8 +30,8 @@ public:
|
||||
virtual ~cNoise3DGenerator() override;
|
||||
|
||||
virtual void Initialize(cIniFile & a_IniFile) override;
|
||||
virtual void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap) override;
|
||||
virtual void Generate(int a_ChunkX, int a_ChunkZ, cChunkDesc & a_ChunkDesc) override;
|
||||
virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap & a_BiomeMap) override;
|
||||
virtual void Generate(cChunkDesc & a_ChunkDesc) override;
|
||||
|
||||
protected:
|
||||
// Linear interpolation step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively:
|
||||
@ -58,8 +58,8 @@ protected:
|
||||
NOISE_DATATYPE m_FrequencyZ;
|
||||
NOISE_DATATYPE m_AirThreshold;
|
||||
|
||||
/** Generates the 3D noise array used for terrain generation; a_Noise is of ChunkData-size */
|
||||
void GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DATATYPE * a_Noise);
|
||||
/** Generates the 3D noise array used for terrain generation into a_Noise; a_Noise is of ChunkData-size */
|
||||
void GenerateNoiseArray(cChunkCoords a_ChunkCoords, NOISE_DATATYPE * a_Noise);
|
||||
|
||||
/** Composes terrain - adds dirt, grass and sand */
|
||||
void ComposeTerrain(cChunkDesc & a_ChunkDesc);
|
||||
|
@ -91,7 +91,7 @@ static void testGenerateOverworld(cChunkGenerator & aDefaultOverworldGen)
|
||||
{
|
||||
// Generate a chunk:
|
||||
cChunkDesc chd({chunkX, 0});
|
||||
aDefaultOverworldGen.Generate(chunkX, 0, chd);
|
||||
aDefaultOverworldGen.Generate(chd);
|
||||
verifyChunkDescHeightmap(chd);
|
||||
|
||||
// Check that it has bedrock at the bottom:
|
||||
@ -155,7 +155,7 @@ static void testGenerateNether(cChunkGenerator & aDefaultNetherGen)
|
||||
{
|
||||
// Generate a chunk:
|
||||
cChunkDesc chd({chunkX, 0});
|
||||
aDefaultNetherGen.Generate(chunkX, 0, chd);
|
||||
aDefaultNetherGen.Generate(chd);
|
||||
verifyChunkDescHeightmap(chd);
|
||||
|
||||
// Check that the biome is Nether everywhere:
|
||||
@ -244,7 +244,7 @@ static void checkChunkChecksums(
|
||||
for (const auto & coords: aCoordsWithChecksum)
|
||||
{
|
||||
cChunkDesc chd(coords.mCoords);
|
||||
aGenerator.Generate(coords.mCoords.m_ChunkX, coords.mCoords.m_ChunkZ, chd);
|
||||
aGenerator.Generate(chd);
|
||||
auto checksum = chunkSHA1(chd);
|
||||
TEST_EQUAL_MSG(checksum, coords.mChecksum,
|
||||
Printf("%s chunk %s SHA1: expected %s, got %s", aDimension, coords.mCoords.ToString(), coords.mChecksum, checksum)
|
||||
|
Loading…
Reference in New Issue
Block a user