Try fix collision mispredicts (#16298)
This commit is contained in:
@@ -2,11 +2,10 @@ using Content.Shared.Movement.Components;
|
||||
using Content.Shared.Movement.Systems;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Physics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Physics.Controllers
|
||||
{
|
||||
@@ -22,16 +21,51 @@ namespace Content.Client.Physics.Controllers
|
||||
SubscribeLocalEvent<RelayInputMoverComponent, PlayerDetachedEvent>(OnRelayPlayerDetached);
|
||||
SubscribeLocalEvent<InputMoverComponent, PlayerAttachedEvent>(OnPlayerAttached);
|
||||
SubscribeLocalEvent<InputMoverComponent, PlayerDetachedEvent>(OnPlayerDetached);
|
||||
|
||||
SubscribeLocalEvent<InputMoverComponent, UpdateIsPredictedEvent>(OnUpdatePredicted);
|
||||
SubscribeLocalEvent<MovementRelayTargetComponent, UpdateIsPredictedEvent>(OnUpdateRelayTargetPredicted);
|
||||
SubscribeLocalEvent<SharedPullableComponent, UpdateIsPredictedEvent>(OnUpdatePullablePredicted);
|
||||
}
|
||||
|
||||
private void OnUpdatePredicted(EntityUid uid, InputMoverComponent component, ref UpdateIsPredictedEvent args)
|
||||
{
|
||||
// Enable prediction if an entity is controlled by the player
|
||||
if (uid == _playerManager.LocalPlayer?.ControlledEntity)
|
||||
args.IsPredicted = true;
|
||||
}
|
||||
|
||||
private void OnUpdateRelayTargetPredicted(EntityUid uid, MovementRelayTargetComponent component, ref UpdateIsPredictedEvent args)
|
||||
{
|
||||
if (component.Source == _playerManager.LocalPlayer?.ControlledEntity)
|
||||
args.IsPredicted = true;
|
||||
}
|
||||
|
||||
private void OnUpdatePullablePredicted(EntityUid uid, SharedPullableComponent component, ref UpdateIsPredictedEvent args)
|
||||
{
|
||||
// Enable prediction if an entity is being pulled by the player.
|
||||
// Disable prediction if an entity is being pulled by some non-player entity.
|
||||
|
||||
if (component.Puller == _playerManager.LocalPlayer?.ControlledEntity)
|
||||
args.IsPredicted = true;
|
||||
else if (component.Puller != null)
|
||||
args.BlockPrediction = true;
|
||||
|
||||
// TODO recursive pulling checks?
|
||||
// What if the entity is being pulled by a vehicle controlled by the player?
|
||||
}
|
||||
|
||||
private void OnRelayPlayerAttached(EntityUid uid, RelayInputMoverComponent component, PlayerAttachedEvent args)
|
||||
{
|
||||
Physics.UpdateIsPredicted(uid);
|
||||
Physics.UpdateIsPredicted(component.RelayEntity);
|
||||
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
|
||||
SetMoveInput(inputMover, MoveButtons.None);
|
||||
}
|
||||
|
||||
private void OnRelayPlayerDetached(EntityUid uid, RelayInputMoverComponent component, PlayerDetachedEvent args)
|
||||
{
|
||||
Physics.UpdateIsPredicted(uid);
|
||||
Physics.UpdateIsPredicted(component.RelayEntity);
|
||||
if (TryComp<InputMoverComponent>(component.RelayEntity, out var inputMover))
|
||||
SetMoveInput(inputMover, MoveButtons.None);
|
||||
}
|
||||
@@ -53,12 +87,8 @@ namespace Content.Client.Physics.Controllers
|
||||
if (_playerManager.LocalPlayer?.ControlledEntity is not {Valid: true} player)
|
||||
return;
|
||||
|
||||
if (TryComp<RelayInputMoverComponent>(player, out var relayMover)
|
||||
&& TryComp(relayMover.RelayEntity, out MovementRelayTargetComponent? targetComp))
|
||||
{
|
||||
DebugTools.Assert(targetComp.Entities.Count <= 1, "Multiple relayed movers are not supported at the moment");
|
||||
HandleClientsideMovement(relayMover.RelayEntity.Value, frameTime);
|
||||
}
|
||||
if (TryComp<RelayInputMoverComponent>(player, out var relayMover))
|
||||
HandleClientsideMovement(relayMover.RelayEntity, frameTime);
|
||||
|
||||
HandleClientsideMovement(player, frameTime);
|
||||
}
|
||||
@@ -70,7 +100,6 @@ namespace Content.Client.Physics.Controllers
|
||||
var relayTargetQuery = GetEntityQuery<MovementRelayTargetComponent>();
|
||||
var mobMoverQuery = GetEntityQuery<MobMoverComponent>();
|
||||
var pullableQuery = GetEntityQuery<SharedPullableComponent>();
|
||||
var physicsQuery = GetEntityQuery<PhysicsComponent>();
|
||||
var modifierQuery = GetEntityQuery<MovementSpeedModifierComponent>();
|
||||
|
||||
if (!moverQuery.TryGetComponent(player, out var mover) ||
|
||||
@@ -98,42 +127,6 @@ namespace Content.Client.Physics.Controllers
|
||||
return;
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
// 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?)
|
||||
|
||||
if (TryComp(player, out JointComponent? jointComponent))
|
||||
{
|
||||
foreach (var joint in jointComponent.GetJoints.Values)
|
||||
{
|
||||
if (physicsQuery.TryGetComponent(joint.BodyAUid, out var physics))
|
||||
physics.Predict = true;
|
||||
|
||||
if (physicsQuery.TryGetComponent(joint.BodyBUid, out physics))
|
||||
physics.Predict = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If we're being pulled then we won't predict anything and will receive server lerps so it looks way smoother.
|
||||
if (pullableQuery.TryGetComponent(player, out var pullableComp))
|
||||
{
|
||||
if (pullableComp.Puller is {Valid: true} puller && TryComp<PhysicsComponent>(puller, out var pullerBody))
|
||||
{
|
||||
pullerBody.Predict = false;
|
||||
body.Predict = false;
|
||||
|
||||
if (TryComp<SharedPullerComponent>(player, out var playerPuller) && playerPuller.Pulling != null &&
|
||||
physicsQuery.TryGetComponent(playerPuller.Pulling, out var pulledBody))
|
||||
{
|
||||
pulledBody.Predict = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Server-side should just be handled on its own so we'll just do this shizznit
|
||||
HandleMobMovement(
|
||||
player,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Content.Client.Clickable;
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Input;
|
||||
using Robust.Client.Physics;
|
||||
using Robust.Client.State;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Map;
|
||||
@@ -18,6 +18,7 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
[Dependency] private readonly IInputManager _inputManager = default!;
|
||||
[Dependency] private readonly InputSystem _inputSystem = default!;
|
||||
[Dependency] private readonly PhysicsSystem _physics = default!;
|
||||
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
@@ -34,6 +35,13 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<PredictTetherEvent>(OnPredictTether);
|
||||
SubscribeNetworkEvent<TetherGunToggleMessage>(OnTetherGun);
|
||||
SubscribeLocalEvent<UpdateIsPredictedEvent>(OnUpdatePrediction);
|
||||
}
|
||||
|
||||
private void OnUpdatePrediction(ref UpdateIsPredictedEvent ev)
|
||||
{
|
||||
if (ev.Uid == _dragging || ev.Uid == _tether)
|
||||
ev.IsPredicted = true;
|
||||
}
|
||||
|
||||
private void OnTetherGun(TetherGunToggleMessage ev)
|
||||
@@ -43,22 +51,13 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
||||
|
||||
private void OnPredictTether(PredictTetherEvent ev)
|
||||
{
|
||||
if (_dragging != ev.Entity) return;
|
||||
if (_dragging != ev.Entity || _tether == ev.Entity)
|
||||
return;
|
||||
|
||||
var oldTether = _tether;
|
||||
_tether = ev.Entity;
|
||||
}
|
||||
|
||||
public override void FrameUpdate(float frameTime)
|
||||
{
|
||||
base.FrameUpdate(frameTime);
|
||||
if (!TryComp<PhysicsComponent>(_dragging, out var body)) return;
|
||||
|
||||
body.Predict = true;
|
||||
|
||||
if (TryComp<PhysicsComponent>(_tether, out var tetherBody))
|
||||
{
|
||||
tetherBody.Predict = true;
|
||||
}
|
||||
_physics.UpdateIsPredicted(oldTether);
|
||||
_physics.UpdateIsPredicted(_tether);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
@@ -102,13 +101,6 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
||||
return;
|
||||
}
|
||||
|
||||
body.Predict = true;
|
||||
|
||||
if (TryComp<PhysicsComponent>(_tether, out var tetherBody))
|
||||
{
|
||||
tetherBody.Predict = true;
|
||||
}
|
||||
|
||||
if (_lastMousePosition.Value.Position.EqualsApprox(mousePos.Position)) return;
|
||||
|
||||
_lastMousePosition = mousePos;
|
||||
@@ -123,10 +115,15 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
||||
{
|
||||
if (_dragging == null) return;
|
||||
|
||||
var oldDrag = _dragging;
|
||||
var oldTether = _tether;
|
||||
RaiseNetworkEvent(new StopTetherEvent());
|
||||
_dragging = null;
|
||||
_lastMousePosition = null;
|
||||
_tether = null;
|
||||
|
||||
_physics.UpdateIsPredicted(oldDrag);
|
||||
_physics.UpdateIsPredicted(oldTether);
|
||||
}
|
||||
|
||||
private void StartDragging(EntityUid uid, MapCoordinates coordinates)
|
||||
@@ -138,5 +135,8 @@ public sealed class TetherGunSystem : SharedTetherGunSystem
|
||||
Entity = _dragging!.Value,
|
||||
Coordinates = coordinates,
|
||||
});
|
||||
|
||||
_physics.UpdateIsPredicted(uid);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user