diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/Generating/BioGen.cpp | 13 | ||||
-rw-r--r-- | source/Generating/CompoGen.cpp | 5 | ||||
-rw-r--r-- | source/Generating/DistortedHeightmap.cpp | 7 | ||||
-rw-r--r-- | source/Generating/HeiGen.cpp | 3 | ||||
-rw-r--r-- | source/Generating/Noise3DGenerator.cpp | 3 | ||||
-rw-r--r-- | source/Generating/StructGen.cpp | 5 | ||||
-rw-r--r-- | source/LinearUpscale.h | 70 | ||||
-rw-r--r-- | source/Noise.cpp | 50 | ||||
-rw-r--r-- | source/Noise.h | 59 |
9 files changed, 91 insertions, 124 deletions
diff --git a/source/Generating/BioGen.cpp b/source/Generating/BioGen.cpp index 1a73fe109..13e7c88ae 100644 --- a/source/Generating/BioGen.cpp +++ b/source/Generating/BioGen.cpp @@ -6,6 +6,7 @@ #include "Globals.h" #include "BioGen.h" #include "../../iniFile/iniFile.h" +#include "../LinearUpscale.h" @@ -339,8 +340,8 @@ void cBioGenDistortedVoronoi::GenBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::B Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z]); } - IntArrayLinearInterpolate2D(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); - IntArrayLinearInterpolate2D(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + ArrayLinearUpscale2D(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + ArrayLinearUpscale2D(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); for (int z = 0; z < cChunkDef::Width; z++) { @@ -446,8 +447,8 @@ void cBioGenMultiStepMap::DecideOceanLandMushroom(int a_ChunkX, int a_ChunkZ, cC { Distort(BaseX + x * 4, BaseZ + z * 4, DistortX[4 * x][4 * z], DistortZ[4 * x][4 * z], DistortSize); } - IntArrayLinearInterpolate2D(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); - IntArrayLinearInterpolate2D(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + ArrayLinearUpscale2D(&DistortX[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); + ArrayLinearUpscale2D(&DistortZ[0][0], cChunkDef::Width + 1, cChunkDef::Width + 1, 4, 4); // Prepare a 9x9 area of neighboring cell seeds // (assuming that 7x7 cell area is larger than a chunk being generated) @@ -620,8 +621,8 @@ void cBioGenMultiStepMap::BuildTemperatureHumidityMaps(int a_ChunkX, int a_Chunk HumidityMap[x + 17 * z] = NoiseH; } // for x } // for z - ArrayLinearInterpolate2D(TemperatureMap, 17, 17, 8, 8); - ArrayLinearInterpolate2D(HumidityMap, 17, 17, 8, 8); + ArrayLinearUpscale2D(TemperatureMap, 17, 17, 8, 8); + ArrayLinearUpscale2D(HumidityMap, 17, 17, 8, 8); // Re-map into integral values in [0 .. 255] range: for (int idx = 0; idx < ARRAYCOUNT(a_TemperatureMap); idx++) diff --git a/source/Generating/CompoGen.cpp b/source/Generating/CompoGen.cpp index 1d2affc94..c8f8ac069 100644 --- a/source/Generating/CompoGen.cpp +++ b/source/Generating/CompoGen.cpp @@ -10,6 +10,7 @@ #include "Globals.h" #include "CompoGen.h" #include "../BlockID.h" +#include "../LinearUpscale.h" @@ -441,7 +442,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc) m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, 0, BaseZ + INTERPOL_Z * z) / 256; } // for x, z - FloorLo[] - IntArrayLinearInterpolate2D(FloorLo, 17, 17, INTERPOL_X, INTERPOL_Z); + ArrayLinearUpscale2D(FloorLo, 17, 17, INTERPOL_X, INTERPOL_Z); // Interpolate segments: for (int Segment = 0; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) @@ -454,7 +455,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc) m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256; } // for x, z - FloorLo[] - IntArrayLinearInterpolate2D(FloorHi, 17, 17, INTERPOL_X, INTERPOL_Z); + ArrayLinearUpscale2D(FloorHi, 17, 17, INTERPOL_X, INTERPOL_Z); // Interpolate between FloorLo and FloorHi: for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) diff --git a/source/Generating/DistortedHeightmap.cpp b/source/Generating/DistortedHeightmap.cpp index 2ffaab089..d44ef60e5 100644 --- a/source/Generating/DistortedHeightmap.cpp +++ b/source/Generating/DistortedHeightmap.cpp @@ -8,6 +8,7 @@ #include "DistortedHeightmap.h"
#include "../OSSupport/File.h"
#include "../../iniFile/iniFile.h"
+#include "../LinearUpscale.h"
@@ -157,7 +158,7 @@ void cDistortedHeightmap::GenerateHeightArray(void) CurFloor[idx + x * INTERPOL_X] = (NOISE_DATATYPE)GetHeightmapAt(DistX, DistZ) + (NOISE_DATATYPE)0.5;
} // for x
} // for z
- ArrayLinearInterpolate2D(CurFloor, 17, 17, INTERPOL_X, INTERPOL_Z);
+ ArrayLinearUpscale2D(CurFloor, 17, 17, INTERPOL_X, INTERPOL_Z);
} // for y
// Finish the 3D linear interpolation by interpolating between each XZ-floors on the Y axis
@@ -344,8 +345,8 @@ void cDistortedHeightmap::UpdateDistortAmps(void) GetDistortAmpsAt(Biomes, x, z, m_DistortAmpX[x + 17 * z], m_DistortAmpZ[x + 17 * z]);
}
}
- ArrayLinearInterpolate2D(m_DistortAmpX, 17, 17, STEPX, STEPZ);
- ArrayLinearInterpolate2D(m_DistortAmpZ, 17, 17, STEPX, STEPZ);
+ ArrayLinearUpscale2D(m_DistortAmpX, 17, 17, STEPX, STEPZ);
+ ArrayLinearUpscale2D(m_DistortAmpZ, 17, 17, STEPX, STEPZ);
}
diff --git a/source/Generating/HeiGen.cpp b/source/Generating/HeiGen.cpp index 99fe5bd32..055ef87e2 100644 --- a/source/Generating/HeiGen.cpp +++ b/source/Generating/HeiGen.cpp @@ -5,6 +5,7 @@ #include "Globals.h" #include "HeiGen.h" +#include "../LinearUpscale.h" @@ -265,7 +266,7 @@ void cHeiGenBiomal::GenHeightMap(int a_ChunkX, int a_ChunkZ, cChunkDef::HeightMa Height[x + 17 * z] = GetHeightAt(x, z, a_ChunkX, a_ChunkZ, Biomes); } } - ArrayLinearInterpolate2D(Height, 17, 17, STEPX, STEPZ); + ArrayLinearUpscale2D(Height, 17, 17, STEPX, STEPZ); // Copy into the heightmap for (int z = 0; z < cChunkDef::Width; z++) diff --git a/source/Generating/Noise3DGenerator.cpp b/source/Generating/Noise3DGenerator.cpp index e406127ed..cebb982fd 100644 --- a/source/Generating/Noise3DGenerator.cpp +++ b/source/Generating/Noise3DGenerator.cpp @@ -8,6 +8,7 @@ #include "../OSSupport/File.h"
#include "../../iniFile/iniFile.h"
#include "../LinearInterpolation.h"
+#include "../LinearUpscale.h"
@@ -439,7 +440,7 @@ void cNoise3DComposable::GenerateNoiseArrayIfNeeded(int a_ChunkX, int a_ChunkZ) }
}
// Linear-interpolate this XZ floor:
- ArrayLinearInterpolate2D(CurFloor, 17, 17, INTERPOL_X, INTERPOL_Z);
+ ArrayLinearUpscale2D(CurFloor, 17, 17, INTERPOL_X, INTERPOL_Z);
}
// Finish the 3D linear interpolation by interpolating between each XZ-floors on the Y axis
diff --git a/source/Generating/StructGen.cpp b/source/Generating/StructGen.cpp index 044e789b5..e5ac03b49 100644 --- a/source/Generating/StructGen.cpp +++ b/source/Generating/StructGen.cpp @@ -6,6 +6,7 @@ #include "../BlockID.h" #include "Trees.h" #include "../BlockArea.h" +#include "../LinearUpscale.h" @@ -558,7 +559,7 @@ void cStructGenDirectOverhangs::GenStructures(cChunkDesc & a_ChunkDesc) m_Noise2.IntNoise3DInt(BaseX + INTERPOL_X * x, BaseY, BaseZ + INTERPOL_Z * z) / 256; } // for x, z - FloorLo[] - IntArrayLinearInterpolate2D(FloorLo, 17, 17, INTERPOL_X, INTERPOL_Z); + ArrayLinearUpscale2D(FloorLo, 17, 17, INTERPOL_X, INTERPOL_Z); // Interpolate segments: for (int Segment = BaseY; Segment < MaxHeight; Segment += SEGMENT_HEIGHT) @@ -571,7 +572,7 @@ void cStructGenDirectOverhangs::GenStructures(cChunkDesc & a_ChunkDesc) m_Noise2.IntNoise3DInt(BaseX + INTERPOL_Z * x, Segment + SEGMENT_HEIGHT, BaseZ + INTERPOL_Z * z) / 256; } // for x, z - FloorLo[] - IntArrayLinearInterpolate2D(FloorHi, 17, 17, INTERPOL_X, INTERPOL_Z); + ArrayLinearUpscale2D(FloorHi, 17, 17, INTERPOL_X, INTERPOL_Z); // Interpolate between FloorLo and FloorHi: for (int z = 0; z < 16; z++) for (int x = 0; x < 16; x++) diff --git a/source/LinearUpscale.h b/source/LinearUpscale.h new file mode 100644 index 000000000..c20e3d3bb --- /dev/null +++ b/source/LinearUpscale.h @@ -0,0 +1,70 @@ +
+// LinearUpscale.h
+
+// Declares the functions for linearly upscaling arrays
+
+/*
+Upscaling means that the array is divided into same-size "cells", and each cell is
+linearly interpolated between its corners. The array's dimensions are therefore
+1 + CellSize * NumCells, for each direction.
+
+Upscaling is more efficient than linear interpolation, because the cell sizes are integral
+and therefore the cells' boundaries are on the array points.
+
+However, upscaling usually requires generating the "1 +" in each direction.
+
+Upscaling is implemented in templates, so that it's compatible with multiple datatypes.
+Therefore, there is no cpp file.
+*/
+
+
+
+
+/// Linearly interpolates values in the array between the equidistant anchor points; universal data type
+template<typename TYPE> void ArrayLinearUpscale2D(
+ TYPE * a_Array,
+ int a_SizeX, int a_SizeY, // Dimensions of the array
+ int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction
+)
+{
+ // First interpolate columns where the anchor points are:
+ int LastYCell = a_SizeY - a_AnchorStepY;
+ for (int y = 0; y < LastYCell; y += a_AnchorStepY)
+ {
+ int Idx = a_SizeX * y;
+ for (int x = 0; x < a_SizeX; x += a_AnchorStepX)
+ {
+ TYPE StartValue = a_Array[Idx];
+ TYPE EndValue = a_Array[Idx + a_SizeX * a_AnchorStepY];
+ TYPE Diff = EndValue - StartValue;
+ for (int CellY = 1; CellY < a_AnchorStepY; CellY++)
+ {
+ a_Array[Idx + a_SizeX * CellY] = StartValue + Diff * CellY / a_AnchorStepY;
+ } // for CellY
+ Idx += a_AnchorStepX;
+ } // for x
+ } // for y
+
+ // Now interpolate in rows, each row has values in the anchor columns
+ int LastXCell = a_SizeX - a_AnchorStepX;
+ for (int y = 0; y < a_SizeY; y++)
+ {
+ int Idx = a_SizeX * y;
+ for (int x = 0; x < LastXCell; x += a_AnchorStepX)
+ {
+ TYPE StartValue = a_Array[Idx];
+ TYPE EndValue = a_Array[Idx + a_AnchorStepX];
+ TYPE Diff = EndValue - StartValue;
+ for (int CellX = 1; CellX < a_AnchorStepX; CellX++)
+ {
+ a_Array[Idx + CellX] = StartValue + CellX * Diff / a_AnchorStepX;
+ } // for CellY
+ Idx += a_AnchorStepX;
+ }
+ }
+}
+
+
+
+
+
diff --git a/source/Noise.cpp b/source/Noise.cpp index fb369c6a0..87b3bd4a5 100644 --- a/source/Noise.cpp +++ b/source/Noise.cpp @@ -18,56 +18,6 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// Globals: - -void IntArrayLinearInterpolate2D( - int * a_Array, - int a_SizeX, int a_SizeY, // Dimensions of the array - int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction -) -{ - // First interpolate columns where the anchor points are: - int LastYCell = a_SizeY - a_AnchorStepY; - for (int y = 0; y < LastYCell; y += a_AnchorStepY) - { - int Idx = a_SizeX * y; - for (int x = 0; x < a_SizeX; x += a_AnchorStepX) - { - int StartValue = a_Array[Idx]; - int EndValue = a_Array[Idx + a_SizeX * a_AnchorStepY]; - int Diff = EndValue - StartValue; - for (int CellY = 1; CellY < a_AnchorStepY; CellY++) - { - a_Array[Idx + a_SizeX * CellY] = StartValue + CellY * Diff / a_AnchorStepY; - } // for CellY - Idx += a_AnchorStepX; - } // for x - } // for y - - // Now interpolate in rows, each row has values in the anchor columns - int LastXCell = a_SizeX - a_AnchorStepX; - for (int y = 0; y < a_SizeY; y++) - { - int Idx = a_SizeX * y; - for (int x = 0; x < LastXCell; x += a_AnchorStepX) - { - int StartValue = a_Array[Idx]; - int EndValue = a_Array[Idx + a_AnchorStepX]; - int Diff = EndValue - StartValue; - for (int CellX = 1; CellX < a_AnchorStepX; CellX++) - { - a_Array[Idx + CellX] = StartValue + CellX * Diff / a_AnchorStepX; - } // for CellY - Idx += a_AnchorStepX; - } - } -} - - - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cCubicCell2D: class cCubicCell2D diff --git a/source/Noise.h b/source/Noise.h index cc1c169fb..a38406937 100644 --- a/source/Noise.h +++ b/source/Noise.h @@ -61,65 +61,6 @@ private: -/// Linearly interpolates values in the array between the anchor points -extern void IntArrayLinearInterpolate2D( - int * a_Array, - int a_SizeX, int a_SizeY, // Dimensions of the array - int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction -); - - - - - -/// Linearly interpolates values in the array between the anchor points; universal data type -template<typename TYPE> void ArrayLinearInterpolate2D( - TYPE * a_Array, - int a_SizeX, int a_SizeY, // Dimensions of the array - int a_AnchorStepX, int a_AnchorStepY // Distances between the anchor points in each direction -) -{ - // First interpolate columns where the anchor points are: - int LastYCell = a_SizeY - a_AnchorStepY; - for (int y = 0; y < LastYCell; y += a_AnchorStepY) - { - int Idx = a_SizeX * y; - for (int x = 0; x < a_SizeX; x += a_AnchorStepX) - { - TYPE StartValue = a_Array[Idx]; - TYPE EndValue = a_Array[Idx + a_SizeX * a_AnchorStepY]; - TYPE Diff = EndValue - StartValue; - for (int CellY = 1; CellY < a_AnchorStepY; CellY++) - { - a_Array[Idx + a_SizeX * CellY] = StartValue + Diff * CellY / a_AnchorStepY; - } // for CellY - Idx += a_AnchorStepX; - } // for x - } // for y - - // Now interpolate in rows, each row has values in the anchor columns - int LastXCell = a_SizeX - a_AnchorStepX; - for (int y = 0; y < a_SizeY; y++) - { - int Idx = a_SizeX * y; - for (int x = 0; x < LastXCell; x += a_AnchorStepX) - { - TYPE StartValue = a_Array[Idx]; - TYPE EndValue = a_Array[Idx + a_AnchorStepX]; - TYPE Diff = EndValue - StartValue; - for (int CellX = 1; CellX < a_AnchorStepX; CellX++) - { - a_Array[Idx + CellX] = StartValue + CellX * Diff / a_AnchorStepX; - } // for CellY - Idx += a_AnchorStepX; - } - } -} - - - - - class cCubicNoise { public: |