From 70b79bb9ff1ebb3ad97dd84d7a6dbf5cc7c7f6d4 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 16 Apr 2013 20:48:13 +0000 Subject: Added a test program for the new noise git-svn-id: http://mc-server.googlecode.com/svn/trunk@1388 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- Tests/NoiseTest/NoiseTest.cpp | 100 +++++++++++++++ Tests/NoiseTest/NoiseTest.sln | 20 +++ Tests/NoiseTest/NoiseTest.vcproj | 258 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 378 insertions(+) create mode 100644 Tests/NoiseTest/NoiseTest.cpp create mode 100644 Tests/NoiseTest/NoiseTest.sln create mode 100644 Tests/NoiseTest/NoiseTest.vcproj (limited to 'Tests') diff --git a/Tests/NoiseTest/NoiseTest.cpp b/Tests/NoiseTest/NoiseTest.cpp new file mode 100644 index 000000000..a5d13a235 --- /dev/null +++ b/Tests/NoiseTest/NoiseTest.cpp @@ -0,0 +1,100 @@ + +// NoiseTest.cpp + +// Implements the main app entrypoint + +#include "Globals.h" +#include +#include "Noise.h" + + + + + +void SaveValues(NOISE_DATATYPE * a_Values, const AString & a_FileName) +{ + cFile f; + if (!f.Open(a_FileName, cFile::fmWrite)) + { + LOGWARNING("Cannot write file %s", a_FileName.c_str()); + return; + } + for (int y = 0; y < 256; y++) + { + unsigned char val[256]; + for (int x = 0; x < 256; x++) + { + val[x] = std::min(255, std::max(0, (int)(256 * a_Values[x + 256 * y]))); + } + f.Write(val, 256); + } +} + + + + + +clock_t TestCubicNoise(void) +{ + cCubicNoise Cubic(0); + NOISE_DATATYPE Values[256 * 256]; + + // Do a speed test: + clock_t Begin = clock(); + for (int i = 0; i < 1000; i++) + { + Cubic.Generate2D(Values, 256, 256, 0, 25.6, 0, 25.6); + } + clock_t Ticks = clock() - Begin; + LOG("cCubicNoise generating 1000 * 256x256 values took %d ticks (%.02f sec)", Ticks, (double)Ticks / CLOCKS_PER_SEC); + + // Save the results into a file for visual comparison: + SaveValues(Values, "NoiseCubic.raw"); + + return Ticks; +} + + + + + +clock_t TestOldNoise(void) +{ + cNoise Noise(0); + NOISE_DATATYPE Values[256 * 256]; + + // Do a speed test: + clock_t Begin = clock(); + for (int i = 0; i < 1000; i++) + { + for (int y = 0; y < 256; y++) + { + float fy = (float)y / 10; + for (int x = 0; x < 256; x++) + { + Values[x + 256 * y] = Noise.CubicNoise2D((float)x / 10, fy); + } // for x + } // for y + } + clock_t Ticks = clock() - Begin; + LOG("cNoise generating 1000 * 256x256 values took %d ticks (%.02f sec)", Ticks, (double)Ticks / CLOCKS_PER_SEC); + + // Save the results into a file for visual comparison: + SaveValues(Values, "NoiseOld.raw"); + + return Ticks; +} + + + + + +int main(int argc, char * argv[]) +{ + new cMCLogger(); // Create a logger (will set itself as the main instance + + clock_t NewTicks = TestCubicNoise(); + clock_t OldTicks = TestOldNoise(); + LOG("New method is %.02fx faster", (double)OldTicks / NewTicks); + getchar(); +} diff --git a/Tests/NoiseTest/NoiseTest.sln b/Tests/NoiseTest/NoiseTest.sln new file mode 100644 index 000000000..bd55aeef1 --- /dev/null +++ b/Tests/NoiseTest/NoiseTest.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NoiseTest", "NoiseTest.vcproj", "{8FDBCFC4-E1CF-4704-999C-29A08F9D6053}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8FDBCFC4-E1CF-4704-999C-29A08F9D6053}.Debug|Win32.ActiveCfg = Debug|Win32 + {8FDBCFC4-E1CF-4704-999C-29A08F9D6053}.Debug|Win32.Build.0 = Debug|Win32 + {8FDBCFC4-E1CF-4704-999C-29A08F9D6053}.Release|Win32.ActiveCfg = Release|Win32 + {8FDBCFC4-E1CF-4704-999C-29A08F9D6053}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/Tests/NoiseTest/NoiseTest.vcproj b/Tests/NoiseTest/NoiseTest.vcproj new file mode 100644 index 000000000..a95740e82 --- /dev/null +++ b/Tests/NoiseTest/NoiseTest.vcproj @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3