feat: add multi-chunk world with cross-chunk face culling
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.
This commit is contained in:
19
World/Chunk/Chunk.cs
Normal file
19
World/Chunk/Chunk.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace VoxelEngine.World.Chunk;
|
||||
|
||||
public sealed class Chunk
|
||||
{
|
||||
public const int Size = 16;
|
||||
|
||||
private readonly ushort[] _ids = new ushort[Chunk.Size * Chunk.Size * Chunk.Size];
|
||||
|
||||
public ushort this[int x, int y, int z]
|
||||
{
|
||||
get => this._ids[Chunk.Index(x, y, z)];
|
||||
set => this._ids[Chunk.Index(x, y, z)] = value;
|
||||
}
|
||||
|
||||
public static bool InBounds(int x, int y, int z) =>
|
||||
x is >= 0 and < Chunk.Size && y is >= 0 and < Chunk.Size && z is >= 0 and < Chunk.Size;
|
||||
|
||||
private static int Index(int x, int y, int z) => (x * Chunk.Size + y) * Chunk.Size + z;
|
||||
}
|
||||
Reference in New Issue
Block a user