use double precision numbers in love.math.noise

This commit is contained in:
megagrump
2021-11-22 14:57:05 +01:00
parent 9cc98df218
commit 136c3cd277
7 changed files with 146 additions and 157 deletions
+4 -4
View File
@@ -132,12 +132,12 @@ private:
}; // Math
static inline float noise1(float x)
static inline float noise1(double x)
{
return SimplexNoise1234::noise(x) * 0.5f + 0.5f;
}
static inline float noise2(float x, float y)
static inline float noise2(double x, double y)
{
return SimplexNoise1234::noise(x, y) * 0.5f + 0.5f;
}
@@ -145,12 +145,12 @@ static inline float noise2(float x, float y)
// Perlin noise is used instead of Simplex noise in the 3D and 4D cases to avoid
// patent issues.
static inline float noise3(float x, float y, float z)
static inline float noise3(double x, double y, double z)
{
return Noise1234::noise(x, y, z) * 0.5f + 0.5f;
}
static inline float noise4(float x, float y, float z, float w)
static inline float noise4(double x, double y, double z, double w)
{
return Noise1234::noise(x, y, z, w) * 0.5f + 0.5f;
}
+6 -6
View File
@@ -319,10 +319,10 @@ int w_linearToGamma(lua_State *L)
int w_noise(lua_State *L)
{
int nargs = std::min(std::max(lua_gettop(L), 1), 4);
float args[4];
double args[4];
for (int i = 0; i < nargs; i++)
args[i] = (float) luaL_checknumber(L, i + 1);
args[i] = luaL_checknumber(L, i + 1);
float val = 0.0f;
@@ -349,10 +349,10 @@ int w_noise(lua_State *L)
// C functions in a struct, necessary for the FFI versions of math functions.
struct FFI_Math
{
float (*noise1)(float x);
float (*noise2)(float x, float y);
float (*noise3)(float x, float y, float z);
float (*noise4)(float x, float y, float z, float w);
float (*noise1)(double x);
float (*noise2)(double x, double y);
float (*noise3)(double x, double y, double z);
float (*noise4)(double x, double y, double z, double w);
float (*gammaToLinear)(float c);
float (*linearToGamma)(float c);
+4 -4
View File
@@ -93,10 +93,10 @@ if not status then return end
pcall(ffi.cdef, [[
typedef struct FFI_Math
{
float (*noise1)(float x);
float (*noise2)(float x, float y);
float (*noise3)(float x, float y, float z);
float (*noise4)(float x, float y, float z, float w);
float (*noise1)(double x);
float (*noise2)(double x, double y);
float (*noise3)(double x, double y, double z);
float (*noise4)(double x, double y, double z, double w);
float (*gammaToLinear)(float c);
float (*linearToGamma)(float c);