From 9fef43951b4defeb1feb1c7d7e05c5bf9c00faf3 Mon Sep 17 00:00:00 2001 From: Remi Beges Date: Sat, 27 Oct 2012 18:59:39 +0200 Subject: [PATCH] Replaced templates by float *Since only valid template parameters were float and double, the whole template aspect has been removed. Double precision would only be used in extremely rare occasions (applications needing high precision and slow performances), it is not relevant to template the whole module for it. Former-commit-id: fc6dd028189c608a6a7b4c312b3e5e3f53a01fd7 --- include/Nazara/Noise/Abstract2DNoise.hpp | 10 ++-- include/Nazara/Noise/Abstract3DNoise.hpp | 10 ++-- include/Nazara/Noise/Abstract4DNoise.hpp | 10 ++-- include/Nazara/Noise/Abstract4DNoise.inl | 23 --------- include/Nazara/Noise/ComplexNoiseBase.hpp | 30 +++++------ include/Nazara/Noise/FBM2D.hpp | 15 ++---- include/Nazara/Noise/MappedNoiseBase.hpp | 22 ++++---- include/Nazara/Noise/Perlin2D.hpp | 21 +++----- include/Nazara/Noise/Perlin3D.hpp | 24 ++++----- include/Nazara/Noise/Perlin4D.hpp | 22 +++----- include/Nazara/Noise/Simplex2D.hpp | 27 ++++------ include/Nazara/Noise/Simplex3D.hpp | 27 ++++------ include/Nazara/Noise/Simplex4D.hpp | 27 ++++------ .../Nazara/Noise/Abstract2DNoise.cpp | 13 ++--- .../Nazara/Noise/Abstract3DNoise.cpp | 13 ++--- src/Nazara/Noise/Abstract4DNoise.cpp | 20 ++++++++ .../Nazara/Noise/ComplexNoiseBase.cpp | 38 +++++--------- .../FBM2D.inl => src/Nazara/Noise/FBM2D.cpp | 28 ++++------ .../Nazara/Noise/MappedNoiseBase.cpp | 27 ++++------ .../Nazara/Noise/Perlin2D.cpp | 23 ++++----- .../Nazara/Noise/Perlin3D.cpp | 33 ++++++------ .../Nazara/Noise/Perlin4D.cpp | 51 +++++++++---------- .../Nazara/Noise/Simplex2D.cpp | 21 ++++---- .../Nazara/Noise/Simplex3D.cpp | 23 ++++----- .../Nazara/Noise/Simplex4D.cpp | 27 +++++----- 25 files changed, 239 insertions(+), 346 deletions(-) delete mode 100644 include/Nazara/Noise/Abstract4DNoise.inl rename include/Nazara/Noise/Abstract2DNoise.inl => src/Nazara/Noise/Abstract2DNoise.cpp (52%) rename include/Nazara/Noise/Abstract3DNoise.inl => src/Nazara/Noise/Abstract3DNoise.cpp (50%) create mode 100644 src/Nazara/Noise/Abstract4DNoise.cpp rename include/Nazara/Noise/ComplexNoiseBase.inl => src/Nazara/Noise/ComplexNoiseBase.cpp (62%) rename include/Nazara/Noise/FBM2D.inl => src/Nazara/Noise/FBM2D.cpp (69%) rename include/Nazara/Noise/MappedNoiseBase.inl => src/Nazara/Noise/MappedNoiseBase.cpp (52%) rename include/Nazara/Noise/Perlin2D.inl => src/Nazara/Noise/Perlin2D.cpp (69%) rename include/Nazara/Noise/Perlin3D.inl => src/Nazara/Noise/Perlin3D.cpp (70%) rename include/Nazara/Noise/Perlin4D.inl => src/Nazara/Noise/Perlin4D.cpp (69%) rename include/Nazara/Noise/Simplex2D.inl => src/Nazara/Noise/Simplex2D.cpp (78%) rename include/Nazara/Noise/Simplex3D.inl => src/Nazara/Noise/Simplex3D.cpp (84%) rename include/Nazara/Noise/Simplex4D.inl => src/Nazara/Noise/Simplex4D.cpp (85%) diff --git a/include/Nazara/Noise/Abstract2DNoise.hpp b/include/Nazara/Noise/Abstract2DNoise.hpp index ac9e25e1b..37f035d07 100644 --- a/include/Nazara/Noise/Abstract2DNoise.hpp +++ b/include/Nazara/Noise/Abstract2DNoise.hpp @@ -10,14 +10,12 @@ #include #include -template class NzAbstract2DNoise : public NzMappedNoiseBase +class NAZARA_API NzAbstract2DNoise : public NzMappedNoiseBase { public: - T GetBasicValue(T x, T y); - T GetMappedValue(T x, T y); - virtual T GetValue(T x, T y, T resolution) = 0; + float GetBasicValue(float x, float y); + float GetMappedValue(float x, float y); + virtual float GetValue(float x, float y, float resolution) = 0; }; -#include - #endif // NAZARA_ABSTRACT2DNOISE_HPP diff --git a/include/Nazara/Noise/Abstract3DNoise.hpp b/include/Nazara/Noise/Abstract3DNoise.hpp index 5020cc7df..af1866b97 100644 --- a/include/Nazara/Noise/Abstract3DNoise.hpp +++ b/include/Nazara/Noise/Abstract3DNoise.hpp @@ -10,14 +10,12 @@ #include #include -template class NzAbstract3DNoise : public NzMappedNoiseBase +class NAZARA_API NzAbstract3DNoise : public NzMappedNoiseBase { public: - T GetBasicValue(T x, T y, T z); - T GetMappedValue(T x, T y, T z); - virtual T GetValue(T x, T y, T z, T resolution) = 0; + float GetBasicValue(float x, float y, float z); + float GetMappedValue(float x, float y, float z); + virtual float GetValue(float x, float y, float z, float resolution) = 0; }; -#include - #endif // NAZARA_ABSTRACT3DNOISE_HPP diff --git a/include/Nazara/Noise/Abstract4DNoise.hpp b/include/Nazara/Noise/Abstract4DNoise.hpp index b3969731d..e17f5cb0b 100644 --- a/include/Nazara/Noise/Abstract4DNoise.hpp +++ b/include/Nazara/Noise/Abstract4DNoise.hpp @@ -10,14 +10,12 @@ #include #include -template class NzAbstract4DNoise : public NzMappedNoiseBase +class NAZARA_API NzAbstract4DNoise : public NzMappedNoiseBase { public: - T GetBasicValue(T x, T y, T z, T w); - T GetMappedValue(T x, T y, T z, T w); - virtual T GetValue(T x, T y, T z, T w, T resolution) = 0; + float GetBasicValue(float x, float y, float z, float w); + float GetMappedValue(float x, float y, float z, float w); + virtual float GetValue(float x, float y, float z, float w, float resolution) = 0; }; -#include - #endif // NAZARA_ABSTRACT4DNOISE_HPP diff --git a/include/Nazara/Noise/Abstract4DNoise.inl b/include/Nazara/Noise/Abstract4DNoise.inl deleted file mode 100644 index 579938446..000000000 --- a/include/Nazara/Noise/Abstract4DNoise.inl +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2012 Rémi Bèges -// This file is part of the "Nazara Engine". -// For conditions of distribution and use, see copyright notice in Config.hpp - -#include -#include -#include -#include -#include - -template -T NzAbstract4DNoise::GetBasicValue(T x, T y, T z, T w) -{ - return this->GetValue(x,y,z,w,this->m_resolution); -} - -template -T NzAbstract4DNoise::GetMappedValue(T x, T y, T z, T w) -{ - return (this->GetValue(x,y,z,w,this->m_resolution) + this->m_offset) * this->m_gain ; -} - -#include diff --git a/include/Nazara/Noise/ComplexNoiseBase.hpp b/include/Nazara/Noise/ComplexNoiseBase.hpp index 9f969c1be..95ff6a6e7 100644 --- a/include/Nazara/Noise/ComplexNoiseBase.hpp +++ b/include/Nazara/Noise/ComplexNoiseBase.hpp @@ -8,33 +8,31 @@ #define COMPLEXNOISEBASE_HPP #include +#include -template -class NzComplexNoiseBase +class NAZARA_API NzComplexNoiseBase { public: NzComplexNoiseBase(); ~NzComplexNoiseBase() = default; - T GetOctaveNumber() const; - T GetLacunarity() const; - T GetHurstParameter() const; - void SetLacunarity(T lacunarity); - void SetHurstParameter(T h); - void SetOctavesNumber(T octaves); + const std::array& GetExponentArray() const; //For debug purpose + float GetHurstParameter() const; + float GetLacunarity() const; + float GetOctaveNumber() const; + void SetHurstParameter(float h); + void SetLacunarity(float lacunarity); + void SetOctavesNumber(float octaves); void RecomputeExponentArray(); protected: - T m_lacunarity; - T m_hurst; - T m_octaves; - T exponent_array[30]; - T m_sum; + float m_lacunarity; + float m_hurst; + float m_octaves; + std::array exponent_array; + float m_sum; private: bool m_parametersModified; - }; -#include - #endif // COMPLEXNOISEBASE_HPP diff --git a/include/Nazara/Noise/FBM2D.hpp b/include/Nazara/Noise/FBM2D.hpp index 0223f23f8..0f2b12e79 100644 --- a/include/Nazara/Noise/FBM2D.hpp +++ b/include/Nazara/Noise/FBM2D.hpp @@ -11,23 +11,18 @@ #include #include -template class NzFBM2D : public NzAbstract2DNoise, public NzComplexNoiseBase +class NAZARA_API NzFBM2D : public NzAbstract2DNoise, public NzComplexNoiseBase { public: NzFBM2D(nzNoises source, int seed); - T GetValue(T x, T y, T resolution); + float GetValue(float x, float y, float resolution); ~NzFBM2D(); protected: private: - NzAbstract2DNoise* m_source; - T m_value; - T m_remainder; + NzAbstract2DNoise* m_source; + float m_value; + float m_remainder; nzNoises m_noiseType; }; -typedef NzFBM2D NzFBM2Df; -typedef NzFBM2D NzFBM2Dd; - -#include - #endif // FBM2DNOISE_HPP diff --git a/include/Nazara/Noise/MappedNoiseBase.hpp b/include/Nazara/Noise/MappedNoiseBase.hpp index 5650d1cd4..b17fe4b2e 100644 --- a/include/Nazara/Noise/MappedNoiseBase.hpp +++ b/include/Nazara/Noise/MappedNoiseBase.hpp @@ -10,24 +10,22 @@ #include #include -template class NzMappedNoiseBase : public NzNoiseBase +class NAZARA_API NzMappedNoiseBase : public NzNoiseBase { public: NzMappedNoiseBase(); ~NzMappedNoiseBase() = default; - T GetGain() const; - T GetOffset() const; - T GetResolution() const; - void SetGain(T gain); - void SetOffset(T offset); - void SetResolution(T resolution); + float GetGain() const; + float GetOffset() const; + float GetResolution() const; + void SetGain(float gain); + void SetOffset(float offset); + void SetResolution(float resolution); protected: - T m_gain; - T m_offset; - T m_resolution; + float m_gain; + float m_offset; + float m_resolution; }; -#include - #endif // NAZARA_MAPPEDNOISEBASE_HPP diff --git a/include/Nazara/Noise/Perlin2D.hpp b/include/Nazara/Noise/Perlin2D.hpp index d15f7ebd7..a437020ec 100644 --- a/include/Nazara/Noise/Perlin2D.hpp +++ b/include/Nazara/Noise/Perlin2D.hpp @@ -12,28 +12,23 @@ #include #include -template class NzPerlin2D : public NzAbstract2DNoise +class NAZARA_API NzPerlin2D : public NzAbstract2DNoise { public: NzPerlin2D(); - T GetValue(T x, T y, T resolution); - virtual ~NzPerlin2D() = default; + float GetValue(float x, float y, float resolution); + ~NzPerlin2D() = default; protected: private: int x0, y0; int gi0,gi1,gi2,gi3; int ii, jj; - T gradient2[8][2]; - T s,t,u,v; - T Cx,Cy; - T Li1, Li2; - NzVector2 temp; + float gradient2[8][2]; + float s,t,u,v; + float Cx,Cy; + float Li1, Li2; + NzVector2 temp; }; -typedef NzPerlin2D NzPerlin2Df; -typedef NzPerlin2D NzPerlin2Dd; - -#include - #endif // PERLIN2D_HPP diff --git a/include/Nazara/Noise/Perlin3D.hpp b/include/Nazara/Noise/Perlin3D.hpp index d414ba6be..ada704e9d 100644 --- a/include/Nazara/Noise/Perlin3D.hpp +++ b/include/Nazara/Noise/Perlin3D.hpp @@ -12,30 +12,24 @@ #include #include -template class NzPerlin3D : public NzAbstract3DNoise +class NAZARA_API NzPerlin3D : public NzAbstract3DNoise { public: NzPerlin3D(); - T GetValue(T x, T y, T z, T resolution); + float GetValue(float x, float y, float z, float resolution); ~NzPerlin3D() = default; protected: private: int x0,y0,z0; int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7; int ii,jj,kk; - int gradient3[16][3]; - T Li1,Li2,Li3,Li4,Li5,Li6; - T s[2],t[2],u[2],v[2]; - T Cx,Cy,Cz; - T nx,ny,nz; - T tmp; - NzVector3 temp; - + float gradient3[16][3]; + float Li1,Li2,Li3,Li4,Li5,Li6; + float s[2],t[2],u[2],v[2]; + float Cx,Cy,Cz; + float nx,ny,nz; + float tmp; + NzVector3 temp; }; -typedef NzPerlin3D NzPerlin3Df; -typedef NzPerlin3D NzPerlin3Dd; - -#include - #endif // PERLIN3D_HPP diff --git a/include/Nazara/Noise/Perlin4D.hpp b/include/Nazara/Noise/Perlin4D.hpp index 52be1093e..8a04894b4 100644 --- a/include/Nazara/Noise/Perlin4D.hpp +++ b/include/Nazara/Noise/Perlin4D.hpp @@ -12,29 +12,23 @@ #include #include -template class NzPerlin4D : public NzAbstract4DNoise +class NAZARA_API NzPerlin4D : public NzAbstract4DNoise { public: NzPerlin4D(); - T GetValue(T x, T y, T z, T w, T resolution); + float GetValue(float x, float y, float z, float w, float resolution); ~NzPerlin4D() = default; protected: private: int x0,y0,z0,w0; int gi0,gi1,gi2,gi3,gi4,gi5,gi6,gi7,gi8,gi9,gi10,gi11,gi12,gi13,gi14,gi15; int ii,jj,kk,ll; - int gradient4[32][4]; - T Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14; - T s[4],t[4],u[4],v[4]; - T Cx,Cy,Cz,Cw; - T tmp; - NzVector4 temp; - + float gradient4[32][4]; + float Li1,Li2,Li3,Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12,Li13,Li14; + float s[4],t[4],u[4],v[4]; + float Cx,Cy,Cz,Cw; + float tmp; + NzVector4 temp; }; -typedef NzPerlin4D NzPerlin4Df; -typedef NzPerlin4D NzPerlin4Dd; - -#include - #endif // PERLIN4D_HPP diff --git a/include/Nazara/Noise/Simplex2D.hpp b/include/Nazara/Noise/Simplex2D.hpp index 3de0b1572..c121d0d55 100644 --- a/include/Nazara/Noise/Simplex2D.hpp +++ b/include/Nazara/Noise/Simplex2D.hpp @@ -12,33 +12,26 @@ #include #include -template class NzSimplex2D : public NzAbstract2DNoise +class NAZARA_API NzSimplex2D : public NzAbstract2DNoise { public: NzSimplex2D(); - T GetValue(T x, T y, T resolution); + float GetValue(float x, float y, float resolution); virtual ~NzSimplex2D() = default; protected: private: int ii,jj; int gi0,gi1,gi2; NzVector2i skewedCubeOrigin,off1; - T n1,n2,n3; - T c1,c2,c3; - T gradient2[8][2]; - T UnskewCoeff2D; - T SkewCoeff2D; - T sum; - NzVector2 unskewedCubeOrigin, unskewedDistToOrigin; - NzVector2 d1,d2,d3; - - + float n1,n2,n3; + float c1,c2,c3; + float gradient2[8][2]; + float UnskewCoeff2D; + float SkewCoeff2D; + float sum; + NzVector2 unskewedCubeOrigin, unskewedDistToOrigin; + NzVector2 d1,d2,d3; }; -typedef NzSimplex2D NzSimplex2Df; -typedef NzSimplex2D NzSimplex2Dd; - -#include - #endif // SIMPLEX2D_HPP diff --git a/include/Nazara/Noise/Simplex3D.hpp b/include/Nazara/Noise/Simplex3D.hpp index c90b46678..a6d636875 100644 --- a/include/Nazara/Noise/Simplex3D.hpp +++ b/include/Nazara/Noise/Simplex3D.hpp @@ -12,33 +12,26 @@ #include #include -template class NzSimplex3D : public NzAbstract3DNoise +class NAZARA_API NzSimplex3D : public NzAbstract3DNoise { public: NzSimplex3D(); - T GetValue(T x, T y, T z, T resolution); + float GetValue(float x, float y, float z, float resolution); ~NzSimplex3D() = default; protected: private: int ii,jj,kk; int gi0,gi1,gi2,gi3; NzVector3i skewedCubeOrigin,off1,off2; - T n1,n2,n3,n4; - T c1,c2,c3,c4; - T gradient3[12][3]; - T UnskewCoeff3D; - T SkewCoeff3D; - T sum; - NzVector3 unskewedCubeOrigin, unskewedDistToOrigin; - NzVector3 d1,d2,d3,d4; - - + float n1,n2,n3,n4; + float c1,c2,c3,c4; + float gradient3[12][3]; + float UnskewCoeff3D; + float SkewCoeff3D; + float sum; + NzVector3 unskewedCubeOrigin, unskewedDistToOrigin; + NzVector3 d1,d2,d3,d4; }; -typedef NzSimplex3D NzSimplex3Df; -typedef NzSimplex3D NzSimplex3Dd; - -#include - #endif // SIMPLEX3D_HPP diff --git a/include/Nazara/Noise/Simplex4D.hpp b/include/Nazara/Noise/Simplex4D.hpp index 7aea7dbb7..cf159de79 100644 --- a/include/Nazara/Noise/Simplex4D.hpp +++ b/include/Nazara/Noise/Simplex4D.hpp @@ -12,35 +12,28 @@ #include #include -template class NzSimplex4D : public NzAbstract4DNoise +class NAZARA_API NzSimplex4D : public NzAbstract4DNoise { public: NzSimplex4D(); - T GetValue(T x, T y, T z, T w, T resolution); + float GetValue(float x, float y, float z, float w, float resolution); ~NzSimplex4D() = default; protected: private: int ii,jj,kk,ll; int gi0,gi1,gi2,gi3,gi4; NzVector4i skewedCubeOrigin,off1,off2,off3; - T n1,n2,n3,n4,n5; - T c1,c2,c3,c4,c5,c6; - T gradient4[32][4]; int lookupTable4D[64][4]; int c; - T UnskewCoeff4D; - T SkewCoeff4D; - T sum; - NzVector4 unskewedCubeOrigin, unskewedDistToOrigin; - NzVector4 d1,d2,d3,d4,d5; - - + float n1,n2,n3,n4,n5; + float c1,c2,c3,c4,c5,c6; + float gradient4[32][4]; + float UnskewCoeff4D; + float SkewCoeff4D; + float sum; + NzVector4 unskewedCubeOrigin, unskewedDistToOrigin; + NzVector4 d1,d2,d3,d4,d5; }; -typedef NzSimplex4D NzSimplex4Df; -typedef NzSimplex4D NzSimplex4Dd; - -#include - #endif // SIMPLEX4D_H diff --git a/include/Nazara/Noise/Abstract2DNoise.inl b/src/Nazara/Noise/Abstract2DNoise.cpp similarity index 52% rename from include/Nazara/Noise/Abstract2DNoise.inl rename to src/Nazara/Noise/Abstract2DNoise.cpp index 98b738d36..601e94cbe 100644 --- a/include/Nazara/Noise/Abstract2DNoise.inl +++ b/src/Nazara/Noise/Abstract2DNoise.cpp @@ -7,17 +7,14 @@ #include #include #include +#include -template -T NzAbstract2DNoise::GetBasicValue(T x, T y) +float NzAbstract2DNoise::GetBasicValue(float x, float y) { - return this->GetValue(x,y,this->m_resolution); + return this->GetValue(x,y,m_resolution); } -template -T NzAbstract2DNoise::GetMappedValue(T x, T y) +float NzAbstract2DNoise::GetMappedValue(float x, float y) { - return (this->GetValue(x,y,this->m_resolution) + this->m_offset) * this->m_gain; + return (this->GetValue(x,y,m_resolution) + m_offset) * m_gain; } - -#include diff --git a/include/Nazara/Noise/Abstract3DNoise.inl b/src/Nazara/Noise/Abstract3DNoise.cpp similarity index 50% rename from include/Nazara/Noise/Abstract3DNoise.inl rename to src/Nazara/Noise/Abstract3DNoise.cpp index cc32aa556..b4914a708 100644 --- a/include/Nazara/Noise/Abstract3DNoise.inl +++ b/src/Nazara/Noise/Abstract3DNoise.cpp @@ -7,17 +7,14 @@ #include #include #include +#include -template -T NzAbstract3DNoise::GetBasicValue(T x, T y, T z) +float NzAbstract3DNoise::GetBasicValue(float x, float y, float z) { - return this->GetValue(x,y,z,this->m_resolution); + return this->GetValue(x,y,z,m_resolution); } -template -T NzAbstract3DNoise::GetMappedValue(T x, T y, T z) +float NzAbstract3DNoise::GetMappedValue(float x, float y, float z) { - return (this->GetValue(x,y,z,this->m_resolution) + this->m_offset) * this->m_gain ; + return (this->GetValue(x,y,z,m_resolution) + m_offset) * m_gain ; } - -#include diff --git a/src/Nazara/Noise/Abstract4DNoise.cpp b/src/Nazara/Noise/Abstract4DNoise.cpp new file mode 100644 index 000000000..9abf666c2 --- /dev/null +++ b/src/Nazara/Noise/Abstract4DNoise.cpp @@ -0,0 +1,20 @@ +// Copyright (C) 2012 Rémi Bèges +// This file is part of the "Nazara Engine". +// For conditions of distribution and use, see copyright notice in Config.hpp + +#include +#include +#include +#include +#include +#include + +float NzAbstract4DNoise::GetBasicValue(float x, float y, float z, float w) +{ + return this->GetValue(x,y,z,w,m_resolution); +} + +float NzAbstract4DNoise::GetMappedValue(float x, float y, float z, float w) +{ + return (this->GetValue(x,y,z,w,m_resolution) + m_offset) * m_gain ; +} diff --git a/include/Nazara/Noise/ComplexNoiseBase.inl b/src/Nazara/Noise/ComplexNoiseBase.cpp similarity index 62% rename from include/Nazara/Noise/ComplexNoiseBase.inl rename to src/Nazara/Noise/ComplexNoiseBase.cpp index 29c77e431..b3284f480 100644 --- a/include/Nazara/Noise/ComplexNoiseBase.inl +++ b/src/Nazara/Noise/ComplexNoiseBase.cpp @@ -6,12 +6,9 @@ #include #include #include +#include -#include -using namespace std; - -template -NzComplexNoiseBase::NzComplexNoiseBase() +NzComplexNoiseBase::NzComplexNoiseBase() { m_parametersModified = true; m_lacunarity = 5.0f; @@ -24,27 +21,28 @@ NzComplexNoiseBase::NzComplexNoiseBase() } } -template -T NzComplexNoiseBase::GetLacunarity() const +const std::array& NzComplexNoiseBase::GetExponentArray() const +{ + return exponent_array; +} + +float NzComplexNoiseBase::GetLacunarity() const { return m_lacunarity; } -template -T NzComplexNoiseBase::GetHurstParameter() const +float NzComplexNoiseBase::GetHurstParameter() const { return m_hurst; } -template -T NzComplexNoiseBase::GetOctaveNumber() const +float NzComplexNoiseBase::GetOctaveNumber() const { return m_octaves; } -template -void NzComplexNoiseBase::SetLacunarity(T lacunarity) +void NzComplexNoiseBase::SetLacunarity(float lacunarity) { // if(lacunarity != m_lacunarity) //{ @@ -53,8 +51,7 @@ void NzComplexNoiseBase::SetLacunarity(T lacunarity) //} } -template -void NzComplexNoiseBase::SetHurstParameter(T h) +void NzComplexNoiseBase::SetHurstParameter(float h) { //if(h != m_hurst) //{ @@ -63,8 +60,7 @@ void NzComplexNoiseBase::SetHurstParameter(T h) //} } -template -void NzComplexNoiseBase::SetOctavesNumber(T octaves) +void NzComplexNoiseBase::SetOctavesNumber(float octaves) { if(octaves <= 30.0f) m_octaves = octaves; @@ -75,28 +71,22 @@ void NzComplexNoiseBase::SetOctavesNumber(T octaves) } -template -void NzComplexNoiseBase::RecomputeExponentArray() +void NzComplexNoiseBase::RecomputeExponentArray() { if(m_parametersModified) { - cout<<"Recomputing exponent array"<(m_octaves) ; ++i) { exponent_array[i] = std::pow( frequency, -m_hurst ); - cout<<"expo["<m_sum<m_octaves - static_cast(this->m_octaves); - //if(!NzNumberEquals(remainder, static_cast(0.0))) + //if(!NzNumberEquals(remainder, static_cast(0.0))) // m_value += remainder * Get2DSimplexNoiseValue(x,y,resolution) * exponent_array[(int)m_octaves-1]; //0.65 is an experimental value to make the noise stick closer to [-1 , 1] return m_value / (this->m_sum * 0.65); } -template -NzFBM2D::~NzFBM2D() +NzFBM2D::~NzFBM2D() { switch(m_noiseType) { case PERLIN: - delete dynamic_cast*>(m_source); + delete dynamic_cast(m_source); break; default: - delete dynamic_cast*>(m_source); + delete dynamic_cast(m_source); break; } } - -#include diff --git a/include/Nazara/Noise/MappedNoiseBase.inl b/src/Nazara/Noise/MappedNoiseBase.cpp similarity index 52% rename from include/Nazara/Noise/MappedNoiseBase.inl rename to src/Nazara/Noise/MappedNoiseBase.cpp index 9f70dee87..d7464eb9e 100644 --- a/include/Nazara/Noise/MappedNoiseBase.inl +++ b/src/Nazara/Noise/MappedNoiseBase.cpp @@ -8,48 +8,41 @@ #include #include #include +#include - -template -NzMappedNoiseBase::NzMappedNoiseBase() : m_gain(1), m_offset(0), m_resolution(30) +NzMappedNoiseBase::NzMappedNoiseBase() : m_gain(1.f), m_offset(0.f), m_resolution(30.f) { } -template -T NzMappedNoiseBase::GetGain() const +float NzMappedNoiseBase::GetGain() const { return m_gain; } -template -T NzMappedNoiseBase::GetOffset() const +float NzMappedNoiseBase::GetOffset() const { return m_offset; } -template -T NzMappedNoiseBase::GetResolution() const +float NzMappedNoiseBase::GetResolution() const { return m_resolution; } -template -void NzMappedNoiseBase::SetGain(T gain) +void NzMappedNoiseBase::SetGain(float gain) { m_gain = gain; } -template -void NzMappedNoiseBase::SetOffset(T offset) +void NzMappedNoiseBase::SetOffset(float offset) { m_offset = offset; } -template -void NzMappedNoiseBase::SetResolution(T resolution) +void NzMappedNoiseBase::SetResolution(float resolution) { - if (NzNumberEquals(resolution, static_cast(0.0))) + if (NzNumberEquals(resolution, 0.f)) { NzStringStream ss; ss << __FILE__ << ':' << __LINE__ << " : resolution cannot be 0.0f"; @@ -58,5 +51,3 @@ void NzMappedNoiseBase::SetResolution(T resolution) } m_resolution = resolution; } - -#include diff --git a/include/Nazara/Noise/Perlin2D.inl b/src/Nazara/Noise/Perlin2D.cpp similarity index 69% rename from include/Nazara/Noise/Perlin2D.inl rename to src/Nazara/Noise/Perlin2D.cpp index 169cb6bf8..157dab5d4 100644 --- a/include/Nazara/Noise/Perlin2D.inl +++ b/src/Nazara/Noise/Perlin2D.cpp @@ -4,12 +4,12 @@ #include #include +#include #include -template -NzPerlin2D::NzPerlin2D() +NzPerlin2D::NzPerlin2D() { - T grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1}, + int grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1}, {1,0},{-1,0},{0,1},{0,-1}}; for(int i(0) ; i < 8 ; ++i) @@ -17,22 +17,21 @@ NzPerlin2D::NzPerlin2D() gradient2[i][j] = grad2Temp[i][j]; } -template -T NzPerlin2D::GetValue(T x, T y, T resolution) +float NzPerlin2D::GetValue(float x, float y, float resolution) { x *= resolution; y *= resolution; - x0 = this->fastfloor(x); - y0 = this->fastfloor(y); + x0 = fastfloor(x); + y0 = fastfloor(y); ii = x0 & 255; jj = y0 & 255; - gi0 = this->perm[ii + this->perm[jj]] & 7; - gi1 = this->perm[ii + 1 + this->perm[jj]] & 7; - gi2 = this->perm[ii + this->perm[jj + 1]] & 7; - gi3 = this->perm[ii + 1 + this->perm[jj + 1]] & 7; + gi0 = perm[ii + perm[jj]] & 7; + gi1 = perm[ii + 1 + perm[jj]] & 7; + gi2 = perm[ii + perm[jj + 1]] & 7; + gi3 = perm[ii + 1 + perm[jj + 1]] & 7; temp.x = x-x0; temp.y = y-y0; @@ -56,5 +55,3 @@ T NzPerlin2D::GetValue(T x, T y, T resolution) return Li1 + Cy*(Li2-Li1); } - -#include diff --git a/include/Nazara/Noise/Perlin3D.inl b/src/Nazara/Noise/Perlin3D.cpp similarity index 70% rename from include/Nazara/Noise/Perlin3D.inl rename to src/Nazara/Noise/Perlin3D.cpp index 61e2a14c8..774ee7436 100644 --- a/include/Nazara/Noise/Perlin3D.inl +++ b/src/Nazara/Noise/Perlin3D.cpp @@ -4,12 +4,12 @@ #include #include +#include #include -template -NzPerlin3D::NzPerlin3D() +NzPerlin3D::NzPerlin3D() { - int grad3Temp[][3] = { + float grad3Temp[][3] = { {1,1,0},{-1,1,0},{1,-1,0},{-1,-1,0}, {1,0,1},{-1,0,1},{1,0,-1},{-1,0,-1}, {0,1,1},{0,-1,1},{0,1,-1},{0,-1,-1}, @@ -21,30 +21,29 @@ NzPerlin3D::NzPerlin3D() gradient3[i][j] = grad3Temp[i][j]; } -template -T NzPerlin3D::GetValue(T x, T y, T z, T resolution) +float NzPerlin3D::GetValue(float x, float y, float z, float resolution) { x /= resolution; y /= resolution; z /= resolution; - x0 = this->fastfloor(x); - y0 = this->fastfloor(y); - z0 = this->fastfloor(z); + x0 = fastfloor(x); + y0 = fastfloor(y); + z0 = fastfloor(z); ii = x0 & 255; jj = y0 & 255; kk = z0 & 255; - gi0 = this->perm[ii + this->perm[jj + this->perm[kk]]] & 15; - gi1 = this->perm[ii + 1 + this->perm[jj + this->perm[kk]]] & 15; - gi2 = this->perm[ii + this->perm[jj + 1 + this->perm[kk]]] & 15; - gi3 = this->perm[ii + 1 + this->perm[jj + 1 + this->perm[kk]]] & 15; + gi0 = perm[ii + perm[jj + perm[kk]]] & 15; + gi1 = perm[ii + 1 + perm[jj + perm[kk]]] & 15; + gi2 = perm[ii + perm[jj + 1 + perm[kk]]] & 15; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk]]] & 15; - gi4 = this->perm[ii + this->perm[jj + this->perm[kk + 1]]] & 15; - gi5 = this->perm[ii + 1 + this->perm[jj + this->perm[kk + 1]]] & 15; - gi6 = this->perm[ii + this->perm[jj + 1 + this->perm[kk + 1]]] & 15; - gi7 = this->perm[ii + 1 + this->perm[jj + 1 + this->perm[kk + 1]]] & 15; + gi4 = perm[ii + perm[jj + perm[kk + 1]]] & 15; + gi5 = perm[ii + 1 + perm[jj + perm[kk + 1]]] & 15; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1]]] & 15; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1]]] & 15; temp.x = x-x0; temp.y = y-y0; @@ -88,5 +87,3 @@ T NzPerlin3D::GetValue(T x, T y, T z, T resolution) return Li5 + Cz*(Li6-Li5); } - -#include diff --git a/include/Nazara/Noise/Perlin4D.inl b/src/Nazara/Noise/Perlin4D.cpp similarity index 69% rename from include/Nazara/Noise/Perlin4D.inl rename to src/Nazara/Noise/Perlin4D.cpp index 44d010b27..308a4d3fc 100644 --- a/include/Nazara/Noise/Perlin4D.inl +++ b/src/Nazara/Noise/Perlin4D.cpp @@ -4,12 +4,12 @@ #include #include +#include #include -template -NzPerlin4D::NzPerlin4D() +NzPerlin4D::NzPerlin4D() { - int grad4Temp[][4] = + float grad4Temp[][4] = { {0,1,1,1}, {0,1,1,-1}, {0,1,-1,1}, {0,1,-1,-1}, {0,-1,1,1},{0,-1,1,-1},{0,-1,-1,1},{0,-1,-1,-1}, @@ -26,43 +26,42 @@ NzPerlin4D::NzPerlin4D() gradient4[i][j] = grad4Temp[i][j]; } -template -T NzPerlin4D::GetValue(T x, T y, T z, T w, T resolution) +float NzPerlin4D::GetValue(float x, float y, float z, float w, float resolution) { x *= resolution; y *= resolution; z *= resolution; w *= resolution; - x0 = this->fastfloor(x); - y0 = this->fastfloor(y); - z0 = this->fastfloor(z); - w0 = this->fastfloor(w); + x0 = fastfloor(x); + y0 = fastfloor(y); + z0 = fastfloor(z); + w0 = fastfloor(w); ii = x0 & 255; jj = y0 & 255; kk = z0 & 255; ll = w0 & 255; - gi0 = this->perm[ii + this->perm[jj + this->perm[kk + this->perm[ll]]]] & 31; - gi1 = this->perm[ii + 1 + this->perm[jj + this->perm[kk + this->perm[ll]]]] & 31; - gi2 = this->perm[ii + this->perm[jj + 1 + this->perm[kk + this->perm[ll]]]] & 31; - gi3 = this->perm[ii + 1 + this->perm[jj + 1 + this->perm[kk + this->perm[ll]]]] & 31; + gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] & 31; + gi1 = perm[ii + 1 + perm[jj + perm[kk + perm[ll]]]] & 31; + gi2 = perm[ii + perm[jj + 1 + perm[kk + perm[ll]]]] & 31; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll]]]] & 31; - gi4 = this->perm[ii + this->perm[jj + + this->perm[kk + 1 + this->perm[ll]]]] & 31; - gi5 = this->perm[ii + 1 + this->perm[jj + + this->perm[kk + 1 + this->perm[ll]]]] & 31; - gi6 = this->perm[ii + this->perm[jj + 1 + this->perm[kk + 1 + this->perm[ll]]]] & 31; - gi7 = this->perm[ii + 1 + this->perm[jj + 1 + this->perm[kk + 1 + this->perm[ll]]]] & 31; + gi4 = perm[ii + perm[jj + + perm[kk + 1 + perm[ll]]]] & 31; + gi5 = perm[ii + 1 + perm[jj + + perm[kk + 1 + perm[ll]]]] & 31; + gi6 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll]]]] & 31; + gi7 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll]]]] & 31; - gi8 = this->perm[ii + this->perm[jj + this->perm[kk + this->perm[ll + 1]]]] & 31; - gi9 = this->perm[ii + 1 + this->perm[jj + this->perm[kk + this->perm[ll + 1]]]] & 31; - gi10 = this->perm[ii + this->perm[jj + 1 + this->perm[kk + this->perm[ll + 1]]]] & 31; - gi11 = this->perm[ii + 1 + this->perm[jj + 1 + this->perm[kk + this->perm[ll + 1]]]] & 31; + gi8 = perm[ii + perm[jj + perm[kk + perm[ll + 1]]]] & 31; + gi9 = perm[ii + 1 + perm[jj + perm[kk + perm[ll + 1]]]] & 31; + gi10 = perm[ii + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31; + gi11 = perm[ii + 1 + perm[jj + 1 + perm[kk + perm[ll + 1]]]] & 31; - gi12 = this->perm[ii + this->perm[jj + this->perm[kk + 1 + this->perm[ll + 1]]]] & 31; - gi13 = this->perm[ii + 1 + this->perm[jj + this->perm[kk + 1 + this->perm[ll + 1]]]] & 31; - gi14 = this->perm[ii + this->perm[jj + 1 + this->perm[kk + 1 + this->perm[ll + 1]]]] & 31; - gi15 = this->perm[ii + 1 + this->perm[jj + 1 + this->perm[kk + 1 + this->perm[ll + 1]]]] & 31; + gi12 = perm[ii + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi13 = perm[ii + 1 + perm[jj + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi14 = perm[ii + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31; + gi15 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] & 31; temp.x = x-x0; temp.y = y-y0; @@ -146,5 +145,3 @@ T NzPerlin4D::GetValue(T x, T y, T z, T w, T resolution) return Li13 + Cw*(Li14-Li13); } - -#include diff --git a/include/Nazara/Noise/Simplex2D.inl b/src/Nazara/Noise/Simplex2D.cpp similarity index 78% rename from include/Nazara/Noise/Simplex2D.inl rename to src/Nazara/Noise/Simplex2D.cpp index 0bc9d3d10..26c42eeda 100644 --- a/include/Nazara/Noise/Simplex2D.inl +++ b/src/Nazara/Noise/Simplex2D.cpp @@ -4,12 +4,12 @@ #include #include +#include #include -template -NzSimplex2D::NzSimplex2D() +NzSimplex2D::NzSimplex2D() { - T grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1}, + float grad2Temp[][2] = {{1,1},{-1,1},{1,-1},{-1,-1}, {1,0},{-1,0},{0,1},{0,-1}}; for(int i(0) ; i < 8 ; ++i) @@ -20,15 +20,14 @@ NzSimplex2D::NzSimplex2D() UnskewCoeff2D = (3.0-sqrt(3.0))/6.; } -template -T NzSimplex2D::GetValue(T x, T y, T resolution) +float NzSimplex2D::GetValue(float x, float y, float resolution) { x *= resolution; y *= resolution; sum = (x + y) * SkewCoeff2D; - skewedCubeOrigin.x = this->fastfloor(x + sum); - skewedCubeOrigin.y = this->fastfloor(y + sum); + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); sum = (skewedCubeOrigin.x + skewedCubeOrigin.y) * UnskewCoeff2D; unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; @@ -59,9 +58,9 @@ T NzSimplex2D::GetValue(T x, T y, T resolution) ii = skewedCubeOrigin.x & 255; jj = skewedCubeOrigin.y & 255; - gi0 = this->perm[ii + this->perm[jj ]] & 7; - gi1 = this->perm[ii + off1.x + this->perm[jj + off1.y]] & 7; - gi2 = this->perm[ii + 1 + this->perm[jj + 1 ]] & 7; + gi0 = perm[ii + perm[jj ]] & 7; + gi1 = perm[ii + off1.x + perm[jj + off1.y]] & 7; + gi2 = perm[ii + 1 + perm[jj + 1 ]] & 7; c1 = 0.5 - d1.x * d1.x - d1.y * d1.y; c2 = 0.5 - d2.x * d2.x - d2.y * d2.y; @@ -84,5 +83,3 @@ T NzSimplex2D::GetValue(T x, T y, T resolution) return (n1+n2+n3)*70; } - -#include diff --git a/include/Nazara/Noise/Simplex3D.inl b/src/Nazara/Noise/Simplex3D.cpp similarity index 84% rename from include/Nazara/Noise/Simplex3D.inl rename to src/Nazara/Noise/Simplex3D.cpp index e307c7816..a68739f30 100644 --- a/include/Nazara/Noise/Simplex3D.inl +++ b/src/Nazara/Noise/Simplex3D.cpp @@ -4,10 +4,10 @@ #include #include +#include #include -template -NzSimplex3D::NzSimplex3D() +NzSimplex3D::NzSimplex3D() { SkewCoeff3D = 1/3.; UnskewCoeff3D = 1/6.; @@ -21,17 +21,16 @@ NzSimplex3D::NzSimplex3D() gradient3[i][j] = grad3Temp[i][j]; } -template -T NzSimplex3D::GetValue(T x, T y, T z, T resolution) +float NzSimplex3D::GetValue(float x, float y, float z, float resolution) { x *= resolution; y *= resolution; z *= resolution; sum = (x + y + z) * SkewCoeff3D; - skewedCubeOrigin.x = this->fastfloor(x + sum); - skewedCubeOrigin.y = this->fastfloor(y + sum); - skewedCubeOrigin.z = this->fastfloor(z + sum); + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); + skewedCubeOrigin.z = fastfloor(z + sum); sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z) * UnskewCoeff3D; unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; @@ -121,10 +120,10 @@ T NzSimplex3D::GetValue(T x, T y, T z, T resolution) jj = skewedCubeOrigin.y & 255; kk = skewedCubeOrigin.z & 255; - gi0 = this->perm[ii + this->perm[jj + this->perm[kk ]]] % 12; - gi1 = this->perm[ii + off1.x + this->perm[jj + off1.y + this->perm[kk + off1.z]]] % 12; - gi2 = this->perm[ii + off2.x + this->perm[jj + off2.y + this->perm[kk + off2.z]]] % 12; - gi3 = this->perm[ii + 1 + this->perm[jj + 1 + this->perm[kk + 1 ]]] % 12; + gi0 = perm[ii + perm[jj + perm[kk ]]] % 12; + gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z]]] % 12; + gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z]]] % 12; + gi3 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 ]]] % 12; c1 = 0.6 - d1.x * d1.x - d1.y * d1.y - d1.z * d1.z; c2 = 0.6 - d2.x * d2.x - d2.y * d2.y - d2.z * d2.z; @@ -153,5 +152,3 @@ T NzSimplex3D::GetValue(T x, T y, T z, T resolution) return (n1+n2+n3+n4)*32; } - -#include diff --git a/include/Nazara/Noise/Simplex4D.inl b/src/Nazara/Noise/Simplex4D.cpp similarity index 85% rename from include/Nazara/Noise/Simplex4D.inl rename to src/Nazara/Noise/Simplex4D.cpp index 7e28895b6..62f671e34 100644 --- a/include/Nazara/Noise/Simplex4D.inl +++ b/src/Nazara/Noise/Simplex4D.cpp @@ -4,10 +4,10 @@ #include #include +#include #include -template -NzSimplex4D::NzSimplex4D() +NzSimplex4D::NzSimplex4D() { SkewCoeff4D = (sqrt(5.) - 1.)/4.; UnskewCoeff4D = (5. - sqrt(5.))/20.; @@ -45,8 +45,7 @@ NzSimplex4D::NzSimplex4D() gradient4[i][j] = grad4Temp[i][j]; } -template -T NzSimplex4D::GetValue(T x, T y, T z, T w, T resolution) +float NzSimplex4D::GetValue(float x, float y, float z, float w, float resolution) { x *= resolution; y *= resolution; @@ -54,10 +53,10 @@ T NzSimplex4D::GetValue(T x, T y, T z, T w, T resolution) w *= resolution; sum = (x + y + z + w) * SkewCoeff4D; - skewedCubeOrigin.x = this->fastfloor(x + sum); - skewedCubeOrigin.y = this->fastfloor(y + sum); - skewedCubeOrigin.z = this->fastfloor(z + sum); - skewedCubeOrigin.w = this->fastfloor(w + sum); + skewedCubeOrigin.x = fastfloor(x + sum); + skewedCubeOrigin.y = fastfloor(y + sum); + skewedCubeOrigin.z = fastfloor(z + sum); + skewedCubeOrigin.w = fastfloor(w + sum); sum = (skewedCubeOrigin.x + skewedCubeOrigin.y + skewedCubeOrigin.z + skewedCubeOrigin.w) * UnskewCoeff4D; unskewedCubeOrigin.x = skewedCubeOrigin.x - sum; @@ -120,11 +119,11 @@ T NzSimplex4D::GetValue(T x, T y, T z, T w, T resolution) kk = skewedCubeOrigin.z & 255; ll = skewedCubeOrigin.w & 255; - gi0 = this->perm[ii + this->perm[jj + this->perm[kk + this->perm[ll]]]] & 31; - gi1 = this->perm[ii + off1.x + this->perm[jj + off1.y + this->perm[kk + off1.z + this->perm[ll + off1.w]]]] & 31; - gi2 = this->perm[ii + off2.x + this->perm[jj + off2.y + this->perm[kk + off2.z + this->perm[ll + off2.w]]]] & 31; - gi3 = this->perm[ii + off3.x + this->perm[jj + off3.y + this->perm[kk + off3.z + this->perm[ll + off3.w]]]] & 31; - gi4 = this->perm[ii + 1 + this->perm[jj + 1 + this->perm[kk + 1 + this->perm[ll + 1]]]] % 32; + gi0 = perm[ii + perm[jj + perm[kk + perm[ll]]]] & 31; + gi1 = perm[ii + off1.x + perm[jj + off1.y + perm[kk + off1.z + perm[ll + off1.w]]]] & 31; + gi2 = perm[ii + off2.x + perm[jj + off2.y + perm[kk + off2.z + perm[ll + off2.w]]]] & 31; + gi3 = perm[ii + off3.x + perm[jj + off3.y + perm[kk + off3.z + perm[ll + off3.w]]]] & 31; + gi4 = perm[ii + 1 + perm[jj + 1 + perm[kk + 1 + perm[ll + 1]]]] % 32; c1 = 0.6 - d1.x*d1.x - d1.y*d1.y - d1.z*d1.z - d1.w*d1.w; c2 = 0.6 - d2.x*d2.x - d2.y*d2.y - d2.z*d2.z - d2.w*d2.w; @@ -159,5 +158,3 @@ T NzSimplex4D::GetValue(T x, T y, T z, T w, T resolution) return (n1+n2+n3+n4+n5)*27.0; } - -#include