Fix pulling mispredicts (#22941)
* Fix pulling mispredicts * Make behaviour consistent * Good ol terminating entities
This commit is contained in:
@@ -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