summaryrefslogtreecommitdiffstats
path: root/src/Generating
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-11-20 09:26:05 +0100
committerMattes D <github@xoft.cz>2014-11-20 09:26:05 +0100
commitf1bddc607c2e68cd9ef940c47403bb2948aad46d (patch)
tree9782ecbd191d4c8d9d082b23c2043adb2ac6a7d8 /src/Generating
parentMerge pull request #1598 from mc-server/SignEditor (diff)
parentcInterpolNoise: Implemented optimized 2D generating. (diff)
downloadcuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.gz
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.bz2
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.lz
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.xz
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.tar.zst
cuberite-f1bddc607c2e68cd9ef940c47403bb2948aad46d.zip
Diffstat (limited to 'src/Generating')
-rw-r--r--src/Generating/BioGen.h2
-rw-r--r--src/Generating/Caves.h1
-rw-r--r--src/Generating/ChunkDesc.cpp2
-rw-r--r--src/Generating/CompoGen.h2
-rw-r--r--src/Generating/DistortedHeightmap.h1
-rw-r--r--src/Generating/EndGen.h2
-rw-r--r--src/Generating/FinishGen.cpp1
-rw-r--r--src/Generating/FinishGen.h2
-rw-r--r--src/Generating/GridStructGen.h2
-rw-r--r--src/Generating/HeiGen.h2
-rw-r--r--src/Generating/MineShafts.h1
-rw-r--r--src/Generating/Noise3DGenerator.cpp125
-rw-r--r--src/Generating/Noise3DGenerator.h16
-rw-r--r--src/Generating/PieceGenerator.h2
-rw-r--r--src/Generating/Ravines.h1
-rw-r--r--src/Generating/StructGen.h2
-rw-r--r--src/Generating/Trees.h2
17 files changed, 115 insertions, 51 deletions
diff --git a/src/Generating/BioGen.h b/src/Generating/BioGen.h
index 5fd0844d9..13fb40c5f 100644
--- a/src/Generating/BioGen.h
+++ b/src/Generating/BioGen.h
@@ -15,7 +15,7 @@ Interfaces to the various biome generators:
#pragma once
#include "ComposableGenerator.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
#include "../VoronoiMap.h"
diff --git a/src/Generating/Caves.h b/src/Generating/Caves.h
index 0e17acf9e..691ef3e62 100644
--- a/src/Generating/Caves.h
+++ b/src/Generating/Caves.h
@@ -13,7 +13,6 @@
#pragma once
#include "GridStructGen.h"
-#include "../Noise.h"
diff --git a/src/Generating/ChunkDesc.cpp b/src/Generating/ChunkDesc.cpp
index 020d3bd0f..042b688b7 100644
--- a/src/Generating/ChunkDesc.cpp
+++ b/src/Generating/ChunkDesc.cpp
@@ -7,7 +7,7 @@
#include "ChunkDesc.h"
#include "../BlockArea.h"
#include "../Cuboid.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
#include "../BlockEntities/BlockEntity.h"
diff --git a/src/Generating/CompoGen.h b/src/Generating/CompoGen.h
index b145b6ba3..c65a07fe8 100644
--- a/src/Generating/CompoGen.h
+++ b/src/Generating/CompoGen.h
@@ -17,7 +17,7 @@
#pragma once
#include "ComposableGenerator.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
diff --git a/src/Generating/DistortedHeightmap.h b/src/Generating/DistortedHeightmap.h
index d073f29e4..955e57a1e 100644
--- a/src/Generating/DistortedHeightmap.h
+++ b/src/Generating/DistortedHeightmap.h
@@ -11,7 +11,6 @@
#include "ComposableGenerator.h"
#include "HeiGen.h"
-#include "../Noise.h"
diff --git a/src/Generating/EndGen.h b/src/Generating/EndGen.h
index 322061810..c2278c1e1 100644
--- a/src/Generating/EndGen.h
+++ b/src/Generating/EndGen.h
@@ -10,7 +10,7 @@
#pragma once
#include "ComposableGenerator.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp
index b8afac09a..42ecdf8a8 100644
--- a/src/Generating/FinishGen.cpp
+++ b/src/Generating/FinishGen.cpp
@@ -10,7 +10,6 @@
#include "Globals.h"
#include "FinishGen.h"
-#include "../Noise.h"
#include "../BlockID.h"
#include "../Simulator/FluidSimulator.h" // for cFluidSimulator::CanWashAway()
#include "../Simulator/FireSimulator.h"
diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h
index 4a08d70c8..991a85787 100644
--- a/src/Generating/FinishGen.h
+++ b/src/Generating/FinishGen.h
@@ -16,7 +16,7 @@
#include "ComposableGenerator.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
#include "../ProbabDistrib.h"
diff --git a/src/Generating/GridStructGen.h b/src/Generating/GridStructGen.h
index 03131fce9..b92fb2e9d 100644
--- a/src/Generating/GridStructGen.h
+++ b/src/Generating/GridStructGen.h
@@ -10,7 +10,7 @@
#pragma once
#include "ComposableGenerator.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
diff --git a/src/Generating/HeiGen.h b/src/Generating/HeiGen.h
index 6ae5ba362..b3c9483fb 100644
--- a/src/Generating/HeiGen.h
+++ b/src/Generating/HeiGen.h
@@ -15,7 +15,7 @@ Interfaces to the various height generators:
#pragma once
#include "ComposableGenerator.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
diff --git a/src/Generating/MineShafts.h b/src/Generating/MineShafts.h
index 2850db571..efb11cfee 100644
--- a/src/Generating/MineShafts.h
+++ b/src/Generating/MineShafts.h
@@ -10,7 +10,6 @@
#pragma once
#include "GridStructGen.h"
-#include "../Noise.h"
diff --git a/src/Generating/Noise3DGenerator.cpp b/src/Generating/Noise3DGenerator.cpp
index f2af75999..78b739d32 100644
--- a/src/Generating/Noise3DGenerator.cpp
+++ b/src/Generating/Noise3DGenerator.cpp
@@ -6,6 +6,7 @@
#include "Globals.h"
#include "Noise3DGenerator.h"
#include "../OSSupport/File.h"
+#include "../OSSupport/Timer.h"
#include "../IniFile.h"
#include "../LinearInterpolation.h"
#include "../LinearUpscale.h"
@@ -61,30 +62,86 @@ public:
-/** Linearly interpolates between two values.
-Assumes that a_Ratio is in range [0, 1]. */
-inline static NOISE_DATATYPE Lerp(NOISE_DATATYPE a_Val1, NOISE_DATATYPE a_Val2, NOISE_DATATYPE a_Ratio)
+#if 0
+// Perform speed test of the cInterpolNoise class
+static class cInterpolNoiseSpeedTest
{
- return a_Val1 + (a_Val2 - a_Val1) * a_Ratio;
-}
-
+public:
+ cInterpolNoiseSpeedTest(void)
+ {
+ TestSpeed2D();
+ TestSpeed3D();
+ printf("InterpolNoise speed comparison finished.\n");
+ }
+ /** Compare the speed of the 3D InterpolNoise vs 3D CubicNoise. */
+ void TestSpeed3D(void)
+ {
+ printf("Evaluating 3D noise performance...\n");
+ static const int SIZE_X = 128;
+ static const int SIZE_Y = 128;
+ static const int SIZE_Z = 128;
+ static const NOISE_DATATYPE MUL = 80;
+ std::unique_ptr<NOISE_DATATYPE[]> arr(new NOISE_DATATYPE[SIZE_X * SIZE_Y * SIZE_Z]);
+ cTimer timer;
+ // Test the cInterpolNoise:
+ cInterpolNoise<Interp5Deg> interpNoise(1);
+ long long start = timer.GetNowTime();
+ for (int i = 0; i < 30; i++)
+ {
+ interpNoise.Generate3D(arr.get(), SIZE_X, SIZE_Y, SIZE_Z, MUL * i, MUL * i + MUL, 0, MUL, 0, MUL);
+ }
+ long long end = timer.GetNowTime();
+ printf("InterpolNoise took %.02f sec\n", static_cast<float>(end - start) / 1000);
-/** Linearly interpolates between two values, clamping the ratio to [0, 1] first. */
-inline static NOISE_DATATYPE ClampedLerp(NOISE_DATATYPE a_Val1, NOISE_DATATYPE a_Val2, NOISE_DATATYPE a_Ratio)
-{
- if (a_Ratio < 0)
- {
- return a_Val1;
+ // Test the cCubicNoise:
+ cCubicNoise cubicNoise(1);
+ start = timer.GetNowTime();
+ for (int i = 0; i < 30; i++)
+ {
+ cubicNoise.Generate3D(arr.get(), SIZE_X, SIZE_Y, SIZE_Z, MUL * i, MUL * i + MUL, 0, MUL, 0, MUL);
+ }
+ end = timer.GetNowTime();
+ printf("CubicNoise took %.02f sec\n", static_cast<float>(end - start) / 1000);
+ printf("3D noise performance comparison finished.\n");
}
- if (a_Ratio > 1)
+
+
+ /** Compare the speed of the 2D InterpolNoise vs 2D CubicNoise. */
+ void TestSpeed2D(void)
{
- return a_Val2;
+ printf("Evaluating 2D noise performance...\n");
+ static const int SIZE_X = 128;
+ static const int SIZE_Y = 128;
+ static const NOISE_DATATYPE MUL = 80;
+ std::unique_ptr<NOISE_DATATYPE[]> arr(new NOISE_DATATYPE[SIZE_X * SIZE_Y]);
+ cTimer timer;
+
+ // Test the cInterpolNoise:
+ cInterpolNoise<Interp5Deg> interpNoise(1);
+ long long start = timer.GetNowTime();
+ for (int i = 0; i < 500; i++)
+ {
+ interpNoise.Generate2D(arr.get(), SIZE_X, SIZE_Y, MUL * i, MUL * i + MUL, 0, MUL);
+ }
+ long long end = timer.GetNowTime();
+ printf("InterpolNoise took %.02f sec\n", static_cast<float>(end - start) / 1000);
+
+ // Test the cCubicNoise:
+ cCubicNoise cubicNoise(1);
+ start = timer.GetNowTime();
+ for (int i = 0; i < 500; i++)
+ {
+ cubicNoise.Generate2D(arr.get(), SIZE_X, SIZE_Y, MUL * i, MUL * i + MUL, 0, MUL);
+ }
+ end = timer.GetNowTime();
+ printf("CubicNoise took %.02f sec\n", static_cast<float>(end - start) / 1000);
+ printf("2D noise performance comparison finished.\n");
}
- return Lerp(a_Val1, a_Val2, a_Ratio);
-}
+} g_InterpolNoiseSpeedTest;
+#endif
@@ -98,9 +155,17 @@ cNoise3DGenerator::cNoise3DGenerator(cChunkGenerator & a_ChunkGenerator) :
m_Perlin(1000),
m_Cubic(1000)
{
- m_Perlin.AddOctave(1, (NOISE_DATATYPE)0.5);
- m_Perlin.AddOctave((NOISE_DATATYPE)0.5, 1);
- m_Perlin.AddOctave((NOISE_DATATYPE)0.5, 2);
+ m_Perlin.AddOctave(1, 1);
+ m_Perlin.AddOctave(2, 0.5);
+ m_Perlin.AddOctave(4, 0.25);
+ m_Perlin.AddOctave(8, 0.125);
+ m_Perlin.AddOctave(16, 0.0625);
+
+ m_Cubic.AddOctave(1, 1);
+ m_Cubic.AddOctave(2, 0.5);
+ m_Cubic.AddOctave(4, 0.25);
+ m_Cubic.AddOctave(8, 0.125);
+ m_Cubic.AddOctave(16, 0.0625);
#if 0
// DEBUG: Test the noise generation:
@@ -183,8 +248,8 @@ void cNoise3DGenerator::Initialize(cIniFile & a_IniFile)
{
// Params:
m_SeaLevel = a_IniFile.GetValueSetI("Generator", "Noise3DSeaLevel", 62);
- m_HeightAmplification = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DHeightAmplification", 0);
- m_MidPoint = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DMidPoint", 75);
+ m_HeightAmplification = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DHeightAmplification", 0.1);
+ m_MidPoint = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DMidPoint", 68);
m_FrequencyX = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyX", 8);
m_FrequencyY = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyY", 8);
m_FrequencyZ = (NOISE_DATATYPE)a_IniFile.GetValueSetF("Generator", "Noise3DFrequencyZ", 8);
@@ -249,10 +314,10 @@ void cNoise3DGenerator::GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DAT
NOISE_DATATYPE NoiseW[DIM_X * DIM_Y * DIM_Z]; // Workspace that the noise calculation can use and trash
// Our noise array has different layout, XZY, instead of regular chunk's XYZ, that's why the coords are "renamed"
- NOISE_DATATYPE StartX = ((NOISE_DATATYPE)(a_ChunkX * cChunkDef::Width)) / m_FrequencyX;
- NOISE_DATATYPE EndX = ((NOISE_DATATYPE)((a_ChunkX + 1) * cChunkDef::Width) - 1) / m_FrequencyX;
- NOISE_DATATYPE StartZ = ((NOISE_DATATYPE)(a_ChunkZ * cChunkDef::Width)) / m_FrequencyZ;
- NOISE_DATATYPE EndZ = ((NOISE_DATATYPE)((a_ChunkZ + 1) * cChunkDef::Width) - 1) / m_FrequencyZ;
+ NOISE_DATATYPE StartX = ((NOISE_DATATYPE)(a_ChunkX * cChunkDef::Width)) / m_FrequencyX;
+ NOISE_DATATYPE EndX = ((NOISE_DATATYPE)((a_ChunkX + 1) * cChunkDef::Width)) / m_FrequencyX;
+ NOISE_DATATYPE StartZ = ((NOISE_DATATYPE)(a_ChunkZ * cChunkDef::Width)) / m_FrequencyZ;
+ NOISE_DATATYPE EndZ = ((NOISE_DATATYPE)((a_ChunkZ + 1) * cChunkDef::Width)) / m_FrequencyZ;
NOISE_DATATYPE StartY = 0;
NOISE_DATATYPE EndY = ((NOISE_DATATYPE)256) / m_FrequencyY;
@@ -262,23 +327,23 @@ void cNoise3DGenerator::GenerateNoiseArray(int a_ChunkX, int a_ChunkZ, NOISE_DAT
// Precalculate a "height" array:
NOISE_DATATYPE Height[DIM_X * DIM_Z]; // Output for the cubic noise heightmap ("source")
- m_Cubic.Generate2D(Height, DIM_X, DIM_Z, StartX / 25, EndX / 25, StartZ / 25, EndZ / 25);
+ m_Cubic.Generate2D(Height, DIM_X, DIM_Z, StartX / 5, EndX / 5, StartZ / 5, EndZ / 5);
for (size_t i = 0; i < ARRAYCOUNT(Height); i++)
{
- Height[i] = std::abs(Height[i]) * m_HeightAmplification + 1;
+ Height[i] = Height[i] * m_HeightAmplification;
}
// Modify the noise by height data:
for (int y = 0; y < DIM_Y; y++)
{
- NOISE_DATATYPE AddHeight = (y * UPSCALE_Y - m_MidPoint) / 20;
- AddHeight *= AddHeight * AddHeight;
+ NOISE_DATATYPE AddHeight = (y * UPSCALE_Y - m_MidPoint) / 30;
+ // AddHeight *= AddHeight * AddHeight;
for (int z = 0; z < DIM_Z; z++)
{
NOISE_DATATYPE * CurRow = &(NoiseO[y * DIM_X + z * DIM_X * DIM_Y]);
for (int x = 0; x < DIM_X; x++)
{
- CurRow[x] += AddHeight / Height[x + DIM_X * z];
+ CurRow[x] += AddHeight + Height[x + DIM_X * z];
}
}
}
diff --git a/src/Generating/Noise3DGenerator.h b/src/Generating/Noise3DGenerator.h
index ba541fbcc..07767ba84 100644
--- a/src/Generating/Noise3DGenerator.h
+++ b/src/Generating/Noise3DGenerator.h
@@ -13,7 +13,8 @@
#pragma once
#include "ComposableGenerator.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
+#include "../Noise/InterpolNoise.h"
@@ -34,17 +35,20 @@ public:
protected:
// Linear interpolation step sizes, must be divisors of cChunkDef::Width and cChunkDef::Height, respectively:
- static const int UPSCALE_X = 8;
- static const int UPSCALE_Y = 4;
- static const int UPSCALE_Z = 8;
+ static const int UPSCALE_X = 4;
+ static const int UPSCALE_Y = 8;
+ static const int UPSCALE_Z = 4;
// Linear interpolation buffer dimensions, calculated from the step sizes:
static const int DIM_X = 1 + cChunkDef::Width / UPSCALE_X;
static const int DIM_Y = 1 + cChunkDef::Height / UPSCALE_Y;
static const int DIM_Z = 1 + cChunkDef::Width / UPSCALE_Z;
- cPerlinNoise m_Perlin; // The base 3D noise source for the actual composition
- cCubicNoise m_Cubic; // The noise used for heightmap directing
+ /** The base 3D noise source for the actual composition */
+ cOctavedNoise<cInterp5DegNoise> m_Perlin;
+
+ /** The noise used for heightmap directing. */
+ cOctavedNoise<cInterp5DegNoise> m_Cubic;
int m_SeaLevel;
NOISE_DATATYPE m_HeightAmplification;
diff --git a/src/Generating/PieceGenerator.h b/src/Generating/PieceGenerator.h
index f06029280..43ffed7a2 100644
--- a/src/Generating/PieceGenerator.h
+++ b/src/Generating/PieceGenerator.h
@@ -20,7 +20,7 @@ Each uses a slightly different approach to generating:
#include "../Defines.h"
#include "../Cuboid.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
diff --git a/src/Generating/Ravines.h b/src/Generating/Ravines.h
index 3e41c5ce6..b11037433 100644
--- a/src/Generating/Ravines.h
+++ b/src/Generating/Ravines.h
@@ -10,7 +10,6 @@
#pragma once
#include "GridStructGen.h"
-#include "../Noise.h"
diff --git a/src/Generating/StructGen.h b/src/Generating/StructGen.h
index 906fdd722..d3b0b5544 100644
--- a/src/Generating/StructGen.h
+++ b/src/Generating/StructGen.h
@@ -14,7 +14,7 @@
#pragma once
#include "ComposableGenerator.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"
diff --git a/src/Generating/Trees.h b/src/Generating/Trees.h
index c9eb7de80..cc0fa87d9 100644
--- a/src/Generating/Trees.h
+++ b/src/Generating/Trees.h
@@ -18,7 +18,7 @@ logs can overwrite others(leaves), but others shouldn't overwrite logs. This is
#pragma once
#include "../ChunkDef.h"
-#include "../Noise.h"
+#include "../Noise/Noise.h"