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
|
|
@ -1,6 +1,7 @@
|
|||
using System.Numerics;
|
||||
using AcDream.App.UI;
|
||||
using AcDream.App.UI.Layout;
|
||||
using AcDream.App.World;
|
||||
using AcDream.Core.Items;
|
||||
using AcDream.Core.Net;
|
||||
using AcDream.Core.Net.Messages;
|
||||
|
|
@ -210,8 +211,8 @@ public sealed class RadarSnapshotProviderTests
|
|||
[unrelated] = Entity(unrelated, new Vector3(6f, 0f, 0f), Quaternion.Identity),
|
||||
};
|
||||
var spawns = entities.Keys.ToDictionary(guid => guid, Spawn);
|
||||
uint copiedCell = 0;
|
||||
int copiedRadius = -1;
|
||||
var spatialQuery = new RecordingSpatialQuery(
|
||||
new KeyValuePair<uint, WorldEntity>(nearby, entities[nearby]));
|
||||
var provider = new RadarSnapshotProvider(
|
||||
objects,
|
||||
() => entities,
|
||||
|
|
@ -222,20 +223,70 @@ public sealed class RadarSnapshotProviderTests
|
|||
selectedGuid: () => null,
|
||||
coordinatesOnRadar: () => true,
|
||||
uiLocked: () => false,
|
||||
copySpatialCandidates: (cell, radius, destination) =>
|
||||
{
|
||||
copiedCell = cell;
|
||||
copiedRadius = radius;
|
||||
destination.Add(new KeyValuePair<uint, WorldEntity>(nearby, entities[nearby]));
|
||||
});
|
||||
spatialQuery: () => spatialQuery);
|
||||
|
||||
UiRadarSnapshot snapshot = provider.BuildSnapshot();
|
||||
|
||||
Assert.Equal(0xA9B40001u, copiedCell);
|
||||
Assert.Equal(1, copiedRadius);
|
||||
Assert.Equal(0xA9B40001u, spatialQuery.CopiedCell);
|
||||
Assert.Equal(1, spatialQuery.CopiedRadius);
|
||||
Assert.Equal(nearby, Assert.Single(snapshot.Blips).ObjectId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BuildSnapshot_ResolvesSpatialOwnerAfterBootstrapReplacement()
|
||||
{
|
||||
const uint player = 50u;
|
||||
const uint monster = 51u;
|
||||
var objects = new ClientObjectTable();
|
||||
objects.Ingest(Weenie(player, "Player", ItemType.Creature));
|
||||
objects.Ingest(Weenie(monster, "Drudge", ItemType.Creature) with
|
||||
{
|
||||
RadarBehavior = (byte)RadarBehavior.ShowAlways,
|
||||
});
|
||||
var entities = new Dictionary<uint, WorldEntity>
|
||||
{
|
||||
[player] = Entity(player, Vector3.Zero, Quaternion.Identity),
|
||||
[monster] = Entity(monster, new Vector3(5f, 0f, 0f), Quaternion.Identity),
|
||||
};
|
||||
var spawns = entities.Keys.ToDictionary(guid => guid, Spawn);
|
||||
ILiveEntitySpatialQuery currentSpatialQuery = new RecordingSpatialQuery();
|
||||
var provider = new RadarSnapshotProvider(
|
||||
objects,
|
||||
() => entities,
|
||||
() => spawns,
|
||||
playerGuid: () => player,
|
||||
playerYawRadians: () => 0f,
|
||||
playerCellId: () => 0xA9B40001u,
|
||||
selectedGuid: () => null,
|
||||
coordinatesOnRadar: () => true,
|
||||
uiLocked: () => false,
|
||||
spatialQuery: () => currentSpatialQuery);
|
||||
|
||||
Assert.Empty(provider.BuildSnapshot().Blips);
|
||||
|
||||
currentSpatialQuery = new RecordingSpatialQuery(
|
||||
new KeyValuePair<uint, WorldEntity>(monster, entities[monster]));
|
||||
|
||||
Assert.Equal(monster, Assert.Single(provider.BuildSnapshot().Blips).ObjectId);
|
||||
}
|
||||
|
||||
private sealed class RecordingSpatialQuery(
|
||||
params KeyValuePair<uint, WorldEntity>[] candidates) : ILiveEntitySpatialQuery
|
||||
{
|
||||
public uint CopiedCell { get; private set; }
|
||||
public int CopiedRadius { get; private set; } = -1;
|
||||
|
||||
public void CopyLiveEntitiesNearLandblock(
|
||||
uint centerCellOrLandblockId,
|
||||
int landblockRadius,
|
||||
List<KeyValuePair<uint, WorldEntity>> destination)
|
||||
{
|
||||
CopiedCell = centerCellOrLandblockId;
|
||||
CopiedRadius = landblockRadius;
|
||||
destination.AddRange(candidates);
|
||||
}
|
||||
}
|
||||
|
||||
private static WorldEntity Entity(uint guid, Vector3 position, Quaternion rotation) => new()
|
||||
{
|
||||
Id = guid,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue