From d777c7efd9fa63f56291f1d77e446e17b33b0707 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Sat, 21 Dec 2013 12:59:41 +0000 Subject: Moved some files. --- Tests/ConsoleColors/ConsoleColors.cpp | 62 -------- Tests/NoiseTest/GNUmakefile | 163 --------------------- Tests/NoiseTest/NoiseTest.cpp | 101 ------------- Tests/NoiseTest/NoiseTest.sln | 20 --- Tests/NoiseTest/NoiseTest.vcproj | 258 ---------------------------------- tests/ConsoleColors/ConsoleColors.cpp | 62 ++++++++ tests/NoiseTest/GNUmakefile | 163 +++++++++++++++++++++ tests/NoiseTest/NoiseTest.cpp | 101 +++++++++++++ tests/NoiseTest/NoiseTest.sln | 20 +++ tests/NoiseTest/NoiseTest.vcproj | 258 ++++++++++++++++++++++++++++++++++ 10 files changed, 604 insertions(+), 604 deletions(-) delete mode 100644 Tests/ConsoleColors/ConsoleColors.cpp delete mode 100644 Tests/NoiseTest/GNUmakefile delete mode 100644 Tests/NoiseTest/NoiseTest.cpp delete mode 100644 Tests/NoiseTest/NoiseTest.sln delete mode 100644 Tests/NoiseTest/NoiseTest.vcproj create mode 100644 tests/ConsoleColors/ConsoleColors.cpp create mode 100644 tests/NoiseTest/GNUmakefile create mode 100644 tests/NoiseTest/NoiseTest.cpp create mode 100644 tests/NoiseTest/NoiseTest.sln create mode 100644 tests/NoiseTest/NoiseTest.vcproj diff --git a/Tests/ConsoleColors/ConsoleColors.cpp b/Tests/ConsoleColors/ConsoleColors.cpp deleted file mode 100644 index 7efc698b2..000000000 --- a/Tests/ConsoleColors/ConsoleColors.cpp +++ /dev/null @@ -1,62 +0,0 @@ - -// ConsoleColors.cpp - -// Tests the various console color combinations - -#include -#include - - - - - -/// Evaluates to the number of elements in an array (compile-time!) -#define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X))) - - - - - -int main(void) -{ - static const char * Attribs[] = - { - "0", // All attribs off - "1", // bold - "2", // faint - "7", // inverse - "1;7", // bold inverse - "2;7", // faint inverse - } ; - for (int i = 0; i < ARRAYCOUNT(Attribs); i++) - { - const char * Attrib = Attribs[i]; - for (int fg = 30; fg <= 37; fg++) - { - for (int bg = 40; bg <= 47; bg++) - { - printf("\x1b[%s;%d;%dm %s;%d;%d ", Attrib, fg, bg, Attrib, fg, bg); - } // for bg - puts("\x1b[0m"); // Reset terminal back to normal colors for the newline - } // for fg - } // for i - Attribs[] - - for (int i = 1; i < ARRAYCOUNT(Attribs); i++) - { - const char * Attrib = Attribs[i]; - for (int fg = 30; fg <= 37; fg++) - { - for (int bg = 40; bg <= 47; bg++) - { - printf("\x1b[%d;%d;%sm %d;%d;%s ", fg, bg, Attrib, fg, bg, Attrib); - } // for bg - puts("\x1b[0m"); // Reset terminal back to normal colors for the newline - } // for fg - } // for i - Attribs[] - - return 0; -} - - - - diff --git a/Tests/NoiseTest/GNUmakefile b/Tests/NoiseTest/GNUmakefile deleted file mode 100644 index 436cfdcfe..000000000 --- a/Tests/NoiseTest/GNUmakefile +++ /dev/null @@ -1,163 +0,0 @@ -################################################### -# -# Makefile for NoiseTest -# Creator: xoft -# -################################################### -# -# Usage: -# To make a release build, call "make" -# To make a debug build, call "make debug=1" -# -################################################### - -# -# Macros -# - -CC = /usr/bin/g++ - - -all: NoiseTest - - - - - -################################################### -# Set the variables used for compiling, based on the build mode requested: -# CC_OPTIONS ... options for the C code compiler -# CXX_OPTIONS ... options for the C++ code compiler -# LNK_OPTIONS ... options for the linker -# LNK_LIBS ... libraries to link in -# -- according to http://stackoverflow.com/questions/6183899/undefined-reference-to-dlopen, libs must come after all sources -# BUILDDIR ... folder where the intermediate object files are built - -LNK_LIBS = -lstdc++ -ldl - -ifeq ($(debug),1) -################ -# debug build - fully traceable by gdb in C++ code, slowest -# Since C code is used only for supporting libraries (zlib, lua), it is still O3-optimized -################ -CC_OPTIONS = -s -ggdb -g -D_DEBUG -O3 -CXX_OPTIONS = -s -ggdb -g -D_DEBUG -LNK_OPTIONS = -pthread -g -ggdb -BUILDDIR = build/debug/ - -else -ifeq ($(profile),1) -################ -# profile build - a release build with symbols and profiling engine built in -################ -CC_OPTIONS = -s -g -ggdb -O3 -pg -DNDEBUG -CXX_OPTIONS = -s -g -ggdb -O3 -pg -DNDEBUG -LNK_OPTIONS = -pthread -ggdb -O3 -pg -BUILDDIR = build/profile/ - -else -ifeq ($(pedantic),1) -################ -# pedantic build - basically a debug build with lots of warnings -################ -CC_OPTIONS = -s -g -ggdb -D_DEBUG -Wall -Wextra -pedantic -ansi -Wno-long-long -CXX_OPTIONS = -s -g -ggdb -D_DEBUG -Wall -Wextra -pedantic -ansi -Wno-long-long -LNK_OPTIONS = -pthread -ggdb -BUILDDIR = build/pedantic/ - -else -################ -# release build - fastest run-time, no gdb support -################ -CC_OPTIONS = -s -g -O3 -DNDEBUG -CXX_OPTIONS = -s -g -O3 -DNDEBUG -LNK_OPTIONS = -pthread -O3 -BUILDDIR = build/release/ -endif -endif -endif - - - - - -################################################### -# INCLUDE directories -# - -INCLUDE = -I.\ - -I../../source\ - - - - - -################################################### -# Build NoiseTest -# - -SOURCES = NoiseTest.cpp - -SHAREDSOURCES = \ - source/Log.cpp \ - source/MCLogger.cpp \ - source/Noise.cpp \ - source/StringUtils.cpp \ - source/OSSupport/CriticalSection.cpp \ - source/OSSupport/File.cpp \ - source/OSSupport/IsThread.cpp \ - source/OSSupport/MakeDir.cpp \ - -OBJECTS := $(patsubst %.c,$(BUILDDIR)%.o,$(SOURCES)) -OBJECTS := $(patsubst %.cpp,$(BUILDDIR)%.o,$(OBJECTS)) - -SHAREDOBJECTS := $(patsubst %.c,$(BUILDDIR)%.o,$(SHAREDSOURCES)) -SHAREDOBJECTS := $(patsubst %.cpp,$(BUILDDIR)%.o,$(SHAREDOBJECTS)) - --include $(patsubst %.o,%.d,$(OBJECTS)) --include $(patsubst %.o,%.d,$(SHAREDOBJECTS)) - -NoiseTest : $(OBJECTS) $(SHAREDOBJECTS) - $(CC) $(LNK_OPTIONS) $(OBJECTS) $(SHAREDOBJECTS) $(LNK_LIBS) -o NoiseTest - -clean : - rm -rf $(BUILDDIR) NoiseTest - - - - - -################################################### -# Build the parts of MCServer -# -# options used: -# -x c ... compile as C code -# -c ... compile but do not link -# -MM ... generate a list of includes - -$(BUILDDIR)%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CC_OPTIONS) -x c -c $(INCLUDE) $< -o $@ - @$(CC) $(CC_OPTIONS) -x c -MM $(INCLUDE) $< > $(patsubst %.o,%.d,$@) - @mv -f $(patsubst %.o,%.d,$@) $(patsubst %.o,%.d,$@).tmp - @sed -e "s|.*:|$(BUILDDIR)$*.o:|" < $(patsubst %.o,%.d,$@).tmp > $(patsubst %.o,%.d,$@) - @sed -e 's/.*://' -e 's/\\$$//' < $(patsubst %.o,%.d,$@).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(patsubst %.o,%.d,$@) - @rm -f $(patsubst %.o,%.d,$@).tmp - -$(BUILDDIR)%.o: %.cpp - @mkdir -p $(dir $@) - $(CC) $(CXX_OPTIONS) -c $(INCLUDE) $< -o $@ - @$(CC) $(CXX_OPTIONS) -MM $(INCLUDE) $< > $(patsubst %.o,%.d,$@) - @mv -f $(patsubst %.o,%.d,$@) $(patsubst %.o,%.d,$@).tmp - @sed -e "s|.*:|$(BUILDDIR)$*.o:|" < $(patsubst %.o,%.d,$@).tmp > $(patsubst %.o,%.d,$@) - @sed -e 's/.*://' -e 's/\\$$//' < $(patsubst %.o,%.d,$@).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(patsubst %.o,%.d,$@) - @rm -f $(patsubst %.o,%.d,$@).tmp - -$(BUILDDIR)source/%.o: ../../source/%.cpp - @mkdir -p $(dir $@) - $(CC) $(CXX_OPTIONS) -c $(INCLUDE) $< -o $@ - @$(CC) $(CXX_OPTIONS) -MM $(INCLUDE) $< > $(patsubst %.o,%.d,$@) - @mv -f $(patsubst %.o,%.d,$@) $(patsubst %.o,%.d,$@).tmp - @sed -e "s|.*:|$(BUILDDIR)$*.o:|" < $(patsubst %.o,%.d,$@).tmp > $(patsubst %.o,%.d,$@) - @sed -e 's/.*://' -e 's/\\$$//' < $(patsubst %.o,%.d,$@).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(patsubst %.o,%.d,$@) - @rm -f $(patsubst %.o,%.d,$@).tmp diff --git a/Tests/NoiseTest/NoiseTest.cpp b/Tests/NoiseTest/NoiseTest.cpp deleted file mode 100644 index 5542f3ca6..000000000 --- a/Tests/NoiseTest/NoiseTest.cpp +++ /dev/null @@ -1,101 +0,0 @@ - -// 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, (NOISE_DATATYPE)25.6, 0, (NOISE_DATATYPE)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); - LOG("Press Enter to quit program"); - getchar(); -} diff --git a/Tests/NoiseTest/NoiseTest.sln b/Tests/NoiseTest/NoiseTest.sln deleted file mode 100644 index 240e97d01..000000000 --- a/Tests/NoiseTest/NoiseTest.sln +++ /dev/null @@ -1,20 +0,0 @@ - -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 deleted file mode 100644 index d8741f74c..000000000 --- a/Tests/NoiseTest/NoiseTest.vcproj +++ /dev/null @@ -1,258 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/ConsoleColors/ConsoleColors.cpp b/tests/ConsoleColors/ConsoleColors.cpp new file mode 100644 index 000000000..7efc698b2 --- /dev/null +++ b/tests/ConsoleColors/ConsoleColors.cpp @@ -0,0 +1,62 @@ + +// ConsoleColors.cpp + +// Tests the various console color combinations + +#include +#include + + + + + +/// Evaluates to the number of elements in an array (compile-time!) +#define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X))) + + + + + +int main(void) +{ + static const char * Attribs[] = + { + "0", // All attribs off + "1", // bold + "2", // faint + "7", // inverse + "1;7", // bold inverse + "2;7", // faint inverse + } ; + for (int i = 0; i < ARRAYCOUNT(Attribs); i++) + { + const char * Attrib = Attribs[i]; + for (int fg = 30; fg <= 37; fg++) + { + for (int bg = 40; bg <= 47; bg++) + { + printf("\x1b[%s;%d;%dm %s;%d;%d ", Attrib, fg, bg, Attrib, fg, bg); + } // for bg + puts("\x1b[0m"); // Reset terminal back to normal colors for the newline + } // for fg + } // for i - Attribs[] + + for (int i = 1; i < ARRAYCOUNT(Attribs); i++) + { + const char * Attrib = Attribs[i]; + for (int fg = 30; fg <= 37; fg++) + { + for (int bg = 40; bg <= 47; bg++) + { + printf("\x1b[%d;%d;%sm %d;%d;%s ", fg, bg, Attrib, fg, bg, Attrib); + } // for bg + puts("\x1b[0m"); // Reset terminal back to normal colors for the newline + } // for fg + } // for i - Attribs[] + + return 0; +} + + + + diff --git a/tests/NoiseTest/GNUmakefile b/tests/NoiseTest/GNUmakefile new file mode 100644 index 000000000..436cfdcfe --- /dev/null +++ b/tests/NoiseTest/GNUmakefile @@ -0,0 +1,163 @@ +################################################### +# +# Makefile for NoiseTest +# Creator: xoft +# +################################################### +# +# Usage: +# To make a release build, call "make" +# To make a debug build, call "make debug=1" +# +################################################### + +# +# Macros +# + +CC = /usr/bin/g++ + + +all: NoiseTest + + + + + +################################################### +# Set the variables used for compiling, based on the build mode requested: +# CC_OPTIONS ... options for the C code compiler +# CXX_OPTIONS ... options for the C++ code compiler +# LNK_OPTIONS ... options for the linker +# LNK_LIBS ... libraries to link in +# -- according to http://stackoverflow.com/questions/6183899/undefined-reference-to-dlopen, libs must come after all sources +# BUILDDIR ... folder where the intermediate object files are built + +LNK_LIBS = -lstdc++ -ldl + +ifeq ($(debug),1) +################ +# debug build - fully traceable by gdb in C++ code, slowest +# Since C code is used only for supporting libraries (zlib, lua), it is still O3-optimized +################ +CC_OPTIONS = -s -ggdb -g -D_DEBUG -O3 +CXX_OPTIONS = -s -ggdb -g -D_DEBUG +LNK_OPTIONS = -pthread -g -ggdb +BUILDDIR = build/debug/ + +else +ifeq ($(profile),1) +################ +# profile build - a release build with symbols and profiling engine built in +################ +CC_OPTIONS = -s -g -ggdb -O3 -pg -DNDEBUG +CXX_OPTIONS = -s -g -ggdb -O3 -pg -DNDEBUG +LNK_OPTIONS = -pthread -ggdb -O3 -pg +BUILDDIR = build/profile/ + +else +ifeq ($(pedantic),1) +################ +# pedantic build - basically a debug build with lots of warnings +################ +CC_OPTIONS = -s -g -ggdb -D_DEBUG -Wall -Wextra -pedantic -ansi -Wno-long-long +CXX_OPTIONS = -s -g -ggdb -D_DEBUG -Wall -Wextra -pedantic -ansi -Wno-long-long +LNK_OPTIONS = -pthread -ggdb +BUILDDIR = build/pedantic/ + +else +################ +# release build - fastest run-time, no gdb support +################ +CC_OPTIONS = -s -g -O3 -DNDEBUG +CXX_OPTIONS = -s -g -O3 -DNDEBUG +LNK_OPTIONS = -pthread -O3 +BUILDDIR = build/release/ +endif +endif +endif + + + + + +################################################### +# INCLUDE directories +# + +INCLUDE = -I.\ + -I../../source\ + + + + + +################################################### +# Build NoiseTest +# + +SOURCES = NoiseTest.cpp + +SHAREDSOURCES = \ + source/Log.cpp \ + source/MCLogger.cpp \ + source/Noise.cpp \ + source/StringUtils.cpp \ + source/OSSupport/CriticalSection.cpp \ + source/OSSupport/File.cpp \ + source/OSSupport/IsThread.cpp \ + source/OSSupport/MakeDir.cpp \ + +OBJECTS := $(patsubst %.c,$(BUILDDIR)%.o,$(SOURCES)) +OBJECTS := $(patsubst %.cpp,$(BUILDDIR)%.o,$(OBJECTS)) + +SHAREDOBJECTS := $(patsubst %.c,$(BUILDDIR)%.o,$(SHAREDSOURCES)) +SHAREDOBJECTS := $(patsubst %.cpp,$(BUILDDIR)%.o,$(SHAREDOBJECTS)) + +-include $(patsubst %.o,%.d,$(OBJECTS)) +-include $(patsubst %.o,%.d,$(SHAREDOBJECTS)) + +NoiseTest : $(OBJECTS) $(SHAREDOBJECTS) + $(CC) $(LNK_OPTIONS) $(OBJECTS) $(SHAREDOBJECTS) $(LNK_LIBS) -o NoiseTest + +clean : + rm -rf $(BUILDDIR) NoiseTest + + + + + +################################################### +# Build the parts of MCServer +# +# options used: +# -x c ... compile as C code +# -c ... compile but do not link +# -MM ... generate a list of includes + +$(BUILDDIR)%.o: %.c + @mkdir -p $(dir $@) + $(CC) $(CC_OPTIONS) -x c -c $(INCLUDE) $< -o $@ + @$(CC) $(CC_OPTIONS) -x c -MM $(INCLUDE) $< > $(patsubst %.o,%.d,$@) + @mv -f $(patsubst %.o,%.d,$@) $(patsubst %.o,%.d,$@).tmp + @sed -e "s|.*:|$(BUILDDIR)$*.o:|" < $(patsubst %.o,%.d,$@).tmp > $(patsubst %.o,%.d,$@) + @sed -e 's/.*://' -e 's/\\$$//' < $(patsubst %.o,%.d,$@).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(patsubst %.o,%.d,$@) + @rm -f $(patsubst %.o,%.d,$@).tmp + +$(BUILDDIR)%.o: %.cpp + @mkdir -p $(dir $@) + $(CC) $(CXX_OPTIONS) -c $(INCLUDE) $< -o $@ + @$(CC) $(CXX_OPTIONS) -MM $(INCLUDE) $< > $(patsubst %.o,%.d,$@) + @mv -f $(patsubst %.o,%.d,$@) $(patsubst %.o,%.d,$@).tmp + @sed -e "s|.*:|$(BUILDDIR)$*.o:|" < $(patsubst %.o,%.d,$@).tmp > $(patsubst %.o,%.d,$@) + @sed -e 's/.*://' -e 's/\\$$//' < $(patsubst %.o,%.d,$@).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(patsubst %.o,%.d,$@) + @rm -f $(patsubst %.o,%.d,$@).tmp + +$(BUILDDIR)source/%.o: ../../source/%.cpp + @mkdir -p $(dir $@) + $(CC) $(CXX_OPTIONS) -c $(INCLUDE) $< -o $@ + @$(CC) $(CXX_OPTIONS) -MM $(INCLUDE) $< > $(patsubst %.o,%.d,$@) + @mv -f $(patsubst %.o,%.d,$@) $(patsubst %.o,%.d,$@).tmp + @sed -e "s|.*:|$(BUILDDIR)$*.o:|" < $(patsubst %.o,%.d,$@).tmp > $(patsubst %.o,%.d,$@) + @sed -e 's/.*://' -e 's/\\$$//' < $(patsubst %.o,%.d,$@).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(patsubst %.o,%.d,$@) + @rm -f $(patsubst %.o,%.d,$@).tmp diff --git a/tests/NoiseTest/NoiseTest.cpp b/tests/NoiseTest/NoiseTest.cpp new file mode 100644 index 000000000..5542f3ca6 --- /dev/null +++ b/tests/NoiseTest/NoiseTest.cpp @@ -0,0 +1,101 @@ + +// 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, (NOISE_DATATYPE)25.6, 0, (NOISE_DATATYPE)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); + LOG("Press Enter to quit program"); + getchar(); +} diff --git a/tests/NoiseTest/NoiseTest.sln b/tests/NoiseTest/NoiseTest.sln new file mode 100644 index 000000000..240e97d01 --- /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..d8741f74c --- /dev/null +++ b/tests/NoiseTest/NoiseTest.vcproj @@ -0,0 +1,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3