From be2317b605d46483dca4240c6b8d0fe76ce5c114 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 2 Jun 2015 17:07:42 +1000 Subject: [PATCH] n/basis: add seed accessor method --- noise/basis/perlin.hpp | 5 +++-- noise/basis/perlin.ipp | 31 +++++++++++++++++++++---------- noise/basis/value.hpp | 6 ++++-- noise/basis/value.ipp | 29 ++++++++++++++++++++--------- noise/basis/worley.hpp | 5 +++-- noise/basis/worley.ipp | 31 +++++++++++++++++++++---------- noise/fractal/base.ipp | 12 ++++++------ tools/noise.cpp | 6 +++--- 8 files changed, 81 insertions(+), 44 deletions(-) diff --git a/noise/basis/perlin.hpp b/noise/basis/perlin.hpp index e0baabdc..60a9133a 100644 --- a/noise/basis/perlin.hpp +++ b/noise/basis/perlin.hpp @@ -27,15 +27,16 @@ namespace util { namespace noise { namespace basis { template L> struct perlin { perlin (seed_t); - perlin (); range bounds (void) const; constexpr T operator() (point<2,T>) const; - seed_t seed; + constexpr seed_t seed (void) const; + seed_t seed (seed_t); private: constexpr vector<2,T> gradient (point<2,intmax_t>) const; + seed_t m_seed; }; } } } diff --git a/noise/basis/perlin.ipp b/noise/basis/perlin.ipp index 7265cc1c..f2a0fd09 100644 --- a/noise/basis/perlin.ipp +++ b/noise/basis/perlin.ipp @@ -25,14 +25,7 @@ namespace util { namespace noise { namespace basis { /////////////////////////////////////////////////////////////////////////// template L> perlin::perlin (seed_t _seed): - seed (_seed) - { ; } - - - //------------------------------------------------------------------------- - template L> - perlin::perlin (): - seed (time (nullptr)) + m_seed (_seed) { ; } @@ -48,6 +41,24 @@ namespace util { namespace noise { namespace basis { } + //------------------------------------------------------------------------- + template L> + constexpr seed_t + perlin::seed (void) const + { + return m_seed; + } + + + //------------------------------------------------------------------------- + template L> + seed_t + perlin::seed (seed_t _seed) + { + return m_seed = _seed; + } + + //------------------------------------------------------------------------- template L> constexpr T @@ -93,8 +104,8 @@ namespace util { namespace noise { namespace basis { { using util::hash::murmur2::mix; - auto u = mix (seed, mix (uint64_t (p.x), uint64_t (p.y))); - auto v = mix (u, seed); + auto u = mix (m_seed, mix (uint64_t (p.x), uint64_t (p.y))); + auto v = mix (u, m_seed); auto r = util::vector<2,T> { (u & 0xffff) / T{0xffff}, diff --git a/noise/basis/value.hpp b/noise/basis/value.hpp index b02a8297..8b862126 100644 --- a/noise/basis/value.hpp +++ b/noise/basis/value.hpp @@ -27,15 +27,17 @@ namespace util { namespace noise { namespace basis { template > struct value { value (seed_t); - value (); range bounds (void) const; constexpr T operator() (util::point<2,T>) const; - seed_t seed; + constexpr seed_t seed (void) const; + seed_t seed (seed_t); private: constexpr T generate (point<2,intmax_t>) const; + + seed_t m_seed; }; } } } diff --git a/noise/basis/value.ipp b/noise/basis/value.ipp index 698b667e..122b0404 100644 --- a/noise/basis/value.ipp +++ b/noise/basis/value.ipp @@ -25,14 +25,7 @@ namespace util { namespace noise { namespace basis { /////////////////////////////////////////////////////////////////////////// template L> value::value (seed_t _seed): - seed (_seed) - { ; } - - - //------------------------------------------------------------------------- - template L> - value::value (): - seed (time (nullptr)) + m_seed (_seed) { ; } @@ -45,6 +38,24 @@ namespace util { namespace noise { namespace basis { } + //------------------------------------------------------------------------- + template L> + constexpr seed_t + value::seed (void) const + { + return m_seed; + } + + + //------------------------------------------------------------------------- + template L> + seed_t + value::seed (seed_t _seed) + { + return m_seed = _seed; + } + + //------------------------------------------------------------------------- template L> constexpr T @@ -87,7 +98,7 @@ namespace util { namespace noise { namespace basis { using util::hash::murmur2::mix; T v = mix ( - seed, + m_seed, mix ( uint64_t (p.y), uint64_t (p.x) diff --git a/noise/basis/worley.hpp b/noise/basis/worley.hpp index add2a95f..51f2a5bd 100644 --- a/noise/basis/worley.hpp +++ b/noise/basis/worley.hpp @@ -26,15 +26,16 @@ namespace util { namespace noise { namespace basis { template struct worley { worley (seed_t); - worley (); range bounds (void) const; constexpr T operator() (util::point<2,T>) const; - seed_t seed; + constexpr seed_t seed (void) const; + seed_t seed (seed_t); private: constexpr point<2,T> generate (point<2,intmax_t>) const; + seed_t m_seed; }; } } } diff --git a/noise/basis/worley.ipp b/noise/basis/worley.ipp index 132fe8b2..d9956049 100644 --- a/noise/basis/worley.ipp +++ b/noise/basis/worley.ipp @@ -28,14 +28,7 @@ namespace util { namespace noise { namespace basis { /////////////////////////////////////////////////////////////////////////// template worley::worley (seed_t _seed): - seed (_seed) - { ; } - - - //------------------------------------------------------------------------- - template - worley::worley (): - worley (time (nullptr)) + m_seed (_seed) { ; } @@ -48,6 +41,24 @@ namespace util { namespace noise { namespace basis { } + //------------------------------------------------------------------------- + template + constexpr seed_t + worley::seed (void) const + { + return m_seed; + } + + + //------------------------------------------------------------------------- + template + seed_t + worley::seed (seed_t _seed) + { + return m_seed = _seed; + } + + //------------------------------------------------------------------------- template constexpr T @@ -95,8 +106,8 @@ namespace util { namespace noise { namespace basis { { using util::hash::murmur2::mix; - auto u = mix (seed, mix (uint64_t (p.x), uint64_t (p.y))); - auto v = mix (u, seed); + auto u = mix (m_seed, mix (uint64_t (p.x), uint64_t (p.y))); + auto v = mix (u, m_seed); auto r = util::point<2,T> { (u & 0xffff) / T{0xffff}, diff --git a/noise/fractal/base.ipp b/noise/fractal/base.ipp index 179ee309..557743ab 100644 --- a/noise/fractal/base.ipp +++ b/noise/fractal/base.ipp @@ -90,10 +90,10 @@ namespace util { namespace noise { namespace fractal { //------------------------------------------------------------------------- - //template - //typename base::seed_t - //base::seed (seed_t _seed) - //{ - // return basis.seed (_seed); - //} + template + typename base::seed_t + base::seed (seed_t _seed) + { + return m_basis.seed (_seed); + } } } } diff --git a/tools/noise.cpp b/tools/noise.cpp index 1fb06b63..99e84e7a 100644 --- a/tools/noise.cpp +++ b/tools/noise.cpp @@ -28,18 +28,18 @@ main (void) uint64_t seed = time (nullptr); // setup the noise generator - util::noise::fractal::fbm> b (seed); + //util::noise::fractal::fbm> b (seed); //util::noise::fractal::rmf> b (seed); //util::noise::fractal::fbm> b (seed); //util::noise::fractal::rmf> b (seed); //util::noise::fractal::hmf> b (seed); - //util::noise::fractal::hetero> b (seed); + util::noise::fractal::hetero> b (seed); b.octaves (8); b.frequency (10.f / size.w); //b.lacunarity = 2.f; //b.H = 1.0f; - //b.basis.seed = time (NULL); + b.seed (seed); // generate the values. offset positions slightly to avoid simple axis issues with perlin basis {