Skip to content

Commit

Permalink
fix cave generation
Browse files Browse the repository at this point in the history
  • Loading branch information
danilwhale committed Aug 13, 2024
1 parent 9fc29a8 commit 872dabf
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions SharpCraft/World/WorldGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace SharpCraft.World;
public static class WorldGen
{
private static readonly Random Random = new();

public static void Generate(World world)
{
// LoadingScreen.Display("Generating level...", "Raising...");
DoTerrainPass(world);

// LoadingScreen.Display("Generating level...", "Carving...");
DoCavePass(world);
}
Expand All @@ -35,7 +35,7 @@ private static void DoTerrainPass(World world)
{
secondValue = firstValue;
}

var maxHeight = Math.Max(firstValue, secondValue) / 8 + world.Height / 3;
var maxRockHeight = rockMap[x + z * world.Width] / 8 + world.Height / 3;

Expand All @@ -58,7 +58,7 @@ private static void DoTerrainPass(World world)
{
id = Registries.Tiles.Dirt.Id;
}

world.DirectSetTile(x, y, z, id);
}
}
Expand All @@ -67,9 +67,9 @@ private static void DoTerrainPass(World world)

private static void DoCavePass(World world)
{
var wormCount = world.Width * world.Height * world.Depth / 256 / 64;
var caveCount = world.Width * world.Height * world.Depth / 256 / 64;

for (var worm = 0; worm < wormCount; worm++)
for (var cave = 0; cave < caveCount; cave++)
{
var x = Random.NextSingle() * world.Width;
var y = Random.NextSingle() * world.Height;
Expand All @@ -87,7 +87,7 @@ private static void DoCavePass(World world)
{
x += MathF.Sin(yaw) * MathF.Cos(pitch);
y += MathF.Sin(pitch);
z += MathF.Sin(yaw) * MathF.Cos(pitch);
z += MathF.Cos(yaw) * MathF.Cos(pitch);

yaw += yawDelta * 0.2f;

Expand Down Expand Up @@ -124,7 +124,6 @@ private static void DoCavePass(World world)
if (distanceSq >= size * size) continue;

if (world.DirectGetTile(xx, yy, zz) != Registries.Tiles.Rock.Id) continue;

world.DirectSetTile(xx, yy, zz, 0);
}
}
Expand Down

0 comments on commit 872dabf

Please sign in to comment.