|
@@ -6,11 +6,12 @@
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
-DimensionGenerator::DimensionGenerator(int dimensionId)
|
|
|
+DimensionGenerator::DimensionGenerator(int dimensionId, CaveGenerator* caveGenerator)
|
|
|
: ReferenceCounter(),
|
|
|
dimensionId(dimensionId),
|
|
|
minTemplateAffectedPosition(0, 0, 0),
|
|
|
- maxTemplateAffectedPosition(0, 0, 0)
|
|
|
+ maxTemplateAffectedPosition(0, 0, 0),
|
|
|
+ caveGenerator(caveGenerator)
|
|
|
{
|
|
|
StaticRegistry<DimensionGenerator>::INSTANCE.registerT(this, dimensionId);
|
|
|
}
|
|
@@ -18,9 +19,15 @@ DimensionGenerator::DimensionGenerator(int dimensionId)
|
|
|
DimensionGenerator::~DimensionGenerator()
|
|
|
{}
|
|
|
|
|
|
-BiomGenerator* DimensionGenerator::zBiomGenerator(int seed, int x, int y)
|
|
|
+void DimensionGenerator::initialize(int seed)
|
|
|
{
|
|
|
- double noise = zBiomNoise(seed)->getNoise((double)x, (double)y, 0.0);
|
|
|
+ this->seed = seed + dimensionId;
|
|
|
+ caveGenerator->initialize(this->seed);
|
|
|
+}
|
|
|
+
|
|
|
+BiomGenerator* DimensionGenerator::zBiomGenerator(int x, int y)
|
|
|
+{
|
|
|
+ double noise = zBiomNoise()->getNoise((double)x, (double)y, 0.0);
|
|
|
double border = 0;
|
|
|
BiomGenerator* gen = 0;
|
|
|
auto genI = biomGenerators.begin();
|
|
@@ -48,7 +55,7 @@ void DimensionGenerator::registerBiom(BiomGenerator* generator, double possibili
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-Framework::RCArray<GeneratedStructure>* DimensionGenerator::getGeneratedStructoresForArea(int seed, Framework::Vec3<int> minPos, Framework::Vec3<int> maxPos)
|
|
|
+Framework::RCArray<GeneratedStructure>* DimensionGenerator::getGeneratedStructoresForArea(Framework::Vec3<int> minPos, Framework::Vec3<int> maxPos)
|
|
|
{
|
|
|
Framework::RCArray<GeneratedStructure>* result = new Framework::RCArray<GeneratedStructure>();
|
|
|
|
|
@@ -59,13 +66,13 @@ Framework::RCArray<GeneratedStructure>* DimensionGenerator::getGeneratedStructor
|
|
|
int maxSearchY = maxPos.y - minTemplateAffectedPosition.y;
|
|
|
int maxSearchZ = MIN(maxPos.z - minTemplateAffectedPosition.z, WORLD_HEIGHT - 1);
|
|
|
|
|
|
- Noise* structureNoise = zStructureNoise(seed + dimensionId);
|
|
|
+ Noise* structureNoise = zStructureNoise();
|
|
|
for (int x = minSearchX; x <= maxSearchX; x++)
|
|
|
{
|
|
|
for (int y = minSearchY; y <= maxSearchY; y++)
|
|
|
{
|
|
|
- BiomGenerator* biom = zBiomGenerator(seed + dimensionId, x, y);
|
|
|
- int height = MIN_AIR_LEVEL + (int)(biom->zHeightMapNoise(seed + dimensionId)->getNoise((double)(x), (double)(y), 0.0) * (MAX_AIR_LEVEL - MIN_AIR_LEVEL));
|
|
|
+ BiomGenerator* biom = zBiomGenerator(x, y);
|
|
|
+ int height = MIN_AIR_LEVEL + (int)(biom->zHeightMapNoise(seed)->getNoise((double)(x), (double)(y), 0.0) * (MAX_AIR_LEVEL - MIN_AIR_LEVEL));
|
|
|
for (int z = minSearchZ; z <= maxSearchZ; z++)
|
|
|
{
|
|
|
if (z < height)
|
|
@@ -92,20 +99,21 @@ Framework::RCArray<GeneratedStructure>* DimensionGenerator::getGeneratedStructor
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-Chunk* DimensionGenerator::generateChunk(int seed, int centerX, int centerY)
|
|
|
+Chunk* DimensionGenerator::generateChunk(int centerX, int centerY)
|
|
|
{
|
|
|
- Framework::RCArray<GeneratedStructure>* structures = getGeneratedStructoresForArea(seed, Framework::Vec3<int>(centerX - CHUNK_SIZE / 2, centerY - CHUNK_SIZE / 2, 0), Framework::Vec3<int>(centerX + CHUNK_SIZE / 2, centerY + CHUNK_SIZE / 2, WORLD_HEIGHT - 1));
|
|
|
+ Framework::RCArray<GeneratedStructure>* structures = getGeneratedStructoresForArea(Framework::Vec3<int>(centerX - CHUNK_SIZE / 2, centerY - CHUNK_SIZE / 2, 0), Framework::Vec3<int>(centerX + CHUNK_SIZE / 2, centerY + CHUNK_SIZE / 2, WORLD_HEIGHT - 1));
|
|
|
std::cout << "generating chunk " << centerX << ", " << centerY << "\n";
|
|
|
+ CaveChunkGenerator* caveGen = caveGenerator->getGeneratorForChunk(centerX, centerY);
|
|
|
Chunk* chunk = new Chunk(Framework::Punkt(centerX, centerY), dimensionId);
|
|
|
for (int x = -CHUNK_SIZE / 2; x < CHUNK_SIZE / 2; x++)
|
|
|
{
|
|
|
for (int y = -CHUNK_SIZE / 2; y < CHUNK_SIZE / 2; y++)
|
|
|
{
|
|
|
- BiomGenerator* biom = zBiomGenerator(seed + dimensionId, x + centerX, y + centerY);
|
|
|
+ BiomGenerator* biom = zBiomGenerator(x + centerX, y + centerY);
|
|
|
// TODO: use Noise interpolator for height map between different bioms
|
|
|
- int height = MIN_AIR_LEVEL + (int)(biom->zHeightMapNoise(seed + dimensionId)->getNoise((double)(x + centerX), (double)(y + centerY), 0.0) * (MAX_AIR_LEVEL - MIN_AIR_LEVEL));
|
|
|
+ int height = MIN_AIR_LEVEL + (int)(biom->zHeightMapNoise(seed)->getNoise((double)(x + centerX), (double)(y + centerY), 0.0) * (MAX_AIR_LEVEL - MIN_AIR_LEVEL));
|
|
|
int maxSurfaceHeight = (int)(MAX_SURFACE_HEIGHT * (1.f - (float)(height - MIN_AIR_LEVEL) / (float)(MAX_AIR_LEVEL - MIN_AIR_LEVEL)));
|
|
|
- int actualSurfaceHeight = (int)((float)maxSurfaceHeight * (1.f - VARIABLE_SURFACE_PART) + ((float)maxSurfaceHeight * VARIABLE_SURFACE_PART * (float)biom->zHeightMapNoise(seed + dimensionId)->getNoise((double)(x + centerX), (double)(y + centerY), 10.0)));
|
|
|
+ int actualSurfaceHeight = (int)((float)maxSurfaceHeight * (1.f - VARIABLE_SURFACE_PART) + ((float)maxSurfaceHeight * VARIABLE_SURFACE_PART * (float)biom->zHeightMapNoise(seed)->getNoise((double)(x + centerX), (double)(y + centerY), 10.0)));
|
|
|
for (int z = 0; z < WORLD_HEIGHT; z++)
|
|
|
{
|
|
|
Framework::Either<Block*, int> generated = AirBlockBlockType::ID;
|
|
@@ -121,7 +129,9 @@ Chunk* DimensionGenerator::generateChunk(int seed, int centerX, int centerY)
|
|
|
}
|
|
|
if (!structureAffected)
|
|
|
{
|
|
|
- if (z < height && z >= height - actualSurfaceHeight)
|
|
|
+ if (caveGen->isInCave(x + centerX, y + centerY, z))
|
|
|
+ generated = biom->generateCaveBlock(x + centerX, y + centerY, z);
|
|
|
+ else if (z < height && z >= height - actualSurfaceHeight)
|
|
|
generated = biom->generateSurfaceBlock(x + centerX, y + centerY, z);
|
|
|
else if (z < height)
|
|
|
generated = biom->generateBelowSurfaceBlock(x + centerX, y + centerY, z);
|
|
@@ -133,18 +143,19 @@ Chunk* DimensionGenerator::generateChunk(int seed, int centerX, int centerY)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ caveGen->release();
|
|
|
structures->release();
|
|
|
return chunk;
|
|
|
}
|
|
|
|
|
|
-Framework::Either<Block*, int> DimensionGenerator::generateBlock(int seed, Framework::Vec3<int> location)
|
|
|
+Framework::Either<Block*, int> DimensionGenerator::generateBlock(Framework::Vec3<int> location)
|
|
|
{
|
|
|
- Framework::RCArray<GeneratedStructure>* structures = getGeneratedStructoresForArea(seed, location, location);
|
|
|
- BiomGenerator* biom = zBiomGenerator(seed + dimensionId, location.x, location.y);
|
|
|
+ Framework::RCArray<GeneratedStructure>* structures = getGeneratedStructoresForArea(location, location);
|
|
|
+ BiomGenerator* biom = zBiomGenerator(location.x, location.y);
|
|
|
// TODO: use Noise interpolator for height map between different bioms
|
|
|
- int height = MIN_AIR_LEVEL + (int)(biom->zHeightMapNoise(seed + dimensionId)->getNoise((double)(location.x), (double)(location.y), 0.0) * (MAX_AIR_LEVEL - MIN_AIR_LEVEL));
|
|
|
+ int height = MIN_AIR_LEVEL + (int)(biom->zHeightMapNoise(seed)->getNoise((double)(location.x), (double)(location.y), 0.0) * (MAX_AIR_LEVEL - MIN_AIR_LEVEL));
|
|
|
int maxSurfaceHeight = (int)(MAX_SURFACE_HEIGHT * (1.f - (float)(height - MIN_AIR_LEVEL) / (float)(MAX_AIR_LEVEL - MIN_AIR_LEVEL)));
|
|
|
- int actualSurfaceHeight = (int)((float)maxSurfaceHeight * (1.f - VARIABLE_SURFACE_PART) + ((float)maxSurfaceHeight * VARIABLE_SURFACE_PART * (float)biom->zHeightMapNoise(seed + dimensionId)->getNoise((double)(location.x), (double)(location.y), 10.0)));
|
|
|
+ int actualSurfaceHeight = (int)((float)maxSurfaceHeight * (1.f - VARIABLE_SURFACE_PART) + ((float)maxSurfaceHeight * VARIABLE_SURFACE_PART * (float)biom->zHeightMapNoise(seed)->getNoise((double)(location.x), (double)(location.y), 10.0)));
|
|
|
for (auto structure : *structures)
|
|
|
{
|
|
|
if (structure->isBlockAffected(location))
|