more stuff

This commit is contained in:
UnknownShadow200 2017-04-11 19:35:51 +10:00
parent 2f533727fa
commit e4bbe8876f
6 changed files with 181 additions and 1 deletions

73
src/Client/Block.h Normal file
View File

@ -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

View File

@ -47,7 +47,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
@ -158,7 +158,9 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="Block.h" />
<ClInclude Include="Compiler.h" />
<ClInclude Include="Funcs.h" />
<ClInclude Include="Noise.h" />
<ClInclude Include="Random.h" />
<ClInclude Include="NotchyGenerator.h" />

View File

@ -39,6 +39,12 @@
<ClInclude Include="Compiler.h">
<Filter>Header Files\Defines</Filter>
</ClInclude>
<ClInclude Include="Funcs.h">
<Filter>Header Files\Defines</Filter>
</ClInclude>
<ClInclude Include="Block.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="NotchyGenerator.c">

6
src/Client/Funcs.h Normal file
View File

@ -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

View File

@ -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;
}

View File

@ -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