refactor: store-owned diff snapshot and drop dead ChunkJob.ExistingChunk

TryGetDiff now returns an independent copy so callers can safely retain the
reference; removes the defensive copy from ChunkStreamer.DispatchLoad.
ChunkJob.ExistingChunk was never populated (DispatchRemesh uses closures
instead), so the field is removed along with its misleading record-level
comment.
This commit is contained in:
2026-06-01 13:31:05 +02:00
parent 6b148362c0
commit 34f923cbca
3 changed files with 9 additions and 13 deletions

View File

@@ -3,12 +3,12 @@ using VoxelEngine.World.Chunk;
namespace VoxelEngine.World.Streaming;
// Job dispatched to an IJobExecutor. For a fresh load, ExistingChunk is null
// and the worker generates + applies diff + meshes. For a remesh-only job,
// ExistingChunk holds the chunk and the worker only meshes (no generation).
// Job dispatched to an IJobExecutor for a fresh chunk load. The worker
// generates the chunk, applies any modification diff, and meshes the result.
// Remesh-only jobs are dispatched separately by DispatchRemesh and capture
// their state via closures, so they do not use this record.
internal sealed record ChunkJob(
Vector3i Pos,
Chunk.Chunk? ExistingChunk,
NeighborSnapshots Neighbors,
IReadOnlyDictionary<int, ushort>? Diff);

View File

@@ -299,15 +299,9 @@ public sealed class ChunkStreamer : IDisposable
private void DispatchLoad(Vector3i pos)
{
NeighborSnapshots neighbors = this.SnapshotNeighbors(pos);
IReadOnlyDictionary<int, ushort>? diff = null;
if (this._world.ModificationStore.TryGetDiff(pos, out var d) && d != null)
{
// Copy: TryGetDiff returns the live internal dictionary, which the
// main thread may mutate via World.SetBlock while the worker iterates.
diff = new Dictionary<int, ushort>(d);
}
this._world.ModificationStore.TryGetDiff(pos, out IReadOnlyDictionary<int, ushort>? diff);
var job = new ChunkJob(pos, ExistingChunk: null, neighbors, diff);
var job = new ChunkJob(pos, neighbors, diff);
this._inFlight++;
IChunkMesher mesher = this._mesher;