1
0
Fork 0

Renamed linear interpolation from Noise.h to a more proper LinearUpscale and moved it to a separate file.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1475 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-05-12 17:55:49 +00:00
parent d851c47acd
commit 1927095d25
10 changed files with 95 additions and 124 deletions

View File

@ -517,6 +517,10 @@
RelativePath="..\source\LinearInterpolation.h"
>
</File>
<File
RelativePath="..\source\LinearUpscale.h"
>
</File>
<File
RelativePath="..\source\Log.cpp"
>

View File

@ -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++)

View File

@ -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++)

View File

@ -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);
}

View File

@ -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++)

View File

@ -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

View File

@ -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++)

70
source/LinearUpscale.h Normal file
View File

@ -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;
}
}
}

View File

@ -17,56 +17,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:

View File

@ -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: