Skip to content
Permalink
Browse files

Mapgen V7: Huge rewrite, also tweaks to cavegen et al.

  • Loading branch information
kwolekr committed Jul 6, 2013
1 parent 3607fae commit 18d7bc7fa1f2621eb593969b7bcccfeb4918c05f
Showing with 453 additions and 197 deletions.
  1. +35 −20 src/biome.cpp
  2. +11 −5 src/biome.h
  3. +13 −6 src/cavegen.cpp
  4. +1 −0 src/cavegen.h
  5. +9 −6 src/defaultsettings.cpp
  6. +18 −5 src/mapgen.cpp
  7. +2 −0 src/mapgen.h
  8. +5 −6 src/mapgen_math.cpp
  9. +1 −1 src/mapgen_math.h
  10. +302 −123 src/mapgen_v7.cpp
  11. +29 −12 src/mapgen_v7.h
  12. +27 −13 src/script/lua_api/luaapi.cpp
@@ -43,9 +43,9 @@ BiomeDefManager::BiomeDefManager() {
b->flags = 0;

b->c_top = CONTENT_AIR;
b->top_depth = 0;
b->c_filler = b->c_top;
b->filler_height = MAP_GENERATION_LIMIT;
b->depth_top = 0;
b->c_filler = CONTENT_AIR;
b->depth_filler = 0;

b->height_min = -MAP_GENERATION_LIMIT;
b->height_max = MAP_GENERATION_LIMIT;
@@ -101,27 +101,42 @@ void BiomeDefManager::resolveNodeNames(INodeDefManager *ndef) {

biome_registration_finished = true;

for (size_t i = 0; i != biomes.size(); i++) {
for (size_t i = 1; i < biomes.size(); i++) {
b = biomes[i];


b->c_top = ndef->getId(b->nname_top);
if (b->c_top == CONTENT_IGNORE) {
b->c_top = ndef->getId(b->top_nodename);
if (b->c_top == CONTENT_IGNORE) {
errorstream << "BiomeDefManager::resolveNodeNames: node '"
<< b->top_nodename << "' not defined" << std::endl;
b->c_top = CONTENT_AIR;
b->top_depth = 0;
}
errorstream << "BiomeDefManager::resolveNodeNames: node '"
<< b->nname_top << "' not defined" << std::endl;
b->c_top = CONTENT_AIR;
b->depth_top = 0;
}


b->c_filler = ndef->getId(b->nname_filler);
if (b->c_filler == CONTENT_IGNORE) {
b->c_filler = ndef->getId(b->filler_nodename);
if (b->c_filler == CONTENT_IGNORE) {
errorstream << "BiomeDefManager::resolveNodeNames: node '"
<< b->filler_nodename << "' not defined" << std::endl;
b->c_filler = CONTENT_AIR;
b->filler_height = MAP_GENERATION_LIMIT;
}
errorstream << "BiomeDefManager::resolveNodeNames: node '"
<< b->nname_filler << "' not defined" << std::endl;
b->c_filler = CONTENT_AIR;
b->depth_filler = 0;
}

b->c_water = ndef->getId(b->nname_water);
if (b->c_water == CONTENT_IGNORE) {
errorstream << "BiomeDefManager::resolveNodeNames: node '"
<< b->nname_water << "' not defined" << std::endl;
b->c_water = CONTENT_AIR;
}

b->c_dust = ndef->getId(b->nname_dust);
if (b->c_dust == CONTENT_IGNORE) {
errorstream << "BiomeDefManager::resolveNodeNames: node '"
<< b->nname_dust << "' not defined" << std::endl;
}

b->c_dust_water = ndef->getId(b->nname_dust_water);
if (b->c_dust_water == CONTENT_IGNORE) {
errorstream << "BiomeDefManager::resolveNodeNames: node '"
<< b->nname_dust_water << "' not defined" << std::endl;
}
}
}
@@ -45,14 +45,20 @@ class Biome {
std::string name;
u32 flags;

std::string top_nodename;
std::string filler_nodename;
std::string nname_top;
std::string nname_filler;
std::string nname_water;
std::string nname_dust;
std::string nname_dust_water;

content_t c_top;
s16 top_depth;

content_t c_filler;
s16 filler_height;
content_t c_water;
content_t c_dust;
content_t c_dust_water;

s16 depth_top;
s16 depth_filler;

s16 height_min;
s16 height_max;
@@ -275,6 +275,7 @@ CaveV7::CaveV7(MapgenV7 *mg, PseudoRandom *ps, bool is_large_cave) {
this->ps = ps;
this->c_water_source = mg->c_water_source;
this->c_lava_source = mg->c_lava_source;
this->c_ice = mg->c_ice;
this->np_caveliquids = &nparams_caveliquids;

dswitchint = ps->range(1, 14);
@@ -454,8 +455,9 @@ void CaveV7::makeTunnel(bool dirswitch) {
bool randomize_xz = (ps->range(1, 2) == 1);

// Make a ravine every once in a while if it's long enough
float xylen = vec.X * vec.X + vec.Z * vec.Z;
bool is_ravine = (xylen > 500.0) && !large_cave && (ps->range(1, 8) == 1);
//float xylen = vec.X * vec.X + vec.Z * vec.Z;
//disable ravines for now
bool is_ravine = false; //(xylen > 500.0) && !large_cave && (ps->range(1, 8) == 1);

// Carve routes
for (float f = 0; f < 1.0; f += 1.0 / veclen)
@@ -490,6 +492,7 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
}

bool flat_cave_floor = !large_cave && ps->range(0, 2) == 2;
bool should_make_cave_hole = ps->range(1, 10) == 1;

for (s16 z0 = d0; z0 <= d1; z0++) {
s16 si = rs / 2 - MYMAX(0, abs(z0) - rs / 7 - 1);
@@ -513,10 +516,10 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
v3s16 p(cp.X + x0, cp.Y + y0, cp.Z + z0);
p += of;

if (!is_ravine && mg->heightmap) {
if (!is_ravine && mg->heightmap && should_make_cave_hole) {
int maplen = node_max.X - node_min.X + 1;
int idx = (p.Z - node_min.Z) * maplen + (p.X - node_min.X);
if (p.Y >= mg->heightmap[idx])
if (p.Y >= mg->heightmap[idx] - 2)
continue;
}

@@ -525,9 +528,10 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {

u32 i = vm->m_area.index(p);

// Don't replace air or water or lava
// Don't replace air, water, lava, or ice
content_t c = vm->m_data[i].getContent();
if (c == CONTENT_AIR || c == c_water_source || c == c_lava_source)
if (c == CONTENT_AIR || c == c_water_source ||
c == c_lava_source || c == c_ice)
continue;

if (large_cave) {
@@ -541,6 +545,9 @@ void CaveV7::carveRoute(v3f vec, float f, bool randomize_xz, bool is_ravine) {
else
vm->m_data[i] = airnode;
} else {
if (c == CONTENT_IGNORE)
continue;

vm->m_data[i] = airnode;
vm->m_flags[i] |= VMANIP_FLAG_CAVE;
}
@@ -104,6 +104,7 @@ class CaveV7 {

content_t c_water_source;
content_t c_lava_source;
content_t c_ice;

int water_level;

@@ -235,12 +235,15 @@ void set_default_settings(Settings *settings)
settings->setDefault("mgv6_np_trees", "0, 1, (125, 125, 125), 2, 4, 0.66");
settings->setDefault("mgv6_np_apple_trees", "0, 1, (100, 100, 100), 342902, 3, 0.45");

settings->setDefault("mgv7_np_terrain_base", "0, 80, (250, 250, 250), 82341, 5, 0.6");
settings->setDefault("mgv7_np_terrain_alt", "0, 20, (250, 250, 250), 5934, 5, 0.6");
settings->setDefault("mgv7_np_terrain_mod", "0, 1, (350, 350, 350), 85039, 5, 0.6");
settings->setDefault("mgv7_np_terrain_persist", "0, 1, (500, 500, 500), 539, 3, 0.6");
settings->setDefault("mgv7_np_height_select", "0.5, 0.5, (250, 250, 250), 4213, 5, 0.69");
settings->setDefault("mgv7_np_ridge", "0, 1, (100, 100, 100), 6467, 4, 0.75");
settings->setDefault("mgv7_np_terrain_base", "4, 70, (300, 300, 300), 82341, 6, 0.7");
settings->setDefault("mgv7_np_terrain_alt", "4, 25, (600, 600, 600), 5934, 5, 0.6");
settings->setDefault("mgv7_np_terrain_persist", "0.6, 0.1, (500, 500, 500), 539, 3, 0.6");
settings->setDefault("mgv7_np_height_select", "-0.5, 1, (250, 250, 250), 4213, 5, 0.69");
settings->setDefault("mgv7_np_filler_depth", "0, 1.2, (150, 150, 150), 261, 4, 0.7");
settings->setDefault("mgv7_np_mount_height", "100, 30, (500, 500, 500), 72449, 4, 0.6");
settings->setDefault("mgv7_np_ridge_uwater", "0, 1, (500, 500, 500), 85039, 4, 0.6");
settings->setDefault("mgv7_np_mountain", "0, 1, (250, 350, 250), 5333, 5, 0.68");
settings->setDefault("mgv7_np_ridge", "0, 1, (100, 120, 100), 6467, 4, 0.75");

settings->setDefault("mgindev_np_terrain_base", "-4, 20, (250, 250, 250), 82341, 5, 0.6, 10, 10");
settings->setDefault("mgindev_np_terrain_higher", "20, 16, (500, 500, 500), 85039, 5, 0.6, 10, 10");
@@ -291,7 +291,7 @@ void Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) {
continue;

int height = getHeight();
int max_y = nmax.Y + MAP_BLOCKSIZE;
int max_y = nmax.Y;// + MAP_BLOCKSIZE - 1;
if (y + 1 + height > max_y) {
continue;
#if 0
@@ -859,9 +859,16 @@ void Mapgen::updateHeightmap(v3s16 nmin, v3s16 nmax) {
//TimeTaker t("Mapgen::updateHeightmap", NULL, PRECISION_MICRO);
int index = 0;
for (s16 z = nmin.Z; z <= nmax.Z; z++) {
for (s16 x = nmin.X; x <= nmax.X; x++) {
for (s16 x = nmin.X; x <= nmax.X; x++, index++) {
s16 y = findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
heightmap[index++] = y;

// if the values found are out of range, trust the old heightmap
if (y == nmax.Y && heightmap[index] > nmax.Y)
continue;
if (y == nmin.Y - 1 && heightmap[index] < nmin.Y)
continue;

heightmap[index] = y;
}
}
//printf("updateHeightmap: %dus\n", t.stop());
@@ -1060,9 +1067,12 @@ bool MapgenV7Params::readParams(Settings *settings) {
bool success =
settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base) &&
settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt) &&
settings->getNoiseParams("mgv7_np_terrain_mod", np_terrain_mod) &&
settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist) &&
settings->getNoiseParams("mgv7_np_height_select", np_height_select) &&
settings->getNoiseParams("mgv7_np_filler_depth", np_filler_depth) &&
settings->getNoiseParams("mgv7_np_mount_height", np_mount_height) &&
settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater) &&
settings->getNoiseParams("mgv7_np_mountain", np_mountain) &&
settings->getNoiseParams("mgv7_np_ridge", np_ridge);
return success;
}
@@ -1071,9 +1081,12 @@ bool MapgenV7Params::readParams(Settings *settings) {
void MapgenV7Params::writeParams(Settings *settings) {
settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base);
settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
settings->setNoiseParams("mgv7_np_terrain_mod", np_terrain_mod);
settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
settings->setNoiseParams("mgv7_np_height_select", np_height_select);
settings->setNoiseParams("mgv7_np_filler_depth", np_filler_depth);
settings->setNoiseParams("mgv7_np_mount_height", np_mount_height);
settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
settings->setNoiseParams("mgv7_np_mountain", np_mountain);
settings->setNoiseParams("mgv7_np_ridge", np_ridge);
}

@@ -36,6 +36,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MGV6_BIOME_BLEND 0x10
#define MG_FLAT 0x20
#define MG_NOLIGHT 0x40
#define MGV7_MOUNTAINS 0x80
#define MGV7_RIDGES 0x100

/////////////////// Ore generation flags
// Use absolute value of height to determine ore placement
@@ -172,7 +172,6 @@ void MapgenMathParams::writeParams(Settings *settings) {
MapgenMath::MapgenMath(int mapgenid, MapgenMathParams *params_, EmergeManager *emerge) : MapgenV7(mapgenid, params_, emerge) {
mg_params = params_;
this->flags |= MG_NOLIGHT;
this->ridges = 0;

Json::Value & params = mg_params->params;
invert = params["invert"].empty() ? 1 : params["invert"].asBool(); //params["invert"].empty()?1:params["invert"].asBool();
@@ -238,7 +237,7 @@ MapgenMath::~MapgenMath() {

//////////////////////// Map generator

void MapgenMath::generateTerrain() {
int MapgenMath::generateTerrain() {

MapNode n_air(CONTENT_AIR, LIGHT_SUN), n_water_source(c_water_source, LIGHT_SUN);
MapNode n_stone(c_stone, LIGHT_SUN);
@@ -263,9 +262,9 @@ void MapgenMath::generateTerrain() {
double d = (*func)(vec.X, vec.Y, vec.Z, distance, iterations);
if ((!invert && d > 0) || (invert && d == 0) ) {
if (vm->m_data[i].getContent() == CONTENT_IGNORE)
vm->m_data[i] = (y > water_level + biome->filler_height) ?
MapNode(biome->c_filler) : n_stone;
// vm->m_data[i] = n_stone;
// vm->m_data[i] = (y > water_level + biome->filler) ?
// MapNode(biome->c_filler) : n_stone;
vm->m_data[i] = n_stone;
} else if (y <= water_level) {
vm->m_data[i] = n_water_source;
} else {
@@ -361,7 +360,7 @@ void MapgenMath::generateTerrain() {


#endif

return 0;
}

int MapgenMath::getGroundLevelAtPoint(v2s16 p) {
@@ -42,7 +42,7 @@ class MapgenMath : public MapgenV7 {
MapgenMath(int mapgenid, MapgenMathParams *mg_params, EmergeManager *emerge);
~MapgenMath();

void generateTerrain();
int generateTerrain();
int getGroundLevelAtPoint(v2s16 p);

bool invert;

0 comments on commit 18d7bc7

Please sign in to comment.