aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen
diff options
context:
space:
mode:
Diffstat (limited to 'src/mapgen')
-rw-r--r--src/mapgen/dungeongen.cpp2
-rw-r--r--src/mapgen/mapgen.cpp13
-rw-r--r--src/mapgen/mapgen.h42
-rw-r--r--src/mapgen/mapgen_flat.cpp2
-rw-r--r--src/mapgen/mapgen_fractal.cpp1
-rw-r--r--src/mapgen/mg_biome.cpp2
-rw-r--r--src/mapgen/mg_ore.cpp4
7 files changed, 52 insertions, 14 deletions
diff --git a/src/mapgen/dungeongen.cpp b/src/mapgen/dungeongen.cpp
index acdb1a0f0..1d439abeb 100644
--- a/src/mapgen/dungeongen.cpp
+++ b/src/mapgen/dungeongen.cpp
@@ -71,7 +71,7 @@ DungeonGen::DungeonGen(const NodeDefManager *ndef,
dp.num_dungeons = 1;
dp.notifytype = GENNOTIFY_DUNGEON;
- dp.np_alt_wall =
+ dp.np_alt_wall =
NoiseParams(-0.4, 1.0, v3f(40.0, 40.0, 40.0), 32474, 6, 1.1, 2.0);
}
}
diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp
index d767bd264..99db50426 100644
--- a/src/mapgen/mapgen.cpp
+++ b/src/mapgen/mapgen.cpp
@@ -238,7 +238,8 @@ u32 Mapgen::getBlockSeed(v3s16 p, s32 seed)
u32 Mapgen::getBlockSeed2(v3s16 p, s32 seed)
{
- u32 n = 1619 * p.X + 31337 * p.Y + 52591 * p.Z + 1013 * seed;
+ // Multiply by unsigned number to avoid signed overflow (UB)
+ u32 n = 1619U * p.X + 31337U * p.Y + 52591U * p.Z + 1013U * seed;
n = (n >> 13) ^ n;
return (n * (n * n * 60493 + 19990303) + 1376312589);
}
@@ -452,9 +453,8 @@ void Mapgen::lightSpread(VoxelArea &a, std::queue<std::pair<v3s16, u8>> &queue,
!ndef->get(n).light_propagates)
return;
- // Since this recursive function only terminates when there is no light from
- // either bank left, we need to take the max of both banks into account for
- // the case where spreading has stopped for one light bank but not the other.
+ // MYMAX still needed here because we only exit early if both banks have
+ // nothing to propagate anymore.
light = MYMAX(light_day, n.param1 & 0x0F) |
MYMAX(light_night, n.param1 & 0xF0);
@@ -469,12 +469,9 @@ void Mapgen::calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nm
bool propagate_shadow)
{
ScopeProfiler sp(g_profiler, "EmergeThread: update lighting", SPT_AVG);
- //TimeTaker t("updateLighting");
propagateSunlight(nmin, nmax, propagate_shadow);
spreadLight(full_nmin, full_nmax);
-
- //printf("updateLighting: %dms\n", t.stop());
}
@@ -1041,6 +1038,8 @@ void MapgenParams::readParams(const Settings *settings)
settings->getS16NoEx("chunksize", chunksize);
settings->getFlagStrNoEx("mg_flags", flags, flagdesc_mapgen);
+ chunksize = rangelim(chunksize, 1, 10);
+
delete bparams;
bparams = BiomeManager::createBiomeParams(BIOMEGEN_ORIGINAL);
if (bparams) {
diff --git a/src/mapgen/mapgen.h b/src/mapgen/mapgen.h
index 61db4f3b9..ef5de6029 100644
--- a/src/mapgen/mapgen.h
+++ b/src/mapgen/mapgen.h
@@ -190,12 +190,38 @@ public:
void updateLiquid(UniqueQueue<v3s16> *trans_liquid, v3s16 nmin, v3s16 nmax);
+ /**
+ * Set light in entire area to fixed value.
+ * @param light Light value (contains both banks)
+ * @param nmin Area to operate on
+ * @param nmax ^
+ */
void setLighting(u8 light, v3s16 nmin, v3s16 nmax);
- void lightSpread(VoxelArea &a, std::queue<std::pair<v3s16, u8>> &queue,
- const v3s16 &p, u8 light);
+ /**
+ * Run all lighting calculations.
+ * @param nmin Area to spread sunlight in
+ * @param nmax ^
+ * @param full_nmin Area to recalculate light in
+ * @param full_nmax ^
+ * @param propagate_shadow see propagateSunlight()
+ */
void calcLighting(v3s16 nmin, v3s16 nmax, v3s16 full_nmin, v3s16 full_nmax,
bool propagate_shadow = true);
+ /**
+ * Spread sunlight from the area above downwards.
+ * Note that affected nodes have their night bank cleared so you want to
+ * run a light spread afterwards.
+ * @param nmin Area to operate on
+ * @param nmax ^
+ * @param propagate_shadow Ignore obstructions above and spread sun anyway
+ */
void propagateSunlight(v3s16 nmin, v3s16 nmax, bool propagate_shadow);
+ /**
+ * Spread light in the given area.
+ * Artificial light is taken from nodedef, sunlight must already be set.
+ * @param nmin Area to operate on
+ * @param nmax ^
+ */
void spreadLight(const v3s16 &nmin, const v3s16 &nmax);
virtual void makeChunk(BlockMakeData *data) {}
@@ -218,6 +244,18 @@ public:
static void setDefaultSettings(Settings *settings);
private:
+ /**
+ * Spread light to the node at the given position, add to queue if changed.
+ * The given light value is diminished once.
+ * @param a VoxelArea being operated on
+ * @param queue Queue for later lightSpread() calls
+ * @param p Node position
+ * @param light Light value (contains both banks)
+ *
+ */
+ void lightSpread(VoxelArea &a, std::queue<std::pair<v3s16, u8>> &queue,
+ const v3s16 &p, u8 light);
+
// isLiquidHorizontallyFlowable() is a helper function for updateLiquid()
// that checks whether there are floodable nodes without liquid beneath
// the node at index vi.
diff --git a/src/mapgen/mapgen_flat.cpp b/src/mapgen/mapgen_flat.cpp
index 342455029..6b249ea1f 100644
--- a/src/mapgen/mapgen_flat.cpp
+++ b/src/mapgen/mapgen_flat.cpp
@@ -177,7 +177,7 @@ void MapgenFlatParams::setDefaultSettings(Settings *settings)
int MapgenFlat::getSpawnLevelAtPoint(v2s16 p)
{
s16 stone_level = ground_level;
- float n_terrain =
+ float n_terrain =
((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS)) ?
NoisePerlin2D(&noise_terrain->np, p.X, p.Y, seed) :
0.0f;
diff --git a/src/mapgen/mapgen_fractal.cpp b/src/mapgen/mapgen_fractal.cpp
index fabb1b2b1..c9071cecf 100644
--- a/src/mapgen/mapgen_fractal.cpp
+++ b/src/mapgen/mapgen_fractal.cpp
@@ -131,6 +131,7 @@ void MapgenFractalParams::readParams(const Settings *settings)
settings->getNoiseParams("mgfractal_np_cave1", np_cave1);
settings->getNoiseParams("mgfractal_np_cave2", np_cave2);
settings->getNoiseParams("mgfractal_np_dungeons", np_dungeons);
+ iterations = std::max<u16>(iterations, 1);
}
diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp
index f08cc190f..8b4c96cd5 100644
--- a/src/mapgen/mg_biome.cpp
+++ b/src/mapgen/mg_biome.cpp
@@ -273,7 +273,7 @@ Biome *BiomeGenOriginal::calcBiomeFromNoise(float heat, float humidity, v3s16 po
pos.Y - biome_closest_blend->max_pos.Y)
return biome_closest_blend;
- return (biome_closest) ? biome_closest : (Biome *)m_bmgr->getRaw(BIOME_NONE);
+ return (biome_closest) ? biome_closest : (Biome *)m_bmgr->getRaw(BIOME_NONE);
}
diff --git a/src/mapgen/mg_ore.cpp b/src/mapgen/mg_ore.cpp
index 5814f433a..4f0c35548 100644
--- a/src/mapgen/mg_ore.cpp
+++ b/src/mapgen/mg_ore.cpp
@@ -498,8 +498,8 @@ void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed,
}
// randval ranges from -1..1
- /*
- Note: can generate values slightly larger than 1
+ /*
+ Note: can generate values slightly larger than 1
but this can't be changed as mapgen must be deterministic accross versions.
*/
float randval = (float)pr.next() / float(pr.RANDOM_RANGE / 2) - 1.f;