using OpenTK.Mathematics; namespace VoxelEngine.World.Persistence; public sealed class InMemoryChunkModificationStore : IChunkModificationStore { private readonly Dictionary> _diffs = new(); public bool TryGetDiff(Vector3i chunkPos, out IReadOnlyDictionary? diff) { if (this._diffs.TryGetValue(chunkPos, out Dictionary? d)) { // Returned snapshot: callers may safely retain and enumerate even // after concurrent RecordEdit on the same chunk. diff = new Dictionary(d); return true; } diff = null; return false; } public void RecordEdit(Vector3i chunkPos, int localIndex, ushort blockId) { if (!this._diffs.TryGetValue(chunkPos, out Dictionary? d)) { d = new Dictionary(); 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); }