diff options
author | paramat <paramat@users.noreply.github.com> | 2017-09-30 10:23:57 +0100 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2017-10-01 22:31:44 +0100 |
commit | e2afcf85ce5945a6ed08313dfed9f68d02912f73 (patch) | |
tree | 684f7f9bec103e188289fc2996b495a701651f48 /src | |
parent | 9fa78b7387ec6eb5f6e3419d37ae631085c69e1a (diff) | |
download | minetest-e2afcf85ce5945a6ed08313dfed9f68d02912f73.tar.gz minetest-e2afcf85ce5945a6ed08313dfed9f68d02912f73.tar.bz2 minetest-e2afcf85ce5945a6ed08313dfed9f68d02912f73.zip |
Stratum ore: Allow use with no noise for simple horizontal strata
If either of the 2 noise parameters are omitted the ore will occur from y_min
to y_max in a simple horizontal stratum. As this does not compute noise
performance improves, and is ideal for placing many layers.
Clean up some nearby ore documentation.
Diffstat (limited to 'src')
-rw-r--r-- | src/mg_ore.cpp | 32 | ||||
-rw-r--r-- | src/mg_ore.h | 2 | ||||
-rw-r--r-- | src/script/lua_api/l_mapgen.cpp | 4 |
3 files changed, 25 insertions, 13 deletions
diff --git a/src/mg_ore.cpp b/src/mg_ore.cpp index 4f4c9c711..979135ed4 100644 --- a/src/mg_ore.cpp +++ b/src/mg_ore.cpp @@ -433,14 +433,16 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, PcgRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); - if (!noise) { - int sx = nmax.X - nmin.X + 1; - int sz = nmax.Z - nmin.Z + 1; - noise = new Noise(&np, 0, sx, sz); - noise_stratum_thickness = new Noise(&np_stratum_thickness, 0, sx, sz); + if (flags & OREFLAG_USE_NOISE) { + if (!(noise && noise_stratum_thickness)) { + int sx = nmax.X - nmin.X + 1; + int sz = nmax.Z - nmin.Z + 1; + noise = new Noise(&np, 0, sx, sz); + noise_stratum_thickness = new Noise(&np_stratum_thickness, 0, sx, sz); + } + noise->perlinMap2D(nmin.X, nmin.Z); + noise_stratum_thickness->perlinMap2D(nmin.X, nmin.Z); } - noise->perlinMap2D(nmin.X, nmin.Z); - noise_stratum_thickness->perlinMap2D(nmin.X, nmin.Z); size_t index = 0; @@ -452,10 +454,18 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed, continue; } - float nmid = noise->result[index]; - float nhalfthick = noise_stratum_thickness->result[index] / 2.0f; - int y0 = MYMAX(nmin.Y, nmid - nhalfthick); - int y1 = MYMIN(nmax.Y, nmid + nhalfthick); + int y0; + int y1; + + if (flags & OREFLAG_USE_NOISE) { + float nmid = noise->result[index]; + float nhalfthick = noise_stratum_thickness->result[index] / 2.0f; + y0 = MYMAX(nmin.Y, nmid - nhalfthick); + y1 = MYMIN(nmax.Y, nmid + nhalfthick); + } else { + y0 = nmin.Y; + y1 = nmax.Y; + } for (int y = y0; y <= y1; y++) { if (pr.range(1, clust_scarcity) != 1) diff --git a/src/mg_ore.h b/src/mg_ore.h index 4801b152e..e715f348b 100644 --- a/src/mg_ore.h +++ b/src/mg_ore.h @@ -135,7 +135,7 @@ public: class OreStratum : public Ore { public: - static const bool NEEDS_NOISE = true; + static const bool NEEDS_NOISE = false; NoiseParams np_stratum_thickness; Noise *noise_stratum_thickness = nullptr; diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 7757ea80c..b179ac407 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -1156,7 +1156,9 @@ int ModApiMapgen::l_register_ore(lua_State *L) OreStratum *orestratum = (OreStratum *)ore; lua_getfield(L, index, "np_stratum_thickness"); - read_noiseparams(L, -1, &orestratum->np_stratum_thickness); + // If thickness noise missing unset 'use noise' flag + if (!read_noiseparams(L, -1, &orestratum->np_stratum_thickness)) + ore->flags &= ~OREFLAG_USE_NOISE; lua_pop(L, 1); break; |