feat(A.5 T13): StreamingController two-tier Tick
Replaces the single-radius Tick with a two-tier model that consumes StreamingRegion's TwoTierDiff (5-list) and routes to the appropriate JobKind: - ToLoadFar -> _enqueueLoad(id, LoadFar) - ToLoadNear -> _enqueueLoad(id, LoadNear) - ToPromote -> _enqueueLoad(id, PromoteToNear) - ToDemote -> _state.RemoveEntitiesFromLandblock(id) on render thread - ToUnload -> _enqueueUnload(id) Drain switch handles Loaded (terrain + entity layer), Promoted (entity layer only -- terrain already loaded), Unloaded, Failed, WorkerCrashed. Constructor signature: nearRadius/farRadius separate ints. Old single- radius ctor removed; existing single-radius tests updated to pass nearRadius=farRadius for backward-compat coverage. GameWindow's enqueueLoad lambda updated from (id =>...) to (id, kind) => to match new Action<uint, LandblockStreamJobKind> signature; radius: arg renamed to nearRadius:/farRadius: (both set to _streamingRadius until T16 wires the full two-tier env-var parsing). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
aff35d2a76
commit
b8d80fe282
4 changed files with 79 additions and 29 deletions
|
|
@ -17,7 +17,7 @@ namespace AcDream.App.Streaming;
|
|||
/// </summary>
|
||||
public sealed class StreamingController
|
||||
{
|
||||
private readonly Action<uint> _enqueueLoad;
|
||||
private readonly Action<uint, LandblockStreamJobKind> _enqueueLoad;
|
||||
private readonly Action<uint> _enqueueUnload;
|
||||
private readonly Func<int, IReadOnlyList<LandblockStreamResult>> _drainCompletions;
|
||||
private readonly Action<LoadedLandblock, LandblockMeshData> _applyTerrain;
|
||||
|
|
@ -25,7 +25,8 @@ public sealed class StreamingController
|
|||
private readonly GpuWorldState _state;
|
||||
private StreamingRegion? _region;
|
||||
|
||||
public int Radius { get; set; }
|
||||
public int NearRadius { get; set; }
|
||||
public int FarRadius { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cap on completions drained per <see cref="Tick"/> call. The cap is
|
||||
|
|
@ -46,12 +47,13 @@ public sealed class StreamingController
|
|||
public int MaxCompletionsPerFrame { get; set; } = 4;
|
||||
|
||||
public StreamingController(
|
||||
Action<uint> enqueueLoad,
|
||||
Action<uint, LandblockStreamJobKind> enqueueLoad,
|
||||
Action<uint> enqueueUnload,
|
||||
Func<int, IReadOnlyList<LandblockStreamResult>> drainCompletions,
|
||||
Action<LoadedLandblock, LandblockMeshData> applyTerrain,
|
||||
GpuWorldState state,
|
||||
int radius,
|
||||
int nearRadius,
|
||||
int farRadius,
|
||||
Action<uint>? removeTerrain = null)
|
||||
{
|
||||
_enqueueLoad = enqueueLoad;
|
||||
|
|
@ -60,29 +62,42 @@ public sealed class StreamingController
|
|||
_applyTerrain = applyTerrain;
|
||||
_removeTerrain = removeTerrain;
|
||||
_state = state;
|
||||
Radius = radius;
|
||||
NearRadius = nearRadius;
|
||||
FarRadius = farRadius;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Advance one frame. <paramref name="observerCx"/>/<paramref name="observerCy"/>
|
||||
/// are landblock coordinates (0..255) of the current viewer — the camera
|
||||
/// in offline mode, the server-sent player position in live.
|
||||
///
|
||||
/// <para>Two-tier model (Phase A.5 T13):</para>
|
||||
/// <list type="bullet">
|
||||
/// <item><see cref="TwoTierDiff.ToLoadFar"/> → enqueue LoadFar (terrain only, no entities)</item>
|
||||
/// <item><see cref="TwoTierDiff.ToLoadNear"/> → enqueue LoadNear (terrain + entities)</item>
|
||||
/// <item><see cref="TwoTierDiff.ToPromote"/> → enqueue PromoteToNear (entity layer for already-loaded terrain)</item>
|
||||
/// <item><see cref="TwoTierDiff.ToDemote"/> → drop entities on render thread immediately (terrain stays)</item>
|
||||
/// <item><see cref="TwoTierDiff.ToUnload"/> → enqueue full unload</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public void Tick(int observerCx, int observerCy)
|
||||
{
|
||||
// First-tick bootstrap: no region yet, so the whole visible window
|
||||
// is a load diff.
|
||||
if (_region is null)
|
||||
{
|
||||
_region = new StreamingRegion(observerCx, observerCy, Radius);
|
||||
foreach (var id in _region.Visible)
|
||||
_enqueueLoad(id);
|
||||
_region = new StreamingRegion(observerCx, observerCy, NearRadius, FarRadius);
|
||||
var bootstrap = _region.ComputeFirstTickDiff();
|
||||
foreach (var id in bootstrap.ToLoadFar) _enqueueLoad(id, LandblockStreamJobKind.LoadFar);
|
||||
foreach (var id in bootstrap.ToLoadNear) _enqueueLoad(id, LandblockStreamJobKind.LoadNear);
|
||||
_region.MarkResidentFromBootstrap();
|
||||
}
|
||||
else if (_region.CenterX != observerCx || _region.CenterY != observerCy)
|
||||
{
|
||||
var diff = _region.RecenterToSingleTier(observerCx, observerCy);
|
||||
foreach (var id in diff.ToLoad) _enqueueLoad(id);
|
||||
foreach (var id in diff.ToUnload) _enqueueUnload(id);
|
||||
var diff = _region.RecenterTo(observerCx, observerCy);
|
||||
foreach (var id in diff.ToLoadFar) _enqueueLoad(id, LandblockStreamJobKind.LoadFar);
|
||||
foreach (var id in diff.ToLoadNear) _enqueueLoad(id, LandblockStreamJobKind.LoadNear);
|
||||
foreach (var id in diff.ToPromote) _enqueueLoad(id, LandblockStreamJobKind.PromoteToNear);
|
||||
foreach (var id in diff.ToDemote) _state.RemoveEntitiesFromLandblock(id);
|
||||
foreach (var id in diff.ToUnload) _enqueueUnload(id);
|
||||
}
|
||||
|
||||
// Drain up to N completions per frame so a big diff doesn't spike
|
||||
|
|
@ -96,6 +111,9 @@ public sealed class StreamingController
|
|||
_applyTerrain(loaded.Landblock, loaded.MeshData);
|
||||
_state.AddLandblock(loaded.Landblock);
|
||||
break;
|
||||
case LandblockStreamResult.Promoted promoted:
|
||||
_state.AddEntitiesToExistingLandblock(promoted.LandblockId, promoted.Entities);
|
||||
break;
|
||||
case LandblockStreamResult.Unloaded unloaded:
|
||||
_state.RemoveLandblock(unloaded.LandblockId);
|
||||
_removeTerrain?.Invoke(unloaded.LandblockId);
|
||||
|
|
@ -108,12 +126,6 @@ public sealed class StreamingController
|
|||
Console.WriteLine(
|
||||
$"streaming: worker CRASHED: {crashed.Error}");
|
||||
break;
|
||||
case LandblockStreamResult.Promoted:
|
||||
// TODO(A.5 T13): merge promoted entities into existing
|
||||
// GpuWorldState entry via AddEntitiesToExistingLandblock.
|
||||
// Today the streamer never produces Promoted (only LoadNear /
|
||||
// LoadFar), so this arm is unreachable and silently consumed.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue