Minor fixes
*Seed is uint instead of int *Permutation table is uint instead of int, could lead before to program crash with negative seeds Former-commit-id: 49ad04987a09a5f5b4bcab6ee3916db9818172b6
This commit is contained in:
parent
a0b7364eed
commit
d0545eb760
|
|
@ -16,7 +16,6 @@ class NAZARA_API NzComplexNoiseBase
|
|||
NzComplexNoiseBase();
|
||||
~NzComplexNoiseBase() = default;
|
||||
|
||||
const std::array<float, 30>& GetExponentArray() const; //For debug purpose
|
||||
float GetHurstParameter() const;
|
||||
float GetLacunarity() const;
|
||||
float GetOctaveNumber() const;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
class NAZARA_API NzFBM2D : public NzAbstract2DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzFBM2D(nzNoises source, int seed);
|
||||
NzFBM2D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
~NzFBM2D();
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
class NAZARA_API NzFBM3D : public NzAbstract3DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzFBM3D(nzNoises source, int seed);
|
||||
NzFBM3D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~NzFBM3D();
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
class NAZARA_API NzFBM4D : public NzAbstract4DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzFBM4D(nzNoises source, int seed);
|
||||
NzFBM4D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~NzFBM4D();
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
class NAZARA_API NzHybridMultiFractal3D : public NzAbstract3DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzHybridMultiFractal3D(nzNoises source, int seed);
|
||||
NzHybridMultiFractal3D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~NzHybridMultiFractal3D();
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
class NAZARA_API NzHybridMultiFractal4D : public NzAbstract4DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzHybridMultiFractal4D(nzNoises source, int seed);
|
||||
NzHybridMultiFractal4D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~NzHybridMultiFractal4D();
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
class NAZARA_API NzHybridMultiFractal2D : public NzAbstract2DNoise, public NzComplexNoiseBase
|
||||
{
|
||||
public:
|
||||
NzHybridMultiFractal2D(nzNoises source, int seed);
|
||||
NzHybridMultiFractal2D(nzNoises source, unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
~NzHybridMultiFractal2D();
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef NAZARA_NOISE_HPP
|
||||
#define NAZARA_NOISE_HPP
|
||||
|
||||
#include <Nazara/Prerequesites.hpp>
|
||||
#include <Nazara/Core/Initializer.hpp>
|
||||
|
||||
class NAZARA_API NzNoise
|
||||
{
|
||||
public:
|
||||
NzNoise() = delete;
|
||||
~NzNoise() = delete;
|
||||
|
||||
static bool Initialize();
|
||||
|
||||
static bool IsInitialized();
|
||||
|
||||
static void Uninitialize();
|
||||
|
||||
private:
|
||||
static unsigned int s_moduleReferenceCouter;
|
||||
};
|
||||
|
||||
#endif // NAZARA_NOISE_HPP
|
||||
|
|
@ -19,21 +19,23 @@ enum nzNoises
|
|||
class NAZARA_API NzNoiseBase
|
||||
{
|
||||
public:
|
||||
NzNoiseBase(int seed = 0);
|
||||
NzNoiseBase(unsigned int seed = 0);
|
||||
~NzNoiseBase() = default;
|
||||
|
||||
void SetNewSeed(int seed);
|
||||
int GetUniformRandomValue();
|
||||
void SetNewSeed(unsigned int seed);
|
||||
|
||||
void ShufflePermutationTable();
|
||||
|
||||
unsigned int GetUniformRandomValue();
|
||||
|
||||
int fastfloor(float n);
|
||||
int JenkinsHash(int a, int b, int c);
|
||||
protected:
|
||||
int perm[512];
|
||||
unsigned int perm[512];
|
||||
private:
|
||||
int Ua, Uc, Um;
|
||||
int UcurrentSeed;
|
||||
int Uprevious, Ulast;
|
||||
unsigned int Ua, Uc, Um;
|
||||
unsigned int UcurrentSeed;
|
||||
unsigned int Uprevious, Ulast;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class NAZARA_API NzPerlin2D : public NzAbstract2DNoise
|
|||
{
|
||||
public:
|
||||
NzPerlin2D();
|
||||
NzPerlin2D(int seed);
|
||||
NzPerlin2D(unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
~NzPerlin2D() = default;
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class NAZARA_API NzPerlin3D : public NzAbstract3DNoise
|
|||
{
|
||||
public:
|
||||
NzPerlin3D();
|
||||
NzPerlin3D(int seed);
|
||||
NzPerlin3D(unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~NzPerlin3D() = default;
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class NAZARA_API NzPerlin4D : public NzAbstract4DNoise
|
|||
{
|
||||
public:
|
||||
NzPerlin4D();
|
||||
NzPerlin4D(int seed);
|
||||
NzPerlin4D(unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~NzPerlin4D() = default;
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class NAZARA_API NzSimplex2D : public NzAbstract2DNoise
|
|||
{
|
||||
public:
|
||||
NzSimplex2D();
|
||||
NzSimplex2D(int seed);
|
||||
NzSimplex2D(unsigned int seed);
|
||||
float GetValue(float x, float y, float resolution);
|
||||
virtual ~NzSimplex2D() = default;
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class NAZARA_API NzSimplex3D : public NzAbstract3DNoise
|
|||
{
|
||||
public:
|
||||
NzSimplex3D();
|
||||
NzSimplex3D(int seed);
|
||||
NzSimplex3D(unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float resolution);
|
||||
~NzSimplex3D() = default;
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class NAZARA_API NzSimplex4D : public NzAbstract4DNoise
|
|||
{
|
||||
public:
|
||||
NzSimplex4D();
|
||||
NzSimplex4D(int seed);
|
||||
NzSimplex4D(unsigned int seed);
|
||||
float GetValue(float x, float y, float z, float w, float resolution);
|
||||
~NzSimplex4D() = default;
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -21,11 +21,6 @@ NzComplexNoiseBase::NzComplexNoiseBase()
|
|||
}
|
||||
}
|
||||
|
||||
const std::array<float, 30>& NzComplexNoiseBase::GetExponentArray() const
|
||||
{
|
||||
return m_exponent_array;
|
||||
}
|
||||
|
||||
float NzComplexNoiseBase::GetLacunarity() const
|
||||
{
|
||||
|
||||
|
|
@ -44,20 +39,16 @@ float NzComplexNoiseBase::GetOctaveNumber() const
|
|||
|
||||
void NzComplexNoiseBase::SetLacunarity(float lacunarity)
|
||||
{
|
||||
// if(lacunarity != m_lacunarity)
|
||||
//{
|
||||
m_lacunarity = lacunarity;
|
||||
m_parametersModified = true;
|
||||
//}
|
||||
m_lacunarity = lacunarity;
|
||||
m_parametersModified = true;
|
||||
|
||||
}
|
||||
|
||||
void NzComplexNoiseBase::SetHurstParameter(float h)
|
||||
{
|
||||
//if(h != m_hurst)
|
||||
//{
|
||||
m_hurst = h;
|
||||
m_parametersModified = true;
|
||||
//}
|
||||
|
||||
m_hurst = h;
|
||||
m_parametersModified = true;
|
||||
}
|
||||
|
||||
void NzComplexNoiseBase::SetOctavesNumber(float octaves)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <Nazara/Noise/Simplex2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzFBM2D::NzFBM2D(nzNoises source, int seed)
|
||||
NzFBM2D::NzFBM2D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <Nazara/Noise/Simplex3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzFBM3D::NzFBM3D(nzNoises source, int seed)
|
||||
NzFBM3D::NzFBM3D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <Nazara/Noise/Simplex4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzFBM4D::NzFBM4D(nzNoises source, int seed)
|
||||
NzFBM4D::NzFBM4D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <Nazara/Noise/Simplex3D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzHybridMultiFractal3D::NzHybridMultiFractal3D(nzNoises source, int seed)
|
||||
NzHybridMultiFractal3D::NzHybridMultiFractal3D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <Nazara/Noise/Simplex4D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzHybridMultiFractal4D::NzHybridMultiFractal4D(nzNoises source, int seed)
|
||||
NzHybridMultiFractal4D::NzHybridMultiFractal4D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#include <Nazara/Noise/Simplex2D.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzHybridMultiFractal2D::NzHybridMultiFractal2D(nzNoises source, int seed)
|
||||
NzHybridMultiFractal2D::NzHybridMultiFractal2D(nzNoises source, unsigned int seed)
|
||||
{
|
||||
switch(source)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
// Copyright (C) 2012 Rémi Bèges
|
||||
// This file is part of the "Nazara Engine - Noise module"
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Noise/Noise.hpp>
|
||||
#include <Nazara/Core/Core.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Core/Log.hpp>
|
||||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
bool NzNoise::Initialize()
|
||||
{
|
||||
if (s_moduleReferenceCouter++ != 0)
|
||||
return true; // Déjà initialisé
|
||||
|
||||
// Initialisation des dépendances
|
||||
if (!NzCore::Initialize())
|
||||
{
|
||||
NazaraError("Failed to initialize core module");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialisation du module
|
||||
|
||||
NazaraNotice("Initialized: Noise module");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NzNoise::IsInitialized()
|
||||
{
|
||||
return s_moduleReferenceCouter != 0;
|
||||
}
|
||||
|
||||
void NzNoise::Uninitialize()
|
||||
{
|
||||
if (--s_moduleReferenceCouter != 0)
|
||||
return; // Encore utilisé
|
||||
|
||||
// Libération du module
|
||||
|
||||
// Libération des dépendances
|
||||
NzCore::Uninitialize();
|
||||
|
||||
NazaraNotice("Uninitialized: Noise module");
|
||||
}
|
||||
|
||||
unsigned int NzNoise::s_moduleReferenceCouter = 0;
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
#include <Nazara/Noise/Config.hpp>
|
||||
#include <Nazara/Noise/Debug.hpp>
|
||||
|
||||
NzNoiseBase::NzNoiseBase(int seed)
|
||||
NzNoiseBase::NzNoiseBase(unsigned int seed)
|
||||
{
|
||||
Ua = 16807;
|
||||
Uc = 0;
|
||||
|
|
@ -22,13 +22,13 @@ NzNoiseBase::NzNoiseBase(int seed)
|
|||
|
||||
}
|
||||
|
||||
void NzNoiseBase::SetNewSeed(int seed)
|
||||
void NzNoiseBase::SetNewSeed(unsigned int seed)
|
||||
{
|
||||
Uprevious = seed;
|
||||
UcurrentSeed = seed;
|
||||
}
|
||||
|
||||
int NzNoiseBase::GetUniformRandomValue()
|
||||
unsigned int NzNoiseBase::GetUniformRandomValue()
|
||||
{
|
||||
Ulast = Ua*Uprevious + Uc%Um;
|
||||
Uprevious = Ulast;
|
||||
|
|
@ -40,11 +40,11 @@ void NzNoiseBase::ShufflePermutationTable()
|
|||
int xchanger;
|
||||
unsigned int ncase;
|
||||
|
||||
for(int i(0) ; i < 256 ; i++)
|
||||
for(unsigned int i(0) ; i < 256 ; i++)
|
||||
perm[i] = i;
|
||||
|
||||
for(int j(0) ; j < 20 ; ++j)
|
||||
for (int i(0); i < 256 ; ++i)
|
||||
for(unsigned int j(0) ; j < 20 ; ++j)
|
||||
for (unsigned int i(0); i < 256 ; ++i)
|
||||
{
|
||||
ncase = this->GetUniformRandomValue() & 255;
|
||||
xchanger = perm[i];
|
||||
|
|
@ -52,7 +52,7 @@ void NzNoiseBase::ShufflePermutationTable()
|
|||
perm[ncase] = xchanger;
|
||||
}
|
||||
|
||||
for(int i(256) ; i < 512; ++i)
|
||||
for(unsigned int i(256) ; i < 512; ++i)
|
||||
perm[i] = perm[i & 255];
|
||||
}
|
||||
|
||||
|
|
@ -74,5 +74,3 @@ int NzNoiseBase::JenkinsHash(int a, int b, int c)
|
|||
c = c-a; c = c - b; c = c^(static_cast<unsigned int>(b) >> 15);
|
||||
return c;
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ NzPerlin2D::NzPerlin2D()
|
|||
gradient2[i][j] = grad2Temp[i][j];
|
||||
}
|
||||
|
||||
NzPerlin2D::NzPerlin2D(int seed) : NzPerlin2D()
|
||||
NzPerlin2D::NzPerlin2D(unsigned int seed) : NzPerlin2D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ NzPerlin3D::NzPerlin3D()
|
|||
gradient3[i][j] = grad3Temp[i][j];
|
||||
}
|
||||
|
||||
NzPerlin3D::NzPerlin3D(int seed) : NzPerlin3D()
|
||||
NzPerlin3D::NzPerlin3D(unsigned int seed) : NzPerlin3D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ NzPerlin4D::NzPerlin4D()
|
|||
gradient4[i][j] = grad4Temp[i][j];
|
||||
}
|
||||
|
||||
NzPerlin4D::NzPerlin4D(int seed) : NzPerlin4D()
|
||||
NzPerlin4D::NzPerlin4D(unsigned int seed) : NzPerlin4D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ NzSimplex2D::NzSimplex2D()
|
|||
UnskewCoeff2D = (3.0-sqrt(3.0))/6.;
|
||||
}
|
||||
|
||||
NzSimplex2D::NzSimplex2D(int seed) : NzSimplex2D()
|
||||
NzSimplex2D::NzSimplex2D(unsigned int seed) : NzSimplex2D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ NzSimplex3D::NzSimplex3D()
|
|||
gradient3[i][j] = grad3Temp[i][j];
|
||||
}
|
||||
|
||||
NzSimplex3D::NzSimplex3D(int seed) : NzSimplex3D()
|
||||
NzSimplex3D::NzSimplex3D(unsigned int seed) : NzSimplex3D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ NzSimplex4D::NzSimplex4D()
|
|||
gradient4[i][j] = grad4Temp[i][j];
|
||||
}
|
||||
|
||||
NzSimplex4D::NzSimplex4D(int seed) : NzSimplex4D()
|
||||
NzSimplex4D::NzSimplex4D(unsigned int seed) : NzSimplex4D()
|
||||
{
|
||||
this->SetNewSeed(seed);
|
||||
this->ShufflePermutationTable();
|
||||
|
|
|
|||
Loading…
Reference in New Issue