feat(physics): R5-V2 — wire TargetManager voyeur system per-entity, retire AP-79
Replace the AP-79 P4 TargetTracker poll adapter with the ported retail TargetManager voyeur subscription system, wired per entity. Behaviorally a faithful no-op refactor for the common cases (server-directed creature chase + auto-walk-to-object), now driven by the retail mechanism instead of the GameWindow poll. New: EntityPhysicsHost (App) — the per-entity IPhysicsObjHost (retail CPhysicsObj stand-in), owning a TargetManager. Delegate-injected accessors so it stays free of GameWindow internals (code-structure rule #1). Wiring (GameWindow): - _physicsHosts registry (guid → host) = retail CObjectMaint::GetObjectA, backing the voyeur round-trip's cross-entity delivery. - ResolvePhysicsHost lazily creates a minimal position-only host for ANY known entity — retail lets every CPhysicsObj host a target_manager, so a STATIC object (chest/corpse) still answers add_voyeur; without this, auto-walk to a never-animated object would arm the moveto but never receive the immediate target snapshot and never start. - MoveToManager set_target/clear_target/quantum seams repointed at the host's TargetManager (remote + player). - HandleTargetting ticked unconditionally per entity BEFORE UseTime (retail UpdateObjectInternal order): per-remote loop for remotes, pre-Update block for the player. The player's tick is load-bearing for creature-chase — the player as a watched target pushes its position to the chasing NPCs' HandleUpdateTarget each frame, ahead of their UseTime. - Despawn (RemoveLiveEntityByServerGuid): NotifyVoyeurOfEvent(ExitWorld) to the entity's watchers before pruning the host — the only cleanup for a watcher whose target already sent an Ok (past Undefined, the 10s staleness never fires). Deleted: RemoteMotion.TrackedTarget* fields + _playerMoveToTarget* GameWindow fields + the two manual poll blocks. AP-79 register row retired same commit (AP section 73→72). Delivery is now synchronous-on-set_target (retail: set_target is last in MoveToObject, so the immediate snapshot lands with all moveto state in place) vs AP-79's next-frame poll — more faithful. Full suite 4006 green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
2b5e8a6738
commit
fffe90b30a
3 changed files with 295 additions and 130 deletions
115
src/AcDream.App/Rendering/EntityPhysicsHost.cs
Normal file
115
src/AcDream.App/Rendering/EntityPhysicsHost.cs
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using AcDream.Core.Physics;
|
||||
using AcDream.Core.Physics.Motion;
|
||||
|
||||
namespace AcDream.App.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// R5-V2 — the App-side <see cref="IPhysicsObjHost"/> per entity: acdream's
|
||||
/// stand-in for retail's <c>CPhysicsObj</c> as the movement managers see it.
|
||||
/// One is built per entity (a remote <c>RemoteMotion</c> or the local player)
|
||||
/// in <c>GameWindow.EnsureRemoteMotionBindings</c> / <c>EnterPlayerModeNow</c>
|
||||
/// and registered in <c>GameWindow._physicsHosts</c> (guid → host), so
|
||||
/// <see cref="GetObjectA"/> can resolve OTHER entities' hosts — the
|
||||
/// cross-entity delivery path the <see cref="TargetManager"/> voyeur system
|
||||
/// needs.
|
||||
///
|
||||
/// <para>Owns a <see cref="TargetManager"/> (retail
|
||||
/// <c>CPhysicsObj::target_manager</c>). Its <c>set_target</c>/<c>clear_target</c>/
|
||||
/// <c>add_voyeur</c>/<c>remove_voyeur</c>/<c>receive_target_update</c> seams
|
||||
/// forward to it exactly as retail's CPhysicsObj does; the movement managers'
|
||||
/// target seams are repointed here, replacing the AP-79 poll adapter. The
|
||||
/// per-entity accessors (position/velocity/radius/contact/clocks) and the
|
||||
/// <see cref="HandleUpdateTarget"/> fan-out are injected by GameWindow so this
|
||||
/// class stays free of GameWindow's internals (code-structure rule #1).</para>
|
||||
///
|
||||
/// <para>PositionManager (sticky) is R5-V3 — this host gains a
|
||||
/// <c>PositionManager</c> and <see cref="HandleUpdateTarget"/> fans to it then;
|
||||
/// V2 delivers only to the MoveToManager.</para>
|
||||
/// </summary>
|
||||
public sealed class EntityPhysicsHost : IPhysicsObjHost
|
||||
{
|
||||
private readonly Func<Position> _getPosition;
|
||||
private readonly Func<Vector3> _getVelocity;
|
||||
private readonly Func<float> _getRadius;
|
||||
private readonly Func<bool> _inContact;
|
||||
private readonly Func<float?> _minterpMaxSpeed;
|
||||
private readonly Func<double> _curTime;
|
||||
private readonly Func<double> _physicsTimerTime;
|
||||
private readonly Func<uint, IPhysicsObjHost?> _getObjectA;
|
||||
private readonly Action<TargetInfo> _handleUpdateTarget;
|
||||
private readonly Action _interruptCurrentMovement;
|
||||
private readonly TargetManager _targetManager;
|
||||
|
||||
public EntityPhysicsHost(
|
||||
uint id,
|
||||
Func<Position> getPosition,
|
||||
Func<Vector3> getVelocity,
|
||||
Func<float> getRadius,
|
||||
Func<bool> inContact,
|
||||
Func<float?> minterpMaxSpeed,
|
||||
Func<double> curTime,
|
||||
Func<double> physicsTimerTime,
|
||||
Func<uint, IPhysicsObjHost?> getObjectA,
|
||||
Action<TargetInfo> handleUpdateTarget,
|
||||
Action interruptCurrentMovement)
|
||||
{
|
||||
Id = id;
|
||||
_getPosition = getPosition ?? throw new ArgumentNullException(nameof(getPosition));
|
||||
_getVelocity = getVelocity ?? throw new ArgumentNullException(nameof(getVelocity));
|
||||
_getRadius = getRadius ?? throw new ArgumentNullException(nameof(getRadius));
|
||||
_inContact = inContact ?? throw new ArgumentNullException(nameof(inContact));
|
||||
_minterpMaxSpeed = minterpMaxSpeed ?? throw new ArgumentNullException(nameof(minterpMaxSpeed));
|
||||
_curTime = curTime ?? throw new ArgumentNullException(nameof(curTime));
|
||||
_physicsTimerTime = physicsTimerTime ?? throw new ArgumentNullException(nameof(physicsTimerTime));
|
||||
_getObjectA = getObjectA ?? throw new ArgumentNullException(nameof(getObjectA));
|
||||
_handleUpdateTarget = handleUpdateTarget ?? throw new ArgumentNullException(nameof(handleUpdateTarget));
|
||||
_interruptCurrentMovement = interruptCurrentMovement
|
||||
?? throw new ArgumentNullException(nameof(interruptCurrentMovement));
|
||||
_targetManager = new TargetManager(this);
|
||||
}
|
||||
|
||||
// ── IPhysicsObjHost accessors ──────────────────────────────────────────
|
||||
public uint Id { get; }
|
||||
public Position Position => _getPosition();
|
||||
public Vector3 Velocity => _getVelocity();
|
||||
public float Radius => _getRadius();
|
||||
public bool InContact => _inContact();
|
||||
public float? MinterpMaxSpeed => _minterpMaxSpeed();
|
||||
public double CurTime => _curTime();
|
||||
public double PhysicsTimerTime => _physicsTimerTime();
|
||||
|
||||
/// <summary>The owned voyeur manager (retail
|
||||
/// <c>CPhysicsObj::target_manager</c>).</summary>
|
||||
public TargetManager TargetManager => _targetManager;
|
||||
|
||||
// ── IPhysicsObjHost fan-out / target-tracking seams ────────────────────
|
||||
public IPhysicsObjHost? GetObjectA(uint id) => _getObjectA(id);
|
||||
public void HandleUpdateTarget(TargetInfo info) => _handleUpdateTarget(info);
|
||||
public void InterruptCurrentMovement() => _interruptCurrentMovement();
|
||||
|
||||
public void SetTarget(uint contextId, uint objectId, float radius, double quantum)
|
||||
=> _targetManager.SetTarget(contextId, objectId, radius, quantum);
|
||||
|
||||
public void ClearTarget() => _targetManager.ClearTarget();
|
||||
public void ReceiveTargetUpdate(TargetInfo info) => _targetManager.ReceiveUpdate(info);
|
||||
public void AddVoyeur(uint watcherId, float radius, double quantum)
|
||||
=> _targetManager.AddVoyeur(watcherId, radius, quantum);
|
||||
public void RemoveVoyeur(uint watcherId) => _targetManager.RemoveVoyeur(watcherId);
|
||||
|
||||
// ── per-tick driver + lifecycle (called by GameWindow) ─────────────────
|
||||
|
||||
/// <summary>Retail <c>TargetManager::HandleTargetting</c> — the per-tick
|
||||
/// voyeur sweep (self-throttled to 0.5 s). Retail runs it unconditionally
|
||||
/// for every entity in <c>UpdateObjectInternal</c>, BEFORE the movement
|
||||
/// managers' <c>UseTime</c>.</summary>
|
||||
public void HandleTargetting() => _targetManager.HandleTargetting();
|
||||
|
||||
/// <summary>Retail <c>CPhysicsObj::exit_world</c>'s
|
||||
/// <c>TargetManager::NotifyVoyeurOfEvent(ExitWorld)</c> — tell every
|
||||
/// watcher of this entity that it left the world (they drop the
|
||||
/// stick/moveto). Called on despawn before the host is removed from the
|
||||
/// registry.</summary>
|
||||
public void NotifyExitWorld() => _targetManager.NotifyVoyeurOfEvent(TargetStatus.ExitWorld);
|
||||
}
|
||||
|
|
@ -435,15 +435,12 @@ public sealed class GameWindow : IDisposable
|
|||
/// EnsureRemoteMotionBindings beside the R2-Q5/R3 binds.</summary>
|
||||
public AcDream.Core.Physics.Motion.MoveToManager? MoveTo;
|
||||
|
||||
// R4-V4 (pin P4): the minimal TargetTracker adapter state — the
|
||||
// manager's setTarget/clearTarget seams store the tracked guid here;
|
||||
// the per-tick block feeds HandleUpdateTarget(Ok/ExitWorld) from the
|
||||
// live entity table. Full TargetManager port is R5 (register row).
|
||||
public uint TrackedTargetGuid;
|
||||
public float TrackedTargetRadius;
|
||||
public System.Numerics.Vector3 TrackedTargetLastFedPos;
|
||||
public bool TrackedTargetFedOnce;
|
||||
public double TargetQuantum;
|
||||
// R5-V2: the entity's CPhysicsObj stand-in — owns the TargetManager
|
||||
// voyeur system (retail CPhysicsObj::target_manager). Replaces the
|
||||
// AP-79 TrackedTarget* poll fields: the MoveToManager's set_target/
|
||||
// clear_target/quantum seams route here, HandleTargetting ticks per
|
||||
// frame, and OTHER entities resolve this one via GameWindow._physicsHosts.
|
||||
public EntityPhysicsHost? Host;
|
||||
/// <summary>
|
||||
/// True while a server MoveToObject/MoveToPosition packet is the
|
||||
/// active locomotion source. Retail runs these through MoveToManager
|
||||
|
|
@ -952,17 +949,19 @@ public sealed class GameWindow : IDisposable
|
|||
// time. Cleared before the deferred send fires — single-fire, no retry.
|
||||
private (uint Guid, bool IsPickup)? _pendingPostArrivalAction;
|
||||
|
||||
// R4-V5 (pin P4): the local player's minimal TargetTracker adapter
|
||||
// state — the exact twin of RemoteMotion's TrackedTarget* fields. The
|
||||
// player MoveToManager's setTarget/clearTarget seams store the tracked
|
||||
// guid here; the pre-Update feed in OnUpdateFrame delivers
|
||||
// HandleUpdateTarget(Ok/ExitWorld) from the live entity table. Full
|
||||
// TargetManager port is R5 (register row, landed with V4).
|
||||
private uint _playerMoveToTargetGuid;
|
||||
private float _playerMoveToTargetRadius;
|
||||
private System.Numerics.Vector3 _playerMoveToTargetLastFedPos;
|
||||
private bool _playerMoveToTargetFedOnce;
|
||||
private double _playerMoveToTargetQuantum;
|
||||
// R5-V2: the local player's CPhysicsObj stand-in — owns the player's
|
||||
// TargetManager voyeur system, registered in _physicsHosts so remote
|
||||
// entities chasing the player resolve it. Replaces the AP-79
|
||||
// _playerMoveToTarget* poll fields.
|
||||
private EntityPhysicsHost? _playerHost;
|
||||
|
||||
// R5-V2: guid → per-entity IPhysicsObjHost registry (retail's
|
||||
// CObjectMaint::GetObjectA lookup). Backs every host's GetObjectA seam,
|
||||
// giving the TargetManager voyeur round-trip its cross-entity delivery
|
||||
// path. Populated in EnsureRemoteMotionBindings (remotes) + EnterPlayerModeNow
|
||||
// (player); pruned in RemoveLiveEntityByServerGuid.
|
||||
private readonly Dictionary<uint, AcDream.Core.Physics.Motion.IPhysicsObjHost> _physicsHosts = new();
|
||||
|
||||
private static bool IsPlayerGuid(uint guid) => (guid & 0xFF000000u) == 0x50000000u;
|
||||
private const double ServerControlledVelocityStaleSeconds = 0.60;
|
||||
private int _liveSpawnReceived; // diagnostics
|
||||
|
|
@ -4267,6 +4266,11 @@ public sealed class GameWindow : IDisposable
|
|||
// distance/heading math matches the harness exactly.
|
||||
var rmT = rm;
|
||||
var mtBody = rm.Body;
|
||||
// R5-V2: forward-declared so the MoveToManager's target seams route
|
||||
// into the entity's TargetManager (retail CPhysicsObj::set_target →
|
||||
// TargetManager::SetTarget). Assigned right after the manager is built.
|
||||
EntityPhysicsHost host = null!;
|
||||
double NowSeconds() => (System.DateTime.UtcNow - System.DateTime.UnixEpoch).TotalSeconds;
|
||||
rm.MoveTo = new AcDream.Core.Physics.Motion.MoveToManager(
|
||||
rm.Motion,
|
||||
stopCompletely: () => rmT.Motion.StopCompletely(),
|
||||
|
|
@ -4276,37 +4280,101 @@ public sealed class GameWindow : IDisposable
|
|||
mtBody.Orientation),
|
||||
setHeading: (h, _) => mtBody.Orientation =
|
||||
AcDream.Core.Physics.Motion.MoveToMath.SetHeading(mtBody.Orientation, h),
|
||||
getOwnRadius: () => 0f, // pin P4 note: setup cylsphere radius lands with R5's TargetManager port
|
||||
getOwnRadius: () => 0f, // pin P4 note: setup cylsphere radius lands with R5-V3
|
||||
getOwnHeight: () => 0f,
|
||||
contact: () => mtBody.OnWalkable,
|
||||
isInterpolating: () => rmT.Interp.IsActive,
|
||||
getVelocity: () => mtBody.Velocity,
|
||||
getSelfId: () => serverGuid,
|
||||
setTarget: (_, tlid, radius, _) =>
|
||||
{
|
||||
rmT.TrackedTargetGuid = tlid;
|
||||
rmT.TrackedTargetRadius = radius;
|
||||
rmT.TrackedTargetFedOnce = false;
|
||||
},
|
||||
clearTarget: () => rmT.TrackedTargetGuid = 0,
|
||||
getTargetQuantum: () => rmT.TargetQuantum,
|
||||
setTargetQuantum: q => rmT.TargetQuantum = q,
|
||||
// R4-V5: real clock (same epoch-seconds base the per-remote
|
||||
// tick uses). V4 left this on the ctor's per-CALL stub, which
|
||||
// advanced 1/30 s per _curTime() READ — multiple reads inside
|
||||
// one dispatch skewed the progress/fail-distance clocks
|
||||
// (CheckProgressMade's 1 s window). The V2 harness contract
|
||||
// says production always supplies a real clock.
|
||||
curTime: () => (System.DateTime.UtcNow - System.DateTime.UnixEpoch).TotalSeconds);
|
||||
// R5-V2: retail CPhysicsObj::set_target/clear_target/target_quantum
|
||||
// → the entity's TargetManager (replaces the AP-79 TrackedTarget*
|
||||
// poll). The manager passes (0, top_level_id, 0.5, 0.0).
|
||||
setTarget: (ctx, tlid, radius, q) => host.SetTarget(ctx, tlid, radius, q),
|
||||
clearTarget: () => host.ClearTarget(),
|
||||
getTargetQuantum: () => host.TargetManager.GetTargetQuantum(),
|
||||
setTargetQuantum: q => host.TargetManager.SetTargetQuantum(q),
|
||||
// R4-V5: real clock (same epoch-seconds base the per-remote tick uses).
|
||||
curTime: NowSeconds);
|
||||
// TS-36 (remote side): the interp's interrupt seam is retail's
|
||||
// interrupt_current_movement → MovementManager::CancelMoveTo(0x36)
|
||||
// chain (V2's reentrancy tests prove the wiring is inert-safe).
|
||||
rm.Motion.InterruptCurrentMovement =
|
||||
() => rmT.MoveTo?.CancelMoveTo(
|
||||
AcDream.Core.Physics.WeenieError.ActionCancelled);
|
||||
|
||||
// R5-V2: the entity's CPhysicsObj stand-in + its TargetManager. Position
|
||||
// is the entity's WORLD position (WorldEntity.Position — exactly the
|
||||
// source the AP-79 poll used for a tracked target, so the voyeur system
|
||||
// delivers the identical position for a moveto's quantum-0 case).
|
||||
// HandleTargetting ticks per frame (added in the per-remote loop);
|
||||
// HandleUpdateTarget fans deliveries to this entity's MoveToManager
|
||||
// (PositionManager sticky joins the fan-out in V3).
|
||||
host = new EntityPhysicsHost(
|
||||
serverGuid,
|
||||
getPosition: () => new AcDream.Core.Physics.Position(
|
||||
rmT.CellId,
|
||||
_entitiesByServerGuid.TryGetValue(serverGuid, out var selfEnt)
|
||||
? selfEnt.Position : mtBody.Position,
|
||||
mtBody.Orientation),
|
||||
getVelocity: () => mtBody.Velocity,
|
||||
getRadius: () => 0f, // R5-V3: real setup cylsphere radius
|
||||
inContact: () => mtBody.OnWalkable,
|
||||
minterpMaxSpeed: () => rmT.Motion.GetMaxSpeed(),
|
||||
curTime: NowSeconds,
|
||||
physicsTimerTime: NowSeconds,
|
||||
getObjectA: ResolvePhysicsHost,
|
||||
handleUpdateTarget: info => rmT.MoveTo?.HandleUpdateTarget(info),
|
||||
interruptCurrentMovement: () => rmT.MoveTo?.CancelMoveTo(
|
||||
AcDream.Core.Physics.WeenieError.ActionCancelled));
|
||||
rm.Host = host;
|
||||
_physicsHosts[serverGuid] = host;
|
||||
return rm.Sink;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// R5-V2 — retail <c>CObjectMaint::GetObjectA(id)</c>: resolve any entity's
|
||||
/// <see cref="AcDream.Core.Physics.Motion.IPhysicsObjHost"/> by guid, the
|
||||
/// cross-entity seam every host's <c>GetObjectA</c> uses. If the entity has
|
||||
/// a bound host (from <see cref="EnsureRemoteMotionBindings"/> or
|
||||
/// <c>EnterPlayerModeNow</c>) return it; otherwise, for any entity that
|
||||
/// EXISTS in the world, lazily create a minimal position-only host. Retail
|
||||
/// gives every <c>CPhysicsObj</c> the capacity to host a
|
||||
/// <c>target_manager</c> — a STATIC object (chest, corpse) must still answer
|
||||
/// <c>add_voyeur</c> so a mover can moveto/stick to it (without this,
|
||||
/// auto-walk to a never-animated object would arm the moveto but never
|
||||
/// receive the immediate target snapshot, and never start). The minimal
|
||||
/// host is registered so subsequent lookups reuse it; it is NOT ticked
|
||||
/// (a static object never drifts, so the AddVoyeur immediate snapshot is
|
||||
/// all a watcher needs; despawn still fires ExitWorld via the registry).
|
||||
/// </summary>
|
||||
private AcDream.Core.Physics.Motion.IPhysicsObjHost? ResolvePhysicsHost(uint id)
|
||||
{
|
||||
if (_physicsHosts.TryGetValue(id, out var existing))
|
||||
return existing;
|
||||
if (!_entitiesByServerGuid.ContainsKey(id))
|
||||
return null;
|
||||
|
||||
double NowSeconds() => (System.DateTime.UtcNow - System.DateTime.UnixEpoch).TotalSeconds;
|
||||
var minimal = new EntityPhysicsHost(
|
||||
id,
|
||||
getPosition: () => new AcDream.Core.Physics.Position(
|
||||
0u,
|
||||
_entitiesByServerGuid.TryGetValue(id, out var e)
|
||||
? e.Position : System.Numerics.Vector3.Zero,
|
||||
System.Numerics.Quaternion.Identity),
|
||||
getVelocity: () => System.Numerics.Vector3.Zero, // static target
|
||||
getRadius: () => 0f,
|
||||
inContact: () => true,
|
||||
minterpMaxSpeed: () => null,
|
||||
curTime: NowSeconds,
|
||||
physicsTimerTime: NowSeconds,
|
||||
getObjectA: ResolvePhysicsHost,
|
||||
handleUpdateTarget: _ => { }, // not a watcher
|
||||
interruptCurrentMovement: () => { });
|
||||
_physicsHosts[id] = minimal;
|
||||
return minimal;
|
||||
}
|
||||
|
||||
private bool RemoveLiveEntityByServerGuid(uint serverGuid)
|
||||
{
|
||||
if (!_entitiesByServerGuid.TryGetValue(serverGuid, out var existingEntity))
|
||||
|
|
@ -4323,6 +4391,16 @@ public sealed class GameWindow : IDisposable
|
|||
aeGone.Sequencer?.Manager.HandleExitWorld();
|
||||
if (_remoteDeadReckon.TryGetValue(serverGuid, out var rmGone))
|
||||
rmGone.Motion.HandleExitWorld();
|
||||
// R5-V2: retail CPhysicsObj::exit_world tells every voyeur of this
|
||||
// entity that it left the world (TargetManager::NotifyVoyeurOfEvent
|
||||
// ExitWorld) — a watcher moving-to/stuck-to this entity drops the
|
||||
// moveto/stick. This is the ONLY clean-up for a watcher whose target
|
||||
// already sent an Ok (once status != Undefined the 10 s staleness
|
||||
// timeout never fires), so it must run before the host is pruned.
|
||||
if (_physicsHosts.TryGetValue(serverGuid, out var hostGone)
|
||||
&& hostGone is EntityPhysicsHost ephGone)
|
||||
ephGone.NotifyExitWorld();
|
||||
_physicsHosts.Remove(serverGuid);
|
||||
_animatedEntities.Remove(existingEntity.Id);
|
||||
_classificationCache.InvalidateEntity(existingEntity.Id);
|
||||
_physicsEngine.ShadowObjects.Deregister(existingEntity.Id);
|
||||
|
|
@ -4457,51 +4535,20 @@ public sealed class GameWindow : IDisposable
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// R4-V5 (extracted from the V4 NPC tick block, now shared with the
|
||||
/// grounded player-remote pipeline — the glide fix): the P4
|
||||
/// TargetTracker delivery + the per-tick MoveToManager drive. Feeds
|
||||
/// <c>HandleUpdateTarget(Ok)</c> from the live entity table when the
|
||||
/// tracked target moved beyond the voyeur radius (ExitWorld on
|
||||
/// despawn), then runs <c>UseTime()</c> — steering, arrival,
|
||||
/// fail-distance. Safe for any remote: a manager with no armed moveto
|
||||
/// no-ops, and airborne bodies are held by UseTime's contact gate.
|
||||
/// R4-V5 / R5-V2: the per-tick <see cref="AcDream.Core.Physics.Motion.MoveToManager"/>
|
||||
/// drive (<c>UseTime()</c> — steering, arrival, fail-distance). The P4
|
||||
/// TargetTracker POLL is gone (R5-V2): target-position delivery now flows
|
||||
/// through the <see cref="AcDream.Core.Physics.Motion.TargetManager"/>
|
||||
/// voyeur system — the target's own <c>HandleTargetting</c> pushes updates
|
||||
/// into this entity's <c>HandleUpdateTarget</c>, which is called
|
||||
/// unconditionally per remote in the per-tick loop BEFORE this drive
|
||||
/// (retail <c>UpdateObjectInternal</c> order). Safe for any remote: a
|
||||
/// manager with no armed moveto no-ops, airborne bodies held by
|
||||
/// <c>UseTime</c>'s contact gate.
|
||||
/// </summary>
|
||||
private void TickRemoteMoveTo(RemoteMotion rm)
|
||||
{
|
||||
if (rm.MoveTo is not { } mtm)
|
||||
return;
|
||||
|
||||
if (rm.TrackedTargetGuid != 0)
|
||||
{
|
||||
if (_entitiesByServerGuid.TryGetValue(rm.TrackedTargetGuid, out var trackedEnt))
|
||||
{
|
||||
var tpos = trackedEnt.Position;
|
||||
if (!rm.TrackedTargetFedOnce
|
||||
|| System.Numerics.Vector3.Distance(tpos, rm.TrackedTargetLastFedPos)
|
||||
> rm.TrackedTargetRadius)
|
||||
{
|
||||
rm.TrackedTargetFedOnce = true;
|
||||
rm.TrackedTargetLastFedPos = tpos;
|
||||
var tp = new AcDream.Core.Physics.Position(
|
||||
rm.CellId, tpos, System.Numerics.Quaternion.Identity);
|
||||
mtm.HandleUpdateTarget(new AcDream.Core.Physics.Motion.TargetInfo(
|
||||
rm.TrackedTargetGuid,
|
||||
AcDream.Core.Physics.Motion.TargetStatus.Ok,
|
||||
tp, tp));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var lp = new AcDream.Core.Physics.Position(
|
||||
rm.CellId, rm.TrackedTargetLastFedPos,
|
||||
System.Numerics.Quaternion.Identity);
|
||||
mtm.HandleUpdateTarget(new AcDream.Core.Physics.Motion.TargetInfo(
|
||||
rm.TrackedTargetGuid,
|
||||
AcDream.Core.Physics.Motion.TargetStatus.ExitWorld,
|
||||
lp, lp));
|
||||
}
|
||||
}
|
||||
mtm.UseTime();
|
||||
rm.MoveTo?.UseTime();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -7985,43 +8032,14 @@ public sealed class GameWindow : IDisposable
|
|||
? localEnt.Id
|
||||
: 0u;
|
||||
|
||||
// R4-V5 (pin P4): feed the player MoveToManager's target tracker
|
||||
// BEFORE Update ticks UseTime — same feed-then-tick order the
|
||||
// per-remote block uses. One immediate delivery after set_target,
|
||||
// then re-delivery when the target moved beyond the voyeur
|
||||
// radius; despawn delivers ExitWorld (the manager cancels
|
||||
// 0x37/0x38 itself).
|
||||
if (_playerController.MoveTo is { } playerMtm
|
||||
&& _playerMoveToTargetGuid != 0)
|
||||
{
|
||||
if (_entitiesByServerGuid.TryGetValue(_playerMoveToTargetGuid, out var trackedEnt))
|
||||
{
|
||||
var tpos = trackedEnt.Position;
|
||||
if (!_playerMoveToTargetFedOnce
|
||||
|| System.Numerics.Vector3.Distance(tpos, _playerMoveToTargetLastFedPos)
|
||||
> _playerMoveToTargetRadius)
|
||||
{
|
||||
_playerMoveToTargetFedOnce = true;
|
||||
_playerMoveToTargetLastFedPos = tpos;
|
||||
var tp = new AcDream.Core.Physics.Position(
|
||||
_playerController.CellId, tpos, System.Numerics.Quaternion.Identity);
|
||||
playerMtm.HandleUpdateTarget(new AcDream.Core.Physics.Motion.TargetInfo(
|
||||
_playerMoveToTargetGuid,
|
||||
AcDream.Core.Physics.Motion.TargetStatus.Ok,
|
||||
tp, tp));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var lp = new AcDream.Core.Physics.Position(
|
||||
_playerController.CellId, _playerMoveToTargetLastFedPos,
|
||||
System.Numerics.Quaternion.Identity);
|
||||
playerMtm.HandleUpdateTarget(new AcDream.Core.Physics.Motion.TargetInfo(
|
||||
_playerMoveToTargetGuid,
|
||||
AcDream.Core.Physics.Motion.TargetStatus.ExitWorld,
|
||||
lp, lp));
|
||||
}
|
||||
}
|
||||
// R5-V2: tick the player's TargetManager BEFORE Update ticks
|
||||
// MoveToManager.UseTime (retail UpdateObjectInternal order). This is
|
||||
// the load-bearing call for creature-chase: the player, as a watched
|
||||
// target, pushes its position to its voyeurs (the NPCs moving-to it)
|
||||
// here — that push lands in each NPC's HandleUpdateTarget the same
|
||||
// frame, ahead of the NPCs' own UseTime in the per-remote loop
|
||||
// (which runs after this block). Replaces the AP-79 player poll.
|
||||
_playerHost?.HandleTargetting();
|
||||
|
||||
var result = _playerController.Update((float)dt, input);
|
||||
|
||||
|
|
@ -9616,6 +9634,16 @@ public sealed class GameWindow : IDisposable
|
|||
// TickAnimations advance.
|
||||
&& rm.LastServerPosTime > 0)
|
||||
{
|
||||
// R5-V2: retail UpdateObjectInternal ticks TargetManager::
|
||||
// HandleTargetting UNCONDITIONALLY per entity, BEFORE the
|
||||
// movement managers' UseTime. This is where this entity, as a
|
||||
// watched target, pushes its position to its voyeurs (any entity
|
||||
// moving-to it), and where its own target-info staleness times
|
||||
// out. Runs for every remote regardless of the grounded/airborne
|
||||
// branch below (which drive MoveToManager.UseTime via
|
||||
// TickRemoteMoveTo). No-op for entities with no target + no voyeurs.
|
||||
rm.Host?.HandleTargetting();
|
||||
|
||||
if (IsPlayerGuid(serverGuid) && !rm.Airborne)
|
||||
{
|
||||
// ── L.3 M2/M3 (2026-05-05): queue + anim chase for grounded player remotes ──
|
||||
|
|
@ -12987,6 +13015,9 @@ public sealed class GameWindow : IDisposable
|
|||
// server-side on its own turn paths; the full-frame diff lands with
|
||||
// the R7 outbound-cadence port.
|
||||
var pcMoveTo = _playerController;
|
||||
// R5-V2: forward-declared so the player MoveToManager's target seams
|
||||
// route into the player's TargetManager (retail CPhysicsObj::set_target).
|
||||
EntityPhysicsHost playerHost = null!;
|
||||
var playerMoveTo = new AcDream.Core.Physics.Motion.MoveToManager(
|
||||
pcMoveTo.Motion,
|
||||
stopCompletely: () => pcMoveTo.Motion.StopCompletely(),
|
||||
|
|
@ -13001,19 +13032,39 @@ public sealed class GameWindow : IDisposable
|
|||
isInterpolating: () => false,
|
||||
getVelocity: () => pcMoveTo.BodyVelocity,
|
||||
getSelfId: () => _playerServerGuid,
|
||||
setTarget: (_, tlid, radius, _) =>
|
||||
{
|
||||
_playerMoveToTargetGuid = tlid;
|
||||
_playerMoveToTargetRadius = radius;
|
||||
_playerMoveToTargetFedOnce = false;
|
||||
},
|
||||
clearTarget: () => _playerMoveToTargetGuid = 0,
|
||||
getTargetQuantum: () => _playerMoveToTargetQuantum,
|
||||
setTargetQuantum: q => _playerMoveToTargetQuantum = q,
|
||||
// R5-V2: retail CPhysicsObj::set_target/clear_target/quantum → the
|
||||
// player's TargetManager (replaces the AP-79 _playerMoveToTarget* poll).
|
||||
setTarget: (ctx, tlid, radius, q) => playerHost.SetTarget(ctx, tlid, radius, q),
|
||||
clearTarget: () => playerHost.ClearTarget(),
|
||||
getTargetQuantum: () => playerHost.TargetManager.GetTargetQuantum(),
|
||||
setTargetQuantum: q => playerHost.TargetManager.SetTargetQuantum(q),
|
||||
curTime: () => pcMoveTo.SimTimeSeconds);
|
||||
_playerMoveToTargetGuid = 0;
|
||||
_playerMoveToTargetFedOnce = false;
|
||||
_playerMoveToTargetQuantum = 0.0;
|
||||
|
||||
// R5-V2: the player's CPhysicsObj stand-in + TargetManager. Position is
|
||||
// the player's WORLD position (WorldEntity.Position — what the AP-79
|
||||
// poll used), so an NPC watching the player receives the identical
|
||||
// position. Registered in _physicsHosts so those NPCs' GetObjectA
|
||||
// resolves the player; HandleTargetting is ticked in the player
|
||||
// pre-Update block.
|
||||
playerHost = new EntityPhysicsHost(
|
||||
_playerServerGuid,
|
||||
getPosition: () => new AcDream.Core.Physics.Position(
|
||||
pcMoveTo.CellId,
|
||||
_entitiesByServerGuid.TryGetValue(_playerServerGuid, out var pSelf)
|
||||
? pSelf.Position : pcMoveTo.Position,
|
||||
pcMoveTo.BodyOrientation),
|
||||
getVelocity: () => pcMoveTo.BodyVelocity,
|
||||
getRadius: () => 0f, // R5-V3: real setup cylsphere radius
|
||||
inContact: () => pcMoveTo.BodyInContact,
|
||||
minterpMaxSpeed: () => pcMoveTo.Motion.GetMaxSpeed(),
|
||||
curTime: () => pcMoveTo.SimTimeSeconds,
|
||||
physicsTimerTime: () => pcMoveTo.SimTimeSeconds,
|
||||
getObjectA: ResolvePhysicsHost,
|
||||
handleUpdateTarget: info => _playerController?.MoveTo?.HandleUpdateTarget(info),
|
||||
interruptCurrentMovement: () => _playerController?.MoveTo?.CancelMoveTo(
|
||||
AcDream.Core.Physics.WeenieError.ActionCancelled));
|
||||
_playerHost = playerHost;
|
||||
_physicsHosts[_playerServerGuid] = playerHost;
|
||||
|
||||
// AD-27 re-anchored (was the deleted AutoWalkArrived event): fire
|
||||
// the deferred close-range Use/PickUp action when the moveto
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue