feat: add IChunkModificationStore and in-memory implementation
This commit is contained in:
33
World/Persistence/InMemoryChunkModificationStore.cs
Normal file
33
World/Persistence/InMemoryChunkModificationStore.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user