Skip to content

Commit c367f73

Browse files
paramatkwolekr
authored andcommittedJan 12, 2015
Mapgen V5: Move cave generation from base terrain loop to optional function
This fixes biome surface in tunnels
1 parent a77c85f commit c367f73

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed
 

‎src/mapgen_v5.cpp

+31-6
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ void MapgenV5::makeChunk(BlockMakeData *data)
268268
// Actually place the biome-specific nodes
269269
generateBiomes();
270270

271+
// Generate caves
272+
if ((flags & MG_CAVES) && (stone_surface_max_y >= node_min.Y))
273+
generateCaves();
274+
271275
// Generate dungeons and desert temples
272276
if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
273277
DungeonGen dgen(this, NULL);
@@ -309,8 +313,11 @@ void MapgenV5::calculateNoise()
309313
noise_factor->perlinMap2D(x, z);
310314
noise_height->perlinMap2D(x, z);
311315

312-
noise_cave1->perlinMap3D(x, y, z);
313-
noise_cave2->perlinMap3D(x, y, z);
316+
if (flags & MG_CAVES) {
317+
noise_cave1->perlinMap3D(x, y, z);
318+
noise_cave2->perlinMap3D(x, y, z);
319+
}
320+
314321
noise_ground->perlinMap3D(x, y, z);
315322

316323
if (spflags & MGV5_BLOBS) {
@@ -363,16 +370,12 @@ int MapgenV5::generateBaseTerrain()
363370
else if(f >= 1.0)
364371
f *= 1.6;
365372
float h = water_level + noise_height->result[index2d];
366-
float d1 = contour(noise_cave1->result[index]);
367-
float d2 = contour(noise_cave2->result[index]);
368373

369374
if(noise_ground->result[index] * f < y - h) {
370375
if(y <= water_level)
371376
vm->m_data[i] = MapNode(c_water_source);
372377
else
373378
vm->m_data[i] = MapNode(CONTENT_AIR);
374-
} else if(d1*d2 > 0.2) {
375-
vm->m_data[i] = MapNode(CONTENT_AIR);
376379
} else {
377380
vm->m_data[i] = MapNode(c_stone);
378381
if (y > stone_surface_max_y)
@@ -508,6 +511,28 @@ void MapgenV5::generateBiomes()
508511
}
509512

510513

514+
void MapgenV5::generateCaves()
515+
{
516+
u32 index = 0;
517+
518+
for(s16 z=node_min.Z; z<=node_max.Z; z++) {
519+
for(s16 y=node_min.Y - 1; y<=node_max.Y + 1; y++) {
520+
u32 i = vm->m_area.index(node_min.X, y, z);
521+
for(s16 x=node_min.X; x<=node_max.X; x++, i++, index++) {
522+
content_t c = vm->m_data[i].getContent();
523+
if(c == CONTENT_AIR || c == c_water_source)
524+
continue;
525+
526+
float d1 = contour(noise_cave1->result[index]);
527+
float d2 = contour(noise_cave2->result[index]);
528+
if(d1*d2 > 0.2)
529+
vm->m_data[i] = MapNode(CONTENT_AIR);
530+
}
531+
}
532+
}
533+
}
534+
535+
511536
void MapgenV5::dustTopNodes()
512537
{
513538
v3s16 em = vm->m_area.getExtent();

‎src/mapgen_v5.h

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class MapgenV5 : public Mapgen {
9797
int generateBaseTerrain();
9898
void generateBlobs();
9999
void generateBiomes();
100+
void generateCaves();
100101
void dustTopNodes();
101102
};
102103

0 commit comments

Comments
 (0)
Please sign in to comment.