|
|
|
using System;
|
|
|
|
using gaemstone.ECS;
|
|
|
|
using static gaemstone.Bloxel.Components.CoreComponents;
|
|
|
|
using static gaemstone.Bloxel.Constants;
|
|
|
|
|
|
|
|
namespace gaemstone.Bloxel.Systems;
|
|
|
|
|
|
|
|
[Module]
|
|
|
|
[DependsOn<gaemstone.Bloxel.Components.CoreComponents>]
|
|
|
|
public class BasicWorldGenerator
|
|
|
|
{
|
|
|
|
private readonly FastNoiseLite _noise;
|
|
|
|
|
|
|
|
public BasicWorldGenerator()
|
|
|
|
{
|
|
|
|
_noise = new(new Random().Next());
|
|
|
|
_noise.SetNoiseType(FastNoiseLite.NoiseType.OpenSimplex2);
|
|
|
|
_noise.SetFractalType(FastNoiseLite.FractalType.Ridged);
|
|
|
|
_noise.SetFractalOctaves(4);
|
|
|
|
_noise.SetFractalGain(0.6F);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Tag]
|
|
|
|
public struct HasBasicWorldGeneration { }
|
|
|
|
|
|
|
|
[System]
|
|
|
|
public void Populate(Universe universe, EntityRef entity,
|
|
|
|
in Chunk chunk, ChunkStoreBlocks blocks,
|
|
|
|
[Not] HasBasicWorldGeneration _)
|
|
|
|
{
|
|
|
|
var stone = universe.LookupOrThrow("Stone");
|
|
|
|
for (var lx = 0; lx < ChunkLength; lx++)
|
|
|
|
for (var ly = 0; ly < ChunkLength; ly++)
|
|
|
|
for (var lz = 0; lz < ChunkLength; lz++) {
|
|
|
|
var gx = chunk.Position.X << ChunkBitShift | lx;
|
|
|
|
var gy = chunk.Position.Y << ChunkBitShift | ly;
|
|
|
|
var gz = chunk.Position.Z << ChunkBitShift | lz;
|
|
|
|
var bias = Math.Clamp(gy / 32.0F + 1.0F, 0.0F, 1.0F);
|
|
|
|
if (_noise.GetNoise(gx, gy, gz) > bias)
|
|
|
|
blocks[lx, ly, lz] = stone;
|
|
|
|
}
|
|
|
|
entity.Add<HasBasicWorldGeneration>();
|
|
|
|
}
|
|
|
|
}
|