mirror of
https://github.com/moparisthebest/minetest
synced 2024-11-05 17:05:05 -05:00
Mapgen: Remove calculateNoise from most mapgens
This commit moves noise calculation to the functions where the noise is actually required, increasing the separation of concerns and level of interdependency for each mapgen method. Valleys Mapgen is left unmodified.
This commit is contained in:
parent
c5968049bb
commit
0df5c01a8c
@ -386,6 +386,8 @@ MgStoneType MapgenBasic::generateBiomes()
|
||||
u32 index = 0;
|
||||
MgStoneType stone_type = MGSTONE_STONE;
|
||||
|
||||
noise_filler_depth->perlinMap2D(node_min.X, node_min.Z);
|
||||
|
||||
for (s16 z = node_min.Z; z <= node_max.Z; z++)
|
||||
for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
|
||||
Biome *biome = NULL;
|
||||
|
@ -227,9 +227,6 @@ void MapgenFlat::makeChunk(BlockMakeData *data)
|
||||
|
||||
blockseed = getBlockSeed2(full_node_min, seed);
|
||||
|
||||
// Make some noise
|
||||
calculateNoise();
|
||||
|
||||
// Generate base terrain, mountains, and ridges with initial heightmaps
|
||||
s16 stone_surface_max_y = generateTerrain();
|
||||
|
||||
@ -312,24 +309,6 @@ void MapgenFlat::makeChunk(BlockMakeData *data)
|
||||
}
|
||||
|
||||
|
||||
void MapgenFlat::calculateNoise()
|
||||
{
|
||||
//TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
|
||||
s16 x = node_min.X;
|
||||
s16 z = node_min.Z;
|
||||
|
||||
if ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS))
|
||||
noise_terrain->perlinMap2D(x, z);
|
||||
|
||||
// Cave noises are calculated in generateCaves()
|
||||
// only if solid terrain is present in mapchunk
|
||||
|
||||
noise_filler_depth->perlinMap2D(x, z);
|
||||
|
||||
//printf("calculateNoise: %dus\n", t.stop());
|
||||
}
|
||||
|
||||
|
||||
s16 MapgenFlat::generateTerrain()
|
||||
{
|
||||
MapNode n_air(CONTENT_AIR);
|
||||
@ -340,13 +319,14 @@ s16 MapgenFlat::generateTerrain()
|
||||
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
|
||||
u32 ni2d = 0;
|
||||
|
||||
bool use_noise = (spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS);
|
||||
if (use_noise)
|
||||
noise_terrain->perlinMap2D(node_min.X, node_min.Z);
|
||||
|
||||
for (s16 z = node_min.Z; z <= node_max.Z; z++)
|
||||
for (s16 x = node_min.X; x <= node_max.X; x++, ni2d++) {
|
||||
s16 stone_level = ground_level;
|
||||
float n_terrain = 0.0f;
|
||||
|
||||
if ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS))
|
||||
n_terrain = noise_terrain->result[ni2d];
|
||||
float n_terrain = use_noise ? noise_terrain->result[ni2d] : 0.0f;
|
||||
|
||||
if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) {
|
||||
s16 depress = (lake_threshold - n_terrain) * lake_steepness;
|
||||
|
@ -78,7 +78,6 @@ public:
|
||||
|
||||
virtual void makeChunk(BlockMakeData *data);
|
||||
int getSpawnLevelAtPoint(v2s16 p);
|
||||
void calculateNoise();
|
||||
s16 generateTerrain();
|
||||
};
|
||||
|
||||
|
@ -243,9 +243,6 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
|
||||
|
||||
blockseed = getBlockSeed2(full_node_min, seed);
|
||||
|
||||
// Make some noise
|
||||
calculateNoise();
|
||||
|
||||
// Generate base terrain, mountains, and ridges with initial heightmaps
|
||||
s16 stone_surface_max_y = generateTerrain();
|
||||
|
||||
@ -328,23 +325,6 @@ void MapgenFractal::makeChunk(BlockMakeData *data)
|
||||
}
|
||||
|
||||
|
||||
void MapgenFractal::calculateNoise()
|
||||
{
|
||||
//TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
|
||||
s16 x = node_min.X;
|
||||
s16 z = node_min.Z;
|
||||
|
||||
noise_seabed->perlinMap2D(x, z);
|
||||
|
||||
// Cave noises are calculated in generateCaves()
|
||||
// only if solid terrain is present in mapchunk
|
||||
|
||||
noise_filler_depth->perlinMap2D(x, z);
|
||||
|
||||
//printf("calculateNoise: %dus\n", t.stop());
|
||||
}
|
||||
|
||||
|
||||
bool MapgenFractal::getFractalAtPoint(s16 x, s16 y, s16 z)
|
||||
{
|
||||
float cx, cy, cz, cw, ox, oy, oz, ow;
|
||||
@ -474,6 +454,8 @@ s16 MapgenFractal::generateTerrain()
|
||||
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
|
||||
u32 index2d = 0;
|
||||
|
||||
noise_seabed->perlinMap2D(node_min.X, node_min.Z);
|
||||
|
||||
for (s16 z = node_min.Z; z <= node_max.Z; z++) {
|
||||
for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
|
||||
u32 vi = vm->m_area.index(node_min.X, y, z);
|
||||
|
@ -88,7 +88,6 @@ public:
|
||||
|
||||
virtual void makeChunk(BlockMakeData *data);
|
||||
int getSpawnLevelAtPoint(v2s16 p);
|
||||
void calculateNoise();
|
||||
bool getFractalAtPoint(s16 x, s16 y, s16 z);
|
||||
s16 generateTerrain();
|
||||
};
|
||||
|
@ -225,9 +225,6 @@ void MapgenV5::makeChunk(BlockMakeData *data)
|
||||
// Create a block-specific seed
|
||||
blockseed = getBlockSeed2(full_node_min, seed);
|
||||
|
||||
// Make some noise
|
||||
calculateNoise();
|
||||
|
||||
// Generate base terrain
|
||||
s16 stone_surface_max_y = generateBaseTerrain();
|
||||
|
||||
@ -312,26 +309,6 @@ void MapgenV5::makeChunk(BlockMakeData *data)
|
||||
}
|
||||
|
||||
|
||||
void MapgenV5::calculateNoise()
|
||||
{
|
||||
//TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
|
||||
s16 x = node_min.X;
|
||||
s16 y = node_min.Y - 1;
|
||||
s16 z = node_min.Z;
|
||||
|
||||
noise_factor->perlinMap2D(x, z);
|
||||
noise_height->perlinMap2D(x, z);
|
||||
noise_ground->perlinMap3D(x, y, z);
|
||||
|
||||
// Cave noises are calculated in generateCaves()
|
||||
// only if solid terrain is present in mapchunk
|
||||
|
||||
noise_filler_depth->perlinMap2D(x, z);
|
||||
|
||||
//printf("calculateNoise: %dus\n", t.stop());
|
||||
}
|
||||
|
||||
|
||||
//bool is_cave(u32 index) {
|
||||
// double d1 = contour(noise_cave1->result[index]);
|
||||
// double d2 = contour(noise_cave2->result[index]);
|
||||
@ -355,6 +332,10 @@ int MapgenV5::generateBaseTerrain()
|
||||
u32 index2d = 0;
|
||||
int stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
|
||||
|
||||
noise_factor->perlinMap2D(node_min.X, node_min.Z);
|
||||
noise_height->perlinMap2D(node_min.X, node_min.Z);
|
||||
noise_ground->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
|
||||
|
||||
for (s16 z=node_min.Z; z<=node_max.Z; z++) {
|
||||
for (s16 y=node_min.Y - 1; y<=node_max.Y + 1; y++) {
|
||||
u32 vi = vm->m_area.index(node_min.X, y, z);
|
||||
|
@ -69,7 +69,6 @@ public:
|
||||
|
||||
virtual void makeChunk(BlockMakeData *data);
|
||||
int getSpawnLevelAtPoint(v2s16 p);
|
||||
void calculateNoise();
|
||||
int generateBaseTerrain();
|
||||
};
|
||||
|
||||
|
@ -252,9 +252,6 @@ void MapgenV7::makeChunk(BlockMakeData *data)
|
||||
|
||||
blockseed = getBlockSeed2(full_node_min, seed);
|
||||
|
||||
// Make some noise
|
||||
calculateNoise();
|
||||
|
||||
// Generate terrain and ridges with initial heightmaps
|
||||
s16 stone_surface_max_y = generateTerrain();
|
||||
|
||||
@ -340,37 +337,6 @@ void MapgenV7::makeChunk(BlockMakeData *data)
|
||||
}
|
||||
|
||||
|
||||
void MapgenV7::calculateNoise()
|
||||
{
|
||||
//TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
|
||||
s16 x = node_min.X;
|
||||
s16 y = node_min.Y - 1;
|
||||
s16 z = node_min.Z;
|
||||
|
||||
noise_terrain_persist->perlinMap2D(x, z);
|
||||
float *persistmap = noise_terrain_persist->result;
|
||||
|
||||
noise_terrain_base->perlinMap2D(x, z, persistmap);
|
||||
noise_terrain_alt->perlinMap2D(x, z, persistmap);
|
||||
noise_height_select->perlinMap2D(x, z);
|
||||
|
||||
if (spflags & MGV7_MOUNTAINS) {
|
||||
noise_mountain->perlinMap3D(x, y, z);
|
||||
noise_mount_height->perlinMap2D(x, z);
|
||||
}
|
||||
|
||||
if ((spflags & MGV7_RIDGES) && node_max.Y >= water_level) {
|
||||
noise_ridge->perlinMap3D(x, y, z);
|
||||
noise_ridge_uwater->perlinMap2D(x, z);
|
||||
}
|
||||
|
||||
// Cave noises are calculated in generateCaves()
|
||||
// only if solid terrain is present in mapchunk
|
||||
|
||||
//printf("calculateNoise: %dus\n", t.stop());
|
||||
}
|
||||
|
||||
|
||||
float MapgenV7::baseTerrainLevelAtPoint(s16 x, s16 z)
|
||||
{
|
||||
float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed);
|
||||
@ -430,10 +396,23 @@ int MapgenV7::generateTerrain()
|
||||
MapNode n_stone(c_stone);
|
||||
MapNode n_water(c_water_source);
|
||||
|
||||
//// Calculate noise for terrain generation
|
||||
noise_terrain_persist->perlinMap2D(node_min.X, node_min.Z);
|
||||
float *persistmap = noise_terrain_persist->result;
|
||||
|
||||
noise_terrain_base->perlinMap2D(node_min.X, node_min.Z, persistmap);
|
||||
noise_terrain_alt->perlinMap2D(node_min.X, node_min.Z, persistmap);
|
||||
noise_height_select->perlinMap2D(node_min.X, node_min.Z);
|
||||
|
||||
if (spflags & MGV7_MOUNTAINS) {
|
||||
noise_mountain->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
|
||||
noise_mount_height->perlinMap2D(node_min.X, node_min.Z);
|
||||
}
|
||||
|
||||
//// Place nodes
|
||||
v3s16 em = vm->m_area.getExtent();
|
||||
s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
|
||||
u32 index2d = 0;
|
||||
bool mountain_flag = spflags & MGV7_MOUNTAINS;
|
||||
|
||||
for (s16 z = node_min.Z; z <= node_max.Z; z++)
|
||||
for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
|
||||
@ -450,7 +429,7 @@ int MapgenV7::generateTerrain()
|
||||
if (vm->m_data[vi].getContent() == CONTENT_IGNORE) {
|
||||
if (y <= surface_y) {
|
||||
vm->m_data[vi] = n_stone; // Base terrain
|
||||
} else if (mountain_flag &&
|
||||
} else if ((spflags & MGV7_MOUNTAINS) &&
|
||||
getMountainTerrainFromMap(index3d, index2d, y)) {
|
||||
vm->m_data[vi] = n_stone; // Mountain terrain
|
||||
if (y > stone_surface_max_y)
|
||||
@ -475,6 +454,9 @@ void MapgenV7::generateRidgeTerrain()
|
||||
if (node_max.Y < water_level - 16)
|
||||
return;
|
||||
|
||||
noise_ridge->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
|
||||
noise_ridge_uwater->perlinMap2D(node_min.X, node_min.Z);
|
||||
|
||||
MapNode n_water(c_water_source);
|
||||
MapNode n_air(CONTENT_AIR);
|
||||
u32 index = 0;
|
||||
|
@ -87,9 +87,6 @@ public:
|
||||
float baseTerrainLevelFromMap(int index);
|
||||
bool getMountainTerrainAtPoint(s16 x, s16 y, s16 z);
|
||||
bool getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y);
|
||||
|
||||
void calculateNoise();
|
||||
|
||||
int generateTerrain();
|
||||
void generateRidgeTerrain();
|
||||
};
|
||||
|
@ -388,7 +388,6 @@ void MapgenValleys::calculateNoise()
|
||||
|
||||
//TimeTaker tcn("actualNoise");
|
||||
|
||||
noise_filler_depth->perlinMap2D(x, z);
|
||||
noise_inter_valley_slope->perlinMap2D(x, z);
|
||||
noise_rivers->perlinMap2D(x, z);
|
||||
noise_terrain_height->perlinMap2D(x, z);
|
||||
|
Loading…
Reference in New Issue
Block a user