mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Use double-precision on all noise-related functions.
This commit is contained in:
@@ -83,14 +83,14 @@ float linearToGamma(float c);
|
||||
*
|
||||
* @return Noise value in the range of [0, 1].
|
||||
**/
|
||||
static float simplexNoise1(double x);
|
||||
static float simplexNoise2(double x, double y);
|
||||
static float simplexNoise3(double x, double y, double z);
|
||||
static float simplexNoise4(double x, double y, double z, double w);
|
||||
static float perlinNoise1(double x);
|
||||
static float perlinNoise2(double x, double y);
|
||||
static float perlinNoise3(double x, double y, double z);
|
||||
static float perlinNoise4(double x, double y, double z, double w);
|
||||
static double simplexNoise1(double x);
|
||||
static double simplexNoise2(double x, double y);
|
||||
static double simplexNoise3(double x, double y, double z);
|
||||
static double simplexNoise4(double x, double y, double z, double w);
|
||||
static double perlinNoise1(double x);
|
||||
static double perlinNoise2(double x, double y);
|
||||
static double perlinNoise3(double x, double y, double z);
|
||||
static double perlinNoise4(double x, double y, double z, double w);
|
||||
|
||||
|
||||
class Math : public Module
|
||||
@@ -136,44 +136,44 @@ private:
|
||||
}; // Math
|
||||
|
||||
|
||||
static inline float simplexNoise1(double x)
|
||||
static inline double simplexNoise1(double x)
|
||||
{
|
||||
return SimplexNoise1234::noise(x) * 0.5f + 0.5f;
|
||||
return SimplexNoise1234::noise(x) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float simplexNoise2(double x, double y)
|
||||
static inline double simplexNoise2(double x, double y)
|
||||
{
|
||||
return SimplexNoise1234::noise(x, y) * 0.5f + 0.5f;
|
||||
return SimplexNoise1234::noise(x, y) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float simplexNoise3(double x, double y, double z)
|
||||
static inline double simplexNoise3(double x, double y, double z)
|
||||
{
|
||||
return SimplexNoise1234::noise(x, y, z) * 0.5f + 0.5f;
|
||||
return SimplexNoise1234::noise(x, y, z) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float simplexNoise4(double x, double y, double z, double w)
|
||||
static inline double simplexNoise4(double x, double y, double z, double w)
|
||||
{
|
||||
return SimplexNoise1234::noise(x, y, z, w) * 0.5f + 0.5f;
|
||||
return SimplexNoise1234::noise(x, y, z, w) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float perlinNoise1(double x)
|
||||
static inline double perlinNoise1(double x)
|
||||
{
|
||||
return Noise1234::noise(x) * 0.5f + 0.5f;
|
||||
return Noise1234::noise(x) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float perlinNoise2(double x, double y)
|
||||
static inline double perlinNoise2(double x, double y)
|
||||
{
|
||||
return Noise1234::noise(x, y) * 0.5f + 0.5f;
|
||||
return Noise1234::noise(x, y) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float perlinNoise3(double x, double y, double z)
|
||||
static inline double perlinNoise3(double x, double y, double z)
|
||||
{
|
||||
return Noise1234::noise(x, y, z) * 0.5f + 0.5f;
|
||||
return Noise1234::noise(x, y, z) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
static inline float perlinNoise4(double x, double y, double z, double w)
|
||||
static inline double perlinNoise4(double x, double y, double z, double w)
|
||||
{
|
||||
return Noise1234::noise(x, y, z, w) * 0.5f + 0.5f;
|
||||
return Noise1234::noise(x, y, z, w) * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
} // math
|
||||
|
||||
@@ -326,7 +326,7 @@ int w_noise(lua_State *L)
|
||||
for (int i = 0; i < nargs; i++)
|
||||
args[i] = luaL_checknumber(L, i + 1);
|
||||
|
||||
float val = 0.0f;
|
||||
double val = 0.0;
|
||||
|
||||
switch (nargs)
|
||||
{
|
||||
@@ -356,7 +356,7 @@ int w_perlinNoise(lua_State* L)
|
||||
for (int i = 0; i < nargs; i++)
|
||||
args[i] = luaL_checknumber(L, i + 1);
|
||||
|
||||
float val = 0.0f;
|
||||
double val = 0.0;
|
||||
|
||||
switch (nargs)
|
||||
{
|
||||
@@ -386,7 +386,7 @@ int w_simplexNoise(lua_State* L)
|
||||
for (int i = 0; i < nargs; i++)
|
||||
args[i] = luaL_checknumber(L, i + 1);
|
||||
|
||||
float val = 0.0f;
|
||||
double val = 0.0;
|
||||
|
||||
switch (nargs)
|
||||
{
|
||||
@@ -411,14 +411,14 @@ int w_simplexNoise(lua_State* L)
|
||||
// C functions in a struct, necessary for the FFI versions of math functions.
|
||||
struct FFI_Math
|
||||
{
|
||||
float (*snoise1)(double x);
|
||||
float (*snoise2)(double x, double y);
|
||||
float (*snoise3)(double x, double y, double z);
|
||||
float (*snoise4)(double x, double y, double z, double w);
|
||||
float (*pnoise1)(double x);
|
||||
float (*pnoise2)(double x, double y);
|
||||
float (*pnoise3)(double x, double y, double z);
|
||||
float (*pnoise4)(double x, double y, double z, double w);
|
||||
double (*snoise1)(double x);
|
||||
double (*snoise2)(double x, double y);
|
||||
double (*snoise3)(double x, double y, double z);
|
||||
double (*snoise4)(double x, double y, double z, double w);
|
||||
double (*pnoise1)(double x);
|
||||
double (*pnoise2)(double x, double y);
|
||||
double (*pnoise3)(double x, double y, double z);
|
||||
double (*pnoise4)(double x, double y, double z, double w);
|
||||
|
||||
float (*gammaToLinear)(float c);
|
||||
float (*linearToGamma)(float c);
|
||||
|
||||
@@ -93,14 +93,14 @@ if not status then return end
|
||||
pcall(ffi.cdef, [[
|
||||
typedef struct FFI_Math
|
||||
{
|
||||
float (*snoise1)(double x);
|
||||
float (*snoise2)(double x, double y);
|
||||
float (*snoise3)(double x, double y, double z);
|
||||
float (*snoise4)(double x, double y, double z, double w);
|
||||
float (*pnoise1)(double x);
|
||||
float (*pnoise2)(double x, double y);
|
||||
float (*pnoise3)(double x, double y, double z);
|
||||
float (*pnoise4)(double x, double y, double z, double w);
|
||||
double (*snoise1)(double x);
|
||||
double (*snoise2)(double x, double y);
|
||||
double (*snoise3)(double x, double y, double z);
|
||||
double (*snoise4)(double x, double y, double z, double w);
|
||||
double (*pnoise1)(double x);
|
||||
double (*pnoise2)(double x, double y);
|
||||
double (*pnoise3)(double x, double y, double z);
|
||||
double (*pnoise4)(double x, double y, double z, double w);
|
||||
|
||||
float (*gammaToLinear)(float c);
|
||||
float (*linearToGamma)(float c);
|
||||
@@ -108,7 +108,7 @@ typedef struct FFI_Math
|
||||
]])
|
||||
|
||||
local ffifuncs = ffi.cast("FFI_Math **", ffifuncspointer_str)[0]
|
||||
|
||||
local love = require("love")
|
||||
|
||||
-- Overwrite some regular love.math functions with FFI implementations.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user