Skip to content

Commit 9aabfd5

Browse files
committedFeb 16, 2017
Cavegen: Place correct biome surface in tunnel entrances
Previously in tunnel entrance floors only a single biome 'top' node was placed and 'filler' nodes were missing. Place 'top' and 'filler' nodes in tunnel entrance floors with depths defined by the biome. In tunnel entrances under rivers 'riverbed' nodes are placed to the biome-defined depth.
1 parent 3955f51 commit 9aabfd5

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed
 

‎src/cavegen.cpp

+33-15
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,23 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
7474
noise_cave2->perlinMap3D(nmin.X, nmin.Y - 1, nmin.Z);
7575

7676
v3s16 em = vm->m_area.getExtent();
77-
u32 index2d = 0;
77+
u32 index2d = 0; // Biomemap index
7878

7979
for (s16 z = nmin.Z; z <= nmax.Z; z++)
8080
for (s16 x = nmin.X; x <= nmax.X; x++, index2d++) {
8181
bool column_is_open = false; // Is column open to overground
8282
bool is_under_river = false; // Is column under river water
83-
bool is_tunnel = false; // Is tunnel or tunnel floor
83+
bool is_under_tunnel = false; // Is tunnel or is under tunnel
84+
// Indexes at column top
8485
u32 vi = vm->m_area.index(x, nmax.Y, z);
8586
u32 index3d = (z - nmin.Z) * m_zstride_1d + m_csize.Y * m_ystride +
86-
(x - nmin.X);
87+
(x - nmin.X); // 3D noise index
8788
// Biome of column
8889
Biome *biome = (Biome *)m_bmgr->getRaw(biomemap[index2d]);
89-
90+
u16 depth_top = biome->depth_top;
91+
u16 base_filler = depth_top + biome->depth_filler;
92+
u16 depth_riverbed = biome->depth_riverbed;
93+
u16 nplaced = 0;
9094
// Don't excavate the overgenerated stone at nmax.Y + 1,
9195
// this creates a 'roof' over the tunnel, preventing light in
9296
// tunnels at mapchunk borders when generating mapchunks upwards.
@@ -112,20 +116,34 @@ void CavesNoiseIntersection::generateCaves(MMVManip *vm,
112116
if (d1 * d2 > m_cave_width && m_ndef->get(c).is_ground_content) {
113117
// In tunnel and ground content, excavate
114118
vm->m_data[vi] = MapNode(CONTENT_AIR);
115-
is_tunnel = true;
116-
} else {
117-
// Not in tunnel or not ground content
118-
if (is_tunnel && column_is_open &&
119-
(c == biome->c_filler || c == biome->c_stone)) {
120-
// Tunnel entrance floor
121-
if (is_under_river)
119+
is_under_tunnel = true;
120+
} else if (column_is_open && is_under_tunnel &&
121+
(c == biome->c_stone || c == biome->c_filler)) {
122+
// Tunnel entrance floor, place biome surface nodes
123+
if (is_under_river) {
124+
if (nplaced < depth_riverbed) {
122125
vm->m_data[vi] = MapNode(biome->c_riverbed);
123-
else
124-
vm->m_data[vi] = MapNode(biome->c_top);
126+
nplaced++;
127+
} else {
128+
// Disable top/filler placement
129+
column_is_open = false;
130+
is_under_river = false;
131+
is_under_tunnel = false;
132+
}
133+
} else if (nplaced < depth_top) {
134+
vm->m_data[vi] = MapNode(biome->c_top);
135+
nplaced++;
136+
} else if (nplaced < base_filler) {
137+
vm->m_data[vi] = MapNode(biome->c_filler);
138+
nplaced++;
139+
} else {
140+
// Disable top/filler placement
141+
column_is_open = false;
142+
is_under_tunnel = false;
125143
}
126-
144+
} else {
145+
// Not tunnel or tunnel entrance floor
127146
column_is_open = false;
128-
is_tunnel = false;
129147
}
130148
}
131149
}

0 commit comments

Comments
 (0)
Please sign in to comment.