feat: add block model with IBlock flyweight and registry

This commit is contained in:
2026-05-28 11:53:15 +02:00
parent 17503820e6
commit f4d3f9aab4
8 changed files with 156 additions and 0 deletions

26
World/BlockRegistry.cs Normal file
View File

@@ -0,0 +1,26 @@
using VoxelEngine.World.Blocks;
namespace VoxelEngine.World;
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.
var blocks = new IBlock[] { Air, Stone, Dirt, Grass };
_byId = new IBlock[blocks.Length];
foreach (IBlock block in blocks)
{
_byId[block.Id] = block;
}
}
public IBlock Get(ushort id) => _byId[id];
}