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:
parent
e02acb870c
commit
f4cf802330
5 changed files with 90 additions and 17 deletions
|
|
@ -2264,7 +2264,7 @@ public sealed class GameWindow : IDisposable
|
|||
coordinatesOnRadar: () => _persistedGameplay.CoordinatesOnRadar,
|
||||
uiLocked: () => _persistedGameplay.LockUI,
|
||||
playerEntities: () => _entitiesByServerGuid,
|
||||
copySpatialCandidates: _worldState.CopyLiveEntitiesNearLandblock);
|
||||
spatialQuery: () => _worldState);
|
||||
var retailChatVm = new AcDream.UI.Abstractions.Panels.Chat.ChatVM(Chat, displayLimit: 200);
|
||||
_retailChatVm = retailChatVm;
|
||||
AcDream.App.UI.RetailUiPersistenceBindings? persistence = _settingsStore is null
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Linq;
|
|||
using System.Numerics;
|
||||
using AcDream.App.Rendering.Vfx;
|
||||
using AcDream.App.Rendering.Wb;
|
||||
using AcDream.App.World;
|
||||
using AcDream.Core.World;
|
||||
|
||||
namespace AcDream.App.Streaming;
|
||||
|
|
@ -39,7 +40,7 @@ namespace AcDream.App.Streaming;
|
|||
/// Threading: not thread-safe. All calls must happen on the render thread.
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
public sealed class GpuWorldState
|
||||
public sealed class GpuWorldState : ILiveEntitySpatialQuery
|
||||
{
|
||||
private readonly LandblockSpawnAdapter? _wbSpawnAdapter;
|
||||
private readonly EntityScriptActivator? _entityScriptActivator;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
16
src/AcDream.App/World/ILiveEntitySpatialQuery.cs
Normal file
16
src/AcDream.App/World/ILiveEntitySpatialQuery.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using AcDream.Core.World;
|
||||
|
||||
namespace AcDream.App.World;
|
||||
|
||||
/// <summary>
|
||||
/// Read-only spatial broadphase for live server-object projections.
|
||||
/// Consumers resolve this owner late because <c>GameWindow</c> replaces its
|
||||
/// empty bootstrap world state after retained UI construction.
|
||||
/// </summary>
|
||||
public interface ILiveEntitySpatialQuery
|
||||
{
|
||||
void CopyLiveEntitiesNearLandblock(
|
||||
uint centerCellOrLandblockId,
|
||||
int landblockRadius,
|
||||
List<KeyValuePair<uint, WorldEntity>> destination);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue