]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/mapgen_v7.cpp
Mapgen: Use mapgen-specific names for constants in headers
[dragonfireclient.git] / src / mapgen_v7.cpp
index a46bf8f17d1b20b48c0a32f8926cfb7f0a805344..77b9721c782557b8baed72546ecec3a07e2c48b7 100644 (file)
@@ -1,6 +1,7 @@
 /*
 Minetest
-Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2010-2015 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
+Copyright (C) 2010-2015 paramat, Matt Gregory
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as published by
@@ -27,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "content_sao.h"
 #include "nodedef.h"
 #include "voxelalgorithms.h"
+//#include "profiler.h" // For TimeTaker
 #include "settings.h" // For g_settings
 #include "emerge.h"
 #include "dungeongen.h"
@@ -146,17 +148,17 @@ MapgenV7Params::MapgenV7Params()
 {
        spflags = MGV7_MOUNTAINS | MGV7_RIDGES;
 
-       np_terrain_base    = NoiseParams(4,    70,   v3f(600,  600,  600),  82341, 5, 0.6,  2.0);
-       np_terrain_alt     = NoiseParams(4,    25,   v3f(600,  600,  600),  5934,  5, 0.6,  2.0);
-       np_terrain_persist = NoiseParams(0.6,  0.12, v3f(2000, 2000, 2000), 539,   3, 0.5,  2.0);
-       np_height_select   = NoiseParams(-12,  24,   v3f(500,  500,  500),  4213,  6, 0.69, 2.0);
-       np_filler_depth    = NoiseParams(0,    1.2,  v3f(150,  150,  150),  261,   4, 0.7,  2.0);
-       np_mount_height    = NoiseParams(184,  72,   v3f(1000, 1000, 1000), 72449, 3, 0.5,  2.0);
-       np_ridge_uwater    = NoiseParams(0,    1,    v3f(1000, 1000, 1000), 85039, 5, 0.6,  2.0);
-       np_mountain        = NoiseParams(-0.6, 1,    v3f(250,  350,  250),  5333,  5, 0.68, 2.0);
-       np_ridge           = NoiseParams(0,    1,    v3f(100,  100,  100),  6467,  4, 0.75, 2.0);
-       np_cave1           = NoiseParams(0,    12,   v3f(100,  100,  100),  52534, 4, 0.5,  2.0);
-       np_cave2           = NoiseParams(0,    12,   v3f(100,  100,  100),  10325, 4, 0.5,  2.0);
+       np_terrain_base    = NoiseParams(4,    70,  v3f(600,  600,  600),  82341, 5, 0.6,  2.0);
+       np_terrain_alt     = NoiseParams(4,    25,  v3f(600,  600,  600),  5934,  5, 0.6,  2.0);
+       np_terrain_persist = NoiseParams(0.6,  0.1, v3f(2000, 2000, 2000), 539,   3, 0.6,  2.0);
+       np_height_select   = NoiseParams(-12,  24,  v3f(500,  500,  500),  4213,  6, 0.7,  2.0);
+       np_filler_depth    = NoiseParams(0,    1.2, v3f(150,  150,  150),  261,   3, 0.7,  2.0);
+       np_mount_height    = NoiseParams(256,  112, v3f(1000, 1000, 1000), 72449, 3, 0.6,  2.0);
+       np_ridge_uwater    = NoiseParams(0,    1,   v3f(1000, 1000, 1000), 85039, 5, 0.6,  2.0);
+       np_mountain        = NoiseParams(-0.6, 1,   v3f(250,  350,  250),  5333,  5, 0.63, 2.0);
+       np_ridge           = NoiseParams(0,    1,   v3f(100,  100,  100),  6467,  4, 0.75, 2.0);
+       np_cave1           = NoiseParams(0,    12,  v3f(100,  100,  100),  52534, 4, 0.5,  2.0);
+       np_cave2           = NoiseParams(0,    12,  v3f(100,  100,  100),  10325, 4, 0.5,  2.0);
 }
 
 
@@ -180,7 +182,7 @@ void MapgenV7Params::readParams(const Settings *settings)
 
 void MapgenV7Params::writeParams(Settings *settings) const
 {
-       settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, (u32)-1);
+       settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, U32_MAX);
 
        settings->setNoiseParams("mgv7_np_terrain_base",    np_terrain_base);
        settings->setNoiseParams("mgv7_np_terrain_alt",     np_terrain_alt);
@@ -429,16 +431,20 @@ float MapgenV7::baseTerrainLevelFromMap(int index)
 bool MapgenV7::getMountainTerrainAtPoint(s16 x, s16 y, s16 z)
 {
        float mnt_h_n = NoisePerlin2D(&noise_mount_height->np, x, z, seed);
+       float density_gradient = -((float)y / mnt_h_n);
        float mnt_n = NoisePerlin3D(&noise_mountain->np, x, y, z, seed);
-       return mnt_n * mnt_h_n >= (float)y;
+
+       return mnt_n + density_gradient >= 0.0;
 }
 
 
 bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y)
 {
        float mounthn = noise_mount_height->result[idx_xz];
+       float density_gradient = -((float)y / mounthn);
        float mountn = noise_mountain->result[idx_xyz];
-       return mountn * mounthn >= (float)y;
+
+       return mountn + density_gradient >= 0.0;
 }
 
 
@@ -501,8 +507,8 @@ void MapgenV7::generateBaseTerrain(s16 *stone_surface_min_y, s16 *stone_surface_
        MapNode n_water(c_water_source);
 
        v3s16 em = vm->m_area.getExtent();
-       s16 surface_min_y = MAP_GENERATION_LIMIT;
-       s16 surface_max_y = -MAP_GENERATION_LIMIT;
+       s16 surface_min_y = MAX_MAP_GENERATION_LIMIT;
+       s16 surface_max_y = -MAX_MAP_GENERATION_LIMIT;
        u32 index = 0;
 
        for (s16 z = node_min.Z; z <= node_max.Z; z++)
@@ -631,7 +637,7 @@ MgStoneType MapgenV7::generateBiomes(float *heat_map, float *humidity_map)
 
                // If there is air or water above enable top/filler placement, otherwise force
                // nplaced to stone level by setting a number exceeding any possible filler depth.
-               u16 nplaced = (air_above || water_above) ? 0 : (u16)-1;
+               u16 nplaced = (air_above || water_above) ? 0 : U16_MAX;
 
                for (s16 y = node_max.Y; y >= node_min.Y; y--) {
                        content_t c = vm->m_data[vi].getContent();
@@ -668,7 +674,7 @@ MgStoneType MapgenV7::generateBiomes(float *heat_map, float *humidity_map)
                                // This is done by aborting the cycle of top/filler placement
                                // immediately by forcing nplaced to stone level.
                                if (c_below == CONTENT_AIR || c_below == c_water_source)
-                                       nplaced = (u16)-1;
+                                       nplaced = U16_MAX;
 
                                if (nplaced < depth_top) {
                                        vm->m_data[vi] = MapNode(biome->c_top);
@@ -693,7 +699,7 @@ MgStoneType MapgenV7::generateBiomes(float *heat_map, float *humidity_map)
                                air_above = true;
                                water_above = false;
                        } else {  // Possible various nodes overgenerated from neighbouring mapchunks
-                               nplaced = (u16)-1;  // Disable top/filler placement
+                               nplaced = U16_MAX;  // Disable top/filler placement
                                air_above = false;
                                water_above = false;
                        }
@@ -881,4 +887,3 @@ void MapgenV7::generateCaves(s16 max_stone_y)
                cave.makeCave(node_min, node_max, max_stone_y);
        }
 }
-