34 lines
996 B
C#
34 lines
996 B
C#
using OpenTK.Mathematics;
|
|
|
|
namespace VoxelEngine.World.Persistence;
|
|
|
|
public sealed class InMemoryChunkModificationStore : IChunkModificationStore
|
|
{
|
|
private readonly Dictionary<Vector3i, Dictionary<int, ushort>> _diffs = new();
|
|
|
|
public bool TryGetDiff(Vector3i chunkPos, out IReadOnlyDictionary<int, ushort>? diff)
|
|
{
|
|
if (this._diffs.TryGetValue(chunkPos, out Dictionary<int, ushort>? d))
|
|
{
|
|
diff = d;
|
|
return true;
|
|
}
|
|
diff = null;
|
|
return false;
|
|
}
|
|
|
|
public void RecordEdit(Vector3i chunkPos, int localIndex, ushort blockId)
|
|
{
|
|
if (!this._diffs.TryGetValue(chunkPos, out Dictionary<int, ushort>? d))
|
|
{
|
|
d = new Dictionary<int, ushort>();
|
|
this._diffs[chunkPos] = d;
|
|
}
|
|
d[localIndex] = blockId;
|
|
}
|
|
|
|
public void ClearDiff(Vector3i chunkPos) => this._diffs.Remove(chunkPos);
|
|
|
|
public bool HasDiff(Vector3i chunkPos) => this._diffs.ContainsKey(chunkPos);
|
|
}
|