diff options
Diffstat (limited to 'src/Noise')
-rw-r--r-- | src/Noise/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Noise/Noise.cpp | 32 | ||||
-rw-r--r-- | src/Noise/Noise.h | 15 |
3 files changed, 28 insertions, 23 deletions
diff --git a/src/Noise/CMakeLists.txt b/src/Noise/CMakeLists.txt index e1837500f..ab4cf031b 100644 --- a/src/Noise/CMakeLists.txt +++ b/src/Noise/CMakeLists.txt @@ -14,6 +14,10 @@ SET (HDRS RidgedNoise.h ) +if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set_source_files_properties(Noise.cpp PROPERTIES COMPILE_FLAGS "-Wno-error=old-style-cast") +endif() + if(NOT MSVC) add_library(Noise ${SRCS} ${HDRS}) diff --git a/src/Noise/Noise.cpp b/src/Noise/Noise.cpp index d11c47bc2..703ec3d30 100644 --- a/src/Noise/Noise.cpp +++ b/src/Noise/Noise.cpp @@ -112,22 +112,22 @@ public: //////////////////////////////////////////////////////////////////////////////// // Globals: -void Debug3DNoise(const NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, int a_SizeZ, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff) +void Debug3DNoise(const NOISE_DATATYPE * a_Noise, size_t a_SizeX, size_t a_SizeY, size_t a_SizeZ, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff) { const int BUF_SIZE = 512; ASSERT(a_SizeX <= BUF_SIZE); // Just stretch it, if needed // Save in XY cuts: cFile f1; - if (f1.Open(Printf("%s_XY (%d).grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) + if (f1.Open(Printf("%s_XY (" SIZE_T_FMT ").grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) { - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - for (int y = 0; y < a_SizeY; y++) + for (size_t y = 0; y < a_SizeY; y++) { - int idx = y * a_SizeX + z * a_SizeX * a_SizeY; + size_t idx = y * a_SizeX + z * a_SizeX * a_SizeY; unsigned char buf[BUF_SIZE]; - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { buf[x] = static_cast<unsigned char>(Clamp((int)(128 + a_Coeff * a_Noise[idx++]), 0, 255)); } @@ -140,15 +140,15 @@ void Debug3DNoise(const NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, int } // if (XY file open) cFile f2; - if (f2.Open(Printf("%s_XZ (%d).grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) + if (f2.Open(Printf("%s_XZ (" SIZE_T_FMT ").grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) { - for (int y = 0; y < a_SizeY; y++) + for (size_t y = 0; y < a_SizeY; y++) { - for (int z = 0; z < a_SizeZ; z++) + for (size_t z = 0; z < a_SizeZ; z++) { - int idx = y * a_SizeX + z * a_SizeX * a_SizeY; + size_t idx = y * a_SizeX + z * a_SizeX * a_SizeY; unsigned char buf[BUF_SIZE]; - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { buf[x] = static_cast<unsigned char>(Clamp((int)(128 + a_Coeff * a_Noise[idx++]), 0, 255)); } @@ -165,19 +165,19 @@ void Debug3DNoise(const NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, int -void Debug2DNoise(const NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff) +void Debug2DNoise(const NOISE_DATATYPE * a_Noise, size_t a_SizeX, size_t a_SizeY, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff) { const int BUF_SIZE = 512; ASSERT(a_SizeX <= BUF_SIZE); // Just stretch it, if needed cFile f1; - if (f1.Open(Printf("%s (%d).grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) + if (f1.Open(Printf("%s (" SIZE_T_FMT ").grab", a_FileNameBase.c_str(), a_SizeX), cFile::fmWrite)) { - for (int y = 0; y < a_SizeY; y++) + for (size_t y = 0; y < a_SizeY; y++) { - int idx = y * a_SizeX; + size_t idx = y * a_SizeX; unsigned char buf[BUF_SIZE]; - for (int x = 0; x < a_SizeX; x++) + for (size_t x = 0; x < a_SizeX; x++) { buf[x] = static_cast<unsigned char>(Clamp((int)(128 + a_Coeff * a_Noise[idx++]), 0, 255)); } diff --git a/src/Noise/Noise.h b/src/Noise/Noise.h index 323194bfd..be3b282ac 100644 --- a/src/Noise/Noise.h +++ b/src/Noise/Noise.h @@ -185,7 +185,7 @@ typedef cOctavedNoise<cRidgedNoise<cCubicNoise>> cRidgedMultiNoise; NOISE_DATATYPE cNoise::IntNoise1D(int a_X) const { int x = ((a_X * m_Seed) << 13) ^ a_X; - return (1 - (NOISE_DATATYPE)((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824); + return (1 - static_cast<NOISE_DATATYPE>((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824); // returns a float number in the range of [-1, 1] } @@ -197,7 +197,7 @@ NOISE_DATATYPE cNoise::IntNoise2D(int a_X, int a_Y) const { int n = a_X + a_Y * 57 + m_Seed * 57 * 57; n = (n << 13) ^ n; - return (1 - (NOISE_DATATYPE)((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824); + return (1 - static_cast<NOISE_DATATYPE>((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824); // returns a float number in the range of [-1, 1] } @@ -209,7 +209,8 @@ NOISE_DATATYPE cNoise::IntNoise3D(int a_X, int a_Y, int a_Z) const { int n = a_X + a_Y * 57 + a_Z * 57 * 57 + m_Seed * 57 * 57 * 57; n = (n << 13) ^ n; - return ((NOISE_DATATYPE)1 - (NOISE_DATATYPE)((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f); + return (static_cast<NOISE_DATATYPE>(1) - + static_cast<NOISE_DATATYPE>((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f); // returns a float number in the range of [-1, 1] } @@ -265,8 +266,8 @@ NOISE_DATATYPE cNoise::CubicInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE cNoise::CosineInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, NOISE_DATATYPE a_Pct) { - const NOISE_DATATYPE ft = a_Pct * (NOISE_DATATYPE)3.1415927; - const NOISE_DATATYPE f = (NOISE_DATATYPE)((NOISE_DATATYPE)(1 - cos(ft)) * (NOISE_DATATYPE)0.5); + const NOISE_DATATYPE ft = a_Pct * static_cast<NOISE_DATATYPE>(3.1415927); + const NOISE_DATATYPE f = static_cast<NOISE_DATATYPE>(static_cast<NOISE_DATATYPE>(1 - cos(ft)) * static_cast<NOISE_DATATYPE>(0.5)); return a_A * (1 - f) + a_B * f; } @@ -288,11 +289,11 @@ NOISE_DATATYPE cNoise::LinearInterpolate(NOISE_DATATYPE a_A, NOISE_DATATYPE a_B, /** Exports the noise array into a file. a_Coeff specifies the value that each array value is multiplied by before being converted into a byte. */ -extern void Debug2DNoise(const NOISE_DATATYPE * a_Array, int a_SizeX, int a_SizeY, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff = 32); +extern void Debug2DNoise(const NOISE_DATATYPE * a_Array, size_t a_SizeX, size_t a_SizeY, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff = 32); /** Exports the noise array into a set of files, ordered by XY and XZ. a_Coeff specifies the value that each array value is multiplied by before being converted into a byte. */ -extern void Debug3DNoise(const NOISE_DATATYPE * a_Array, int a_SizeX, int a_SizeY, int a_SizeZ, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff = 32); +extern void Debug3DNoise(const NOISE_DATATYPE * a_Array, size_t a_SizeX, size_t a_SizeY, size_t a_SizeZ, const AString & a_FileNameBase, NOISE_DATATYPE a_Coeff = 32); |