diff options
| author | Mel <einebeere@gmail.com> | 2023-07-08 03:25:44 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2023-07-08 03:25:44 +0200 |
| commit | fe2baedc760c2f29e2c720f6b1132a2de33c5430 (patch) | |
| tree | dfbe1c72a17805a3cab6e0d47433e9021890c9ca /src/Math/Random.hpp | |
| parent | 41fbca10f6c6cdd9c1623f1347e7ecb40f5e7f59 (diff) | |
| download | meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.tar.zst meowcraft-fe2baedc760c2f29e2c720f6b1132a2de33c5430.zip | |
Use own size types
Diffstat (limited to 'src/Math/Random.hpp')
| -rw-r--r-- | src/Math/Random.hpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Math/Random.hpp b/src/Math/Random.hpp index ab94871..d363694 100644 --- a/src/Math/Random.hpp +++ b/src/Math/Random.hpp @@ -1,27 +1,27 @@ #pragma once -#include "array" +#include <array> #include "Common.hpp" namespace Math::Random { -std::array<uint8_t, 4> break_float(float f); -float to_float(uint8_t u); +std::array<U8, 4> break_float(F32 f); +F32 to_float(U8 u); -uint8_t hash(uint8_t x); +U8 hash(U8 x); -float random(); +Real random(); -template <size_t D> +template <USize D> struct Noise { - float at(Vector<D> pos) const { - uint8_t to_hash[D * 4]; - for (int i = 0; i < D; i++) { + Real at(Vector<D> pos) const { + U8 to_hash[D * 4]; + for (Int i = 0; i < D; i++) { auto b = break_float(pos[i]); to_hash[i*4] = b[0]; to_hash[i*4+1] = b[1]; to_hash[i*4+2] = b[2]; to_hash[i*4+3] = b[3]; } - uint8_t h = 0; - for (int i = 0; i < D * 4; i++) { + U8 h = 0; + for (Int i = 0; i < D * 4; i++) { h = hash(h) + to_hash[i]; } return to_float(h); |
