X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fmg_ore.cpp;h=c62f05860edb72078c98bfcb2e88630d75b2df9c;hb=fd70f4f2f040b64064676706e41d6da90c2b00db;hp=2c5712da7f2c1c578484fd748845293c002bd195;hpb=900fa26965a2fbdf2b9de74e2d680c083de91482;p=minetest.git diff --git a/src/mg_ore.cpp b/src/mg_ore.cpp index 2c5712da7..c62f05860 100644 --- a/src/mg_ore.cpp +++ b/src/mg_ore.cpp @@ -27,10 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc., const char *OreManager::ELEMENT_TITLE = "ore"; FlagDesc flagdesc_ore[] = { - {"absheight", OREFLAG_ABSHEIGHT}, - {"scatter_noisedensity", OREFLAG_DENSITY}, - {"claylike_nodeisnt", OREFLAG_NODEISNT}, - {NULL, 0} + {"absheight", OREFLAG_ABSHEIGHT}, + {NULL, 0} }; @@ -43,7 +41,7 @@ OreManager::OreManager(IGameDef *gamedef) : } -size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax) +size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) { size_t nplaced = 0; @@ -52,8 +50,8 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax) if (!ore) continue; - nplaced += ore->placeOre(mg, seed, nmin, nmax); - seed++; + nplaced += ore->placeOre(mg, blockseed, nmin, nmax); + blockseed++; } return nplaced; @@ -97,25 +95,25 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) { int in_range = 0; - in_range |= (nmin.Y <= height_max && nmax.Y >= height_min); + in_range |= (nmin.Y <= y_max && nmax.Y >= y_min); if (flags & OREFLAG_ABSHEIGHT) - in_range |= (nmin.Y >= -height_max && nmax.Y <= -height_min) << 1; + in_range |= (nmin.Y >= -y_max && nmax.Y <= -y_min) << 1; if (!in_range) return 0; - int ymin, ymax; + int actual_ymin, actual_ymax; if (in_range & ORE_RANGE_MIRROR) { - ymin = MYMAX(nmin.Y, -height_max); - ymax = MYMIN(nmax.Y, -height_min); + actual_ymin = MYMAX(nmin.Y, -y_max); + actual_ymax = MYMIN(nmax.Y, -y_min); } else { - ymin = MYMAX(nmin.Y, height_min); - ymax = MYMIN(nmax.Y, height_max); + actual_ymin = MYMAX(nmin.Y, y_min); + actual_ymax = MYMIN(nmax.Y, y_max); } - if (clust_size >= ymax - ymin + 1) + if (clust_size >= actual_ymax - actual_ymin + 1) return 0; - nmin.Y = ymin; - nmax.Y = ymax; + nmin.Y = actual_ymin; + nmax.Y = actual_ymax; generate(mg->vm, mg->seed, blockseed, nmin, nmax); return 1; @@ -125,8 +123,8 @@ size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax) /////////////////////////////////////////////////////////////////////////////// -void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed, - u32 blockseed, v3s16 nmin, v3s16 nmax) +void OreScatter::generate(MMVManip *vm, int mapseed, u32 blockseed, + v3s16 nmin, v3s16 nmax) { PseudoRandom pr(blockseed); MapNode n_ore(c_ore, 0, ore_param2); @@ -144,7 +142,7 @@ void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed, int z0 = pr.range(nmin.Z, nmax.Z - csize + 1); if ((flags & OREFLAG_USE_NOISE) && - (NoisePerlin3D(&np, x0, y0, z0, seed) < nthresh)) + (NoisePerlin3D(&np, x0, y0, z0, mapseed) < nthresh)) continue; for (int z1 = 0; z1 != csize; z1++) @@ -166,8 +164,8 @@ void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed, /////////////////////////////////////////////////////////////////////////////// -void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed, - u32 blockseed, v3s16 nmin, v3s16 nmax) +void OreSheet::generate(MMVManip *vm, int mapseed, u32 blockseed, + v3s16 nmin, v3s16 nmax) { PseudoRandom pr(blockseed + 4234); MapNode n_ore(c_ore, 0, ore_param2); @@ -180,7 +178,7 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed, int sz = nmax.Z - nmin.Z + 1; noise = new Noise(&np, 0, sx, sz); } - noise->seed = seed + y_start; + noise->seed = mapseed + y_start; noise->perlinMap2D(nmin.X, nmin.Z); size_t index = 0; @@ -208,7 +206,7 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed, /////////////////////////////////////////////////////////////////////////////// -void OreBlob::generate(ManualMapVoxelManipulator *vm, int seed, u32 blockseed, +void OreBlob::generate(MMVManip *vm, int mapseed, u32 blockseed, v3s16 nmin, v3s16 nmax) { PseudoRandom pr(blockseed + 2404); @@ -217,11 +215,11 @@ void OreBlob::generate(ManualMapVoxelManipulator *vm, int seed, u32 blockseed, int volume = (nmax.X - nmin.X + 1) * (nmax.Y - nmin.Y + 1) * (nmax.Z - nmin.Z + 1); - int csize = clust_size; + int csize = clust_size; int nblobs = volume / clust_scarcity; if (!noise) - noise = new Noise(&np, seed, csize, csize, csize); + noise = new Noise(&np, mapseed, csize, csize, csize); for (int i = 0; i != nblobs; i++) { int x0 = pr.range(nmin.X, nmax.X - csize + 1); @@ -261,3 +259,61 @@ void OreBlob::generate(ManualMapVoxelManipulator *vm, int seed, u32 blockseed, } } } + + +/////////////////////////////////////////////////////////////////////////////// + +OreVein::OreVein() +{ + noise2 = NULL; +} + + +OreVein::~OreVein() +{ + delete noise2; +} + + +void OreVein::generate(MMVManip *vm, int mapseed, u32 blockseed, + v3s16 nmin, v3s16 nmax) +{ + PseudoRandom pr(blockseed + 520); + MapNode n_ore(c_ore, 0, ore_param2); + + if (!noise) { + int sx = nmax.X - nmin.X + 1; + int sy = nmax.Y - nmin.Y + 1; + int sz = nmax.Z - nmin.Z + 1; + noise = new Noise(&np, mapseed, sx, sy, sz); + noise2 = new Noise(&np, mapseed + 436, sx, sy, sz); + } + bool noise_generated = false; + + size_t index = 0; + for (int z = nmin.Z; z <= nmax.Z; z++) + for (int y = nmin.Y; y <= nmax.Y; y++) + for (int x = nmin.X; x <= nmax.X; x++, index++) { + u32 i = vm->m_area.index(x, y, z); + if (!vm->m_area.contains(i)) + continue; + if (!CONTAINS(c_wherein, vm->m_data[i].getContent())) + continue; + + // Same lazy generation optimization as in OreBlob + if (!noise_generated) { + noise_generated = true; + noise->perlinMap3D(nmin.X, nmin.Y, nmin.Z); + noise2->perlinMap3D(nmin.X, nmin.Y, nmin.Z); + } + + // randval ranges from -1..1 + float randval = (float)pr.next() / (PSEUDORANDOM_MAX / 2) - 1.f; + float noiseval = contour(noise->result[index]); + float noiseval2 = contour(noise2->result[index]); + if (noiseval * noiseval2 + randval * random_factor < nthresh) + continue; + + vm->m_data[i] = n_ore; + } +}