]> git.lizzy.rs Git - minetest.git/blobdiff - src/noise.h
dofile error reporting for syntax errors
[minetest.git] / src / noise.h
index d2287835ea9966dd618602c683e782e1f186cef1..0e4252dd42a5261c436120c625fe7efb103f6cd9 100644 (file)
@@ -26,8 +26,8 @@
 #ifndef NOISE_HEADER
 #define NOISE_HEADER
 
-#include "debug.h"
 #include "irr_v3d.h"
+#include "exceptions.h"
 #include "util/string.h"
 
 extern FlagDesc flagdesc_noiseparams[];
@@ -56,14 +56,16 @@ class PseudoRandom {
 
        inline int range(int min, int max)
        {
-               assert(max >= min);
+               if (max < min)
+                       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
                PcgRandom, we cannot modify this RNG's range as it would change the
                output of this RNG for reverse compatibility.
                */
-               assert((u32)(max - min) <= (RANDOM_RANGE + 1) / 10);
+               if ((u32)(max - min) > (RANDOM_RANGE + 1) / 10)
+                       throw PrngException("Range too large");
 
                return (next() % (max - min + 1)) + min;
        }
@@ -147,18 +149,18 @@ class Noise {
 public:
        NoiseParams np;
        int seed;
-       int sx;
-       int sy;
-       int sz;
+       u32 sx;
+       u32 sy;
+       u32 sz;
        float *noise_buf;
        float *gradient_buf;
        float *persist_buf;
        float *result;
 
-       Noise(NoiseParams *np, int seed, int sx, int sy, int sz=1);
+       Noise(NoiseParams *np, int seed, u32 sx, u32 sy, u32 sz=1);
        ~Noise();
 
-       void setSize(int sx, int sy, int sz=1);
+       void setSize(u32 sx, u32 sy, u32 sz=1);
        void setSpreadFactor(v3f spread);
        void setOctaves(int octaves);