Pullability partial ECS refactor, monkey-gibbing error fix (#4695)

* Migrate lots of pulling logic out of the components and clean it up

* It's buggy, but move more code out of the pullable component

* Pulling system now throws less errors than it did before the refactor

* Finally finish the big parts of refactoring pullability

* Pulling: Handle disconnect properly if the pull joint has been removed by physics shutdown

* Port 2b68449328 to this branch

* Changes as per PR reviews

* Port e801ffac45 (SharedJointSystem) and fix issues encountered during testing

SharedJointSystem.

Also, MinLength and Stiffness appear to have suddenly gained enough meaning that pulling is broken unless they're set.
This commit is contained in:
20kdc
2021-10-04 16:10:54 +01:00
committed by GitHub
parent dacbfffe7c
commit 2a8486a384
16 changed files with 483 additions and 360 deletions

View File

@@ -16,12 +16,15 @@ using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Physics;
using Robust.Shared.Players;
using Robust.Shared.IoC;
namespace Content.Shared.Pulling
{
[UsedImplicitly]
public abstract class SharedPullingSystem : EntitySystem
public abstract partial class SharedPullingSystem : EntitySystem
{
[Dependency] private readonly SharedPullingStateManagementSystem _pullSm = default!;
/// <summary>
/// A mapping of pullers to the entity that they are pulling.
/// </summary>
@@ -101,12 +104,6 @@ namespace Content.Shared.Pulling
private void OnPullStarted(PullStartedMessage message)
{
if (_pullers.TryGetValue(message.Puller.Owner, out var pulled) &&
pulled.TryGetComponent(out SharedPullableComponent? pulledComponent))
{
pulledComponent.TryStopPull();
}
SetPuller(message.Puller.Owner, message.Pulled.Owner);
}
@@ -128,11 +125,20 @@ namespace Content.Shared.Pulling
private void PullerMoved(ref MoveEvent ev)
{
var puller = ev.Sender;
if (!TryGetPulled(ev.Sender, out var pulled))
{
return;
}
// The pulled object may have already been deleted.
// TODO: Work out why. Monkey + meat spike is a good test for this,
// assuming you're still pulling the monkey when it gets gibbed.
if (pulled.Deleted)
{
return;
}
if (!pulled.TryGetComponent(out IPhysBody? physics))
{
return;
@@ -144,7 +150,7 @@ namespace Content.Shared.Pulling
if (pulled.TryGetComponent(out SharedPullableComponent? pullable))
{
pullable.MovingTo = null;
_pullSm.ForceSetMovingTo(pullable, null);
}
}
@@ -153,7 +159,7 @@ namespace Content.Shared.Pulling
{
if (message.Entity.TryGetComponent(out SharedPullableComponent? pullable))
{
pullable.TryStopPull();
TryStopPull(pullable);
}
if (message.Entity.TryGetComponent(out SharedPullerComponent? puller))
@@ -165,7 +171,7 @@ namespace Content.Shared.Pulling
return;
}
pulling.TryStopPull();
TryStopPull(pulling);
}
}
@@ -188,7 +194,7 @@ namespace Content.Shared.Pulling
return false;
}
pullable.TryMoveTo(coords.ToMap(EntityManager));
TryMoveTo(pullable, coords.ToMap(EntityManager));
return false;
}
@@ -238,12 +244,5 @@ namespace Content.Shared.Pulling
pulled.Transform.WorldRotation = newAngle;
}
}
public bool CanPull(IEntity puller, IEntity pulled)
{
var startPull = new StartPullAttemptEvent(puller, pulled);
RaiseLocalEvent(puller.Uid, startPull);
return !startPull.Cancelled;
}
}
}