2021-11-08 15:11:58 +01:00
|
|
|
using Content.Shared.MobState.Components;
|
2021-06-19 10:03:24 +02:00
|
|
|
using Content.Shared.Movement;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Movement.Components;
|
2022-06-24 17:44:30 +10:00
|
|
|
using Content.Shared.Movement.Systems;
|
2021-09-02 12:35:16 +10:00
|
|
|
using Content.Shared.Pulling.Components;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Client.Player;
|
2021-12-27 18:50:00 +01:00
|
|
|
using Robust.Shared.Map;
|
2021-10-04 15:35:03 +11:00
|
|
|
using Robust.Shared.Physics;
|
2022-03-14 02:42:39 +11:00
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
using Robust.Shared.Timing;
|
2021-03-08 04:09:59 +11:00
|
|
|
|
|
|
|
|
namespace Content.Client.Physics.Controllers
|
|
|
|
|
{
|
|
|
|
|
public sealed class MoverController : SharedMoverController
|
|
|
|
|
{
|
2022-03-14 02:42:39 +11:00
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
2021-03-08 04:09:59 +11:00
|
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
|
|
|
|
|
|
|
|
public override void UpdateBeforeSolve(bool prediction, float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateBeforeSolve(prediction, frameTime);
|
|
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player ||
|
2022-02-02 17:34:25 +11:00
|
|
|
!TryComp(player, out IMoverComponent? mover) ||
|
|
|
|
|
!TryComp(player, out PhysicsComponent? body) ||
|
|
|
|
|
!TryComp(player, out TransformComponent? xform))
|
2021-12-05 18:09:01 +01:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-03-08 04:09:59 +11:00
|
|
|
|
2022-06-20 12:14:35 +12:00
|
|
|
if (xform.GridUid != null)
|
2021-12-27 18:50:00 +01:00
|
|
|
mover.LastGridAngle = GetParentGridAngle(xform, mover);
|
|
|
|
|
|
2021-08-04 01:16:42 +10:00
|
|
|
// Essentially we only want to set our mob to predicted so every other entity we just interpolate
|
|
|
|
|
// (i.e. only see what the server has sent us).
|
|
|
|
|
// The exception to this is joints.
|
|
|
|
|
body.Predict = true;
|
2021-03-08 04:09:59 +11:00
|
|
|
|
2021-08-04 01:16:42 +10:00
|
|
|
// We set joints to predicted given these can affect how our mob moves.
|
|
|
|
|
// I would only recommend disabling this if you make pulling not use joints anymore (someday maybe?)
|
2021-10-04 15:35:03 +11:00
|
|
|
|
2022-02-02 17:34:25 +11:00
|
|
|
if (TryComp(player, out JointComponent? jointComponent))
|
2021-08-04 01:02:43 +10:00
|
|
|
{
|
2021-10-04 15:35:03 +11:00
|
|
|
foreach (var joint in jointComponent.GetJoints)
|
|
|
|
|
{
|
|
|
|
|
joint.BodyA.Predict = true;
|
|
|
|
|
joint.BodyB.Predict = true;
|
|
|
|
|
}
|
2021-08-04 01:02:43 +10:00
|
|
|
}
|
|
|
|
|
|
2021-09-02 12:35:16 +10:00
|
|
|
// If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother.
|
2022-02-02 17:34:25 +11:00
|
|
|
if (TryComp(player, out SharedPullableComponent? pullableComp))
|
2021-09-02 12:35:16 +10:00
|
|
|
{
|
2022-02-02 17:34:25 +11:00
|
|
|
if (pullableComp.Puller is {Valid: true} puller && TryComp<PhysicsComponent?>(puller, out var pullerBody))
|
2021-09-02 12:35:16 +10:00
|
|
|
{
|
|
|
|
|
pullerBody.Predict = false;
|
|
|
|
|
body.Predict = false;
|
2022-04-25 17:24:40 +10:00
|
|
|
|
|
|
|
|
if (TryComp<SharedPullerComponent>(player, out var playerPuller) && playerPuller.Pulling != null &&
|
|
|
|
|
TryComp<PhysicsComponent>(playerPuller.Pulling, out var pulledBody))
|
|
|
|
|
{
|
|
|
|
|
pulledBody.Predict = false;
|
|
|
|
|
}
|
2021-09-02 12:35:16 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 04:09:59 +11:00
|
|
|
// Server-side should just be handled on its own so we'll just do this shizznit
|
2022-02-02 17:34:25 +11:00
|
|
|
if (TryComp(player, out IMobMoverComponent? mobMover))
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
2022-06-23 12:13:22 +10:00
|
|
|
HandleMobMovement(mover, body, mobMover, xform, frameTime);
|
2021-03-08 04:09:59 +11:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HandleKinematicMovement(mover, body);
|
|
|
|
|
}
|
2022-03-14 02:42:39 +11:00
|
|
|
|
|
|
|
|
protected override Filter GetSoundPlayers(EntityUid mover)
|
|
|
|
|
{
|
|
|
|
|
return Filter.Local();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool CanSound()
|
|
|
|
|
{
|
|
|
|
|
return _timing.IsFirstTimePredicted && _timing.InSimulation;
|
|
|
|
|
}
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
|
|
|
|
}
|