feat: add Chunk as a dense 16-cubed id array
This commit is contained in:
19
World/Chunk.cs
Normal file
19
World/Chunk.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace VoxelEngine.World;
|
||||
|
||||
public sealed class Chunk
|
||||
{
|
||||
public const int Size = 16;
|
||||
|
||||
private readonly ushort[] _ids = new ushort[Size * Size * Size];
|
||||
|
||||
public ushort this[int x, int y, int z]
|
||||
{
|
||||
get => _ids[Index(x, y, z)];
|
||||
set => _ids[Index(x, y, z)] = value;
|
||||
}
|
||||
|
||||
public static bool InBounds(int x, int y, int z) =>
|
||||
x >= 0 && x < Size && y >= 0 && y < Size && z >= 0 && z < Size;
|
||||
|
||||
private static int Index(int x, int y, int z) => (x * Size + y) * Size + z;
|
||||
}
|
||||
Reference in New Issue
Block a user