Skip to content

Commit 4b553ec

Browse files
committedNov 19, 2017
Stratum ore: Add option for a constant thickness stratum
Add a 'stratum thickness' integer parameter, as an alternative to providing a 2nd noise parameter for thickness variation.
1 parent c655984 commit 4b553ec

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed
 

Diff for: ‎doc/lua_api.txt

+13-9
Original file line numberDiff line numberDiff line change
@@ -1206,20 +1206,25 @@ computationally expensive than any other ore.
12061206
Creates a single undulating ore stratum that is continuous across mapchunk
12071207
borders and horizontally spans the world.
12081208

1209-
The 2D perlin noise described by `noise_params` varies the Y co-ordinate of the
1209+
The 2D perlin noise described by `noise_params` defines the Y co-ordinate of the
12101210
stratum midpoint. The 2D perlin noise described by `np_stratum_thickness`
1211-
varies the stratum's vertical thickness (in units of nodes). Due to being
1211+
defines the stratum's vertical thickness (in units of nodes). Due to being
12121212
continuous across mapchunk borders the stratum's vertical thickness is
12131213
unlimited.
12141214

1215+
If the noise parameter `noise_params` is omitted the ore will occur from y_min
1216+
to y_max in a simple horizontal stratum.
1217+
1218+
A parameter `stratum_thickness` can be provided instead of the noise parameter
1219+
`np_stratum_thickness`, to create a constant thickness.
1220+
1221+
Leaving out one or both noise parameters makes the ore generation less intensive,
1222+
useful when adding multiple strata.
1223+
12151224
`y_min` and `y_max` define the limits of the ore generation and for performance
12161225
reasons should be set as close together as possible but without clipping the
12171226
stratum's Y variation.
12181227

1219-
If either of the 2 noise parameters are omitted the ore will occur from y_min
1220-
to y_max in a simple horizontal stratum. As this does not compute noise
1221-
performance improves, and is ideal for placing many layers.
1222-
12231228
Each node in the stratum has a 1-in-`clust_scarcity` chance of being ore, so a
12241229
solid-ore stratum would require a `clust_scarcity` of 1.
12251230

@@ -4880,7 +4885,6 @@ Definition tables
48804885
},
48814886
-- ^ See 'Ore types' section above.
48824887
-- ^ The above 2 parameters are only valid for "puff" ore.
4883-
-- ^ Additional noise parameters needed for "puff" ore.
48844888
random_factor = 1.0,
48854889
-- ^ See 'Ore types' section above.
48864890
-- ^ Only valid for "vein" ore.
@@ -4892,9 +4896,9 @@ Definition tables
48924896
octaves = 3,
48934897
persist = 0.7
48944898
},
4899+
stratum_thickness = 8,
48954900
-- ^ See 'Ore types' section above.
4896-
-- ^ Only valid for "stratum" ore.
4897-
-- ^ Additional noise parameter needed for "stratum" ore.
4901+
-- ^ The above 2 parameters are only valid for "stratum" ore.
48984902
}
48994903

49004904
### Biome definition (`register_biome`)

Diff for: ‎src/mapgen/mg_ore.cpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,20 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed,
434434
MapNode n_ore(c_ore, 0, ore_param2);
435435

436436
if (flags & OREFLAG_USE_NOISE) {
437-
if (!(noise && noise_stratum_thickness)) {
437+
if (!noise) {
438438
int sx = nmax.X - nmin.X + 1;
439439
int sz = nmax.Z - nmin.Z + 1;
440440
noise = new Noise(&np, 0, sx, sz);
441-
noise_stratum_thickness = new Noise(&np_stratum_thickness, 0, sx, sz);
442441
}
443442
noise->perlinMap2D(nmin.X, nmin.Z);
443+
}
444+
445+
if (flags & OREFLAG_USE_NOISE2) {
446+
if (!noise_stratum_thickness) {
447+
int sx = nmax.X - nmin.X + 1;
448+
int sz = nmax.Z - nmin.Z + 1;
449+
noise_stratum_thickness = new Noise(&np_stratum_thickness, 0, sx, sz);
450+
}
444451
noise_stratum_thickness->perlinMap2D(nmin.X, nmin.Z);
445452
}
446453

@@ -458,11 +465,13 @@ void OreStratum::generate(MMVManip *vm, int mapseed, u32 blockseed,
458465
int y1;
459466

460467
if (flags & OREFLAG_USE_NOISE) {
468+
float nhalfthick = ((flags & OREFLAG_USE_NOISE2) ?
469+
noise_stratum_thickness->result[index] : (float)stratum_thickness) /
470+
2.0f;
461471
float nmid = noise->result[index];
462-
float nhalfthick = noise_stratum_thickness->result[index] / 2.0f;
463-
y0 = MYMAX(nmin.Y, nmid - nhalfthick);
472+
y0 = MYMAX(nmin.Y, ceil(nmid - nhalfthick));
464473
y1 = MYMIN(nmax.Y, nmid + nhalfthick);
465-
} else {
474+
} else { // Simple horizontal stratum
466475
y0 = nmin.Y;
467476
y1 = nmax.Y;
468477
}

Diff for: ‎src/mapgen/mg_ore.h

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class MMVManip;
3535
#define OREFLAG_PUFF_CLIFFS 0x02
3636
#define OREFLAG_PUFF_ADDITIVE 0x04
3737
#define OREFLAG_USE_NOISE 0x08
38+
#define OREFLAG_USE_NOISE2 0x10
3839

3940
enum OreType {
4041
ORE_SCATTER,
@@ -139,6 +140,7 @@ class OreStratum : public Ore {
139140

140141
NoiseParams np_stratum_thickness;
141142
Noise *noise_stratum_thickness = nullptr;
143+
u16 stratum_thickness;
142144

143145
OreStratum() = default;
144146
virtual ~OreStratum();

Diff for: ‎src/script/lua_api/l_mapgen.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ int ModApiMapgen::l_register_ore(lua_State *L)
11161116
ore->flags |= OREFLAG_USE_NOISE;
11171117
} else if (ore->NEEDS_NOISE) {
11181118
errorstream << "register_ore: specified ore type requires valid "
1119-
"noise parameters" << std::endl;
1119+
"'noise_params' parameter" << std::endl;
11201120
delete ore;
11211121
return 0;
11221122
}
@@ -1161,11 +1161,13 @@ int ModApiMapgen::l_register_ore(lua_State *L)
11611161
OreStratum *orestratum = (OreStratum *)ore;
11621162

11631163
lua_getfield(L, index, "np_stratum_thickness");
1164-
// If thickness noise missing unset 'use noise' flag
1165-
if (!read_noiseparams(L, -1, &orestratum->np_stratum_thickness))
1166-
ore->flags &= ~OREFLAG_USE_NOISE;
1164+
if (read_noiseparams(L, -1, &orestratum->np_stratum_thickness))
1165+
ore->flags |= OREFLAG_USE_NOISE2;
11671166
lua_pop(L, 1);
11681167

1168+
orestratum->stratum_thickness = getintfield_default(L, index,
1169+
"stratum_thickness", 8);
1170+
11691171
break;
11701172
}
11711173
default:

0 commit comments

Comments
 (0)
Please sign in to comment.