]> git.lizzy.rs Git - minetest.git/blobdiff - src/noise.h
Fix MapgenV6::getGroundLevelAtPoint()
[minetest.git] / src / noise.h
index 0ab162b73a9f504e135cf107c382dbd976aaab05..e725b4e4791b2580ccd995a2501ec26ef2ebffa7 100644 (file)
@@ -70,6 +70,10 @@ struct NoiseParams {
 };
 
 
+// Convenience macros for getting/setting NoiseParams in Settings
+#define getNoiseParams(x) getStruct<NoiseParams>((x), "f,f,v3,s32,s32,f")
+#define setNoiseParams(x, y) setStruct((x), "f,f,v3,s32,s32,f", (y))
+
 class Noise {
 public:
        NoiseParams *np;
@@ -85,6 +89,13 @@ class Noise {
        Noise(NoiseParams *np, int seed, int sx, int sy, int sz);
        ~Noise();
 
+       void init(NoiseParams *np, int seed, int sx, int sy, int sz);
+       void setSize(int sx, int sy);
+       void setSize(int sx, int sy, int sz);
+       void setSpreadFactor(v3f spread);
+       void setOctaves(int octaves);
+       void resizeNoiseBuf(bool is3d);
+
        void gradientMap2D(
                float x, float y,
                float step_x, float step_y,
@@ -121,9 +132,33 @@ inline float easeCurve(float t) {
        return t * t * t * (t * (6.f * t - 15.f) + 10.f);
 }
 
-#define NoisePerlin2D(np, x, y, s) ((np)->offset + (np)->scale * \
-               noise2d_perlin((float)(x) * (np)->spread.X, (float)(y) * (np)->spread.Y, \
+#define NoisePerlin2D(np, x, y, s) \
+               ((np)->offset + (np)->scale * noise2d_perlin( \
+               (float)(x) / (np)->spread.X, \
+               (float)(y) / (np)->spread.Y, \
                (s) + (np)->seed, (np)->octaves, (np)->persist))
 
+#define NoisePerlin2DNoTxfm(np, x, y, s) \
+               (noise2d_perlin( \
+               (float)(x) / (np)->spread.X, \
+               (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin2DPosOffset(np, x, xoff, y, yoff, s) \
+               ((np)->offset + (np)->scale * noise2d_perlin( \
+               (float)(xoff) + (float)(x) / (np)->spread.X, \
+               (float)(yoff) + (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin2DNoTxfmPosOffset(np, x, xoff, y, yoff, s) \
+               (noise2d_perlin( \
+               (float)(xoff) + (float)(x) / (np)->spread.X, \
+               (float)(yoff) + (float)(y) / (np)->spread.Y, \
+               (s) + (np)->seed, (np)->octaves, (np)->persist))
+
+#define NoisePerlin3D(np, x, y, z, s) ((np)->offset + (np)->scale * \
+               noise2d_perlin((float)(x) / (np)->spread.X, (float)(y) / (np)->spread.Y, \
+               (float)(z) / (np)->spread.Z, (s) + (np)->seed, (np)->octaves, (np)->persist))
+
 #endif