Add FastNoiseLite / general noise overhaul

- replace OpenSimplexNoise

Co-authored-by: Cory Petkovsek <tinmanjuggernaut@users.noreply.github.com>
This commit is contained in:
Hendrik Brucker
2022-03-20 14:53:45 +01:00
parent c251ea01db
commit 2a55f10e8b
26 changed files with 4084 additions and 2991 deletions

View File

@ -1,25 +0,0 @@
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>

View File

@ -1,133 +0,0 @@
diff -u orig/open-simplex-noise.c misc/open-simplex-noise.c
--- orig/open-simplex-noise.c 2018-09-14 11:11:40.049810000 +0200
+++ misc/open-simplex-noise.c 2018-09-14 11:09:39.726457000 +0200
@@ -13,6 +13,11 @@
* of any particular randomization library, so results
* will be the same when ported to other languages.
*/
+
+// -- GODOT start --
+// Modified to work without allocating memory, also removed some unused function.
+// -- GODOT end --
+
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
@@ -34,11 +39,12 @@
#define DEFAULT_SEED (0LL)
-struct osn_context {
+// -- GODOT start --
+/*struct osn_context {
int16_t *perm;
int16_t *permGradIndex3D;
-};
-
+};*/
+// -- GODOT end --
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
/*
@@ -126,7 +132,9 @@
int xi = (int) x;
return x < xi ? xi - 1 : xi;
}
-
+
+// -- GODOT start --
+/*
static int allocate_perm(struct osn_context *ctx, int nperm, int ngrad)
{
if (ctx->perm)
@@ -154,18 +162,21 @@
memcpy(ctx->perm, p, sizeof(*ctx->perm) * nelements);
for (i = 0; i < 256; i++) {
- /* Since 3D has 24 gradients, simple bitmask won't work, so precompute modulo array. */
+ // Since 3D has 24 gradients, simple bitmask won't work, so precompute modulo array.
ctx->permGradIndex3D[i] = (int16_t)((ctx->perm[i] % (ARRAYSIZE(gradients3D) / 3)) * 3);
}
return 0;
}
+*/
+// -- GODOT end --
/*
* Initializes using a permutation array generated from a 64-bit seed.
* Generates a proper permutation (i.e. doesn't merely perform N successive pair
* swaps on a base array). Uses a simple 64-bit LCG.
*/
-int open_simplex_noise(int64_t seed, struct osn_context **ctx)
+// -- GODOT start --
+int open_simplex_noise(int64_t seed, struct osn_context *ctx)
{
int rc;
int16_t source[256];
@@ -174,20 +185,9 @@
int16_t *permGradIndex3D;
int r;
- *ctx = (struct osn_context *) malloc(sizeof(**ctx));
- if (!(*ctx))
- return -ENOMEM;
- (*ctx)->perm = NULL;
- (*ctx)->permGradIndex3D = NULL;
-
- rc = allocate_perm(*ctx, 256, 256);
- if (rc) {
- free(*ctx);
- return rc;
- }
-
- perm = (*ctx)->perm;
- permGradIndex3D = (*ctx)->permGradIndex3D;
+ perm = ctx->perm;
+ permGradIndex3D = ctx->permGradIndex3D;
+// -- GODOT end --
for (i = 0; i < 256; i++)
source[i] = (int16_t) i;
@@ -206,6 +206,8 @@
return 0;
}
+// -- GODOT start --
+/*
void open_simplex_noise_free(struct osn_context *ctx)
{
if (!ctx)
@@ -220,6 +222,8 @@
}
free(ctx);
}
+*/
+// -- GODOT end --
/* 2D OpenSimplex (Simplectic) Noise. */
double open_simplex_noise2(struct osn_context *ctx, double x, double y)
diff -u orig/open-simplex-noise.h misc/open-simplex-noise.h
--- orig/open-simplex-noise.h 2018-09-14 11:11:19.659807000 +0200
+++ misc/open-simplex-noise.h 2018-09-14 11:10:05.006460000 +0200
@@ -35,11 +35,18 @@
extern "C" {
#endif
-struct osn_context;
+// -- GODOT start --
+// Modified to work without allocating memory, also removed some unused function.
-int open_simplex_noise(int64_t seed, struct osn_context **ctx);
+struct osn_context {
+ int16_t perm[256];
+ int16_t permGradIndex3D[256];
+};
+
+int open_simplex_noise(int64_t seed, struct osn_context *ctx);
+//int open_simplex_noise_init_perm(struct osn_context *ctx, int16_t p[], int nelements);
+// -- GODOT end --
void open_simplex_noise_free(struct osn_context *ctx);
-int open_simplex_noise_init_perm(struct osn_context *ctx, int16_t p[], int nelements);
double open_simplex_noise2(struct osn_context *ctx, double x, double y);
double open_simplex_noise3(struct osn_context *ctx, double x, double y, double z);
double open_simplex_noise4(struct osn_context *ctx, double x, double y, double z, double w);

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +0,0 @@
#ifndef OPEN_SIMPLEX_NOISE_H__
#define OPEN_SIMPLEX_NOISE_H__
/*
* OpenSimplex (Simplectic) Noise in C.
* Ported to C from Kurt Spencer's java implementation by Stephen M. Cameron
*
* v1.1 (October 6, 2014)
* - Ported to C
*
* v1.1 (October 5, 2014)
* - Added 2D and 4D implementations.
* - Proper gradient sets for all dimensions, from a
* dimensionally-generalizable scheme with an actual
* rhyme and reason behind it.
* - Removed default permutation array in favor of
* default seed.
* - Changed seed-based constructor to be independent
* of any particular randomization library, so results
* will be the same when ported to other languages.
*/
#if ((__GNUC_STDC_INLINE__) || (__STDC_VERSION__ >= 199901L))
#include <stdint.h>
#define INLINE inline
#elif (defined (_MSC_VER) || defined (__GNUC_GNU_INLINE__))
#include <stdint.h>
#define INLINE __inline
#else
/* ANSI C doesn't have inline or stdint.h. */
#define INLINE
#endif
#ifdef __cplusplus
extern "C" {
#endif
// -- GODOT start --
// Modified to work without allocating memory, also removed some unused function.
struct osn_context {
int16_t perm[256];
int16_t permGradIndex3D[256];
};
int open_simplex_noise(int64_t seed, struct osn_context *ctx);
//int open_simplex_noise_init_perm(struct osn_context *ctx, int16_t p[], int nelements);
// -- GODOT end --
void open_simplex_noise_free(struct osn_context *ctx);
double open_simplex_noise2(const struct osn_context *ctx, double x, double y);
double open_simplex_noise3(const struct osn_context *ctx, double x, double y, double z);
double open_simplex_noise4(const struct osn_context *ctx, double x, double y, double z, double w);
#ifdef __cplusplus
}
#endif
#endif