summaryrefslogtreecommitdiffstats
path: root/source/Generating/Noise3DGenerator.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-15 17:55:04 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-15 17:55:04 +0200
commit1118ae303329ef0d6d8a9441704f8c99886f83fe (patch)
tree34f5b3d8b742114ffa1ac1564136d340e8b2b45b /source/Generating/Noise3DGenerator.cpp
parentPickup: fixed logging parameters causing a crash. (diff)
downloadcuberite-1118ae303329ef0d6d8a9441704f8c99886f83fe.tar
cuberite-1118ae303329ef0d6d8a9441704f8c99886f83fe.tar.gz
cuberite-1118ae303329ef0d6d8a9441704f8c99886f83fe.tar.bz2
cuberite-1118ae303329ef0d6d8a9441704f8c99886f83fe.tar.lz
cuberite-1118ae303329ef0d6d8a9441704f8c99886f83fe.tar.xz
cuberite-1118ae303329ef0d6d8a9441704f8c99886f83fe.tar.zst
cuberite-1118ae303329ef0d6d8a9441704f8c99886f83fe.zip
Diffstat (limited to 'source/Generating/Noise3DGenerator.cpp')
-rw-r--r--source/Generating/Noise3DGenerator.cpp46
1 files changed, 42 insertions, 4 deletions
diff --git a/source/Generating/Noise3DGenerator.cpp b/source/Generating/Noise3DGenerator.cpp
index 42a0d70d9..79138aa9f 100644
--- a/source/Generating/Noise3DGenerator.cpp
+++ b/source/Generating/Noise3DGenerator.cpp
@@ -61,14 +61,36 @@ void Debug3DNoise(NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, int a_Size
f2.Write(buf, a_SizeX);
} // for y
} // if (XZ file open)
- //*/
-
}
+void Debug2DNoise(NOISE_DATATYPE * a_Noise, int a_SizeX, int a_SizeY, const AString & a_FileNameBase)
+{
+ 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))
+ {
+ for (int y = 0; y < a_SizeY; y++)
+ {
+ int idx = y * a_SizeX;
+ unsigned char buf[BUF_SIZE];
+ for (int x = 0; x < a_SizeX; x++)
+ {
+ buf[x] = (unsigned char)(std::min(255, std::max(0, (int)(128 + 32 * a_Noise[idx++]))));
+ }
+ f1.Write(buf, a_SizeX);
+ } // for y
+ } // if (file open)
+}
+
+
+
+
/*
// Perform an automatic test of upscaling upon program start (use breakpoints to debug):
@@ -78,6 +100,7 @@ public:
Test(void)
{
DoTest1();
+ DoTest2();
}
@@ -88,11 +111,26 @@ public:
{
In[i] = (float)(i % 5);
}
- Debug3DNoise(In, 3, 3, 3, "Upscale in");
+ Debug3DNoise(In, 3, 3, 3, "Upscale3D in");
float Out[17 * 33 * 35];
LinearUpscale3DArray(In, 3, 3, 3, Out, 8, 16, 17);
- Debug3DNoise(Out, 17, 33, 35, "Upscale test");
+ Debug3DNoise(Out, 17, 33, 35, "Upscale3D test");
+ }
+
+
+ void DoTest2(void)
+ {
+ float In[3 * 3];
+ for (int i = 0; i < ARRAYCOUNT(In); i++)
+ {
+ In[i] = (float)(i % 5);
+ }
+ Debug2DNoise(In, 3, 3, "Upscale2D in");
+ float Out[17 * 33];
+ LinearUpscale2DArray(In, 3, 3, Out, 8, 16);
+ Debug2DNoise(Out, 17, 33, "Upscale2D test");
}
+
} gTest;
//*/