]> git.lizzy.rs Git - minetest.git/blobdiff - src/noise.h
Android: Segmentation fault fix, PendingIntent flag, and other fixes (#12960)
[minetest.git] / src / noise.h
index 53cab5754def2ad26ff709a064b5d5d81b9971e3..ee8efea8306dde1d0eeb1925ccc634cbf72fe825 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef NOISE_HEADER
-#define NOISE_HEADER
+#pragma once
 
 #include "irr_v3d.h"
 #include "exceptions.h"
 #include "util/string.h"
 
+#if defined(RANDOM_MIN)
+#undef RANDOM_MIN
+#endif
+#if defined(RANDOM_MAX)
+#undef RANDOM_MAX
+#endif
+
 extern FlagDesc flagdesc_noiseparams[];
 
 // Note: this class is not polymorphic so that its high level of
@@ -60,7 +66,7 @@ class PseudoRandom {
                        throw PrngException("Invalid range (max < min)");
                /*
                Here, we ensure the range is not too large relative to RANDOM_MAX,
-               as otherwise the effects of bias would become noticable.  Unlike
+               as otherwise the effects of bias would become noticeable.  Unlike
                PcgRandom, we cannot modify this RNG's range as it would change the
                output of this RNG for reverse compatibility.
                */
@@ -113,7 +119,7 @@ struct NoiseParams {
 
        NoiseParams() = default;
 
-       NoiseParams(float offset_, float scale_, v3f spread_, s32 seed_,
+       NoiseParams(float offset_, float scale_, const v3f &spread_, s32 seed_,
                u16 octaves_, float persist_, float lacunarity_,
                u32 flags_=NOISE_FLAG_DEFAULTS)
        {
@@ -140,7 +146,7 @@ class Noise {
        float *persist_buf = nullptr;
        float *result = nullptr;
 
-       Noise(NoiseParams *np, s32 seed, u32 sx, u32 sy, u32 sz=1);
+       Noise(const NoiseParams *np, s32 seed, u32 sx, u32 sy, u32 sz=1);
        ~Noise();
 
        void setSize(u32 sx, u32 sy, u32 sz=1);
@@ -181,12 +187,13 @@ class Noise {
 private:
        void allocBuffers();
        void resizeNoiseBuf(bool is3d);
-       void updateResults(float g, float *gmap, float *persistence_map, size_t bufsize);
+       void updateResults(float g, float *gmap, const float *persistence_map,
+                       size_t bufsize);
 
 };
 
-float NoisePerlin2D(NoiseParams *np, float x, float y, s32 seed);
-float NoisePerlin3D(NoiseParams *np, float x, float y, float z, s32 seed);
+float NoisePerlin2D(const NoiseParams *np, float x, float y, s32 seed);
+float NoisePerlin3D(const NoiseParams *np, float x, float y, float z, s32 seed);
 
 inline float NoisePerlin2D_PO(NoiseParams *np, float x, float xoff,
        float y, float yoff, s32 seed)
@@ -217,21 +224,9 @@ float noise3d_gradient(float x, float y, float z, s32 seed, bool eased=false);
 float noise2d_perlin(float x, float y, s32 seed,
                int octaves, float persistence, bool eased=true);
 
-float noise2d_perlin_abs(float x, float y, s32 seed,
-               int octaves, float persistence, bool eased=true);
-
-float noise3d_perlin(float x, float y, float z, s32 seed,
-               int octaves, float persistence, bool eased=false);
-
-float noise3d_perlin_abs(float x, float y, float z, s32 seed,
-               int octaves, float persistence, bool eased=false);
-
 inline float easeCurve(float t)
 {
        return t * t * t * (t * (6.f * t - 15.f) + 10.f);
 }
 
 float contour(float v);
-
-#endif
-