Skip to content

Commit 773aa8c

Browse files
committedMar 2, 2015
Mgv6: Add heightmap. Do not make large caves that are entirely above ground
1 parent 1a175c6 commit 773aa8c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
 

Diff for: ‎src/cavegen.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,36 @@ void CaveV6::makeTunnel(bool dirswitch) {
173173
);
174174
}
175175

176+
// Do not make large caves that are entirely above ground.
177+
// It is only necessary to check the startpoint and endpoint.
178+
if (large_cave) {
179+
v3s16 orpi(orp.X, orp.Y, orp.Z);
180+
v3s16 veci(vec.X, vec.Y, vec.Z);
181+
s16 h1;
182+
s16 h2;
183+
184+
v3s16 p1 = orpi + veci + of + rs / 2;
185+
if (p1.Z >= node_min.Z && p1.Z <= node_max.Z &&
186+
p1.X >= node_min.X && p1.X <= node_max.X) {
187+
u32 index1 = (p1.Z - node_min.Z) * mg->ystride + (p1.X - node_min.X);
188+
h1 = mg->heightmap[index1];
189+
} else {
190+
h1 = water_level; // If not in heightmap
191+
}
192+
193+
v3s16 p2 = orpi + of + rs / 2;
194+
if (p2.Z >= node_min.Z && p2.Z <= node_max.Z &&
195+
p2.X >= node_min.X && p2.X <= node_max.X) {
196+
u32 index2 = (p2.Z - node_min.Z) * mg->ystride + (p2.X - node_min.X);
197+
h2 = mg->heightmap[index2];
198+
} else {
199+
h2 = water_level;
200+
}
201+
202+
if (p1.Y > h1 && p2.Y > h2) // If startpoint and endpoint are above ground
203+
return;
204+
}
205+
176206
vec += main_direction;
177207

178208
v3f rp = orp + vec;

Diff for: ‎src/mapgen_v6.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ MapgenV6::MapgenV6(int mapgenid, MapgenParams *params, EmergeManager *emerge)
5555
this->m_emerge = emerge;
5656
this->ystride = csize.X; //////fix this
5757

58+
this->heightmap = new s16[csize.X * csize.Z];
59+
5860
MapgenV6Params *sp = (MapgenV6Params *)params->sparams;
5961
this->spflags = sp->spflags;
6062
this->freq_desert = sp->freq_desert;
@@ -498,6 +500,9 @@ void MapgenV6::makeChunk(BlockMakeData *data)
498500

499501
}
500502

503+
// Create heightmap after mudflow
504+
updateHeightmap(node_min, node_max);
505+
501506
// Add dungeons
502507
if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
503508
DungeonParams dp;

0 commit comments

Comments
 (0)
Please sign in to comment.