#include "mg_ore.h"
#include "mg_decoration.h"
#include "mapgen_v5.h"
-#include "util/directiontables.h"
FlagDesc flagdesc_mapgen_v5[] = {
}
-int MapgenV5::getGroundLevelAtPoint(v2s16 p)
+int MapgenV5::getSpawnLevelAtPoint(v2s16 p)
{
//TimeTaker t("getGroundLevelAtPoint", NULL, PRECISION_MICRO);
f *= 1.6;
float h = NoisePerlin2D(&noise_height->np, p.X, p.Y, seed);
- s16 search_start = 128; // Only bother searching this range, actual
- s16 search_end = -128; // ground level is rarely higher or lower.
-
- for (s16 y = search_start; y >= search_end; y--) {
+ for (s16 y = 128; y >= -128; y--) {
float n_ground = NoisePerlin3D(&noise_ground->np, p.X, y, p.Y, seed);
- // If solid
- if (n_ground * f > y - h) {
+
+ if (n_ground * f > y - h) { // If solid
// If either top 2 nodes of search are solid this is inside a
- // mountain or floatland with no space for the player to spawn.
- if (y >= search_start - 1)
- return MAX_MAP_GENERATION_LIMIT;
- else
- return y; // Ground below at least 2 nodes of space
+ // mountain or floatland with possibly no space for the player to spawn.
+ if (y >= 127) {
+ return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
+ } else { // Ground below at least 2 nodes of empty space
+ if (y <= water_level || y > water_level + 16)
+ return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
+ else
+ return y;
+ }
}
}
//printf("getGroundLevelAtPoint: %dus\n", t.stop());
- return -MAX_MAP_GENERATION_LIMIT;
+ return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn position, no ground found
}
data->blockpos_requested.Y <= data->blockpos_max.Y &&
data->blockpos_requested.Z <= data->blockpos_max.Z);
- generating = true;
- vm = data->vmanip;
- ndef = data->nodedef;
+ this->generating = true;
+ this->vm = data->vmanip;
+ this->ndef = data->nodedef;
//TimeTaker t("makeChunk");
v3s16 blockpos_min = data->blockpos_min;
void MapgenV5::calculateNoise()
{
//TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
- int x = node_min.X;
- int y = node_min.Y - 1;
- int z = node_min.Z;
+ 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);
- if (flags & MG_CAVES) {
- noise_cave1->perlinMap3D(x, y, z);
- noise_cave2->perlinMap3D(x, y, z);
- }
+ // Cave noises are calculated in generateCaves()
+ // only if solid terrain is present in mapchunk
noise_filler_depth->perlinMap2D(x, z);
noise_heat->perlinMap2D(x, 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 i = vm->m_area.index(node_min.X, y, z);
- for (s16 x=node_min.X; x<=node_max.X; x++, i++, index++, index2d++) {
- if (vm->m_data[i].getContent() != CONTENT_IGNORE)
+ u32 vi = vm->m_area.index(node_min.X, y, z);
+ for (s16 x=node_min.X; x<=node_max.X; x++, vi++, index++, index2d++) {
+ if (vm->m_data[vi].getContent() != CONTENT_IGNORE)
continue;
float f = 0.55 + noise_factor->result[index2d];
if (noise_ground->result[index] * f < y - h) {
if (y <= water_level)
- vm->m_data[i] = MapNode(c_water_source);
+ vm->m_data[vi] = MapNode(c_water_source);
else
- vm->m_data[i] = MapNode(CONTENT_AIR);
+ vm->m_data[vi] = MapNode(CONTENT_AIR);
} else {
- vm->m_data[i] = MapNode(c_stone);
+ vm->m_data[vi] = MapNode(c_stone);
if (y > stone_surface_max_y)
stone_surface_max_y = y;
}
void MapgenV5::generateCaves(int max_stone_y)
{
- if (max_stone_y >= node_min.Y) {
- u32 index = 0;
-
- 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 i = vm->m_area.index(node_min.X, y, z);
- for (s16 x = node_min.X; x <= node_max.X; x++, i++, index++) {
- float d1 = contour(noise_cave1->result[index]);
- float d2 = contour(noise_cave2->result[index]);
- if (d1 * d2 > 0.125f) {
- content_t c = vm->m_data[i].getContent();
- if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
- continue;
-
- vm->m_data[i] = MapNode(CONTENT_AIR);
- }
+ if (max_stone_y < node_min.Y)
+ return;
+
+ noise_cave1->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
+ noise_cave2->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
+
+ u32 index = 0;
+
+ 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);
+ for (s16 x = node_min.X; x <= node_max.X; x++, vi++, index++) {
+ float d1 = contour(noise_cave1->result[index]);
+ float d2 = contour(noise_cave2->result[index]);
+ if (d1 * d2 > 0.125f) {
+ content_t c = vm->m_data[vi].getContent();
+ if (!ndef->get(c).is_ground_content || c == CONTENT_AIR)
+ continue;
+
+ vm->m_data[vi] = MapNode(CONTENT_AIR);
}
}
}