Add a World that stores chunks in a Dictionary keyed by chunk coordinate, with floor-division world<->chunk coordinate mapping (correct for negative coords). The mesher takes an optional neighbor sampler so faces at chunk borders are culled against adjacent chunks instead of always meshing the shell. Render one ChunkRenderer per chunk, placed via the model matrix. Reorganize the World layer into Blocks/ and Chunk/ sub-namespaces.
25 lines
687 B
C#
25 lines
687 B
C#
namespace VoxelEngine.World.Blocks;
|
|
|
|
public sealed class BlockRegistry
|
|
{
|
|
private readonly IBlock[] _byId;
|
|
|
|
public AirBlock Air { get; } = new();
|
|
public StoneBlock Stone { get; } = new();
|
|
public DirtBlock Dirt { get; } = new();
|
|
public GrassBlock Grass { get; } = new();
|
|
|
|
public BlockRegistry()
|
|
{
|
|
// Index by id. Order does not matter; slot = block.Id.
|
|
IBlock[] blocks = new IBlock[] { this.Air, this.Stone, this.Dirt, this.Grass };
|
|
this._byId = new IBlock[blocks.Length];
|
|
foreach (IBlock block in blocks)
|
|
{
|
|
this._byId[block.Id] = block;
|
|
}
|
|
}
|
|
|
|
public IBlock Get(ushort id) => this._byId[id];
|
|
}
|