From d6e80fcf3790fa5c0ef18237bde32c038c2d3a79 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 11 Apr 2017 19:42:33 +1000 Subject: [PATCH] Declare notchygen as C exported funcs --- src/Client/Block.h | 4 ++-- src/Client/Noise.c | 20 ++++++++++---------- src/Client/Noise.h | 1 + src/Client/NotchyGenerator.c | 28 ++++++++++++++++------------ src/Client/NotchyGenerator.h | 12 +++++------- 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/Client/Block.h b/src/Client/Block.h index 05fedaf01..c8ef12642 100644 --- a/src/Client/Block.h +++ b/src/Client/Block.h @@ -1,7 +1,7 @@ #ifndef CS_BLOCK_H #define CS_BLOCK_H -// Classic blocks +/* Classic blocks */ #define Block_Air 0 #define Block_Stone 1 #define Block_Grass 2 @@ -53,7 +53,7 @@ #define Block_MossyRocks 48 #define Block_Obsidian 49 -// CPE blocks +/* CPE blocks */ #define Block_CobblestoneSlab 50 #define Block_Rope 51 #define Block_Sandstone 52 diff --git a/src/Client/Noise.c b/src/Client/Noise.c index 74b4de402..41ca67c98 100644 --- a/src/Client/Noise.c +++ b/src/Client/Noise.c @@ -1,7 +1,7 @@ #include "Noise.h" void ImprovedNoise_Init(UInt8* p, Random* rnd) { - // shuffle randomly using fisher-yates + /* shuffle randomly using fisher-yates */ for (Int32 i = 0; i < 256; i++) { p[i] = (UInt8)i; } @@ -22,26 +22,26 @@ Real64 ImprovedNoise_Compute(UInt8* p, Real64 x, Real64 y) { Int32 X = xFloor & 0xFF, Y = yFloor & 0xFF; x -= xFloor; y -= yFloor; - Real64 u = x * x * x * (x * (x * 6 - 15) + 10); // Fade(x) - Real64 v = y * y * y * (y * (y * 6 - 15) + 10); // Fade(y) + Real64 u = x * x * x * (x * (x * 6 - 15) + 10); /* Fade(x) */ + Real64 v = y * y * y * (y * (y * 6 - 15) + 10); /* Fade(y) */ Int32 A = p[X] + Y, B = p[X + 1] + Y; - // Normally, calculating Grad involves a function call. However, we can directly pack this table - // (since each value indicates either -1, 0 1) into a set of bit flags. This way we avoid needing - // to call another function that performs branching + /* Normally, calculating Grad involves a function call. However, we can directly pack this table + (since each value indicates either -1, 0 1) into a set of bit flags. This way we avoid needing + to call another function that performs branching */ #define xFlags 0x46552222 #define yFlags 0x2222550A Int32 hash = (p[p[A]] & 0xF) << 1; - Real64 g22 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * y; // Grad(p[p[A], x, y) + Real64 g22 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * y; /* Grad(p[p[A], x, y) */ hash = (p[p[B]] & 0xF) << 1; - Real64 g12 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * y; // Grad(p[p[B], x - 1, y) + Real64 g12 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * y; /* Grad(p[p[B], x - 1, y) */ Real64 c1 = g22 + u * (g12 - g22); hash = (p[p[A + 1]] & 0xF) << 1; - Real64 g21 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * (y - 1); // Grad(p[p[A + 1], x, y - 1) + Real64 g21 = (((xFlags >> hash) & 3) - 1) * x + (((yFlags >> hash) & 3) - 1) * (y - 1); /* Grad(p[p[A + 1], x, y - 1) */ hash = (p[p[B + 1]] & 0xF) << 1; - Real64 g11 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * (y - 1); // Grad(p[p[B + 1], x - 1, y - 1) + Real64 g11 = (((xFlags >> hash) & 3) - 1) * (x - 1) + (((yFlags >> hash) & 3) - 1) * (y - 1); /* Grad(p[p[B + 1], x - 1, y - 1) */ Real64 c2 = g21 + u * (g11 - g21); return c1 + v * (c2 - c1); diff --git a/src/Client/Noise.h b/src/Client/Noise.h index 72cf11905..f89adee3a 100644 --- a/src/Client/Noise.h +++ b/src/Client/Noise.h @@ -8,6 +8,7 @@ void ImprovedNoise_Init(UInt8* p, Random* rnd); Real64 ImprovedNoise_Compute(UInt8* p, Real64 x, Real64 y); +/* since we need structure to be a fixed size */ #define MAX_OCTAVES 8 typedef struct { UInt8 p[MAX_OCTAVES][NOISE_TABLE_SIZE]; diff --git a/src/Client/NotchyGenerator.c b/src/Client/NotchyGenerator.c index 21abc5cb0..fe442bef4 100644 --- a/src/Client/NotchyGenerator.c +++ b/src/Client/NotchyGenerator.c @@ -1,15 +1,19 @@ -// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 -// Based on: -// https://github.com/UnknownShadow200/ClassicalSharp/wiki/Minecraft-Classic-map-generation-algorithm -// Thanks to Jerralish for originally reverse engineering classic's algorithm, then preparing a high level overview of the algorithm. -// I believe this process adheres to clean room reverse engineering. +/* Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 */ +/* Based on: + https://github.com/UnknownShadow200/ClassicalSharp/wiki/Minecraft-Classic-map-generation-algorithm + Thanks to Jerralish for originally reverse engineering classic's algorithm, then preparing a high level overview of the algorithm. + I believe this process adheres to clean room reverse engineering.*/ #include "NotchyGenerator.h" +#include "Block.h" +#include "Funcs.h" +#include "Noise.h" #include "Random.h" -// External variables +/* External variables */ +/* TODO: how do they even work? */ Real32 CurrentProgress; -// Internal variables +/* Internal variables */ Int32 Width, Height, Length; Int32 waterLevel, oneY, minHeight; BlockID* Blocks; @@ -65,7 +69,7 @@ void NotchyGen_CreateStrata() { OctaveNoise_Init(&n, &rnd, 8); //CurrentState = "Creating strata"; Int32 hMapIndex = 0, maxY = Height - 1, mapIndex = 0; - // Try to bulk fill bottom of the map if possible + /* Try to bulk fill bottom of the map if possible */ Int32 minStoneY = NotchyGen_CreateStrataFast(); for (Int32 z = 0; z < Length; z++) { @@ -93,7 +97,7 @@ void NotchyGen_CreateStrata() { } Int32 NotchyGen_CreateStrataFast() { - // Make lava layer at bottom + /* Make lava layer at bottom */ Int32 mapIndex = 0; for (Int32 z = 0; z < Length; z++) for (int x = 0; x < Width; x++) @@ -101,11 +105,11 @@ Int32 NotchyGen_CreateStrataFast() { Blocks[mapIndex++] = Block_Lava; } - // Invariant: the lowest value dirtThickness can possible be is -14 + /* Invariant: the lowest value dirtThickness can possible be is -14 */ Int32 stoneHeight = minHeight - 14; - if (stoneHeight <= 0) return 1; // no layer is fully stone + if (stoneHeight <= 0) return 1; /* no layer is fully stone */ - // We can quickly fill in bottom solid layers + /* We can quickly fill in bottom solid layers */ for (Int32 y = 1; y <= stoneHeight; y++) for (Int32 z = 0; z < Length; z++) for (Int32 x = 0; x < Width; x++) diff --git a/src/Client/NotchyGenerator.h b/src/Client/NotchyGenerator.h index e9cf4e49f..9c794e4b3 100644 --- a/src/Client/NotchyGenerator.h +++ b/src/Client/NotchyGenerator.h @@ -1,14 +1,12 @@ #ifndef CS_NOTCHY_GEN_H #define CS_NOTCHY_GEN_H +#include "Compiler.h" #include "Typedefs.h" -#include "Noise.h" -#include "Funcs.h" -#include "Block.h" -void NotchyGen_Init(Int32 width, Int32 height, Int32 length, - Int32 seed, BlockID* blocks, Int16* heightmap); +CLIENT_API void NotchyGen_Init(Int32 width, Int32 height, Int32 length, + Int32 seed, BlockID* blocks, Int16* heightmap); -void NotchyGen_CreateHeightmap(); -void NotchyGen_CreateStrata(); +CLIENT_API void NotchyGen_CreateHeightmap(); +CLIENT_API void NotchyGen_CreateStrata(); Int32 NotchyGen_CreateStrataFast(); #endif \ No newline at end of file