refactor(runtime): extract the live object frame
This commit is contained in:
parent
99a3e819c4
commit
4e4aac2c5a
27 changed files with 1217 additions and 371 deletions
|
|
@ -0,0 +1,46 @@
|
|||
using AcDream.App.Input;
|
||||
using AcDream.App.Physics;
|
||||
using AcDream.App.World;
|
||||
using AcDream.Core.Physics;
|
||||
|
||||
namespace AcDream.App.Rendering;
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the current motion owner without retaining the application window.
|
||||
/// </summary>
|
||||
internal sealed class LiveAnimationPresentationContext
|
||||
: ILiveAnimationPresentationContext
|
||||
{
|
||||
private readonly LiveEntityRuntime _runtime;
|
||||
private readonly ILocalPlayerIdentitySource _localPlayer;
|
||||
private readonly ILocalPlayerControllerSource _playerController;
|
||||
|
||||
public LiveAnimationPresentationContext(
|
||||
LiveEntityRuntime runtime,
|
||||
ILocalPlayerIdentitySource localPlayer,
|
||||
ILocalPlayerControllerSource playerController)
|
||||
{
|
||||
_runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
|
||||
_localPlayer = localPlayer ?? throw new ArgumentNullException(nameof(localPlayer));
|
||||
_playerController = playerController
|
||||
?? throw new ArgumentNullException(nameof(playerController));
|
||||
}
|
||||
|
||||
public uint LocalPlayerGuid => _localPlayer.ServerGuid;
|
||||
|
||||
public MotionInterpreter? ResolveMotionInterpreter(LiveEntityRecord record)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(record);
|
||||
if (!_runtime.TryGetRecord(record.ServerGuid, out LiveEntityRecord current)
|
||||
|| !ReferenceEquals(current, record))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (record.ServerGuid == _localPlayer.ServerGuid)
|
||||
return _playerController.Controller?.Motion;
|
||||
return record.RemoteMotionRuntime is RemoteMotion remote
|
||||
? remote.Motion
|
||||
: null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue