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 * Port2b68449328to this branch * Changes as per PR reviews * Porte801ffac45(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:
@@ -1,6 +1,8 @@
|
||||
using Content.Shared.Alert;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Pulling;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Alert.Click
|
||||
@@ -14,7 +16,11 @@ namespace Content.Server.Alert.Click
|
||||
{
|
||||
public void AlertClicked(ClickAlertEventArgs args)
|
||||
{
|
||||
args.Player.GetComponentOrNull<SharedPullableComponent>()?.TryStopPull(args.Player);
|
||||
var ps = EntitySystem.Get<SharedPullingSystem>();
|
||||
if (args.Player.TryGetComponent<SharedPullableComponent>(out var playerPullable))
|
||||
{
|
||||
ps.TryStopPull(playerPullable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,13 @@ namespace Content.Server.Alert.Click
|
||||
{
|
||||
public void AlertClicked(ClickAlertEventArgs args)
|
||||
{
|
||||
EntitySystem
|
||||
.Get<SharedPullingSystem>()
|
||||
.GetPulled(args.Player)?
|
||||
.GetComponentOrNull<SharedPullableComponent>()?
|
||||
.TryStopPull();
|
||||
var ps = EntitySystem.Get<SharedPullingSystem>();
|
||||
var playerTargetPullable = ps.GetPulled(args.Player)?
|
||||
.GetComponentOrNull<SharedPullableComponent>();
|
||||
if (playerTargetPullable != null)
|
||||
{
|
||||
ps.TryStopPull(playerTargetPullable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ namespace Content.Server.Buckle.Components
|
||||
{
|
||||
if (ownerPullable.Puller != null)
|
||||
{
|
||||
ownerPullable.TryStopPull();
|
||||
EntitySystem.Get<PullingSystem>().TryStopPull(ownerPullable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ namespace Content.Server.Buckle.Components
|
||||
if (toPullable.Puller == Owner)
|
||||
{
|
||||
// can't pull it and buckle to it at the same time
|
||||
toPullable.TryStopPull();
|
||||
EntitySystem.Get<PullingSystem>().TryStopPull(toPullable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Content.Server.Construction.Components
|
||||
{
|
||||
if (pullableComponent.Puller != null)
|
||||
{
|
||||
pullableComponent.TryStopPull();
|
||||
EntitySystem.Get<PullingSystem>().TryStopPull(pullableComponent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace Content.Server.Hands.Components
|
||||
|| puller.Pulling == null || !puller.Pulling.TryGetComponent(out PullableComponent? pullable))
|
||||
return false;
|
||||
|
||||
return pullable.TryStopPull();
|
||||
return _entitySystemManager.GetEntitySystem<PullingSystem>().TryStopPull(pullable);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -47,6 +47,7 @@ namespace Content.Server.Interaction
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
|
||||
[Dependency] private readonly PullingSystem _pullSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -313,7 +314,7 @@ namespace Content.Server.Interaction
|
||||
if (!pulledObject.TryGetComponent(out PullableComponent? pull))
|
||||
return false;
|
||||
|
||||
return pull.TogglePull(userEntity);
|
||||
return _pullSystem.TogglePull(userEntity, pull);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -51,6 +51,10 @@ namespace Content.Server.Physics.Controllers
|
||||
|
||||
foreach (var pullable in _pullableSystem.Moving)
|
||||
{
|
||||
// There's a 1-frame delay between stopping moving something and it leaving the Moving set.
|
||||
// This can include if leaving the Moving set due to not being pulled anymore,
|
||||
// or due to being deleted.
|
||||
|
||||
if (pullable.Deleted)
|
||||
{
|
||||
continue;
|
||||
@@ -61,12 +65,17 @@ namespace Content.Server.Physics.Controllers
|
||||
continue;
|
||||
}
|
||||
|
||||
DebugTools.AssertNotNull(pullable.Puller);
|
||||
if (pullable.Puller == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Now that's over with...
|
||||
|
||||
var pullerPosition = pullable.Puller!.Transform.MapPosition;
|
||||
if (pullable.MovingTo.Value.MapId != pullerPosition.MapId)
|
||||
{
|
||||
pullable.MovingTo = null;
|
||||
_pullableSystem.StopMoveTo(pullable);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -74,22 +83,23 @@ namespace Content.Server.Physics.Controllers
|
||||
physics.BodyType == BodyType.Static ||
|
||||
pullable.MovingTo.Value.MapId != pullable.Owner.Transform.MapID)
|
||||
{
|
||||
pullable.MovingTo = null;
|
||||
_pullableSystem.StopMoveTo(pullable);
|
||||
continue;
|
||||
}
|
||||
|
||||
var movingPosition = pullable.MovingTo.Value.Position;
|
||||
var ownerPosition = pullable.Owner.Transform.MapPosition.Position;
|
||||
|
||||
if (movingPosition.EqualsApprox(ownerPosition, MaximumSettleDistance) && (physics.LinearVelocity.Length < MaximumSettleVelocity))
|
||||
var diff = movingPosition - ownerPosition;
|
||||
var diffLength = diff.Length;
|
||||
|
||||
if ((diffLength < MaximumSettleDistance) && (physics.LinearVelocity.Length < MaximumSettleVelocity))
|
||||
{
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
pullable.MovingTo = null;
|
||||
_pullableSystem.StopMoveTo(pullable);
|
||||
continue;
|
||||
}
|
||||
|
||||
var diff = movingPosition - ownerPosition;
|
||||
var diffLength = diff.Length;
|
||||
var impulseModifierLerp = Math.Min(1.0f, Math.Max(0.0f, (physics.Mass - AccelModifierLowMass) / (AccelModifierHighMass - AccelModifierLowMass)));
|
||||
var impulseModifier = MathHelper.Lerp(AccelModifierLow, AccelModifierHigh, impulseModifierLerp);
|
||||
var multiplier = diffLength < 1 ? impulseModifier * diffLength : impulseModifier;
|
||||
@@ -102,6 +112,7 @@ namespace Content.Server.Physics.Controllers
|
||||
var scaling = (SettleShutdownDistance - diffLength) / SettleShutdownDistance;
|
||||
accel -= physics.LinearVelocity * SettleShutdownMultiplier * scaling;
|
||||
}
|
||||
physics.WakeBody();
|
||||
physics.ApplyLinearImpulse(accel * physics.Mass * frameTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Pulling;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -50,11 +51,11 @@ namespace Content.Server.Pulling
|
||||
// Why no reason? Because they're supposed to be performed in TryStartPull.
|
||||
if (component.Puller == user)
|
||||
{
|
||||
component.TryStopPull();
|
||||
EntitySystem.Get<SharedPullingSystem>().TryStopPull(component);
|
||||
}
|
||||
else
|
||||
{
|
||||
component.TryStartPull(user);
|
||||
EntitySystem.Get<SharedPullingSystem>().TryStartPull(component.Owner, user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Content.Server.Pulling
|
||||
return;
|
||||
}
|
||||
|
||||
pullable.TryStopPull();
|
||||
TryStopPull(pullable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user