fix(ui): bind radar to streamed world state

Resolve the live-entity spatial broadphase at snapshot time so retained UI construction cannot capture GameWindow's empty bootstrap GpuWorldState. Add a replacement-owner regression test covering the exact compass-without-blips failure.

Co-authored-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-21 06:24:05 +02:00
parent e02acb870c
commit f4cf802330
5 changed files with 90 additions and 17 deletions

View file

@ -1,4 +1,5 @@
using System.Numerics;
using AcDream.App.World;
using AcDream.Core.Items;
using AcDream.Core.Net;
using AcDream.Core.Physics.Motion;
@ -29,7 +30,7 @@ public sealed class RadarSnapshotProvider
private readonly Func<bool> _coordinatesOnRadar;
private readonly Func<bool> _uiLocked;
private readonly Func<uint, RadarRelationshipTraits>? _relationshipFor;
private readonly Action<uint, int, List<KeyValuePair<uint, WorldEntity>>>? _copySpatialCandidates;
private readonly Func<ILiveEntitySpatialQuery?>? _spatialQuery;
private readonly List<KeyValuePair<uint, WorldEntity>> _candidateScratch = new();
public RadarSnapshotProvider(
@ -44,7 +45,7 @@ public sealed class RadarSnapshotProvider
Func<bool> uiLocked,
Func<uint, RadarRelationshipTraits>? relationshipFor = null,
Func<IReadOnlyDictionary<uint, WorldEntity>>? playerEntities = null,
Action<uint, int, List<KeyValuePair<uint, WorldEntity>>>? copySpatialCandidates = null)
Func<ILiveEntitySpatialQuery?>? spatialQuery = null)
{
_objects = objects ?? throw new ArgumentNullException(nameof(objects));
_worldEntities = worldEntities ?? throw new ArgumentNullException(nameof(worldEntities));
@ -57,7 +58,7 @@ public sealed class RadarSnapshotProvider
_coordinatesOnRadar = coordinatesOnRadar ?? throw new ArgumentNullException(nameof(coordinatesOnRadar));
_uiLocked = uiLocked ?? throw new ArgumentNullException(nameof(uiLocked));
_relationshipFor = relationshipFor;
_copySpatialCandidates = copySpatialCandidates;
_spatialQuery = spatialQuery;
}
public UiRadarSnapshot BuildSnapshot()
@ -90,12 +91,16 @@ public sealed class RadarSnapshotProvider
float range = RetailRadar.GetRangeMeters(isOutside);
_candidateScratch.Clear();
if (_copySpatialCandidates is not null)
// Retained UI mounts before the production GpuWorldState. Resolve the
// spatial owner per snapshot just like the live dictionaries above;
// retaining a method group here binds forever to the empty bootstrap
// state and produces a working compass with no object blips.
if (_spatialQuery?.Invoke() is { } spatialQuery)
{
// Retail radar is at most 75 metres while a landblock is 192
// metres wide. The current block plus its eight neighbours is a
// complete broadphase (the cheap spatial pre-filter).
_copySpatialCandidates(playerCellId, 1, _candidateScratch);
spatialQuery.CopyLiveEntitiesNearLandblock(playerCellId, 1, _candidateScratch);
}
else
{