summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2016-03-12 10:49:41 +0100
committerMattes D <github@xoft.cz>2016-05-29 19:12:47 +0200
commit1d0bfead3ecc10cbf0cb5e4ac2f51bad982f2300 (patch)
tree991b80250664e869a6117aa16d0df29fa5e98287
parentAdded GetTeamNames to cScoreboard (#3217) (diff)
downloadcuberite-1d0bfead3ecc10cbf0cb5e4ac2f51bad982f2300.tar
cuberite-1d0bfead3ecc10cbf0cb5e4ac2f51bad982f2300.tar.gz
cuberite-1d0bfead3ecc10cbf0cb5e4ac2f51bad982f2300.tar.bz2
cuberite-1d0bfead3ecc10cbf0cb5e4ac2f51bad982f2300.tar.lz
cuberite-1d0bfead3ecc10cbf0cb5e4ac2f51bad982f2300.tar.xz
cuberite-1d0bfead3ecc10cbf0cb5e4ac2f51bad982f2300.tar.zst
cuberite-1d0bfead3ecc10cbf0cb5e4ac2f51bad982f2300.zip
Diffstat (limited to '')
-rw-r--r--.gitignore4
-rw-r--r--CMakeLists.txt1
-rw-r--r--Tools/GrownBiomeGenVisualiser/.gitignore2
-rw-r--r--Tools/GrownBiomeGenVisualiser/CMakeLists.txt104
-rw-r--r--Tools/GrownBiomeGenVisualiser/Globals.cpp10
-rw-r--r--Tools/GrownBiomeGenVisualiser/Globals.h262
-rw-r--r--Tools/GrownBiomeGenVisualiser/GrownBiomeGenVisualiser.cpp456
-rw-r--r--Tools/GrownBiomeGenVisualiser/README.md4
8 files changed, 842 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index ea4ccdd59..caceee4a8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -91,13 +91,15 @@ src/AllFiles.lst
*.opendb
*.idb
-# cmake output folders
+# cmake output folders and files
ZERO_CHECK.dir/
Debug/
DebugProfile/
Release/
ReleaseProfile/
*.dir/
+CPackConfig.cmake
+CPackSourceConfig.cmake
# APIDump-generated status files:
Server/cuberite_api.lua
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2b5abb362..17644e86c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -95,6 +95,7 @@ set(SELF_TEST OFF CACHE BOOL "")
# This has to be done before any flags have been set up.
if(${BUILD_TOOLS})
message("Building tools")
+ add_subdirectory(Tools/GrownBiomeGenVisualiser/)
add_subdirectory(Tools/MCADefrag/)
add_subdirectory(Tools/ProtoProxy/)
endif()
diff --git a/Tools/GrownBiomeGenVisualiser/.gitignore b/Tools/GrownBiomeGenVisualiser/.gitignore
new file mode 100644
index 000000000..c336f9028
--- /dev/null
+++ b/Tools/GrownBiomeGenVisualiser/.gitignore
@@ -0,0 +1,2 @@
+# Ignore the output images:
+*.ppm
diff --git a/Tools/GrownBiomeGenVisualiser/CMakeLists.txt b/Tools/GrownBiomeGenVisualiser/CMakeLists.txt
new file mode 100644
index 000000000..0669275cb
--- /dev/null
+++ b/Tools/GrownBiomeGenVisualiser/CMakeLists.txt
@@ -0,0 +1,104 @@
+
+cmake_minimum_required (VERSION 2.6)
+
+project (GrownBiomeGenVisualiser)
+
+# Without this, the MSVC variable isn't defined for MSVC builds ( https://www.cmake.org/pipermail/cmake/2011-November/047130.html )
+enable_language(CXX C)
+
+include(../../SetFlags.cmake)
+set_flags()
+set_lib_flags()
+enable_profile()
+
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ add_flags_cxx("-Wno-error=sign-conversion -Wno-error=conversion -Wno-error=shorten-64-to-32")
+ add_flags_cxx("-Wno-error=old-style-cast")
+ if ("${CLANG_VERSION}" VERSION_GREATER 3.5)
+ add_flags_cxx("-Wno-error=keyword-macro")
+ endif()
+endif()
+
+# Set include paths to the used libraries:
+include_directories("../../lib")
+include_directories("../../src")
+
+
+function(flatten_files arg1)
+ set(res "")
+ foreach(f ${${arg1}})
+ get_filename_component(f ${f} ABSOLUTE)
+ list(APPEND res ${f})
+ endforeach()
+ set(${arg1} "${res}" PARENT_SCOPE)
+endfunction()
+
+
+# Include the libraries:
+
+set_exe_flags()
+
+# Include the shared files:
+set(SHARED_SRC
+ ../../src/StringUtils.cpp
+ ../../src/Logger.cpp
+ ../../src/Noise/Noise.cpp
+ ../../src/BiomeDef.cpp
+)
+set(SHARED_HDR
+ ../../src/StringUtils.h
+)
+
+flatten_files(SHARED_SRC)
+flatten_files(SHARED_HDR)
+source_group("Shared" FILES ${SHARED_SRC} ${SHARED_HDR})
+
+set(SHARED_OSS_SRC
+ ../../src/OSSupport/CriticalSection.cpp
+ ../../src/OSSupport/Event.cpp
+ ../../src/OSSupport/File.cpp
+ ../../src/OSSupport/IsThread.cpp
+ ../../src/OSSupport/StackTrace.cpp
+)
+
+set(SHARED_OSS_HDR
+ ../../src/OSSupport/CriticalSection.h
+ ../../src/OSSupport/Event.h
+ ../../src/OSSupport/File.h
+ ../../src/OSSupport/IsThread.h
+ ../../src/OSSupport/StackTrace.h
+)
+
+if(WIN32)
+ list (APPEND SHARED_OSS_SRC ../../src/StackWalker.cpp)
+ list (APPEND SHARED_OSS_HDR ../../src/StackWalker.h)
+endif()
+
+flatten_files(SHARED_OSS_SRC)
+flatten_files(SHARED_OSS_HDR)
+
+source_group("Shared\\OSSupport" FILES ${SHARED_OSS_SRC} ${SHARED_OSS_HDR})
+
+
+
+# Include the main source files:
+set(SOURCES
+ GrownBiomeGenVisualiser.cpp
+ Globals.cpp
+)
+set(HEADERS
+ Globals.h
+)
+
+source_group("" FILES ${SOURCES} ${HEADERS})
+
+add_executable(GrownBiomeGenVisualiser
+ ${SOURCES}
+ ${HEADERS}
+ ${SHARED_SRC}
+ ${SHARED_HDR}
+ ${SHARED_OSS_SRC}
+ ${SHARED_OSS_HDR}
+)
+
+set_target_properties(GrownBiomeGenVisualiser PROPERTIES FOLDER Tools)
diff --git a/Tools/GrownBiomeGenVisualiser/Globals.cpp b/Tools/GrownBiomeGenVisualiser/Globals.cpp
new file mode 100644
index 000000000..13c6ae709
--- /dev/null
+++ b/Tools/GrownBiomeGenVisualiser/Globals.cpp
@@ -0,0 +1,10 @@
+
+// Globals.cpp
+
+// This file is used for precompiled header generation in MSVC environments
+
+#include "Globals.h"
+
+
+
+
diff --git a/Tools/GrownBiomeGenVisualiser/Globals.h b/Tools/GrownBiomeGenVisualiser/Globals.h
new file mode 100644
index 000000000..3fcd2f60c
--- /dev/null
+++ b/Tools/GrownBiomeGenVisualiser/Globals.h
@@ -0,0 +1,262 @@
+
+// Globals.h
+
+// This file gets included from every module in the project, so that global symbols may be introduced easily
+// Also used for precompiled header generation in MSVC environments
+
+
+
+
+
+// Compiler-dependent stuff:
+#if defined(_MSC_VER)
+ // MSVC produces warning C4481 on the override keyword usage, so disable the warning altogether
+ #pragma warning(disable:4481)
+
+ // Disable some warnings that we don't care about:
+ #pragma warning(disable:4100)
+
+ #define OBSOLETE __declspec(deprecated)
+
+ // No alignment needed in MSVC
+ #define ALIGN_8
+ #define ALIGN_16
+
+ #define FORMATSTRING(formatIndex, va_argsIndex)
+
+ // MSVC has its own custom version of zu format
+ #define SIZE_T_FMT "%Iu"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu"
+ #define SIZE_T_FMT_HEX "%Ix"
+
+ #define NORETURN __declspec(noreturn)
+
+#elif defined(__GNUC__)
+
+ // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?
+ #define abstract
+
+ // override is part of c++11
+ #if __cplusplus < 201103L
+ #define override
+ #endif
+
+ #define OBSOLETE __attribute__((deprecated))
+
+ #define ALIGN_8 __attribute__((aligned(8)))
+ #define ALIGN_16 __attribute__((aligned(16)))
+
+ // Some portability macros :)
+ #define stricmp strcasecmp
+
+ #define FORMATSTRING(formatIndex, va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
+
+ #if defined(_WIN32)
+ // We're compiling on MinGW, which uses an old MSVCRT library that has no support for size_t printfing.
+ // We need direct size formats:
+ #if defined(_WIN64)
+ #define SIZE_T_FMT "%I64u"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "I64u"
+ #define SIZE_T_FMT_HEX "%I64x"
+ #else
+ #define SIZE_T_FMT "%u"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "u"
+ #define SIZE_T_FMT_HEX "%x"
+ #endif
+ #else
+ // We're compiling on Linux, so we can use libc's size_t printf format:
+ #define SIZE_T_FMT "%zu"
+ #define SIZE_T_FMT_PRECISION(x) "%" #x "zu"
+ #define SIZE_T_FMT_HEX "%zx"
+ #endif
+
+ #define NORETURN __attribute((__noreturn__))
+#else
+
+ #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler"
+
+ /*
+ // Copy and uncomment this into another #elif section based on your compiler identification
+
+ // Explicitly mark classes as abstract (no instances can be created)
+ #define abstract
+
+ // Mark virtual methods as overriding (forcing them to have a virtual function of the same signature in the base class)
+ #define override
+
+ // Mark functions as obsolete, so that their usage results in a compile-time warning
+ #define OBSOLETE
+
+ // Mark types / variables for alignment. Do the platforms need it?
+ #define ALIGN_8
+ #define ALIGN_16
+ */
+
+ #define FORMATSTRING(formatIndex,va_argsIndex) __attribute__((format (printf, formatIndex, va_argsIndex)))
+
+#endif
+
+
+
+
+
+// Integral types with predefined sizes:
+typedef long long Int64;
+typedef int Int32;
+typedef short Int16;
+
+typedef unsigned long long UInt64;
+typedef unsigned int UInt32;
+typedef unsigned short UInt16;
+
+typedef unsigned char Byte;
+
+
+
+
+
+// A macro to disallow the copy constructor and operator= functions
+// This should be used in the private: declarations for any class that shouldn't allow copying itself
+#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
+ TypeName(const TypeName &); \
+ void operator=(const TypeName &)
+
+// A macro that is used to mark unused function parameters, to avoid pedantic warnings in gcc
+#define UNUSED(X) (void)(X)
+
+
+
+
+// OS-dependent stuff:
+#ifdef _WIN32
+ #define WIN32_LEAN_AND_MEAN
+ #include <Windows.h>
+ #include <winsock2.h>
+ #include <ws2tcpip.h>
+
+ // Windows SDK defines min and max macros, messing up with our std::min and std::max usage
+ #undef min
+ #undef max
+
+ // Windows SDK defines GetFreeSpace as a constant, probably a Win16 API remnant
+ #ifdef GetFreeSpace
+ #undef GetFreeSpace
+ #endif // GetFreeSpace
+
+ #define SocketError WSAGetLastError()
+#else
+ #include <sys/types.h>
+ #include <sys/stat.h> // for mkdir
+ #include <sys/time.h>
+ #include <sys/socket.h>
+ #include <netinet/in.h>
+ #include <arpa/inet.h>
+ #include <netdb.h>
+ #include <time.h>
+ #include <dirent.h>
+ #include <errno.h>
+ #include <iostream>
+ #include <unistd.h>
+
+ #include <cstdio>
+ #include <cstring>
+ #include <pthread.h>
+ #include <semaphore.h>
+ #include <errno.h>
+ #include <fcntl.h>
+
+ typedef int SOCKET;
+ enum
+ {
+ INVALID_SOCKET = -1,
+ };
+ #define closesocket close
+ #define SocketError errno
+#if !defined(ANDROID_NDK)
+ #include <tr1/memory>
+#endif
+#endif
+
+#if !defined(ANDROID_NDK)
+ #define USE_SQUIRREL
+#endif
+
+#if defined(ANDROID_NDK)
+ #define FILE_IO_PREFIX "/sdcard/mcserver/"
+#else
+ #define FILE_IO_PREFIX ""
+#endif
+
+
+
+
+
+// CRT stuff:
+#include <assert.h>
+#include <stdio.h>
+#include <math.h>
+#include <stdarg.h>
+#include <time.h>
+
+
+
+
+
+// STL stuff:
+#include <vector>
+#include <list>
+#include <deque>
+#include <string>
+#include <map>
+#include <algorithm>
+#include <memory>
+
+
+
+
+
+// Common headers (without macros):
+#include "StringUtils.h"
+
+
+
+
+
+// Common definitions:
+
+/// Evaluates to the number of elements in an array (compile-time!)
+#define ARRAYCOUNT(X) (sizeof(X) / sizeof(*(X)))
+
+/// Allows arithmetic expressions like "32 KiB" (but consider using parenthesis around it, "(32 KiB)" )
+#define KiB * 1024
+#define MiB * 1024 * 1024
+
+/// Faster than (int)floorf((float)x / (float)div)
+#define FAST_FLOOR_DIV( x, div ) ( (x) < 0 ? (((int)x / div) - 1) : ((int)x / div) )
+
+// Own version of assert() that writes failed assertions to the log for review
+#ifdef NDEBUG
+ #define ASSERT(x) ((void)0)
+#else
+ #define ASSERT assert
+#endif
+
+// Pretty much the same as ASSERT() but stays in Release builds
+#define VERIFY( x ) ( !!(x) || ( LOGERROR("Verification failed: %s, file %s, line %i", #x, __FILE__, __LINE__ ), exit(1), 0 ) )
+
+
+
+
+
+/// A generic interface used mainly in ForEach() functions
+template <typename Type> class cItemCallback
+{
+public:
+ /// Called for each item in the internal list; return true to stop the loop, or false to continue enumerating
+ virtual bool Item(Type * a_Type) = 0;
+ virtual ~cItemCallback() {}
+} ;
+
+
+
+
diff --git a/Tools/GrownBiomeGenVisualiser/GrownBiomeGenVisualiser.cpp b/Tools/GrownBiomeGenVisualiser/GrownBiomeGenVisualiser.cpp
new file mode 100644
index 000000000..531e3edd9
--- /dev/null
+++ b/Tools/GrownBiomeGenVisualiser/GrownBiomeGenVisualiser.cpp
@@ -0,0 +1,456 @@
+
+// GrownBiomeGenVisualiser.cpp
+
+// Implements the main app entrypoint
+
+#include "Globals.h"
+#include <iostream>
+#include <fstream>
+#include <random>
+#define PROT_INT_BUFFER_SIZE (130 * 130)
+#include "Generating/ProtIntGen.h"
+
+
+
+
+
+typedef int Color[3]; // Color is an array of 3 ints
+
+
+
+
+// Forward declarations, needed for GCC and Clang:
+void log(const char * a_Fmt, ...) FORMATSTRING(1, 2);
+void outputBitmapFile(
+ const AString & a_FileName,
+ unsigned a_ImageSizeX, unsigned a_ImageSizeY,
+ const int * a_ColorIndices,
+ unsigned a_IndicesSizeX, unsigned a_IndicesSizeY,
+ const Color * a_Colors,
+ size_t a_NumColors
+);
+void initializeBiomeColors(void);
+void generateZoomLevels(int a_Seed);
+void generateSmoothLevels(int a_Seed);
+void generateExamples(int a_Seed);
+
+
+
+
+
+
+/** Color palette used for algorithm examples.
+No relevance to biomes whatsoever. */
+static const Color spectrumColors[] =
+{
+ {0, 0, 0},
+ {255, 0, 0},
+ {0, 255, 0},
+ {0, 0, 255},
+ {255, 255, 0},
+ {255, 0, 255},
+ {0, 255, 255},
+};
+
+
+
+
+
+/** Color palette used for displaying biome groups. */
+static const Color biomeGroupColors[] =
+{
+ /* bgOcean */ {0x00, 0x00, 0x70},
+ /* bgDesert */ {0xfa, 0x94, 0x18},
+ /* bgTemperate */ {0x05, 0x66, 0x21},
+ /* bgMountains */ {0x60, 0x60, 0x60},
+ /* bgIce */ {0xa0, 0xa0, 0xff},
+};
+
+
+
+
+
+/** Color palette used for outputting biome images.
+Initialized from biomeColorMap[] in initializeBiomeColors(). */
+static Color biomeColors[255];
+
+
+
+
+/** Map of biome -> color, used to initialize biomeColorMap[]. */
+static const struct
+{
+ EMCSBiome biome;
+ Color color;
+}
+biomeColorMap[] =
+{
+ { biOcean, { 0x00, 0x00, 0x70 }, },
+ { biPlains, { 0x8d, 0xb3, 0x60 }, },
+ { biDesert, { 0xfa, 0x94, 0x18 }, },
+ { biExtremeHills, { 0x60, 0x60, 0x60 }, },
+ { biForest, { 0x05, 0x66, 0x21 }, },
+ { biTaiga, { 0x0b, 0x66, 0x59 }, },
+ { biSwampland, { 0x2f, 0xff, 0xda }, },
+ { biRiver, { 0x30, 0x30, 0xaf }, },
+ { biHell, { 0x7f, 0x00, 0x00 }, },
+ { biSky, { 0x00, 0x7f, 0xff }, },
+ { biFrozenOcean, { 0xa0, 0xa0, 0xdf }, },
+ { biFrozenRiver, { 0xa0, 0xa0, 0xff }, },
+ { biIcePlains, { 0xff, 0xff, 0xff }, },
+ { biIceMountains, { 0xa0, 0xa0, 0xa0 }, },
+ { biMushroomIsland, { 0xff, 0x00, 0xff }, },
+ { biMushroomShore, { 0xa0, 0x00, 0xff }, },
+ { biBeach, { 0xfa, 0xde, 0x55 }, },
+ { biDesertHills, { 0xd2, 0x5f, 0x12 }, },
+ { biForestHills, { 0x22, 0x55, 0x1c }, },
+ { biTaigaHills, { 0x16, 0x39, 0x33 }, },
+ { biExtremeHillsEdge, { 0x7f, 0x8f, 0x7f }, },
+ { biJungle, { 0x53, 0x7b, 0x09 }, },
+ { biJungleHills, { 0x2c, 0x42, 0x05 }, },
+
+ { biJungleEdge, { 0x62, 0x8b, 0x17 }, },
+ { biDeepOcean, { 0x00, 0x00, 0x30 }, },
+ { biStoneBeach, { 0xa2, 0xa2, 0x84 }, },
+ { biColdBeach, { 0xfa, 0xf0, 0xc0 }, },
+ { biBirchForest, { 0x30, 0x74, 0x44 }, },
+ { biBirchForestHills, { 0x1f, 0x5f, 0x32 }, },
+ { biRoofedForest, { 0x40, 0x51, 0x1a }, },
+ { biColdTaiga, { 0x31, 0x55, 0x4a }, },
+ { biColdTaigaHills, { 0x59, 0x7d, 0x72 }, },
+ { biMegaTaiga, { 0x59, 0x66, 0x51 }, },
+ { biMegaTaigaHills, { 0x59, 0x66, 0x59 }, },
+ { biExtremeHillsPlus, { 0x50, 0x70, 0x50 }, },
+ { biSavanna, { 0xbd, 0xb2, 0x5f }, },
+ { biSavannaPlateau, { 0xa7, 0x9d, 0x64 }, },
+ { biMesa, { 0xd9, 0x45, 0x15 }, },
+ { biMesaPlateauF, { 0xb0, 0x97, 0x65 }, },
+ { biMesaPlateau, { 0xca, 0x8c, 0x65 }, },
+
+ // M variants:
+ { biSunflowerPlains, { 0xb5, 0xdb, 0x88 }, },
+ { biDesertM, { 0xff, 0xbc, 0x40 }, },
+ { biExtremeHillsM, { 0x88, 0x88, 0x88 }, },
+ { biFlowerForest, { 0x2d, 0x8e, 0x49 }, },
+ { biTaigaM, { 0x33, 0x8e, 0x81 }, },
+ { biSwamplandM, { 0x07, 0xf9, 0xb2 }, },
+ { biIcePlainsSpikes, { 0xb4, 0xdc, 0xdc }, },
+ { biJungleM, { 0x7b, 0xa3, 0x31 }, },
+ { biJungleEdgeM, { 0x62, 0x8b, 0x17 }, },
+ { biBirchForestM, { 0x58, 0x9c, 0x6c }, },
+ { biBirchForestHillsM, { 0x47, 0x87, 0x5a }, },
+ { biRoofedForestM, { 0x68, 0x79, 0x42 }, },
+ { biColdTaigaM, { 0x24, 0x3f, 0x36 }, },
+ { biMegaSpruceTaiga, { 0x45, 0x4f, 0x3e }, },
+ { biMegaSpruceTaigaHills, { 0x45, 0x4f, 0x4e }, },
+ { biExtremeHillsPlusM, { 0x78, 0x98, 0x78 }, },
+ { biSavannaM, { 0xe5, 0xda, 0x87 }, },
+ { biSavannaPlateauM, { 0xa7, 0x9d, 0x74 }, },
+ { biMesaBryce, { 0xff, 0x6d, 0x3d }, },
+ { biMesaPlateauFM, { 0xd8, 0xbf, 0x8d }, },
+ { biMesaPlateauM, { 0xf2, 0xb4, 0x8d }, },
+};
+
+
+
+
+
+void log(const char * a_Fmt, ...)
+{
+ AString buf;
+ va_list args;
+ va_start(args, a_Fmt);
+ AppendVPrintf(buf, a_Fmt, args);
+ va_end(args);
+ std::cout << buf << std::endl << std::flush;
+}
+
+
+
+
+
+void outputBitmapFile(
+ const AString & a_FileName,
+ unsigned a_ImageSizeX, unsigned a_ImageSizeY,
+ const int * a_ColorIndices,
+ unsigned a_IndicesSizeX, unsigned a_IndicesSizeY,
+ const Color * a_Colors,
+ size_t a_NumColors
+)
+{
+ std::ofstream f(a_FileName, std::ios::out | std::ios::binary);
+ if (!f.good())
+ {
+ log("Cannot open file %s for writing. Skipping.", a_FileName.c_str());
+ return;
+ }
+ f << "P3\r\n" << a_ImageSizeX << " " << a_ImageSizeY << "\r\n255\r\n";
+ unsigned oldIndY = 0;
+ for (unsigned y = 0; y < a_ImageSizeY; y++)
+ {
+ unsigned indY = y * a_IndicesSizeY / a_ImageSizeY;
+ if (oldIndY != indY)
+ {
+ // Output a horizontal divider line:
+ for (unsigned x = 0; x < a_ImageSizeX; x++)
+ {
+ f << "128 128 128 ";
+ }
+ f << "\r\n";
+ oldIndY = indY;
+ continue;
+ }
+ unsigned oldIndX = 0;
+ for (unsigned x = 0; x < a_ImageSizeX; x++)
+ {
+ unsigned indX = x * a_IndicesSizeX / a_ImageSizeX;
+ if (indX == oldIndX)
+ {
+ auto & color = a_Colors[a_ColorIndices[indX + a_IndicesSizeX * indY]];
+ f << color[0] << " " << color[1] << " " << color[2] << " ";
+ }
+ else
+ {
+ // vertical divider line:
+ f << "128 128 128 ";
+ }
+ oldIndX = indX;
+ }
+ f << "\r\n";
+ }
+}
+
+
+
+
+
+/** Initializes biomeColors[] using the biomeColorMap[]. */
+void initializeBiomeColors(void)
+{
+ // Initialize all colors to red, so that anything unassigned is visible:
+ for (size_t i = 0; i < ARRAYCOUNT(biomeColors); i++)
+ {
+ auto & color = biomeColors[i];
+ color[0] = 0;
+ color[1] = 0xff;
+ color[2] = 0;
+ }
+
+ // Initialize per-biome:
+ for(size_t i = 0; i < ARRAYCOUNT(biomeColorMap); i++)
+ {
+ auto & dst = biomeColors[biomeColorMap[i].biome];
+ const auto & src = biomeColorMap[i].color;
+ dst[0] = src[0];
+ dst[1] = src[1];
+ dst[2] = src[2];
+ }
+}
+
+
+
+
+
+/** Generates a series of images showing the "zoom" effect of the IntGen zoom operation.
+Each image is the same size, the integer arrays are scaled to fit the image. */
+void generateZoomLevels(int a_Seed)
+{
+ log("Generating zoom levels...");
+ const unsigned NumImages = 7; ///< Number of images to generate. The more images, the larger they will be
+ const unsigned maxArrSize = (1 << NumImages) + 1;
+ for (unsigned i = 1; i <= NumImages; i++)
+ {
+ unsigned arrSize = (1 << i) + 1; // Dimensions of the actually generated array
+ ASSERT(arrSize <= maxArrSize);
+ int workspace[maxArrSize * maxArrSize]; // Workspace for the generated array
+
+ // Chain the zoom operation as many times as the image number:
+ std::shared_ptr<cProtIntGen> gen = std::make_shared<cProtIntGenChoice>(a_Seed, static_cast<int>(ARRAYCOUNT(spectrumColors) + 1));
+ for (unsigned j = 1; j < i; j++)
+ {
+ gen = std::make_shared<cProtIntGenZoom>(a_Seed + static_cast<int>(j), gen);
+ }
+ gen->GetInts(0, 0, arrSize, arrSize, workspace);
+
+ // Output to a bitmap file:
+ AString fnam = Printf("zoomedgrown_%u.pbm", i);
+ outputBitmapFile(fnam, 257, 257, workspace, arrSize, arrSize, spectrumColors, ARRAYCOUNT(spectrumColors));
+ log(" zoom level %u complete", i);
+ } // for i - Image
+}
+
+
+
+
+
+void generateSmoothLevels(int a_Seed)
+{
+ log("Generating smooth levels...");
+ const unsigned NumImages = 7; ///< Number of images to generate. The more images, the larger they will be
+ const unsigned maxArrSize = 65; ///< Size of the underlying generated array
+
+ // Initialize the underlying generator:
+ std::shared_ptr<cProtIntGen> underlyingGen = std::make_shared<cProtIntGenChoice>(a_Seed, static_cast<int>(ARRAYCOUNT(spectrumColors) + 1));
+ for (int j = 1; j < 4; j++)
+ {
+ underlyingGen = std::make_shared<cProtIntGenZoom>(a_Seed + j, underlyingGen);
+ }
+
+ // Generate smooth levels:
+ for (unsigned i = 1; i <= NumImages; i++)
+ {
+ unsigned arrSize = maxArrSize - 2 * i; // Dimensions of the actually generated array
+ int workspace[maxArrSize * maxArrSize]; // Workspace for the generated array
+
+ // Chain the zoom operation as many times as the image number:
+ std::shared_ptr<cProtIntGen> gen = underlyingGen;
+ for (unsigned j = 1; j < i; j++)
+ {
+ gen = std::make_shared<cProtIntGenSmooth>(a_Seed, gen);
+ }
+ gen->GetInts(static_cast<int>(i), static_cast<int>(i), arrSize, arrSize, workspace);
+
+ // Output to a bitmap file:
+ AString fnam = Printf("smoothedgrown_%u.ppm", i);
+ outputBitmapFile(fnam, 257, 257, workspace, arrSize, arrSize, spectrumColors, ARRAYCOUNT(spectrumColors));
+ log(" smooth level %u complete", i);
+ } // for i - Image
+}
+
+
+
+
+
+void generateExamples(int a_Seed)
+{
+ log("Generating examples");
+
+ const int maxArrSize = 65;
+ const int inArrSize = 24;
+ const int imgSize = 256;
+
+ // Create the inputs:
+ auto in1 =
+ std::make_shared<cProtIntGenZoom >(a_Seed + 1,
+ std::make_shared<cProtIntGenAddIslands >(a_Seed + 2000, 200,
+ std::make_shared<cProtIntGenSetRandomly >(a_Seed + 9, 300, bgOcean,
+ std::make_shared<cProtIntGenZoom >(a_Seed + 2,
+ std::make_shared<cProtIntGenLandOcean >(a_Seed + 1, 30
+ )))));
+ auto in2 =
+ std::make_shared<cProtIntGenZoom >(a_Seed + 1,
+ std::make_shared<cProtIntGenBiomeGroupEdges>(in1
+ ));
+ auto in3 =
+ std::make_shared<cProtIntGenZoom >(a_Seed + 1,
+ std::make_shared<cProtIntGenZoom >(a_Seed + 2,
+ std::make_shared<cProtIntGenBiomes >(a_Seed + 3000, in2
+ )));
+ auto inAlt =
+ std::make_shared<cProtIntGenZoom >(a_Seed,
+ std::make_shared<cProtIntGenLandOcean >(a_Seed, 30
+ ));
+ auto inRiver = std::make_shared<cProtIntGenRiver>(a_Seed, in2);
+ int workspace[maxArrSize * maxArrSize];
+ in1->GetInts(0, 0, inArrSize, inArrSize, workspace);
+ outputBitmapFile("grownexample_in1.ppm", imgSize, imgSize, workspace, inArrSize, inArrSize, biomeGroupColors, ARRAYCOUNT(biomeGroupColors));
+ log(" Created example input 1");
+ in2->GetInts(0, 0, inArrSize, inArrSize, workspace);
+ outputBitmapFile("grownexample_in2.ppm", imgSize, imgSize, workspace, inArrSize, inArrSize, biomeGroupColors, ARRAYCOUNT(biomeGroupColors));
+ log(" Created example input 2");
+ in3->GetInts(0, 0, inArrSize, inArrSize, workspace);
+ outputBitmapFile("grownexample_in3.ppm", imgSize, imgSize, workspace, inArrSize, inArrSize, biomeColors, ARRAYCOUNT(biomeColors));
+ log(" Created example input 3");
+ inAlt->GetInts(0, 0, inArrSize, inArrSize, workspace);
+ outputBitmapFile("grownexample_in_alt.ppm", imgSize, imgSize, workspace, inArrSize, inArrSize, biomeGroupColors, ARRAYCOUNT(biomeGroupColors));
+ log(" Created example input alt");
+ inRiver->GetInts(0, 0, inArrSize, inArrSize, workspace);
+ outputBitmapFile("grownexample_in_river.ppm", imgSize, imgSize, workspace, inArrSize, inArrSize, biomeColors, ARRAYCOUNT(biomeColors));
+ log(" Created example input river");
+
+ // Shortcuts for colormaps used for the outputs:
+ struct ColorMap
+ {
+ const Color * colors;
+ size_t count;
+ };
+ static const ColorMap cmGroups = { biomeGroupColors, ARRAYCOUNT(biomeGroupColors) };
+ static const ColorMap cmBiomes = { biomeColors, ARRAYCOUNT(biomeColors) };
+
+ // Create the result generators:
+ struct
+ {
+ const char * name;
+ unsigned size;
+ int offset;
+ const ColorMap & colormap;
+ std::shared_ptr<cProtIntGen> gen;
+ }
+ gens[] =
+ {
+ {"add_islands", inArrSize, 0, cmGroups, std::make_shared<cProtIntGenAddIslands> (a_Seed, 400, in1)},
+ {"alt_biomes", inArrSize, 0, cmBiomes, std::make_shared<cProtIntGenAlternateBiomes>(a_Seed, inAlt, in3)},
+ {"beaches", inArrSize - 2, 1, cmBiomes, std::make_shared<cProtIntGenBeaches> (in3)},
+ {"biome_edges", inArrSize - 2, 1, cmBiomes, std::make_shared<cProtIntGenBiomeEdges> (a_Seed, in3)},
+ {"biomes", inArrSize, 0, cmBiomes, std::make_shared<cProtIntGenBiomes> (a_Seed, in2)},
+ {"grp_edges", inArrSize - 2, 0, cmGroups, std::make_shared<cProtIntGenBiomeGroupEdges>(in1)},
+ {"m_biomes", inArrSize, 0, cmBiomes, std::make_shared<cProtIntGenMBiomes> (a_Seed, inAlt, in3)},
+ {"mix_river", inArrSize, 0, cmBiomes, std::make_shared<cProtIntGenMixRivers> (in3, inRiver)},
+ {"river", inArrSize - 2, 1, cmBiomes, inRiver},
+ {"set_rnd", inArrSize, 0, cmBiomes, std::make_shared<cProtIntGenSetRandomly> (a_Seed, 500, bgOcean, in3)},
+ {"smooth", inArrSize - 2, 1, cmBiomes, std::make_shared<cProtIntGenSmooth> (a_Seed, in3)},
+ {"zoom", inArrSize * 2 - 1, 0, cmBiomes, std::make_shared<cProtIntGenZoom> (a_Seed, in3)},
+ };
+
+ // Create the outputs:
+ for (const auto & gen: gens)
+ {
+ gen.gen->GetInts(gen.offset, gen.offset, gen.size, gen.size, workspace);
+ AString fnam = Printf("grownexample_%s.ppm", gen.name);
+ outputBitmapFile(fnam, 256, 256, workspace, gen.size, gen.size, gen.colormap.colors, gen.colormap.count);
+ log(" Created example \"%s\"", gen.name);
+ } // for gen - gens[]
+
+ log("Examples generated");
+}
+
+
+
+
+
+int main(int argc, char ** argv)
+{
+ log("GrownBiomeGenVisualiser starting");
+
+ // Parse the seed from the command line, if present:
+ int seed;
+ if (argc > 1)
+ {
+ if (!StringToInteger(argv[1], seed))
+ {
+ log("Cannot parse seed from \"%s\", bailing out.", argv[1]);
+ return 1;
+ }
+ }
+ else
+ {
+ // Get a random seed:
+ std::random_device rd;
+ seed = static_cast<int>(rd());
+ }
+
+ log("Seed = %d", seed);
+
+ initializeBiomeColors();
+
+ generateZoomLevels(seed);
+ generateSmoothLevels(seed);
+ generateExamples(seed);
+
+ log("GrownBiomeGenVisualiser finished");
+ return 0;
+}
+
+
+
+
diff --git a/Tools/GrownBiomeGenVisualiser/README.md b/Tools/GrownBiomeGenVisualiser/README.md
new file mode 100644
index 000000000..d8f6919d6
--- /dev/null
+++ b/Tools/GrownBiomeGenVisualiser/README.md
@@ -0,0 +1,4 @@
+GrownBiomeGenVisualiser
+----
+
+This project aims to provide the visualisation of "Grown" biome generator used in Cuberite. It uses the generator to generate several bitmaps showcasing the generator; these images are then used in the generator documentation ($/docs/Generator.html)