refactor(runtime): extract the live object frame

This commit is contained in:
Erik 2026-07-22 00:42:26 +02:00
parent 99a3e819c4
commit 4e4aac2c5a
27 changed files with 1217 additions and 371 deletions

View file

@ -12,8 +12,8 @@ namespace AcDream.App.Rendering;
/// </summary>
internal sealed class LiveEntityAnimationPresenter
{
private readonly Func<LiveEntityRuntime?> _liveEntities;
private readonly Func<ILiveStaticPartFrameSource?> _staticFrames;
private readonly LiveEntityRuntime _liveEntities;
private readonly ILiveStaticPartFrameSource _staticFrames;
private readonly EntityEffectPoseRegistry _effectPoses;
private readonly ILiveAnimationPresentationContext _context;
private readonly AnimationPresentationDiagnostics _diagnostics;
@ -22,8 +22,8 @@ internal sealed class LiveEntityAnimationPresenter
private bool _isPresenting;
public LiveEntityAnimationPresenter(
Func<LiveEntityRuntime?> liveEntities,
Func<ILiveStaticPartFrameSource?> staticFrames,
LiveEntityRuntime liveEntities,
ILiveStaticPartFrameSource staticFrames,
EntityEffectPoseRegistry effectPoses,
ILiveAnimationPresentationContext context,
AnimationPresentationDiagnostics diagnostics,
@ -43,9 +43,8 @@ internal sealed class LiveEntityAnimationPresenter
{
ArgumentNullException.ThrowIfNull(record);
ArgumentNullException.ThrowIfNull(animation);
LiveEntityRuntime? runtime = _liveEntities();
if (runtime is null
|| !runtime.IsCurrentSpatialAnimation(record, animation)
LiveEntityRuntime runtime = _liveEntities;
if (!runtime.IsCurrentSpatialAnimation(record, animation)
|| !ReferenceEquals(record.WorldEntity, animation.Entity)
|| animation.Sequencer is not { MotionDoneTarget: null } sequencer)
{
@ -55,9 +54,8 @@ internal sealed class LiveEntityAnimationPresenter
WorldEntity capturedEntity = animation.Entity;
sequencer.MotionDoneTarget = (motion, success) =>
{
LiveEntityRuntime? current = _liveEntities();
if (current is null
|| !current.IsCurrentSpatialAnimation(record, animation)
LiveEntityRuntime current = _liveEntities;
if (!current.IsCurrentSpatialAnimation(record, animation)
|| !ReferenceEquals(record.WorldEntity, capturedEntity)
|| !ReferenceEquals(animation.Entity, capturedEntity))
{
@ -79,8 +77,8 @@ internal sealed class LiveEntityAnimationPresenter
IReadOnlyDictionary<uint, LiveEntityAnimationSchedule> schedules)
{
ArgumentNullException.ThrowIfNull(schedules);
LiveEntityRuntime? runtime = _liveEntities();
if (runtime is null || _isPresenting)
LiveEntityRuntime runtime = _liveEntities;
if (_isPresenting)
return;
// EffectPoseChanged is synchronous. Presentation is one consuming
@ -112,7 +110,7 @@ internal sealed class LiveEntityAnimationPresenter
ulong projectionVersion = record.ProjectionMutationVersion;
ulong presentationRevision = animation.PresentationRevision;
if (_staticFrames()?.TryTakeLivePartFrames(
if (_staticFrames.TryTakeLivePartFrames(
record,
entity,
animation,