Major refactor and organization, optimizations to chunk, world and renderer
This commit is contained in:
2506
Worldgen/Noise/FastNoiseLite.cs
Normal file
2506
Worldgen/Noise/FastNoiseLite.cs
Normal file
File diff suppressed because it is too large
Load Diff
80
Worldgen/Worldgen.cs
Normal file
80
Worldgen/Worldgen.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Voxel.Core;
|
||||
|
||||
namespace Voxel
|
||||
{
|
||||
public static class Worldgen
|
||||
{
|
||||
private static int baseHeight = 32;
|
||||
|
||||
private static float res1 = 2;
|
||||
private static float res2 = 4;
|
||||
private static float amplitude1 = 4;
|
||||
private static float amplitude2 = 2;
|
||||
|
||||
private static float elevationMapRes = (float)1/8;
|
||||
private static float elevationMapAmplitude = 32;
|
||||
|
||||
private static Random random = new Random();
|
||||
private static FastNoiseLite noise = new FastNoiseLite(random.Next());
|
||||
|
||||
public static int GetHeight(int x, int z)
|
||||
{
|
||||
float map1 = noise.GetNoise(
|
||||
x * res1,
|
||||
z * res1
|
||||
) * amplitude1;
|
||||
|
||||
float map2 = noise.GetNoise(x * res2,
|
||||
z * res2
|
||||
) * amplitude2;
|
||||
|
||||
float elevationMap = (noise.GetNoise(
|
||||
x * elevationMapRes,
|
||||
z * elevationMapRes
|
||||
) + 0.25f) * elevationMapAmplitude;
|
||||
return baseHeight + (int)(elevationMap + map1 + map2);
|
||||
}
|
||||
|
||||
public static Blocks GetBlock(int y, int maxY)
|
||||
{
|
||||
if (y > maxY)
|
||||
{
|
||||
return Blocks.Air;
|
||||
}
|
||||
|
||||
if (y == maxY)
|
||||
{
|
||||
if (y < baseHeight)
|
||||
return Blocks.Sand;
|
||||
else
|
||||
return Blocks.Grass;
|
||||
}
|
||||
|
||||
if (y < 4)
|
||||
{
|
||||
if (y == 0) return Blocks.Bedrock;
|
||||
|
||||
float randomValue = random.NextSingle();
|
||||
|
||||
if (randomValue < (1f / y))
|
||||
{
|
||||
return Blocks.Bedrock;
|
||||
}
|
||||
|
||||
return Blocks.Stone;
|
||||
}
|
||||
|
||||
if (y > maxY - 6)
|
||||
{
|
||||
return Blocks.Dirt;
|
||||
}
|
||||
|
||||
return Blocks.Stone;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user