Skip to content

Commit

Permalink
Noise: Create a deep copy of NoiseParams
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed Dec 10, 2014
1 parent 88c2841 commit fb2bc95
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 91 deletions.
6 changes: 3 additions & 3 deletions src/mapgen_v5.cpp
Expand Up @@ -187,12 +187,12 @@ void MapgenV5Params::writeParams(Settings *settings) {
int MapgenV5::getGroundLevelAtPoint(v2s16 p) {
//TimeTaker t("getGroundLevelAtPoint", NULL, PRECISION_MICRO);

float f = 0.55 + NoisePerlin2D(noise_factor->np, p.X, p.Y, seed);
float f = 0.55 + NoisePerlin2D(&noise_factor->np, p.X, p.Y, seed);
if(f < 0.01)
f = 0.01;
else if(f >= 1.0)
f *= 1.6;
float h = water_level + NoisePerlin2D(noise_height->np, p.X, p.Y, seed);
float h = water_level + NoisePerlin2D(&noise_height->np, p.X, p.Y, seed);

s16 search_top = water_level + 15;
s16 search_base = water_level;
Expand All @@ -202,7 +202,7 @@ int MapgenV5::getGroundLevelAtPoint(v2s16 p) {

s16 level = -31000;
for (s16 y = search_top; y >= search_base; y--) {
float n_ground = NoisePerlin3DEased(noise_ground->np, p.X, y, p.Y, seed);
float n_ground = NoisePerlin3DEased(&noise_ground->np, p.X, y, p.Y, seed);
if(n_ground * f > y - h) {
if(y >= search_top - 7)
break;
Expand Down
36 changes: 18 additions & 18 deletions src/mapgen_v6.cpp
Expand Up @@ -246,13 +246,13 @@ float MapgenV6::baseTerrainLevelFromNoise(v2s16 p) {
if (flags & MG_FLAT)
return water_level;

float terrain_base = NoisePerlin2DPosOffset(noise_terrain_base->np,
float terrain_base = NoisePerlin2DPosOffset(&noise_terrain_base->np,
p.X, 0.5, p.Y, 0.5, seed);
float terrain_higher = NoisePerlin2DPosOffset(noise_terrain_higher->np,
float terrain_higher = NoisePerlin2DPosOffset(&noise_terrain_higher->np,
p.X, 0.5, p.Y, 0.5, seed);
float steepness = NoisePerlin2DPosOffset(noise_steepness->np,
float steepness = NoisePerlin2DPosOffset(&noise_steepness->np,
p.X, 0.5, p.Y, 0.5, seed);
float height_select = NoisePerlin2DNoTxfmPosOffset(noise_height_select->np,
float height_select = NoisePerlin2DNoTxfmPosOffset(&noise_height_select->np,
p.X, 0.5, p.Y, 0.5, seed);

return baseTerrainLevel(terrain_base, terrain_higher,
Expand Down Expand Up @@ -550,37 +550,37 @@ void MapgenV6::calculateNoise() {
// Need to adjust for the original implementation's +.5 offset...
if (!(flags & MG_FLAT)) {
noise_terrain_base->perlinMap2D(
x + 0.5 * noise_terrain_base->np->spread.X,
z + 0.5 * noise_terrain_base->np->spread.Z);
x + 0.5 * noise_terrain_base->np.spread.X,
z + 0.5 * noise_terrain_base->np.spread.Z);
noise_terrain_base->transformNoiseMap();

noise_terrain_higher->perlinMap2D(
x + 0.5 * noise_terrain_higher->np->spread.X,
z + 0.5 * noise_terrain_higher->np->spread.Z);
x + 0.5 * noise_terrain_higher->np.spread.X,
z + 0.5 * noise_terrain_higher->np.spread.Z);
noise_terrain_higher->transformNoiseMap();

noise_steepness->perlinMap2D(
x + 0.5 * noise_steepness->np->spread.X,
z + 0.5 * noise_steepness->np->spread.Z);
x + 0.5 * noise_steepness->np.spread.X,
z + 0.5 * noise_steepness->np.spread.Z);
noise_steepness->transformNoiseMap();

noise_height_select->perlinMap2D(
x + 0.5 * noise_height_select->np->spread.X,
z + 0.5 * noise_height_select->np->spread.Z);
x + 0.5 * noise_height_select->np.spread.X,
z + 0.5 * noise_height_select->np.spread.Z);

noise_mud->perlinMap2D(
x + 0.5 * noise_mud->np->spread.X,
z + 0.5 * noise_mud->np->spread.Z);
x + 0.5 * noise_mud->np.spread.X,
z + 0.5 * noise_mud->np.spread.Z);
noise_mud->transformNoiseMap();
}

noise_beach->perlinMap2D(
x + 0.2 * noise_beach->np->spread.X,
z + 0.7 * noise_beach->np->spread.Z);
x + 0.2 * noise_beach->np.spread.X,
z + 0.7 * noise_beach->np.spread.Z);

noise_biome->perlinMap2D(
x + 0.6 * noise_biome->np->spread.X,
z + 0.2 * noise_biome->np->spread.Z);
x + 0.6 * noise_biome->np.spread.X,
z + 0.2 * noise_biome->np.spread.Z);
}


Expand Down
26 changes: 13 additions & 13 deletions src/mapgen_v7.cpp
Expand Up @@ -173,7 +173,7 @@ int MapgenV7::getGroundLevelAtPoint(v2s16 p) {

// Ridge/river terrain calculation
float width = 0.3;
float uwatern = NoisePerlin2DNoTxfm(noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
float uwatern = NoisePerlin2DNoTxfm(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
// actually computing the depth of the ridge is much more expensive;
// if inside a river, simply guess
if (uwatern >= -width && uwatern <= width)
Expand Down Expand Up @@ -305,26 +305,26 @@ void MapgenV7::calculateNoise() {


Biome *MapgenV7::getBiomeAtPoint(v3s16 p) {
float heat = NoisePerlin2D(noise_heat->np, p.X, p.Z, seed);
float humidity = NoisePerlin2D(noise_humidity->np, p.X, p.Z, seed);
float heat = NoisePerlin2D(&noise_heat->np, p.X, p.Z, seed);
float humidity = NoisePerlin2D(&noise_humidity->np, p.X, p.Z, seed);
s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Z);

return bmgr->getBiome(heat, humidity, groundlevel);
}

//needs to be updated
float MapgenV7::baseTerrainLevelAtPoint(int x, int z) {
float hselect = NoisePerlin2D(noise_height_select->np, x, z, seed);
float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed);
hselect = rangelim(hselect, 0.0, 1.0);

float persist = NoisePerlin2D(noise_terrain_persist->np, x, z, seed);
float persist = NoisePerlin2D(&noise_terrain_persist->np, x, z, seed);
persist = rangelim(persist, 0.4, 0.9);

noise_terrain_base->np->persist = persist;
float height_base = NoisePerlin2D(noise_terrain_base->np, x, z, seed);
noise_terrain_base->np.persist = persist;
float height_base = NoisePerlin2D(&noise_terrain_base->np, x, z, seed);

noise_terrain_alt->np->persist = persist;
float height_alt = NoisePerlin2D(noise_terrain_alt->np, x, z, seed);
noise_terrain_alt->np.persist = persist;
float height_alt = NoisePerlin2D(&noise_terrain_alt->np, x, z, seed);

if (height_alt > height_base)
return height_alt;
Expand All @@ -346,9 +346,9 @@ float MapgenV7::baseTerrainLevelFromMap(int index) {


bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z) {
float mnt_h_n = NoisePerlin2D(noise_mount_height->np, x, z, seed);
float mnt_h_n = NoisePerlin2D(&noise_mount_height->np, x, z, seed);
float height_modifier = -((float)y / rangelim(mnt_h_n, 80.0, 150.0));
float mnt_n = NoisePerlin3D(noise_mountain->np, x, y, z, seed);
float mnt_n = NoisePerlin3D(&noise_mountain->np, x, y, z, seed);

return mnt_n + height_modifier >= 0.6;
}
Expand All @@ -373,10 +373,10 @@ void MapgenV7::carveRivers() {
for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
float terrain_mod = noise_terrain_mod->result[index];
NoiseParams *np = noise_terrain_river->np;
np->persist = noise_terrain_persist->result[index];
np.persist = noise_terrain_persist->result[index];
float terrain_river = NoisePerlin2DNoTxfm(np, x, z, seed);
float height = terrain_river * (1 - abs(terrain_mod)) *
noise_terrain_river->np->scale;
noise_terrain_river->np.scale;
height = log(height * height); //log(h^3) is pretty interesting for terrain

s16 y = heightmap[index];
Expand Down
20 changes: 4 additions & 16 deletions src/mg_ore.cpp
Expand Up @@ -56,19 +56,6 @@ size_t OreManager::placeAllOres(Mapgen *mg, u32 seed, v3s16 nmin, v3s16 nmax)

///////////////////////////////////////////////////////////////////////////////

Ore::Ore()
{
c_ore = CONTENT_IGNORE;
np = NULL;
noise = NULL;
}

Ore::~Ore()
{
delete np;
delete noise;
}


size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
{
Expand Down Expand Up @@ -117,7 +104,8 @@ void OreScatter::generate(ManualMapVoxelManipulator *vm, int seed,
int y0 = pr.range(nmin.Y, nmax.Y - csize + 1);
int z0 = pr.range(nmin.Z, nmax.Z - csize + 1);

if (np && (NoisePerlin3D(np, x0, y0, z0, seed) < nthresh))
if ((flags & OREFLAG_USE_NOISE) &&
(NoisePerlin3D(&np, x0, y0, z0, seed) < nthresh))
continue;

for (int z1 = 0; z1 != csize; z1++)
Expand Down Expand Up @@ -148,7 +136,7 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
if (!noise) {
int sx = nmax.X - nmin.X + 1;
int sz = nmax.Z - nmin.Z + 1;
noise = new Noise(np, 0, sx, sz);
noise = new Noise(&np, seed, sx, sz);
}
noise->seed = seed + y_start;
noise->perlinMap2D(nmin.X, nmin.Z);
Expand All @@ -161,7 +149,7 @@ void OreSheet::generate(ManualMapVoxelManipulator *vm, int seed,
continue;

int height = max_height * (1. / pr.range(1, 3));
int y0 = y_start + np->scale * noiseval; //pr.range(1, 3) - 1;
int y0 = y_start + np.scale * noiseval; //pr.range(1, 3) - 1;
int y1 = y0 + height;
for (int y = y0; y != y1; y++) {
u32 i = vm->m_area.index(x, y, z);
Expand Down
17 changes: 11 additions & 6 deletions src/mg_ore.h
Expand Up @@ -40,6 +40,8 @@ class ManualMapVoxelManipulator;
// nodes isn't the specified node
#define OREFLAG_NODEISNT 0x04 // not yet implemented

#define OREFLAG_USE_NOISE 0x08

#define ORE_RANGE_ACTUAL 1
#define ORE_RANGE_MIRROR 2

Expand All @@ -54,6 +56,8 @@ extern FlagDesc flagdesc_ore[];

class Ore : public GenElement {
public:
static const bool NEEDS_NOISE = false;

content_t c_ore; // the node to place
std::vector<content_t> c_wherein; // the nodes to be placed in
u32 clust_scarcity; // ore cluster has a 1-in-clust_scarcity chance of appearing at a node
Expand All @@ -64,25 +68,26 @@ class Ore : public GenElement {
u8 ore_param2; // to set node-specific attributes
u32 flags; // attributes for this ore
float nthresh; // threshhold for noise at which an ore is placed
NoiseParams *np; // noise for distribution of clusters (NULL for uniform scattering)
NoiseParams np; // noise for distribution of clusters (NULL for uniform scattering)
Noise *noise;

Ore();
virtual ~Ore();

size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax) = 0;
};

class OreScatter : public Ore {
virtual ~OreScatter() {}
public:
static const bool NEEDS_NOISE = false;

virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax);
};

class OreSheet : public Ore {
virtual ~OreSheet() {}
public:
static const bool NEEDS_NOISE = true;

virtual void generate(ManualMapVoxelManipulator *vm, int seed,
u32 blockseed, v3s16 nmin, v3s16 nmax);
};
Expand Down

0 comments on commit fb2bc95

Please sign in to comment.