Skip to content

Commit 37e6d13

Browse files
committedApr 21, 2013
mgv7: Implement getGroundLevelAtPoint(), fix layer of topnodes at chunk Y boundaries, remove growGrass()
1 parent daddd37 commit 37e6d13

File tree

2 files changed

+45
-47
lines changed

2 files changed

+45
-47
lines changed
 

‎src/mapgen_v7.cpp

+45-46
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,23 @@ MapgenV7::~MapgenV7() {
115115

116116

117117
int MapgenV7::getGroundLevelAtPoint(v2s16 p) {
118-
return 20;
118+
s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Y);
119+
float heat = NoisePerlin2D(bmgr->np_heat, p.X, p.Y, seed);
120+
float humidity = NoisePerlin2D(bmgr->np_humidity, p.X, p.Y, seed);
121+
Biome *b = bmgr->getBiome(heat, humidity, groundlevel);
122+
123+
s16 y = groundlevel;
124+
if (y > water_level) {
125+
int iters = 1024; // don't even bother iterating more than 1024 times..
126+
while (iters--) {
127+
float ridgenoise = NoisePerlin3D(noise_ridge->np, p.X, y, p.Y, seed);
128+
if (ridgenoise * (float)(y * y) < 15.0)
129+
break;
130+
y--;
131+
}
132+
}
133+
134+
return y + b->top_depth;
119135
}
120136

121137

@@ -169,12 +185,8 @@ void MapgenV7::makeChunk(BlockMakeData *data) {
169185
generateTerrain();
170186
carveRidges();
171187

172-
//carveRivers();
173-
174-
175188
generateCaves(stone_surface_max_y);
176189
addTopNodes();
177-
growGrass();
178190
//v3s16 central_area_size = node_max - node_min + v3s16(1,1,1);
179191

180192
if (flags & MG_DUNGEONS) {
@@ -193,7 +205,8 @@ void MapgenV7::makeChunk(BlockMakeData *data) {
193205

194206
calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
195207
node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
196-
//setLighting(node_min, node_max, 0xFF);
208+
//setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
209+
// node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
197210

198211
this->generating = false;
199212
}
@@ -256,7 +269,7 @@ float MapgenV7::baseTerrainLevelAtPoint(int x, int z) {
256269
}
257270

258271

259-
float MapgenV7::baseTerrainLevelFromMap(int index) {
272+
float MapgenV7::baseTerrainLevelFromMap(int index) {
260273
float terrain_mod = noise_terrain_mod->result[index];
261274
float hselect = noise_height_select->result[index];
262275
float terrain_base = noise_terrain_base->result[index];
@@ -399,12 +412,12 @@ void MapgenV7::addTopNodes() {
399412
v3s16 em = vm->m_area.getExtent();
400413
s16 ntopnodes;
401414
u32 index = 0;
402-
415+
403416
for (s16 z = node_min.Z; z <= node_max.Z; z++)
404417
for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
405418
Biome *biome = bmgr->biomes[biomemap[index]];
406419

407-
// First, add top nodes below the ridge
420+
//////////////////// First, add top nodes below the ridge
408421
s16 y = ridge_heightmap[index];
409422

410423
// This cutoff is good enough, but not perfect.
@@ -415,7 +428,7 @@ void MapgenV7::addTopNodes() {
415428
y = node_max.Y; // Let's see if we can still go downward anyway
416429
u32 vi = vm->m_area.index(x, y, z);
417430
content_t c = vm->m_data[vi].getContent();
418-
if (c == biome->c_filler || c == c_stone)//c != CONTENT_AIR)
431+
if (ndef->get(c).walkable)
419432
continue;
420433
}
421434

@@ -425,33 +438,41 @@ void MapgenV7::addTopNodes() {
425438
u32 i = vm->m_area.index(x, y, z);
426439
for (; y >= node_min.Y; y--) {
427440
content_t c = vm->m_data[i].getContent();
428-
if (c == biome->c_filler || c == c_stone)//c != CONTENT_AIR)
429-
//if (vm->m_data[i].getContent() != CONTENT_AIR)
441+
if (ndef->get(c).walkable)
430442
break;
431443
vm->m_area.add_y(em, i, -1);
432444
}
433445

434-
435-
436-
if (y != node_min.Y - 1) {
446+
if (y != node_min.Y - 1 && y >= water_level) {
437447
ridge_heightmap[index] = y; //update ridgeheight
438448
ntopnodes = biome->top_depth;
439449
for (; y <= node_max.Y && ntopnodes; y++) {
440450
ntopnodes--;
441451
vm->m_data[i] = MapNode(biome->c_top);
442452
vm->m_area.add_y(em, i, 1);
443453
}
444-
//heightmap[index] = y;
454+
// If dirt, grow grass on it.
455+
if (vm->m_data[i].getContent() == CONTENT_AIR) {
456+
vm->m_area.add_y(em, i, -1);
457+
if (vm->m_data[i].getContent() == c_dirt)
458+
vm->m_data[i] = MapNode(c_dirt_with_grass);
459+
}
445460
}
446461

447-
// Now, add top nodes on top of the ridge
462+
//////////////////// Now, add top nodes on top of the ridge
448463
y = heightmap[index];
464+
if (y > node_max.Y) {
465+
y = node_max.Y; // Let's see if we can still go downward anyway
466+
u32 vi = vm->m_area.index(x, y, z);
467+
content_t c = vm->m_data[vi].getContent();
468+
if (ndef->get(c).walkable)
469+
continue;
470+
}
449471

450472
i = vm->m_area.index(x, y, z);
451473
for (; y >= node_min.Y; y--) {
452474
content_t c = vm->m_data[i].getContent();
453-
if (c == biome->c_filler || c == c_stone)//c != CONTENT_AIR)
454-
//if (vm->m_data[i].getContent() != CONTENT_AIR)
475+
if (ndef->get(c).walkable)
455476
break;
456477
vm->m_area.add_y(em, i, -1);
457478
}
@@ -467,39 +488,17 @@ void MapgenV7::addTopNodes() {
467488
vm->m_data[i] = MapNode(biome->c_top);
468489
vm->m_area.add_y(em, i, 1);
469490
}
470-
}
471-
}
472-
}
473-
474-
475-
void MapgenV7::growGrass() {
476-
for (s16 z = node_min.Z; z <= node_max.Z; z++)
477-
for (s16 x = node_min.X; x <= node_max.X; x++) {
478-
// Find the lowest surface to which enough light ends up to make
479-
// grass grow. Basically just wait until not air and not leaves.
480-
s16 surface_y = 0;
481-
{
482-
v3s16 em = vm->m_area.getExtent();
483-
u32 i = vm->m_area.index(x, node_max.Y, z);
484-
s16 y;
485-
// Go to ground level
486-
for (y = node_max.Y; y >= node_min.Y; y--) {
487-
MapNode &n = vm->m_data[i];
488-
if (ndef->get(n).param_type != CPT_LIGHT ||
489-
ndef->get(n).liquid_type != LIQUID_NONE)
490-
break;
491+
// If dirt, grow grass on it.
492+
if (vm->m_data[i].getContent() == CONTENT_AIR) {
491493
vm->m_area.add_y(em, i, -1);
494+
if (vm->m_data[i].getContent() == c_dirt)
495+
vm->m_data[i] = MapNode(c_dirt_with_grass);
492496
}
493-
surface_y = (y >= node_min.Y) ? y : node_min.Y;
494497
}
495-
496-
u32 i = vm->m_area.index(x, surface_y, z);
497-
MapNode *n = &vm->m_data[i];
498-
if (n->getContent() == c_dirt && surface_y >= water_level - 20)
499-
n->setContent(c_dirt_with_grass);
500498
}
501499
}
502500

501+
503502
#include "mapgen_v6.h"
504503
void MapgenV7::generateCaves(int max_stone_y) {
505504
PseudoRandom ps(blockseed + 21343);

‎src/mapgen_v7.h

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ class MapgenV7 : public Mapgen {
109109

110110
void testBiomes();
111111
void addTopNodes();
112-
void growGrass();
113112

114113
void generateCaves(int max_stone_y);
115114
};

0 commit comments

Comments
 (0)
Please sign in to comment.