open-simplex-noise.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef OPEN_SIMPLEX_NOISE_H__
  2. #define OPEN_SIMPLEX_NOISE_H__
  3. /*
  4. * OpenSimplex (Simplectic) Noise in C.
  5. * Ported to C from Kurt Spencer's java implementation by Stephen M. Cameron
  6. *
  7. * v1.1 (October 6, 2014)
  8. * - Ported to C
  9. *
  10. * v1.1 (October 5, 2014)
  11. * - Added 2D and 4D implementations.
  12. * - Proper gradient sets for all dimensions, from a
  13. * dimensionally-generalizable scheme with an actual
  14. * rhyme and reason behind it.
  15. * - Removed default permutation array in favor of
  16. * default seed.
  17. * - Changed seed-based constructor to be independent
  18. * of any particular randomization library, so results
  19. * will be the same when ported to other languages.
  20. */
  21. #if ((__GNUC_STDC_INLINE__) || (__STDC_VERSION__ >= 199901L))
  22. #include <stdint.h>
  23. #define INLINE inline
  24. #elif (defined (_MSC_VER) || defined (__GNUC_GNU_INLINE__))
  25. #include <stdint.h>
  26. #define INLINE __inline
  27. #else
  28. /* ANSI C doesn't have inline or stdint.h. */
  29. #define INLINE
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. // -- GODOT start --
  35. // Modified to work without allocating memory, also removed some unused function.
  36. struct osn_context {
  37. int16_t perm[256];
  38. int16_t permGradIndex3D[256];
  39. };
  40. int open_simplex_noise(int64_t seed, struct osn_context *ctx);
  41. //int open_simplex_noise_init_perm(struct osn_context *ctx, int16_t p[], int nelements);
  42. // -- GODOT end --
  43. void open_simplex_noise_free(struct osn_context *ctx);
  44. double open_simplex_noise2(const struct osn_context *ctx, double x, double y);
  45. double open_simplex_noise3(const struct osn_context *ctx, double x, double y, double z);
  46. double open_simplex_noise4(const struct osn_context *ctx, double x, double y, double z, double w);
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif