From e4bbe8876fea154722649d751e7ef373aeafc943 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Tue, 11 Apr 2017 19:35:51 +1000 Subject: [PATCH] more stuff --- src/Client/Block.h | 73 ++++++++++++++++++++++++++ src/Client/Client.vcxproj | 4 +- src/Client/Client.vcxproj.filters | 6 +++ src/Client/Funcs.h | 6 +++ src/Client/NotchyGenerator.c | 86 +++++++++++++++++++++++++++++++ src/Client/NotchyGenerator.h | 7 +++ 6 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 src/Client/Block.h create mode 100644 src/Client/Funcs.h diff --git a/src/Client/Block.h b/src/Client/Block.h new file mode 100644 index 000000000..05fedaf01 --- /dev/null +++ b/src/Client/Block.h @@ -0,0 +1,73 @@ +#ifndef CS_BLOCK_H +#define CS_BLOCK_H + +// Classic blocks +#define Block_Air 0 +#define Block_Stone 1 +#define Block_Grass 2 +#define Block_Dirt 3 +#define Block_Cobblestone 4 +#define Block_Wood 5 +#define Block_Sapling 6 +#define Block_Bedrock 7 +#define Block_Water 8 +#define Block_StillWater 9 +#define Block_Lava 10 +#define Block_StillLava 11 +#define Block_Sand 12 +#define Block_Gravel 13 +#define Block_GoldOre 14 +#define Block_IronOre 15 +#define Block_CoalOre 16 +#define Block_Log 17 +#define Block_Leaves 18 +#define Block_Sponge 19 +#define Block_Glass 20 +#define Block_Red 21 +#define Block_Orange 22 +#define Block_Yellow 23 +#define Block_Lime 24 +#define Block_Green 25 +#define Block_Teal 26 +#define Block_Aqua 27 +#define Block_Cyan 28 +#define Block_Blue 29 +#define Block_Indigo 30 +#define Block_Violet 31 +#define Block_Magenta 32 +#define Block_Pink 33 +#define Block_Black 34 +#define Block_Gray 35 +#define Block_White 36 +#define Block_Dandelion 37 +#define Block_Rose 38 +#define Block_BrownMushroom 39 +#define Block_RedMushroom 40 +#define Block_Gold 41 +#define Block_Iron 42 +#define Block_DoubleSlab 43 +#define Block_Slab 44 +#define Block_Brick 45 +#define Block_TNT 46 +#define Block_Bookshelf 47 +#define Block_MossyRocks 48 +#define Block_Obsidian 49 + +// CPE blocks +#define Block_CobblestoneSlab 50 +#define Block_Rope 51 +#define Block_Sandstone 52 +#define Block_Snow 53 +#define Block_Fire 54 +#define Block_LightPink 55 +#define Block_ForestGreen 56 +#define Block_Brown 57 +#define Block_DeepBlue 58 +#define Block_Turquoise 59 +#define Block_Ice 60 +#define Block_CeramicTile 61 +#define Block_Magma 62 +#define Block_Pillar 63 +#define Block_Crate 64 +#define Block_StoneBrick 65 +#endif \ No newline at end of file diff --git a/src/Client/Client.vcxproj b/src/Client/Client.vcxproj index 90c39611d..429d15392 100644 --- a/src/Client/Client.vcxproj +++ b/src/Client/Client.vcxproj @@ -47,7 +47,7 @@ DynamicLibrary false - v140 + v140_xp true Unicode @@ -158,7 +158,9 @@ + + diff --git a/src/Client/Client.vcxproj.filters b/src/Client/Client.vcxproj.filters index 0579e67c4..ee5cb00c0 100644 --- a/src/Client/Client.vcxproj.filters +++ b/src/Client/Client.vcxproj.filters @@ -39,6 +39,12 @@ Header Files\Defines + + Header Files\Defines + + + Header Files + diff --git a/src/Client/Funcs.h b/src/Client/Funcs.h new file mode 100644 index 000000000..16b261425 --- /dev/null +++ b/src/Client/Funcs.h @@ -0,0 +1,6 @@ +#ifndef CS_FUNCS_H +#define CS_FUNCS_H + +#define min(x, y) (x) < (y) ? (x) : (y) +#define max(x, y) (x) > (y) ? (x) : (y) +#endif \ No newline at end of file diff --git a/src/Client/NotchyGenerator.c b/src/Client/NotchyGenerator.c index 3854665cd..21abc5cb0 100644 --- a/src/Client/NotchyGenerator.c +++ b/src/Client/NotchyGenerator.c @@ -27,4 +27,90 @@ void NotchyGen_Init(Int32 width, Int32 height, Int32 length, minHeight = Height; CurrentProgress = 0.0f; +} + + +void NotchyGen_CreateHeightmap() { + CombinedNoise n1, n2; + CombinedNoise_Init(&n1, &rnd, 8, 8); + CombinedNoise_Init(&n2, &rnd, 8, 8); + OctaveNoise n3; + OctaveNoise_Init(&n3, &rnd, 6); + + Int32 index = 0; + //CurrentState = "Building heightmap"; + + for (Int32 z = 0; z < Length; z++) { + CurrentProgress = (Real32)z / Length; + for (Int32 x = 0; x < Width; x++) { + Real64 hLow = CombinedNoise_Compute(&n1, x * 1.3f, z * 1.3f) / 6 - 4, height = hLow; + + if (OctaveNoise_Compute(&n3, x, z) <= 0) { + Real64 hHigh = CombinedNoise_Compute(&n2, x * 1.3f, z * 1.3f) / 5 + 6; + height = max(hLow, hHigh); + } + + height *= 0.5; + if (height < 0) height *= 0.8f; + + Int16 adjHeight = (Int16)(height + waterLevel); + minHeight = adjHeight < minHeight ? adjHeight : minHeight; + Heightmap[index++] = adjHeight; + } + } +} + +void NotchyGen_CreateStrata() { + OctaveNoise n; + 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 + Int32 minStoneY = NotchyGen_CreateStrataFast(); + + for (Int32 z = 0; z < Length; z++) { + CurrentProgress = (Real32)z / Length; + for (Int32 x = 0; x < Width; x++) { + Int32 dirtThickness = (Int32)(OctaveNoise_Compute(&n, x, z) / 24 - 4); + Int32 dirtHeight = Heightmap[hMapIndex++]; + Int32 stoneHeight = dirtHeight + dirtThickness; + + stoneHeight = min(stoneHeight, maxY); + dirtHeight = min(dirtHeight, maxY); + + mapIndex = minStoneY * oneY + z * Width + x; + for (Int32 y = minStoneY; y <= stoneHeight; y++) { + Blocks[mapIndex] = Block_Stone; mapIndex += oneY; + } + + stoneHeight = max(stoneHeight, 0); + mapIndex = (stoneHeight + 1) * oneY + z * Width + x; + for (Int32 y = stoneHeight + 1; y <= dirtHeight; y++) { + Blocks[mapIndex] = Block_Dirt; mapIndex += oneY; + } + } + } +} + +Int32 NotchyGen_CreateStrataFast() { + // Make lava layer at bottom + Int32 mapIndex = 0; + for (Int32 z = 0; z < Length; z++) + for (int x = 0; x < Width; x++) + { + Blocks[mapIndex++] = Block_Lava; + } + + // Invariant: the lowest value dirtThickness can possible be is -14 + Int32 stoneHeight = minHeight - 14; + if (stoneHeight <= 0) return 1; // no layer is fully stone + + // 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++) + { + Blocks[mapIndex++] = Block_Stone; + } + return stoneHeight; } \ No newline at end of file diff --git a/src/Client/NotchyGenerator.h b/src/Client/NotchyGenerator.h index 97975c766..e9cf4e49f 100644 --- a/src/Client/NotchyGenerator.h +++ b/src/Client/NotchyGenerator.h @@ -1,7 +1,14 @@ #ifndef CS_NOTCHY_GEN_H #define CS_NOTCHY_GEN_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); + +void NotchyGen_CreateHeightmap(); +void NotchyGen_CreateStrata(); +Int32 NotchyGen_CreateStrataFast(); #endif \ No newline at end of file