14 #define FAST_FLOOR(x) (((x) < 0) ? ((static_cast<int>(x)) - 1) : (static_cast<int>(x)))
30 int a_SizeX,
int a_SizeY,
49 int a_FromX,
int a_ToX,
50 int a_FromY,
int a_ToY
53 for (
int y = a_FromY; y < a_ToY; y++)
59 int idx = y *
m_SizeX + a_FromX;
60 for (
int x = a_FromX; x < a_ToX; x++)
81 void Move(
int a_NewFloorX,
int a_NewFloorY)
91 int DiffX = OldFloorX - a_NewFloorX;
92 int DiffY = OldFloorY - a_NewFloorY;
93 for (
int x = 0; x < 2; x++)
95 int cx = a_NewFloorX + x;
97 for (
int y = 0; y < 2; y++)
99 int cy = a_NewFloorY + y;
100 int OldY = y - DiffY;
101 if ((OldX >= 0) && (OldX < 2) && (OldY >= 0) && (OldY < 2))
103 (*m_WorkRnds)[x][y] = (*OldWorkRnds)[OldX][OldY];
155 template <
typename T>
162 int a_SizeX,
int a_SizeY,
int a_SizeZ,
185 int a_FromX,
int a_ToX,
186 int a_FromY,
int a_ToY,
187 int a_FromZ,
int a_ToZ
190 for (
int z = a_FromZ; z < a_ToZ; z++)
195 for (
int x = 0; x < 2; x++)
197 for (
int y = 0; y < 2; y++)
202 for (
int y = a_FromY; y < a_ToY; y++)
206 Interp[0] =
Lerp(Interp2[0][0], Interp2[0][1], FracY);
207 Interp[1] =
Lerp(Interp2[1][0], Interp2[1][1], FracY);
208 int idx = idxZ + y *
m_SizeX + a_FromX;
209 for (
int x = a_FromX; x < a_ToX; x++)
236 void Move(
int a_NewFloorX,
int a_NewFloorY,
int a_NewFloorZ)
247 int DiffX = OldFloorX - a_NewFloorX;
248 int DiffY = OldFloorY - a_NewFloorY;
249 int DiffZ = OldFloorZ - a_NewFloorZ;
250 for (
int x = 0; x < 2; x++)
252 int cx = a_NewFloorX + x;
253 int OldX = x - DiffX;
254 for (
int y = 0; y < 2; y++)
256 int cy = a_NewFloorY + y;
257 int OldY = y - DiffY;
258 for (
int z = 0; z < 2; z++)
260 int cz = a_NewFloorZ + z;
261 int OldZ = z - DiffZ;
262 if ((OldX >= 0) && (OldX < 2) && (OldY >= 0) && (OldY < 2) && (OldZ >= 0) && (OldZ < 2))
264 (*m_WorkRnds)[x][y][z] = (*OldWorkRnds)[OldX][OldY][OldZ];
315 template <
typename T>
338 int a_SizeX,
int a_SizeY,
347 ASSERT(a_StartX < a_EndX);
348 ASSERT(a_StartY < a_EndY);
357 int NumSameX, NumSameY;
358 CalcFloorFrac(a_SizeX, a_StartX, a_EndX, FloorX, FracX, SameX, NumSameX);
359 CalcFloorFrac(a_SizeY, a_StartY, a_EndY, FloorY, FracY, SameY, NumSameY);
367 for (
int y = 0; y < NumSameY; y++)
369 int ToY = FromY + SameY[y];
371 int CurFloorY = FloorY[FromY];
372 for (
int x = 0; x < NumSameX; x++)
374 int ToX = FromX + SameX[x];
375 Cell.
Generate(FromX, ToX, FromY, ToY);
376 Cell.
Move(FloorX[ToX], CurFloorY);
379 Cell.
Move(FloorX[0], FloorY[ToY]);
388 int a_SizeX,
int a_SizeY,
int a_SizeZ,
401 ASSERT(a_StartX < a_EndX);
402 ASSERT(a_StartY < a_EndY);
403 ASSERT(a_StartZ < a_EndZ);
415 int NumSameX, NumSameY, NumSameZ;
416 CalcFloorFrac(a_SizeX, a_StartX, a_EndX, FloorX, FracX, SameX, NumSameX);
417 CalcFloorFrac(a_SizeY, a_StartY, a_EndY, FloorY, FracY, SameY, NumSameY);
418 CalcFloorFrac(a_SizeZ, a_StartZ, a_EndZ, FloorZ, FracZ, SameZ, NumSameZ);
422 a_SizeX, a_SizeY, a_SizeZ,
430 for (
int z = 0; z < NumSameZ; z++)
432 int ToZ = FromZ + SameZ[z];
433 int CurFloorZ = FloorZ[FromZ];
435 for (
int y = 0; y < NumSameY; y++)
437 int ToY = FromY + SameY[y];
438 int CurFloorY = FloorY[FromY];
440 for (
int x = 0; x < NumSameX; x++)
442 int ToX = FromX + SameX[x];
443 Cell.
Generate(FromX, ToX, FromY, ToY, FromZ, ToZ);
444 Cell.
Move(FloorX[ToX], CurFloorY, CurFloorZ);
447 Cell.
Move(FloorX[0], FloorY[ToY], CurFloorZ);
450 Cell.
Move(FloorX[0], FloorY[0], FloorZ[ToZ]);
470 int * a_Same,
int & a_NumSame
478 for (
int i = 0; i < a_Size; i++)
481 a_Frac[i] = val - a_Floor[i];
486 int CurFloor = a_Floor[0];
489 for (
int i = 1; i < a_Size; i++)
491 if (a_Floor[i] != CurFloor)
493 a_Same[a_NumSame] = i - LastSame;
496 CurFloor = a_Floor[i];
499 if (LastSame < a_Size)
501 a_Same[a_NumSame] = a_Size - LastSame;
517 return a_Val * a_Val * a_Val * (a_Val * (a_Val * 6 - 15) + 10);
cInterpolNoise< Interp5Deg > cInterp5DegNoise
NOISE_DATATYPE Lerp(NOISE_DATATYPE a_Val1, NOISE_DATATYPE a_Val2, NOISE_DATATYPE a_Ratio)
Linearly interpolates between two values.
float NOISE_DATATYPE
The datatype used by all the noise generators.
NOISE_DATATYPE Workspace[2][2]
Workspace m_Workspace1
Buffer 1 for workspace doublebuffering, used in Move()
const NOISE_DATATYPE * m_FracX
Arrays holding the fractional values of the coords in each direction.
int m_CurFloorX
Coords of the currently calculated m_WorkRnds[].
void Generate(int a_FromX, int a_ToX, int a_FromY, int a_ToY)
Generates part of the output noise array using the current m_WorkRnds[] values.
Workspace * m_WorkRnds
The current random values; points to either m_Workspace1 or m_Workspace2 (doublebuffering)
int m_SizeX
Dimensions of the output array.
Workspace m_Workspace2
Buffer 2 for workspace doublebuffering, used in Move()
void Move(int a_NewFloorX, int a_NewFloorY)
Updates m_WorkRnds[] for the new integral coords.
cInterpolCell2D(const cNoise &a_Noise, NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, const NOISE_DATATYPE *a_FracX, const NOISE_DATATYPE *a_FracY)
const cNoise & m_Noise
The noise used for generating the values at integral coords.
NOISE_DATATYPE * m_Array
The output array to generate into.
const NOISE_DATATYPE * m_FracY
void InitWorkRnds(int a_FloorX, int a_FloorY)
Initializes m_WorkRnds[] with the specified values of the noise at the specified integral coords.
Holds a cache of the last calculated integral noise values and interpolates between them en masse.
NOISE_DATATYPE Workspace[2][2][2]
const NOISE_DATATYPE * m_FracZ
Workspace * m_WorkRnds
The current random values; points to either m_Workspace1 or m_Workspace2 (doublebuffering)
int m_SizeX
Dimensions of the output array.
void Generate(int a_FromX, int a_ToX, int a_FromY, int a_ToY, int a_FromZ, int a_ToZ)
Generates part of the output array using current m_WorkRnds[].
int m_CurFloorX
The integral coords of the currently calculated WorkRnds[].
void InitWorkRnds(int a_FloorX, int a_FloorY, int a_FloorZ)
Initializes m_WorkRnds[] with the specified Floor values.
Workspace m_Workspace2
Buffer 2 for workspace doublebuffering, used in Move()
cInterpolCell3D(const cNoise &a_Noise, NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, int a_SizeZ, const NOISE_DATATYPE *a_FracX, const NOISE_DATATYPE *a_FracY, const NOISE_DATATYPE *a_FracZ)
const NOISE_DATATYPE * m_FracY
void Move(int a_NewFloorX, int a_NewFloorY, int a_NewFloorZ)
Updates m_WorkRnds[] for the new Floor values.
Workspace m_Workspace1
Buffer 1 for workspace doublebuffering, used in Move()
NOISE_DATATYPE * m_Array
The output array where the noise is calculated.
const cNoise & m_Noise
The noise used for generating the values at integral coords.
const NOISE_DATATYPE * m_FracX
Arrays holding the fractional values of the coords in each direction.
void Generate3D(NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, int a_SizeZ, NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY, NOISE_DATATYPE a_StartZ, NOISE_DATATYPE a_EndZ) const
Fills a 3D array with the values of the noise.
cNoise m_Noise
The noise used for the underlying value generation.
void SetSeed(int a_Seed)
Sets a new seed for the generators.
cInterpolNoise(int a_Seed)
static const int MAX_SIZE
Maximum size, for each direction, of the generated array.
void CalcFloorFrac(int a_Size, NOISE_DATATYPE a_Start, NOISE_DATATYPE a_End, int *a_Floor, NOISE_DATATYPE *a_Frac, int *a_Same, int &a_NumSame) const
Calculates the integral and fractional parts along one axis.
void Generate2D(NOISE_DATATYPE *a_Array, int a_SizeX, int a_SizeY, NOISE_DATATYPE a_StartX, NOISE_DATATYPE a_EndX, NOISE_DATATYPE a_StartY, NOISE_DATATYPE a_EndY) const
Fills a 2D array with the values of the noise.
A fifth-degree curve for interpolating.
static NOISE_DATATYPE coeff(NOISE_DATATYPE a_Val)
NOISE_DATATYPE IntNoise2D(int a_X, int a_Y) const
NOISE_DATATYPE IntNoise3D(int a_X, int a_Y, int a_Z) const