Cavegen: Remove CavesV6 dependency on Mapgen

This commit is contained in:
kwolekr 2016-05-10 13:21:13 -04:00
parent bf25837617
commit a605d69092
3 changed files with 97 additions and 62 deletions

@ -27,9 +27,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
NoiseParams nparams_caveliquids(0, 1, v3f(150.0, 150.0, 150.0), 776, 3, 0.6, 2.0); NoiseParams nparams_caveliquids(0, 1, v3f(150.0, 150.0, 150.0), 776, 3, 0.6, 2.0);
////
///////////////////////////////////////// Caves V5 //// CavesRandomWalk
////
CavesRandomWalk::CavesRandomWalk(Mapgen *mg, PseudoRandom *ps) CavesRandomWalk::CavesRandomWalk(Mapgen *mg, PseudoRandom *ps)
{ {
@ -262,13 +262,10 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz)
int full_ymin = node_min.Y - MAP_BLOCKSIZE; int full_ymin = node_min.Y - MAP_BLOCKSIZE;
int full_ymax = node_max.Y + MAP_BLOCKSIZE; int full_ymax = node_max.Y + MAP_BLOCKSIZE;
if (flooded && full_ymin < water_level && if (flooded && full_ymin < water_level && full_ymax > water_level)
full_ymax > water_level) vm->m_data[i] = (p.Y <= water_level) ? waternode : airnode;
vm->m_data[i] = (p.Y <= water_level) ?
waternode : airnode;
else if (flooded && full_ymax < water_level) else if (flooded && full_ymax < water_level)
vm->m_data[i] = (p.Y < startp.Y - 4) ? vm->m_data[i] = (p.Y < startp.Y - 4) ? liquidnode : airnode;
liquidnode : airnode;
else else
vm->m_data[i] = airnode; vm->m_data[i] = airnode;
} }
@ -281,23 +278,51 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz)
//// CavesV6 //// CavesV6
//// ////
CavesV6::CavesV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, CavesV6::CavesV6(INodeDefManager *ndef, GenerateNotifier *gennotify,
bool is_large_cave) int water_level, content_t water_source, content_t lava_source)
{ {
this->mg = mg; assert(ndef);
this->vm = mg->vm;
this->ndef = mg->ndef; this->ndef = ndef;
this->water_level = mg->water_level; this->gennotify = gennotify;
this->large_cave = is_large_cave; this->water_level = water_level;
c_water_source = water_source;
if (c_water_source == CONTENT_IGNORE)
c_water_source = ndef->getId("mapgen_water_source");
if (c_water_source == CONTENT_IGNORE)
c_water_source = CONTENT_AIR;
c_lava_source = lava_source;
if (c_lava_source == CONTENT_IGNORE)
c_lava_source = ndef->getId("mapgen_lava_source");
if (c_lava_source == CONTENT_IGNORE)
c_lava_source = CONTENT_AIR;
}
void CavesV6::makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax,
PseudoRandom *ps, PseudoRandom *ps2,
bool is_large_cave, int max_stone_height, s16 *heightmap)
{
assert(vm);
assert(ps);
assert(ps2);
this->vm = vm;
this->ps = ps; this->ps = ps;
this->ps2 = ps2; this->ps2 = ps2;
this->c_water_source = mg->c_water_source; this->node_min = nmin;
this->c_lava_source = mg->c_lava_source; this->node_max = nmax;
this->heightmap = heightmap;
this->large_cave = is_large_cave;
this->ystride = nmax.X - nmin.X + 1;
// Set initial parameters from randomness
min_tunnel_diameter = 2; min_tunnel_diameter = 2;
max_tunnel_diameter = ps->range(2, 6); max_tunnel_diameter = ps->range(2, 6);
dswitchint = ps->range(1, 14); dswitchint = ps->range(1, 14);
if (large_cave) { if (large_cave) {
part_max_length_rs = ps->range(2, 4); part_max_length_rs = ps->range(2, 4);
tunnel_routepoints = ps->range(5, ps->range(15, 30)); tunnel_routepoints = ps->range(5, ps->range(15, 30));
@ -307,16 +332,8 @@ CavesV6::CavesV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2,
part_max_length_rs = ps->range(2, 9); part_max_length_rs = ps->range(2, 9);
tunnel_routepoints = ps->range(10, ps->range(15, 30)); tunnel_routepoints = ps->range(10, ps->range(15, 30));
} }
large_cave_is_flat = (ps->range(0, 1) == 0); large_cave_is_flat = (ps->range(0, 1) == 0);
}
void CavesV6::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
{
node_min = nmin;
node_max = nmax;
max_stone_y = max_stone_height;
main_direction = v3f(0, 0, 0); main_direction = v3f(0, 0, 0);
// Allowed route area size in nodes // Allowed route area size in nodes
@ -334,7 +351,7 @@ void CavesV6::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
route_y_min = 0; route_y_min = 0;
// Allow half a diameter + 7 over stone surface // Allow half a diameter + 7 over stone surface
route_y_max = -of.Y + max_stone_y + max_tunnel_diameter / 2 + 7; route_y_max = -of.Y + max_stone_height + max_tunnel_diameter / 2 + 7;
// Limit maximum to area // Limit maximum to area
route_y_max = rangelim(route_y_max, 0, ar.Y - 1); route_y_max = rangelim(route_y_max, 0, ar.Y - 1);
@ -363,20 +380,24 @@ void CavesV6::makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height)
); );
// Add generation notify begin event // Add generation notify begin event
if (gennotify != NULL) {
v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); v3s16 abs_pos(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
GenNotifyType notifytype = large_cave ? GenNotifyType notifytype = large_cave ?
GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN; GENNOTIFY_LARGECAVE_BEGIN : GENNOTIFY_CAVE_BEGIN;
mg->gennotify.addEvent(notifytype, abs_pos); gennotify->addEvent(notifytype, abs_pos);
}
// Generate some tunnel starting from orp // Generate some tunnel starting from orp
for (u16 j = 0; j < tunnel_routepoints; j++) for (u16 j = 0; j < tunnel_routepoints; j++)
makeTunnel(j % dswitchint == 0); makeTunnel(j % dswitchint == 0);
// Add generation notify end event // Add generation notify end event
abs_pos = v3s16(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z); if (gennotify != NULL) {
notifytype = large_cave ? v3s16 abs_pos = v3s16(of.X + orp.X, of.Y + orp.Y, of.Z + orp.Z);
GenNotifyType notifytype = large_cave ?
GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END; GENNOTIFY_LARGECAVE_END : GENNOTIFY_CAVE_END;
mg->gennotify.addEvent(notifytype, abs_pos); gennotify->addEvent(notifytype, abs_pos);
}
} }
@ -438,9 +459,9 @@ void CavesV6::makeTunnel(bool dirswitch)
v3s16 p1 = orpi + veci + of + rs / 2; v3s16 p1 = orpi + veci + of + rs / 2;
if (p1.Z >= node_min.Z && p1.Z <= node_max.Z && if (p1.Z >= node_min.Z && p1.Z <= node_max.Z &&
p1.X >= node_min.X && p1.X <= node_max.X) { p1.X >= node_min.X && p1.X <= node_max.X) {
u32 index1 = (p1.Z - node_min.Z) * mg->ystride + u32 index1 = (p1.Z - node_min.Z) * ystride +
(p1.X - node_min.X); (p1.X - node_min.X);
h1 = mg->heightmap[index1]; h1 = heightmap[index1];
} else { } else {
h1 = water_level; // If not in heightmap h1 = water_level; // If not in heightmap
} }
@ -448,9 +469,9 @@ void CavesV6::makeTunnel(bool dirswitch)
v3s16 p2 = orpi + of + rs / 2; v3s16 p2 = orpi + of + rs / 2;
if (p2.Z >= node_min.Z && p2.Z <= node_max.Z && if (p2.Z >= node_min.Z && p2.Z <= node_max.Z &&
p2.X >= node_min.X && p2.X <= node_max.X) { p2.X >= node_min.X && p2.X <= node_max.X) {
u32 index2 = (p2.Z - node_min.Z) * mg->ystride + u32 index2 = (p2.Z - node_min.Z) * ystride +
(p2.X - node_min.X); (p2.X - node_min.X);
h2 = mg->heightmap[index2]; h2 = heightmap[index2];
} else { } else {
h2 = water_level; h2 = water_level;
} }
@ -550,11 +571,9 @@ void CavesV6::carveRoute(v3f vec, float f, bool randomize_xz,
int full_ymax = node_max.Y + MAP_BLOCKSIZE; int full_ymax = node_max.Y + MAP_BLOCKSIZE;
if (full_ymin < water_level && full_ymax > water_level) { if (full_ymin < water_level && full_ymax > water_level) {
vm->m_data[i] = (p.Y <= water_level) ? vm->m_data[i] = (p.Y <= water_level) ? waternode : airnode;
waternode : airnode;
} else if (full_ymax < water_level) { } else if (full_ymax < water_level) {
vm->m_data[i] = (p.Y < startp.Y - 2) ? vm->m_data[i] = (p.Y < startp.Y - 2) ? lavanode : airnode;
lavanode : airnode;
} else { } else {
vm->m_data[i] = airnode; vm->m_data[i] = airnode;
} }

@ -23,13 +23,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1 #define VMANIP_FLAG_CAVE VOXELFLAG_CHECKED1
#define DEFAULT_LAVA_DEPTH (-256) #define DEFAULT_LAVA_DEPTH (-256)
class MapgenV6; class GenerateNotifier;
class CavesRandomWalk { class CavesRandomWalk {
public: public:
Mapgen *mg; Mapgen *mg;
MMVManip *vm; MMVManip *vm;
INodeDefManager *ndef; INodeDefManager *ndef;
s16 *heightmap;
// variables // variables
int lava_depth; int lava_depth;
@ -64,7 +65,7 @@ public:
content_t c_ice; content_t c_ice;
int water_level; int water_level;
int ystride; u16 ystride;
CavesRandomWalk(Mapgen *mg, PseudoRandom *ps); CavesRandomWalk(Mapgen *mg, PseudoRandom *ps);
void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height); void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height);
@ -87,9 +88,18 @@ public:
*/ */
class CavesV6 { class CavesV6 {
public: public:
MapgenV6 *mg;
MMVManip *vm; MMVManip *vm;
INodeDefManager *ndef; INodeDefManager *ndef;
GenerateNotifier *gennotify;
PseudoRandom *ps;
PseudoRandom *ps2;
s16 *heightmap;
content_t c_water_source;
content_t c_lava_source;
int water_level;
u16 ystride;
s16 min_tunnel_diameter; s16 min_tunnel_diameter;
s16 max_tunnel_diameter; s16 max_tunnel_diameter;
@ -100,7 +110,6 @@ public:
bool large_cave; bool large_cave;
bool large_cave_is_flat; bool large_cave_is_flat;
s16 max_stone_y;
v3s16 node_min; v3s16 node_min;
v3s16 node_max; v3s16 node_max;
@ -113,16 +122,22 @@ public:
s16 route_y_min; s16 route_y_min;
s16 route_y_max; s16 route_y_max;
PseudoRandom *ps; // ndef is a mandatory parameter.
PseudoRandom *ps2; // If gennotify is NULL, generation events are not logged.
CavesV6(INodeDefManager *ndef,
GenerateNotifier *gennotify = NULL,
int water_level = 1,
content_t water_source = CONTENT_IGNORE,
content_t lava_source = CONTENT_IGNORE);
content_t c_water_source; // vm, ps, and ps2 are mandatory parameters.
content_t c_lava_source; // If heightmap is NULL, the surface level at all points is assumed to
// be water_level.
void makeCave(MMVManip *vm, v3s16 nmin, v3s16 nmax,
PseudoRandom *ps, PseudoRandom *ps2,
bool is_large_cave, int max_stone_height, s16 *heightmap = NULL);
int water_level; private:
CavesV6(MapgenV6 *mg, PseudoRandom *ps, PseudoRandom *ps2, bool large_cave);
void makeCave(v3s16 nmin, v3s16 nmax, int max_stone_height);
void makeTunnel(bool dirswitch); void makeTunnel(bool dirswitch);
void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground); void carveRoute(v3f vec, float f, bool randomize_xz, bool tunnel_above_ground);
}; };

@ -1066,9 +1066,10 @@ void MapgenV6::generateCaves(int max_stone_y)
} }
for (u32 i = 0; i < caves_count + bruises_count; i++) { for (u32 i = 0; i < caves_count + bruises_count; i++) {
bool large_cave = (i >= caves_count); CavesV6 cave(ndef, &gennotify, water_level, c_water_source, c_lava_source);
CavesV6 cave(this, &ps, &ps2, large_cave);
cave.makeCave(node_min, node_max, max_stone_y); bool large_cave = (i >= caves_count);
cave.makeCave(vm, node_min, node_max, &ps, &ps2,
large_cave, max_stone_y, heightmap);
} }
} }