refactor(update): cut over the frame orchestrator

Reduce GameWindow.OnUpdate to one typed orchestration call and remove transitive window callbacks from teardown, liveness, teleport placement, live presentation, auto-entry, and entity packet routing. Preserve the frozen retail object/network order while making the production owner graph explicit and testable.
This commit is contained in:
Erik 2026-07-22 03:31:38 +02:00
parent 947c61d2d7
commit e91f310279
18 changed files with 864 additions and 348 deletions

View file

@ -0,0 +1,69 @@
using AcDream.App.Input;
using AcDream.Core.Items;
using AcDream.Core.Net;
using AcDream.Core.Net.Messages;
namespace AcDream.App.World;
internal interface ILiveEntityPruneSink
{
bool Prune(LiveEntityPruneCandidate candidate);
}
/// <summary>
/// Owns authoritative and expiry-driven live-object deletion through one
/// generation-safe runtime transaction.
/// </summary>
internal sealed class LiveEntityDeletionController : ILiveEntityPruneSink
{
private readonly LiveEntityRuntime _runtime;
private readonly ClientObjectTable _objects;
private readonly ILiveEntityTeardownCoordinator _teardown;
private readonly ILocalPlayerIdentitySource _identity;
private readonly Action<string>? _diagnostic;
public LiveEntityDeletionController(
LiveEntityRuntime runtime,
ClientObjectTable objects,
ILiveEntityTeardownCoordinator teardown,
ILocalPlayerIdentitySource identity,
Action<string>? diagnostic = null)
{
_runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
_objects = objects ?? throw new ArgumentNullException(nameof(objects));
_teardown = teardown ?? throw new ArgumentNullException(nameof(teardown));
_identity = identity ?? throw new ArgumentNullException(nameof(identity));
_diagnostic = diagnostic;
}
/// <summary>
/// Retail <c>SmartBox::HandleDeleteObject @ 0x00451EA0</c> rejects the
/// player, requires the exact Instance timestamp, then performs one
/// symmetric logical teardown.
/// </summary>
public bool Delete(DeleteObject.Parsed delete)
{
if (delete.Guid == _identity.ServerGuid)
return false;
if (!_runtime.TryGetRecord(delete.Guid, out _))
_teardown.ForgetUnknownOwner(delete.Guid);
bool removed = _runtime.UnregisterLiveEntity(
delete,
isLocalPlayer: false,
beforeTeardown: () =>
ObjectTableWiring.ApplyEntityDelete(_objects, delete));
if (removed)
{
_diagnostic?.Invoke(
$"live: delete guid=0x{delete.Guid:X8} instSeq={delete.InstanceSequence}");
}
return removed;
}
public bool Prune(LiveEntityPruneCandidate candidate) =>
Delete(new DeleteObject.Parsed(
candidate.ServerGuid,
candidate.Generation));
}

View file

@ -1,4 +1,5 @@
using AcDream.App.Rendering;
using AcDream.App.Input;
using AcDream.Core.Items;
using AcDream.Core.Net;
using AcDream.Core.Net.Messages;
@ -146,9 +147,9 @@ internal sealed class LiveEntityHydrationController
private readonly ILiveEntityReadyPublisher _ready;
private readonly ILiveEntityWorldOriginCoordinator _origin;
private readonly ILiveEntityNetworkUpdateSink _networkUpdates;
private readonly ILiveEntityTeardownCoordinator _teardown;
private readonly Action<uint, AcceptedPhysicsTimestamps> _publishTimestamps;
private readonly Func<uint> _playerGuid;
private readonly IAcceptedLocalPhysicsTimestampPublisher _timestamps;
private readonly ILocalPlayerIdentitySource _identity;
private readonly LiveEntityDeletionController _deletion;
private readonly Action<string>? _diagnostic;
public LiveEntityHydrationController(
@ -160,9 +161,9 @@ internal sealed class LiveEntityHydrationController
ILiveEntityReadyPublisher ready,
ILiveEntityWorldOriginCoordinator origin,
ILiveEntityNetworkUpdateSink networkUpdates,
ILiveEntityTeardownCoordinator teardown,
Action<uint, AcceptedPhysicsTimestamps> publishTimestamps,
Func<uint> playerGuid,
IAcceptedLocalPhysicsTimestampPublisher timestamps,
ILocalPlayerIdentitySource identity,
LiveEntityDeletionController deletion,
Action<string>? diagnostic = null)
{
_runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
@ -173,10 +174,9 @@ internal sealed class LiveEntityHydrationController
_ready = ready ?? throw new ArgumentNullException(nameof(ready));
_origin = origin ?? throw new ArgumentNullException(nameof(origin));
_networkUpdates = networkUpdates ?? throw new ArgumentNullException(nameof(networkUpdates));
_teardown = teardown ?? throw new ArgumentNullException(nameof(teardown));
_publishTimestamps = publishTimestamps
?? throw new ArgumentNullException(nameof(publishTimestamps));
_playerGuid = playerGuid ?? throw new ArgumentNullException(nameof(playerGuid));
_timestamps = timestamps ?? throw new ArgumentNullException(nameof(timestamps));
_identity = identity ?? throw new ArgumentNullException(nameof(identity));
_deletion = deletion ?? throw new ArgumentNullException(nameof(deletion));
_diagnostic = diagnostic;
}
@ -207,7 +207,7 @@ internal sealed class LiveEntityHydrationController
try
{
_publishTimestamps(spawn.Guid, result.Timestamps);
_timestamps.Publish(spawn.Guid, result.Timestamps);
if (_runtime.IsCurrentCreateIntegration(
record,
createIntegrationVersion)
@ -353,23 +353,7 @@ internal sealed class LiveEntityHydrationController
// SmartBox::HandleDeleteObject rejects the player before resolving an
// object or touching any queued owner state. A pre-Create player
// Delete must therefore be side-effect-free too.
if (delete.Guid == _playerGuid())
return false;
if (!_runtime.TryGetRecord(delete.Guid, out _))
_teardown.ForgetUnknownOwner(delete.Guid);
bool removed = _runtime.UnregisterLiveEntity(
delete,
isLocalPlayer: false,
beforeTeardown: () =>
ObjectTableWiring.ApplyEntityDelete(_objects, delete));
if (removed)
{
_diagnostic?.Invoke(
$"live: delete guid=0x{delete.Guid:X8} instSeq={delete.InstanceSequence}");
}
return removed;
return _deletion.Delete(delete);
}
/// <summary>
@ -377,9 +361,7 @@ internal sealed class LiveEntityHydrationController
/// generation gate and teardown transaction as an authoritative F747.
/// </summary>
public bool OnPrune(LiveEntityPruneCandidate candidate) =>
OnDelete(new DeleteObject.Parsed(
candidate.ServerGuid,
candidate.Generation));
_deletion.Prune(candidate);
public int RetryPendingTeardowns() => _runtime.RetryPendingTeardowns();
@ -415,7 +397,7 @@ internal sealed class LiveEntityHydrationController
uint canonical = (loadedLandblockId & 0xFFFF0000u) | 0xFFFFu;
LiveEntityRecord[] records = _runtime.Records
.Where(record => (record.ServerGuid != _playerGuid()
.Where(record => (record.ServerGuid != _identity.ServerGuid
|| !record.InitialHydrationCompleted
|| record.CreateProjectionSynchronizationPending
|| record.AppearanceProjectionSynchronizationPending)

View file

@ -1,3 +1,4 @@
using AcDream.App.Input;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Vfx;
using AcDream.App.Streaming;
@ -113,7 +114,17 @@ internal sealed class LiveEntityWorldOriginCoordinator : ILiveEntityWorldOriginC
private readonly StreamingController _streaming;
private readonly GpuWorldState _worldState;
private readonly WorldRevealCoordinator _worldReveal;
private readonly Func<uint> _playerGuid;
private sealed class DelegateIdentitySource : ILocalPlayerIdentitySource
{
private readonly Func<uint> _read;
public DelegateIdentitySource(Func<uint> read) =>
_read = read ?? throw new ArgumentNullException(nameof(read));
public uint ServerGuid => _read();
}
private readonly ILocalPlayerIdentitySource _identity;
private readonly ISealedDungeonCellClassifier _sealedDungeonCells;
private readonly Action<string>? _diagnostic;
@ -122,7 +133,7 @@ internal sealed class LiveEntityWorldOriginCoordinator : ILiveEntityWorldOriginC
StreamingController streaming,
GpuWorldState worldState,
WorldRevealCoordinator worldReveal,
Func<uint> playerGuid,
ILocalPlayerIdentitySource identity,
ISealedDungeonCellClassifier sealedDungeonCells,
Action<string>? diagnostic = null)
{
@ -130,18 +141,37 @@ internal sealed class LiveEntityWorldOriginCoordinator : ILiveEntityWorldOriginC
_streaming = streaming ?? throw new ArgumentNullException(nameof(streaming));
_worldState = worldState ?? throw new ArgumentNullException(nameof(worldState));
_worldReveal = worldReveal ?? throw new ArgumentNullException(nameof(worldReveal));
_playerGuid = playerGuid ?? throw new ArgumentNullException(nameof(playerGuid));
_identity = identity ?? throw new ArgumentNullException(nameof(identity));
_sealedDungeonCells = sealedDungeonCells
?? throw new ArgumentNullException(nameof(sealedDungeonCells));
_diagnostic = diagnostic;
}
internal LiveEntityWorldOriginCoordinator(
LiveWorldOriginState origin,
StreamingController streaming,
GpuWorldState worldState,
WorldRevealCoordinator worldReveal,
Func<uint> playerGuid,
ISealedDungeonCellClassifier sealedDungeonCells,
Action<string>? diagnostic = null)
: this(
origin,
streaming,
worldState,
worldReveal,
new DelegateIdentitySource(playerGuid),
sealedDungeonCells,
diagnostic)
{
}
public bool IsKnown => _origin.IsKnown;
public LiveEntityOriginInitialization TryInitialize(
WorldSession.EntitySpawn spawn)
{
if (spawn.Guid != _playerGuid()
if (spawn.Guid != _identity.ServerGuid
|| spawn.Position is not { } position)
{
return new(_origin.IsKnown, Array.Empty<uint>());

View file

@ -1,4 +1,5 @@
using AcDream.Core.Net.Messages;
using AcDream.App.Input;
namespace AcDream.App.World;
@ -86,19 +87,19 @@ internal sealed class LiveEntityLivenessController
private const double MaintenanceIntervalSeconds = 1.0;
private readonly LiveEntityRuntime _runtime;
private readonly Func<uint> _playerGuid;
private readonly Action<LiveEntityPruneCandidate> _prune;
private readonly ILocalPlayerIdentitySource _identity;
private readonly ILiveEntityPruneSink _prune;
private readonly LiveEntityLivenessTracker _tracker = new();
private readonly List<LiveEntityLivenessSample> _samples = new();
private double _nextMaintenanceAt;
public LiveEntityLivenessController(
LiveEntityRuntime runtime,
Func<uint> playerGuid,
Action<LiveEntityPruneCandidate> prune)
ILocalPlayerIdentitySource identity,
ILiveEntityPruneSink prune)
{
_runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
_playerGuid = playerGuid ?? throw new ArgumentNullException(nameof(playerGuid));
_identity = identity ?? throw new ArgumentNullException(nameof(identity));
_prune = prune ?? throw new ArgumentNullException(nameof(prune));
}
@ -108,7 +109,7 @@ internal sealed class LiveEntityLivenessController
return;
_nextMaintenanceAt = now + MaintenanceIntervalSeconds;
uint playerGuid = _playerGuid();
uint playerGuid = _identity.ServerGuid;
if (playerGuid == 0
|| !_runtime.TryGetRecord(playerGuid, out LiveEntityRecord player)
|| player.Snapshot.Position is not { } playerPosition)
@ -144,7 +145,7 @@ internal sealed class LiveEntityLivenessController
if (_runtime.TryGetRecord(candidate.ServerGuid, out LiveEntityRecord current)
&& current.Generation == candidate.Generation)
{
_prune(candidate);
_prune.Prune(candidate);
}
}
}

View file

@ -1,4 +1,5 @@
using AcDream.App.Interaction;
using AcDream.App.Input;
using AcDream.App.Physics;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Vfx;
@ -38,7 +39,7 @@ internal sealed class LiveEntityRuntimeTeardownController
private readonly ShadowObjectRegistry? _shadows;
private readonly LiveEntityLightController? _lights;
private readonly EntityClassificationCache? _classification;
private readonly Func<uint>? _playerGuid;
private readonly ILocalPlayerIdentitySource? _identity;
private readonly Func<LiveEntityRecord, LiveEntityTeardownPlan> _createPlan;
private readonly Action<uint> _forgetUnknownOwner;
@ -57,7 +58,7 @@ internal sealed class LiveEntityRuntimeTeardownController
ShadowObjectRegistry shadows,
LiveEntityLightController lights,
EntityClassificationCache classification,
Func<uint> playerGuid)
ILocalPlayerIdentitySource identity)
{
_runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
_presentation = presentation ?? throw new ArgumentNullException(nameof(presentation));
@ -77,7 +78,7 @@ internal sealed class LiveEntityRuntimeTeardownController
_lights = lights ?? throw new ArgumentNullException(nameof(lights));
_classification = classification
?? throw new ArgumentNullException(nameof(classification));
_playerGuid = playerGuid ?? throw new ArgumentNullException(nameof(playerGuid));
_identity = identity ?? throw new ArgumentNullException(nameof(identity));
_createPlan = CreatePlan;
_forgetUnknownOwner = effects.ForgetUnknownOwner;
}
@ -158,7 +159,7 @@ internal sealed class LiveEntityRuntimeTeardownController
cleanups.Add(() => _translucencyFades!.ClearEntity(existingEntity.Id));
cleanups.Add(() => _projectionWithdrawal!.LeaveWorld(
record,
_playerGuid!()));
_identity!.ServerGuid));
cleanups.Add(() => _children!.OnLogicalTeardown(record));
cleanups.Add(() => _shadows!.Deregister(existingEntity.Id));
cleanups.Add(() => _lights!.Forget(existingEntity.Id));

View file

@ -1,3 +1,5 @@
using System.Numerics;
namespace AcDream.App.World;
/// <summary>
@ -40,6 +42,23 @@ internal sealed class LiveWorldOriginState
CenterY = centerY;
}
public (int X, int Y) GetCenter() => (CenterX, CenterY);
/// <summary>
/// Converts the streamed render frame back into retail's landblock-local
/// physics frame at the one placement seed boundary.
/// </summary>
public Vector3 CellLocalForSeed(Vector3 worldPosition, uint cellId)
{
int landblockX = (int)((cellId >> 24) & 0xFFu);
int landblockY = (int)((cellId >> 16) & 0xFFu);
var origin = new Vector3(
(landblockX - CenterX) * 192f,
(landblockY - CenterY) * 192f,
0f);
return worldPosition - origin;
}
/// <summary>
/// Ends the accepted-origin lifetime while retaining the last coordinates
/// as the next placeholder. Consumers must gate them on

View file

@ -0,0 +1,43 @@
using AcDream.App.Input;
using AcDream.App.Net;
namespace AcDream.App.World;
internal interface IAcceptedLocalPhysicsTimestampPublisher
{
void Publish(uint serverGuid, AcceptedPhysicsTimestamps timestamps);
}
/// <summary>
/// Publishes accepted local-player physics timestamps to the current exact
/// session without retaining the window host.
/// </summary>
internal sealed class LiveSessionLocalPhysicsTimestampPublisher
: IAcceptedLocalPhysicsTimestampPublisher
{
private readonly ILocalPlayerIdentitySource _identity;
private readonly ILiveWorldSessionSource _session;
public LiveSessionLocalPhysicsTimestampPublisher(
ILocalPlayerIdentitySource identity,
ILiveWorldSessionSource session)
{
_identity = identity ?? throw new ArgumentNullException(nameof(identity));
_session = session ?? throw new ArgumentNullException(nameof(session));
}
public void Publish(uint serverGuid, AcceptedPhysicsTimestamps timestamps)
{
if (serverGuid != _identity.ServerGuid
|| _session.CurrentSession is not { } session)
{
return;
}
session.PublishAcceptedLocalPhysicsTimestamps(
timestamps.Instance,
timestamps.ServerControlledMove,
timestamps.Teleport,
timestamps.ForcePosition);
}
}