Fix pulling mispredicts (#22941)
* Fix pulling mispredicts * Make behaviour consistent * Good ol terminating entities
This commit is contained in:
@@ -5,7 +5,7 @@ using Robust.Shared.Serialization;
|
||||
namespace Content.Shared.Pulling.Components
|
||||
{
|
||||
// Before you try to add another type than SharedPullingStateManagementSystem, consider the can of worms you may be opening!
|
||||
[NetworkedComponent()]
|
||||
[NetworkedComponent, AutoGenerateComponentState]
|
||||
[Access(typeof(SharedPullingStateManagementSystem))]
|
||||
[RegisterComponent]
|
||||
public sealed partial class SharedPullableComponent : Component
|
||||
@@ -13,11 +13,13 @@ namespace Content.Shared.Pulling.Components
|
||||
/// <summary>
|
||||
/// The current entity pulling this component.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public EntityUid? Puller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The pull joint.
|
||||
/// </summary>
|
||||
[DataField, AutoNetworkedField]
|
||||
public string? PullJointId { get; set; }
|
||||
|
||||
public bool BeingPulled => Puller != null;
|
||||
@@ -40,17 +42,6 @@ namespace Content.Shared.Pulling.Components
|
||||
public bool PrevFixedRotation;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PullableComponentState : ComponentState
|
||||
{
|
||||
public readonly NetEntity? Puller;
|
||||
|
||||
public PullableComponentState(NetEntity? puller)
|
||||
{
|
||||
Puller = puller;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised when a request is made to stop pulling an entity.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
namespace Content.Shared.Pulling.Components
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Pulling.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[Access(typeof(SharedPullingStateManagementSystem))]
|
||||
public sealed partial class SharedPullerComponent : Component
|
||||
{
|
||||
@@ -9,7 +11,7 @@
|
||||
|
||||
public float SprintSpeedModifier => Pulling == default ? 1.0f : 0.95f;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField, AutoNetworkedField]
|
||||
public EntityUid? Pulling { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
@@ -26,43 +25,6 @@ namespace Content.Shared.Pulling
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedPullableComponent, ComponentShutdown>(OnShutdown);
|
||||
SubscribeLocalEvent<SharedPullableComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<SharedPullableComponent, ComponentHandleState>(OnHandleState);
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, SharedPullableComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new PullableComponentState(GetNetEntity(component.Puller));
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, SharedPullableComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not PullableComponentState state)
|
||||
return;
|
||||
|
||||
var puller = EnsureEntity<SharedPullableComponent>(state.Puller, uid);
|
||||
|
||||
if (!puller.HasValue)
|
||||
{
|
||||
ForceDisconnectPullable(component);
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.Puller == puller)
|
||||
{
|
||||
// don't disconnect and reconnect a puller for no reason
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryComp<SharedPullerComponent>(puller, out var comp))
|
||||
{
|
||||
Log.Error($"Pullable state for entity {ToPrettyString(uid)} had invalid puller entity {ToPrettyString(puller.Value)}");
|
||||
// ensure it disconnects from any different puller, still
|
||||
ForceDisconnectPullable(component);
|
||||
return;
|
||||
}
|
||||
|
||||
ForceRelationship(comp, component);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, SharedPullableComponent component, ComponentShutdown args)
|
||||
@@ -111,6 +73,9 @@ namespace Content.Shared.Pulling
|
||||
|
||||
public void ForceRelationship(SharedPullerComponent? puller, SharedPullableComponent? pullable)
|
||||
{
|
||||
if (_timing.ApplyingState)
|
||||
return;
|
||||
;
|
||||
if (pullable != null && puller != null && (puller.Pulling == pullable.Owner))
|
||||
{
|
||||
// Already done
|
||||
@@ -187,6 +152,9 @@ namespace Content.Shared.Pulling
|
||||
|
||||
public void ForceSetMovingTo(SharedPullableComponent pullable, EntityCoordinates? movingTo)
|
||||
{
|
||||
if (_timing.ApplyingState)
|
||||
return;
|
||||
|
||||
if (pullable.MovingTo == movingTo)
|
||||
{
|
||||
return;
|
||||
@@ -200,6 +168,7 @@ namespace Content.Shared.Pulling
|
||||
}
|
||||
|
||||
pullable.MovingTo = movingTo;
|
||||
Dirty(pullable);
|
||||
|
||||
if (movingTo == null)
|
||||
{
|
||||
|
||||
@@ -12,6 +12,8 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Pulling
|
||||
{
|
||||
@@ -23,6 +25,7 @@ namespace Content.Shared.Pulling
|
||||
[Dependency] private readonly SharedInteractionSystem _interaction = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
|
||||
public bool CanPull(EntityUid puller, EntityUid pulled)
|
||||
{
|
||||
@@ -90,6 +93,9 @@ namespace Content.Shared.Pulling
|
||||
|
||||
public bool TryStopPull(SharedPullableComponent pullable, EntityUid? user = null)
|
||||
{
|
||||
if (_timing.ApplyingState)
|
||||
return false;
|
||||
|
||||
if (!pullable.BeingPulled)
|
||||
{
|
||||
return false;
|
||||
@@ -127,6 +133,9 @@ namespace Content.Shared.Pulling
|
||||
// The main "start pulling" function.
|
||||
public bool TryStartPull(SharedPullerComponent puller, SharedPullableComponent pullable)
|
||||
{
|
||||
if (_timing.ApplyingState)
|
||||
return false;
|
||||
|
||||
if (puller.Pulling == pullable.Owner)
|
||||
return true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user