summaryrefslogtreecommitdiff
path: root/src/noise.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-12-10 23:35:37 -0500
committerkwolekr <kwolekr@minetest.net>2014-12-10 23:35:37 -0500
commit16baed04677a975c990c56df85a431e2c6468ec8 (patch)
tree94fcbade55f486403eaff8647da7d6dec96f43f3 /src/noise.cpp
parentdcc48976ce92dc0385037e8bf16075396bcb6943 (diff)
downloadminetest-16baed04677a975c990c56df85a431e2c6468ec8.tar.gz
minetest-16baed04677a975c990c56df85a431e2c6468ec8.tar.bz2
minetest-16baed04677a975c990c56df85a431e2c6468ec8.zip
Noise: Automatically transform noise maps if needed
Diffstat (limited to 'src/noise.cpp')
-rw-r--r--src/noise.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/noise.cpp b/src/noise.cpp
index 0d8b118aa..069c60d44 100644
--- a/src/noise.cpp
+++ b/src/noise.cpp
@@ -611,6 +611,11 @@ float *Noise::perlinMap2D(float x, float y, float *persistence_map)
g *= np.persist;
}
+ if (fabs(np.offset - 0.f) > 0.00001 || fabs(np.scale - 1.f) > 0.00001) {
+ for (size_t i = 0; i != bufsize; i++)
+ result[i] = result[i] * np.scale + np.offset;
+ }
+
return result;
}
@@ -644,6 +649,11 @@ float *Noise::perlinMap3D(float x, float y, float z, float *persistence_map)
g *= np.persist;
}
+ if (fabs(np.offset - 0.f) > 0.00001 || fabs(np.scale - 1.f) > 0.00001) {
+ for (size_t i = 0; i != bufsize; i++)
+ result[i] = result[i] * np.scale + np.offset;
+ }
+
return result;
}
@@ -675,16 +685,3 @@ void Noise::updateResults(float g, float *gmap,
}
}
}
-
-
-void Noise::transformNoiseMap()
-{
- // Because sx, sy, and sz are object members whose values may conceivably be
- // modified in other threads. gcc (at least) will consider the buffer size
- // computation as invalidated between loop comparisons, resulting in a ~2x
- // slowdown even with -O2. To prevent this, store the value in a local.
- size_t bufsize = sx * sy * sz;
- for (size_t i = 0; i != bufsize; i++)
- result[i] = result[i] * np.scale + np.offset;
-}
-