this->heightmap = new s16[csize.X * csize.Z];
this->ridge_heightmap = new s16[csize.X * csize.Z];
+ initHeightMap(this->heightmap, csize.X * csize.Z);
+
MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
this->spflags = sp->spflags;
//// 3d terrain noise
noise_mountain = new Noise(&sp->np_mountain, seed, csize.X, csize.Y, csize.Z);
noise_ridge = new Noise(&sp->np_ridge, seed, csize.X, csize.Y, csize.Z);
+ noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y, csize.Z);
+ noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y, csize.Z);
//// Biome noise
noise_heat = new Noise(¶ms->np_biome_heat, seed, csize.X, csize.Z);
}
-MapgenV7::~MapgenV7() {
+MapgenV7::~MapgenV7()
+{
delete noise_terrain_base;
delete noise_terrain_persist;
delete noise_height_select;
delete noise_ridge_uwater;
delete noise_mountain;
delete noise_ridge;
+ delete noise_cave1;
+ delete noise_cave2;
delete noise_heat;
delete noise_humidity;
}
-MapgenV7Params::MapgenV7Params() {
+MapgenV7Params::MapgenV7Params()
+{
spflags = MGV7_MOUNTAINS | MGV7_RIDGES;
np_terrain_base = NoiseParams(4, 70, v3f(300, 300, 300), 82341, 6, 0.7, 2.0);
np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 4, 0.7, 2.0);
np_mount_height = NoiseParams(100, 30, v3f(500, 500, 500), 72449, 4, 0.6, 2.0);
np_ridge_uwater = NoiseParams(0, 1, v3f(500, 500, 500), 85039, 4, 0.6, 2.0);
- np_mountain = NoiseParams(0, 1, v3f(250, 350, 250), 5333, 5, 0.68, 2.0);
+ np_mountain = NoiseParams(-0.6, 1, v3f(250, 350, 250), 5333, 5, 0.68, 2.0);
np_ridge = NoiseParams(0, 1, v3f(100, 100, 100), 6467, 4, 0.75, 2.0);
+ np_cave1 = NoiseParams(0, 12, v3f(100, 100, 100), 52534, 4, 0.5, 2.0);
+ np_cave2 = NoiseParams(0, 12, v3f(100, 100, 100), 10325, 4, 0.5, 2.0);
}
-void MapgenV7Params::readParams(Settings *settings) {
+void MapgenV7Params::readParams(Settings *settings)
+{
settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base);
settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
settings->getNoiseParams("mgv7_np_mountain", np_mountain);
settings->getNoiseParams("mgv7_np_ridge", np_ridge);
+ settings->getNoiseParams("mgv7_np_cave1", np_cave1);
+ settings->getNoiseParams("mgv7_np_cave2", np_cave2);
}
-void MapgenV7Params::writeParams(Settings *settings) {
+void MapgenV7Params::writeParams(Settings *settings)
+{
settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, (u32)-1);
settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base);
settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
settings->setNoiseParams("mgv7_np_mountain", np_mountain);
settings->setNoiseParams("mgv7_np_ridge", np_ridge);
+ settings->setNoiseParams("mgv7_np_cave1", np_cave1);
+ settings->setNoiseParams("mgv7_np_cave2", np_cave2);
}
///////////////////////////////////////
-int MapgenV7::getGroundLevelAtPoint(v2s16 p) {
+int MapgenV7::getGroundLevelAtPoint(v2s16 p)
+{
// Base terrain calculation
s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
// Ridge/river terrain calculation
- float width = 0.3;
+ float width = 0.2;
float uwatern = NoisePerlin2D(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
// actually computing the depth of the ridge is much more expensive;
// if inside a river, simply guess
- if (uwatern >= -width && uwatern <= width)
+ if (fabs(uwatern) <= width)
return water_level - 10;
// Mountain terrain calculation
}
-void MapgenV7::makeChunk(BlockMakeData *data) {
+void MapgenV7::makeChunk(BlockMakeData *data)
+{
+ // Pre-conditions
assert(data->vmanip);
assert(data->nodedef);
assert(data->blockpos_requested.X >= data->blockpos_min.X &&
full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
- blockseed = m_emerge->getBlockSeed(full_node_min); //////use getBlockSeed2()!
+ 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();
+ // Create heightmap
updateHeightmap(node_min, node_max);
- // Calculate biomes
+ // Create biomemap at heightmap surface
bmgr->calcBiomes(csize.X, csize.Z, noise_heat->result,
noise_humidity->result, heightmap, biomemap);
- // Actually place the biome-specific nodes and what not
- generateBiomes();
+ // Actually place the biome-specific nodes
+ generateBiomes(noise_heat->result, noise_humidity->result);
if (flags & MG_CAVES)
generateCaves(stone_surface_max_y);
- if (flags & MG_DUNGEONS) {
+ if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
DungeonGen dgen(this, NULL);
dgen.generate(blockseed, full_node_min, full_node_max);
}
updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
if (flags & MG_LIGHT)
- calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
- node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
+ calcLighting(node_min, node_max);
//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
// node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
}
-void MapgenV7::calculateNoise() {
+void MapgenV7::calculateNoise()
+{
//TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
int x = node_min.X;
int y = node_min.Y;
int z = node_min.Z;
- noise_height_select->perlinMap2D(x, z);
noise_terrain_persist->perlinMap2D(x, z);
float *persistmap = noise_terrain_persist->result;
- for (int i = 0; i != csize.X * csize.Z; i++)
- persistmap[i] = rangelim(persistmap[i], 0.4, 0.9);
noise_terrain_base->perlinMap2D(x, z, persistmap);
noise_terrain_alt->perlinMap2D(x, z, persistmap);
- noise_filler_depth->perlinMap2D(x, z);
+ noise_height_select->perlinMap2D(x, z);
- if (spflags & MGV7_MOUNTAINS) {
- noise_mountain->perlinMap3D(x, y, z);
- noise_mount_height->perlinMap2D(x, z);
+ if (flags & MG_CAVES) {
+ noise_cave1->perlinMap3D(x, y, z);
+ noise_cave2->perlinMap3D(x, y, z);
}
- if (spflags & MGV7_RIDGES) {
+ if ((spflags & MGV7_RIDGES) && node_max.Y >= water_level) {
noise_ridge->perlinMap3D(x, y, z);
noise_ridge_uwater->perlinMap2D(x, z);
}
- noise_heat->perlinMap2D(x, z);
- noise_humidity->perlinMap2D(x, z);
+ if ((spflags & MGV7_MOUNTAINS) && node_max.Y >= 0) {
+ noise_mountain->perlinMap3D(x, y, z);
+ noise_mount_height->perlinMap2D(x, z);
+ }
+ if (node_max.Y >= water_level) {
+ noise_filler_depth->perlinMap2D(x, z);
+ noise_heat->perlinMap2D(x, z);
+ noise_humidity->perlinMap2D(x, z);
+ }
//printf("calculateNoise: %dus\n", t.stop());
}
-Biome *MapgenV7::getBiomeAtPoint(v3s16 p) {
+Biome *MapgenV7::getBiomeAtPoint(v3s16 p)
+{
float heat = NoisePerlin2D(&noise_heat->np, p.X, p.Z, seed);
float humidity = NoisePerlin2D(&noise_humidity->np, p.X, p.Z, seed);
s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Z);
}
//needs to be updated
-float MapgenV7::baseTerrainLevelAtPoint(int x, int z) {
+float MapgenV7::baseTerrainLevelAtPoint(int x, int z)
+{
float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed);
hselect = rangelim(hselect, 0.0, 1.0);
float persist = NoisePerlin2D(&noise_terrain_persist->np, x, z, seed);
- persist = rangelim(persist, 0.4, 0.9);
noise_terrain_base->np.persist = persist;
float height_base = NoisePerlin2D(&noise_terrain_base->np, x, z, seed);
}
-float MapgenV7::baseTerrainLevelFromMap(int index) {
+float MapgenV7::baseTerrainLevelFromMap(int index)
+{
float hselect = rangelim(noise_height_select->result[index], 0.0, 1.0);
float height_base = noise_terrain_base->result[index];
float height_alt = noise_terrain_alt->result[index];
}
-bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z) {
+bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z)
+{
float mnt_h_n = NoisePerlin2D(&noise_mount_height->np, x, z, seed);
- float height_modifier = -((float)y / rangelim(mnt_h_n, 80.0, 150.0));
float mnt_n = NoisePerlin3D(&noise_mountain->np, x, y, z, seed);
-
- return mnt_n + height_modifier >= 0.6;
+ return mnt_n * mnt_h_n >= (float)y;
}
-bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, int y) {
+bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, int y)
+{
float mounthn = noise_mount_height->result[idx_xz];
- float height_modifier = -((float)y / rangelim(mounthn, 80.0, 150.0));
- return (noise_mountain->result[idx_xyz] + height_modifier >= 0.6);
+ float mountn = noise_mountain->result[idx_xyz];
+ return mountn * mounthn >= (float)y;
}
#endif
-int MapgenV7::generateTerrain() {
+int MapgenV7::generateTerrain()
+{
int ymax = generateBaseTerrain();
if (spflags & MGV7_MOUNTAINS)
- generateMountainTerrain();
+ ymax = generateMountainTerrain(ymax);
if (spflags & MGV7_RIDGES)
generateRidgeTerrain();
}
-int MapgenV7::generateBaseTerrain() {
+int MapgenV7::generateBaseTerrain()
+{
MapNode n_air(CONTENT_AIR);
MapNode n_stone(c_stone);
MapNode n_water(c_water_source);
}
-void MapgenV7::generateMountainTerrain() {
- if (node_max.Y <= water_level)
- return;
+int MapgenV7::generateMountainTerrain(int ymax)
+{
+ if (node_max.Y < 0)
+ return ymax;
MapNode n_stone(c_stone);
u32 j = 0;
u32 vi = vm->m_area.index(node_min.X, y, z);
for (s16 x = node_min.X; x <= node_max.X; x++) {
int index = (z - node_min.Z) * csize.X + (x - node_min.X);
+ content_t c = vm->m_data[vi].getContent();
- if (getMountainTerrainFromMap(j, index, y))
+ if (getMountainTerrainFromMap(j, index, y)
+ && (c == CONTENT_AIR || c == c_water_source)) {
vm->m_data[vi] = n_stone;
+ if (y > ymax)
+ ymax = y;
+ }
vi++;
j++;
}
}
+
+ return ymax;
}
-void MapgenV7::generateRidgeTerrain() {
+void MapgenV7::generateRidgeTerrain()
+{
+ if (node_max.Y < water_level)
+ return;
+
MapNode n_water(c_water_source);
MapNode n_air(CONTENT_AIR);
u32 index = 0;
+ float width = 0.2; // TODO: figure out acceptable perlin noise values
for (s16 z = node_min.Z; z <= node_max.Z; z++)
for (s16 y = node_min.Y; y <= node_max.Y; y++) {
for (s16 x = node_min.X; x <= node_max.X; x++, index++, vi++) {
int j = (z - node_min.Z) * csize.X + (x - node_min.X);
- if (heightmap[j] < water_level - 4)
+ if (heightmap[j] < water_level - 16)
continue;
- float widthn = (noise_terrain_persist->result[j] - 0.6) / 0.1;
- //widthn = rangelim(widthn, -0.05, 0.5);
-
- float width = 0.3; // TODO: figure out acceptable perlin noise values
float uwatern = noise_ridge_uwater->result[j] * 2;
- if (uwatern < -width || uwatern > width)
+ if (fabs(uwatern) > width)
continue;
- float height_mod = (float)(y + 17) / 2.5;
- float width_mod = (width - fabs(uwatern));
- float nridge = noise_ridge->result[index] * (float)y / 7.0;
-
- if (y < water_level)
- nridge = -fabs(nridge) * 3.0 * widthn * 0.3;
+ float altitude = y - water_level;
+ float height_mod = (altitude + 17) / 2.5;
+ float width_mod = width - fabs(uwatern);
+ float nridge = noise_ridge->result[index] * MYMAX(altitude, 0) / 7.0;
if (nridge + width_mod * height_mod < 0.6)
continue;
}
-void MapgenV7::generateBiomes() {
+void MapgenV7::generateBiomes(float *heat_map, float *humidity_map)
+{
if (node_max.Y < water_level)
return;
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 = (Biome *)bmgr->get(biomemap[index]);
- s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
- s16 y0_top = biome->depth_top;
- s16 y0_filler = biome->depth_top + dfiller;
- s16 shore_max = water_level + biome->height_shore;
- s16 depth_water_top = biome->depth_water_top;
+ Biome *biome = NULL;
+ s16 dfiller = 0;
+ s16 y0_top = 0;
+ s16 y0_filler = 0;
+ s16 depth_water_top = 0;
s16 nplaced = 0;
u32 i = vm->m_area.index(x, node_max.Y, z);
have_air = !getMountainTerrainFromMap(j, index, y);
}
+ if (c != CONTENT_IGNORE && c != CONTENT_AIR && (y == node_max.Y || have_air)) {
+ biome = bmgr->getBiome(heat_map[index], humidity_map[index], y);
+ dfiller = biome->depth_filler + noise_filler_depth->result[index];
+ y0_top = biome->depth_top;
+ y0_filler = biome->depth_top + dfiller;
+ depth_water_top = biome->depth_water_top;
+ }
+
if (c == c_stone && have_air) {
content_t c_below = vm->m_data[i - em.X].getContent();
if (c_below != CONTENT_AIR) {
if (nplaced < y0_top) {
- if(y < water_level)
- vm->m_data[i] = MapNode(biome->c_underwater);
- else if(y <= shore_max)
- vm->m_data[i] = MapNode(biome->c_shore_top);
- else
- vm->m_data[i] = MapNode(biome->c_top);
+ vm->m_data[i] = MapNode(biome->c_top);
nplaced++;
} else if (nplaced < y0_filler && nplaced >= y0_top) {
- if(y < water_level)
- vm->m_data[i] = MapNode(biome->c_underwater);
- else if(y <= shore_max)
- vm->m_data[i] = MapNode(biome->c_shore_filler);
- else
- vm->m_data[i] = MapNode(biome->c_filler);
+ vm->m_data[i] = MapNode(biome->c_filler);
nplaced++;
} else if (c == c_stone) {
have_air = false;
}
-void MapgenV7::dustTopNodes() {
+void MapgenV7::dustTopNodes()
+{
+ if (node_max.Y < water_level)
+ return;
+
v3s16 em = vm->m_area.getExtent();
u32 index = 0;
- if (water_level > node_max.Y)
- return;
-
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 = (Biome *)bmgr->get(biomemap[index]);
#if 0
-void MapgenV7::addTopNodes() {
+void MapgenV7::addTopNodes()
+{
v3s16 em = vm->m_area.getExtent();
s16 ntopnodes;
u32 index = 0;
#endif
-NoiseParams nparams_v7_def_cave(6, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50, 2.0);
-
-void MapgenV7::generateCaves(int max_stone_y) {
- PseudoRandom ps(blockseed + 21343);
-
- int volume_nodes = (node_max.X - node_min.X + 1) *
- (node_max.Y - node_min.Y + 1) *
- (node_max.Z - node_min.Z + 1);
- float cave_amount = NoisePerlin2D(&nparams_v7_def_cave,
- node_min.X, node_min.Y, seed);
-
- u32 caves_count = MYMAX(0.0, cave_amount) * volume_nodes / 250000;
- for (u32 i = 0; i < caves_count; i++) {
- CaveV7 cave(this, &ps, false);
- cave.makeCave(node_min, node_max, max_stone_y);
+void MapgenV7::generateCaves(int max_stone_y)
+{
+ if (max_stone_y >= node_min.Y) {
+ u32 index = 0;
+ u32 index2d = 0;
+
+ for (s16 z = node_min.Z; z <= node_max.Z; z++) {
+ for (s16 y = node_min.Y; y <= node_max.Y; 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++) {
+ Biome *biome = (Biome *)bmgr->get(biomemap[index2d]);
+ content_t c = vm->m_data[i].getContent();
+ if (c == CONTENT_AIR || (y <= water_level &&
+ c != biome->c_stone && c != c_stone))
+ continue;
+
+ float d1 = contour(noise_cave1->result[index]);
+ float d2 = contour(noise_cave2->result[index]);
+ if (d1 * d2 > 0.3)
+ vm->m_data[i] = MapNode(CONTENT_AIR);
+ }
+ index2d -= ystride;
+ }
+ index2d += ystride;
+ }
}
- u32 bruises_count = (ps.range(1, 8) == 1) ? ps.range(0, ps.range(0, 2)) : 1;
+ PseudoRandom ps(blockseed + 21343);
+ u32 bruises_count = (ps.range(1, 5) == 1) ? ps.range(1, 2) : 0;
for (u32 i = 0; i < bruises_count; i++) {
- CaveV7 cave(this, &ps, true);
+ CaveV7 cave(this, &ps);
cave.makeCave(node_min, node_max, max_stone_y);
}
}
+