You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.2 KiB
42 lines
1.2 KiB
using System; |
|
using gaemstone.ECS; |
|
using static flecs_hub.flecs; |
|
|
|
namespace gaemstone.Bloxel.WorldGen; |
|
|
|
[Module] |
|
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, Entity entity, |
|
in Chunk chunk, ChunkPaletteStorage<ecs_entity_t> storage, |
|
[Not] HasBasicWorldGeneration _) |
|
{ |
|
var stone = universe.Lookup("Stone"); |
|
for (var lx = 0; lx < Chunk.LENGTH; lx++) |
|
for (var ly = 0; ly < Chunk.LENGTH; ly++) |
|
for (var lz = 0; lz < Chunk.LENGTH; lz++) { |
|
var gx = chunk.Position.X << Chunk.BIT_SHIFT | lx; |
|
var gy = chunk.Position.Y << Chunk.BIT_SHIFT | ly; |
|
var gz = chunk.Position.Z << Chunk.BIT_SHIFT | lz; |
|
var bias = Math.Clamp(gy / 32.0F + 1.0F, 0.0F, 1.0F); |
|
if (_noise.GetNoise(gx, gy, gz) > bias) |
|
storage[lx, ly, lz] = stone; |
|
} |
|
entity.Add<HasBasicWorldGeneration>(); |
|
} |
|
}
|
|
|