Pulling fasto (#17696)

* faster pulling + pulling gravity tweaks

* merciful
This commit is contained in:
Nemanja
2023-06-28 16:03:16 -04:00
committed by GitHub
parent afa886d520
commit ba753d0f17
10 changed files with 71 additions and 87 deletions

View File

@@ -1,4 +1,5 @@
using Content.Shared.Pulling;
using Content.Shared.Gravity;
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
using Content.Shared.Rotatable;
using Robust.Shared.Physics;
@@ -36,6 +37,8 @@ namespace Content.Server.Physics.Controllers
private const float MinimumMovementDistance = 0.005f;
[Dependency] private readonly SharedPullingSystem _pullableSystem = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
// TODO: Move this stuff to pullingsystem
/// <summary>
@@ -63,19 +66,19 @@ namespace Content.Server.Physics.Controllers
private void OnPullerMove(EntityUid uid, SharedPullerComponent component, ref MoveEvent args)
{
if (component.Pulling == null ||
!TryComp<SharedPullableComponent>(component.Pulling.Value, out var pullable)) return;
if (component.Pulling is not { } pullable || !TryComp<SharedPullableComponent>(pullable, out var pullableComponent))
return;
UpdatePulledRotation(uid, pullable.Owner);
UpdatePulledRotation(uid, pullable);
if (args.NewPosition.EntityId == args.OldPosition.EntityId &&
(args.NewPosition.Position - args.OldPosition.Position).LengthSquared < MinimumMovementDistance * MinimumMovementDistance)
return;
if (TryComp<PhysicsComponent>(pullable.Owner, out var physics))
PhysicsSystem.WakeBody(pullable.Owner, body: physics);
if (TryComp<PhysicsComponent>(pullable, out var physics))
PhysicsSystem.WakeBody(pullable, body: physics);
_pullableSystem.StopMoveTo(pullable);
_pullableSystem.StopMoveTo(pullableComponent);
}
private void UpdatePulledRotation(EntityUid puller, EntityUid pulled)
@@ -101,7 +104,7 @@ namespace Content.Server.Physics.Controllers
var newAngle = Angle.FromWorldVec(dir);
var diff = newAngle - oldAngle;
if (Math.Abs(diff.Degrees) > (ThresholdRotAngle / 2f))
if (Math.Abs(diff.Degrees) > ThresholdRotAngle / 2f)
{
// Ok, so this bit is difficult because ideally it would look like it's snapping to sane angles.
// Otherwise PIANO DOOR STUCK! happens.
@@ -126,47 +129,45 @@ namespace Content.Server.Physics.Controllers
// or due to being deleted.
if (pullable.Deleted)
{
continue;
}
if (pullable.MovingTo == null)
{
continue;
}
if (pullable.Puller is not {Valid: true} puller)
{
continue;
}
var pullableEnt = pullable.Owner;
var pullableXform = Transform(pullableEnt);
var pullerXform = Transform(puller);
// Now that's over with...
var pullerPosition = EntityManager.GetComponent<TransformComponent>(puller).MapPosition;
var movingTo = pullable.MovingTo.Value.ToMap(EntityManager);
var pullerPosition = pullerXform.MapPosition;
var movingTo = pullable.MovingTo.Value.ToMap(EntityManager, _transform);
if (movingTo.MapId != pullerPosition.MapId)
{
_pullableSystem.StopMoveTo(pullable);
continue;
}
if (!EntityManager.TryGetComponent<PhysicsComponent?>(pullable.Owner, out var physics) ||
if (!TryComp<PhysicsComponent?>(pullableEnt, out var physics) ||
physics.BodyType == BodyType.Static ||
movingTo.MapId != EntityManager.GetComponent<TransformComponent>(pullable.Owner).MapID)
movingTo.MapId != pullableXform.MapID)
{
_pullableSystem.StopMoveTo(pullable);
continue;
}
var movingPosition = movingTo.Position;
var ownerPosition = EntityManager.GetComponent<TransformComponent>(pullable.Owner).MapPosition.Position;
var ownerPosition = pullableXform.MapPosition.Position;
var diff = movingPosition - ownerPosition;
var diffLength = diff.Length;
if (diffLength < MaximumSettleDistance && (physics.LinearVelocity.Length < MaximumSettleVelocity))
if (diffLength < MaximumSettleDistance && physics.LinearVelocity.Length < MaximumSettleVelocity)
{
PhysicsSystem.SetLinearVelocity(pullable.Owner, Vector2.Zero, body: physics);
PhysicsSystem.SetLinearVelocity(pullableEnt, Vector2.Zero, body: physics);
_pullableSystem.StopMoveTo(pullable);
continue;
}
@@ -177,17 +178,25 @@ namespace Content.Server.Physics.Controllers
// Note the implication that the real rules of physics don't apply to pulling control.
var accel = diff.Normalized * multiplier;
// Now for the part where velocity gets shutdown...
if ((diffLength < SettleShutdownDistance) && (physics.LinearVelocity.Length >= SettleMinimumShutdownVelocity))
if (diffLength < SettleShutdownDistance && physics.LinearVelocity.Length >= SettleMinimumShutdownVelocity)
{
// Shutdown velocity increases as we get closer to centre
var scaling = (SettleShutdownDistance - diffLength) / SettleShutdownDistance;
accel -= physics.LinearVelocity * SettleShutdownMultiplier * scaling;
}
PhysicsSystem.WakeBody(pullable.Owner, body: physics);
PhysicsSystem.WakeBody(pullableEnt, body: physics);
var impulse = accel * physics.Mass * frameTime;
PhysicsSystem.ApplyLinearImpulse(pullable.Owner, impulse, body: physics);
PhysicsSystem.ApplyLinearImpulse(pullableEnt, impulse, body: physics);
// if the puller is weightless, then we apply the inverse impulse.
// doing it under gravity produces an unsatisfying wiggling when pulling.
if (_gravity.IsWeightless(puller) && pullerXform.GridUid == null)
{
PhysicsSystem.WakeBody(puller);
PhysicsSystem.ApplyLinearImpulse(puller, -impulse);
}
}
}
}

View File

@@ -50,7 +50,7 @@ namespace Content.Shared.Maps
/// </summary>
[DataField("barestepSounds")] public SoundSpecifier? BarestepSounds { get; } = new SoundCollectionSpecifier("BarestepHard");
[DataField("friction")] public float Friction { get; set; } = 0.3f;
[DataField("friction")] public float Friction { get; set; } = 0.2f;
[DataField("variants")] public byte Variants { get; set; } = 1;

View File

@@ -5,9 +5,9 @@
public sealed class SharedPullerComponent : Component
{
// Before changing how this is updated, please see SharedPullerSystem.RefreshMovementSpeed
public float WalkSpeedModifier => Pulling == default ? 1.0f : 0.9f;
public float WalkSpeedModifier => Pulling == default ? 1.0f : 0.95f;
public float SprintSpeedModifier => Pulling == default ? 1.0f : 0.9f;
public float SprintSpeedModifier => Pulling == default ? 1.0f : 0.95f;
[ViewVariables]
public EntityUid? Pulling { get; set; }

View File

@@ -84,7 +84,7 @@ namespace Content.Shared.Pulling.Systems
private void RefreshMovementSpeed(SharedPullerComponent component)
{
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers((component).Owner);
_movementSpeedModifierSystem.RefreshMovementSpeedModifiers(component.Owner);
}
}
}

View File

@@ -193,7 +193,7 @@ namespace Content.Shared.Pulling
// Don't allow setting a MovingTo if there's no puller.
// The other half of this guarantee (shutting down a MovingTo if the puller goes away) is enforced in ForceRelationship.
if ((pullable.Puller == null) && (movingTo != null))
if (pullable.Puller == null && movingTo != null)
{
return;
}

View File

@@ -1,9 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Alert;
using Content.Shared.GameTicking;
using Content.Shared.Gravity;
using Content.Shared.Input;
using Content.Shared.Movement.Components;
using Content.Shared.Physics.Pull;
using Content.Shared.Pulling.Components;
using Content.Shared.Verbs;
@@ -22,7 +20,6 @@ namespace Content.Shared.Pulling
public abstract partial class SharedPullingSystem : EntitySystem
{
[Dependency] private readonly SharedPullingStateManagementSystem _pullSm = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
[Dependency] private readonly SharedJointSystem _joints = default!;
@@ -102,18 +99,22 @@ namespace Content.Shared.Pulling
//TODO VERB ICONS add pulling icon
if (component.Puller == args.User)
{
Verb verb = new();
verb.Text = Loc.GetString("pulling-verb-get-data-text-stop-pulling");
verb.Act = () => TryStopPull(component, args.User);
verb.DoContactInteraction = false; // pulling handle its own contact interaction.
Verb verb = new()
{
Text = Loc.GetString("pulling-verb-get-data-text-stop-pulling"),
Act = () => TryStopPull(component, args.User),
DoContactInteraction = false // pulling handle its own contact interaction.
};
args.Verbs.Add(verb);
}
else if (CanPull(args.User, args.Target))
{
Verb verb = new();
verb.Text = Loc.GetString("pulling-verb-get-data-text");
verb.Act = () => TryStartPull(args.User, args.Target);
verb.DoContactInteraction = false; // pulling handle its own contact interaction.
Verb verb = new()
{
Text = Loc.GetString("pulling-verb-get-data-text"),
Act = () => TryStartPull(args.User, args.Target),
DoContactInteraction = false // pulling handle its own contact interaction.
};
args.Verbs.Add(verb);
}
}
@@ -124,7 +125,7 @@ namespace Content.Shared.Pulling
if (args.Pulled.Owner != uid)
return;
_alertsSystem.ShowAlert(component.Owner, AlertType.Pulled);
_alertsSystem.ShowAlert(uid, AlertType.Pulled);
}
private void PullableHandlePullStopped(EntityUid uid, SharedPullableComponent component, PullStoppedMessage args)
@@ -132,7 +133,7 @@ namespace Content.Shared.Pulling
if (args.Pulled.Owner != uid)
return;
_alertsSystem.ClearAlert(component.Owner, AlertType.Pulled);
_alertsSystem.ClearAlert(uid, AlertType.Pulled);
}
public bool IsPulled(EntityUid uid, SharedPullableComponent? component = null)
@@ -178,19 +179,17 @@ namespace Content.Shared.Pulling
// TODO: When Joint networking is less shitcodey fix this to use a dedicated joints message.
private void HandleContainerInsert(EntInsertedIntoContainerMessage message)
{
if (EntityManager.TryGetComponent(message.Entity, out SharedPullableComponent? pullable))
if (TryComp(message.Entity, out SharedPullableComponent? pullable))
{
TryStopPull(pullable);
}
if (EntityManager.TryGetComponent(message.Entity, out SharedPullerComponent? puller))
if (TryComp(message.Entity, out SharedPullerComponent? puller))
{
if (puller.Pulling == null) return;
if (!EntityManager.TryGetComponent(puller.Pulling.Value, out SharedPullableComponent? pulling))
{
if (!TryComp(puller.Pulling.Value, out SharedPullableComponent? pulling))
return;
}
TryStopPull(pulling);
}
@@ -203,17 +202,12 @@ namespace Content.Shared.Pulling
return false;
if (!TryGetPulled(player, out var pulled))
{
return false;
}
if (!EntityManager.TryGetComponent(pulled.Value, out SharedPullableComponent? pullable))
{
if (!TryComp(pulled.Value, out SharedPullableComponent? pullable))
return false;
}
if (_containerSystem.IsEntityInContainer(player) ||
_gravity.IsWeightless(player))
if (_containerSystem.IsEntityInContainer(player))
return false;
TryMoveTo(pullable, coords);

View File

@@ -41,7 +41,7 @@
shape:
!type:PhysShapeAabb
bounds: "-0.25,-0.48,0.25,0.48"
density: 145
density: 75
mask:
- MachineMask
layer:

View File

@@ -29,7 +29,7 @@
shape:
!type:PhysShapeAabb
bounds: "-0.4,-0.4,0.4,0.29"
density: 190
density: 50
mask:
- SmallMobMask #this is so they can go under plastic flaps
layer:

View File

@@ -79,7 +79,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemSteel
heatCapacity: 10000
@@ -94,7 +93,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemSteel
heatCapacity: 10000
@@ -109,7 +107,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemSteel
heatCapacity: 10000
@@ -124,7 +121,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemSteel
heatCapacity: 10000
@@ -169,7 +165,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -184,7 +179,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -199,7 +193,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -214,7 +207,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -229,7 +221,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -244,7 +235,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -259,7 +249,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -274,7 +263,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -289,7 +277,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -304,7 +291,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemWhite
heatCapacity: 10000
@@ -375,7 +361,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemDark
heatCapacity: 10000
@@ -390,7 +375,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemDark
heatCapacity: 10000
@@ -405,7 +389,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemDark
heatCapacity: 10000
@@ -420,7 +403,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemDark
heatCapacity: 10000
@@ -435,7 +417,6 @@
canCrowbar: true
footstepSounds:
collection: FootstepTile
friction: 0.25
itemDrop: FloorTileItemDark
heatCapacity: 10000
@@ -672,7 +653,7 @@
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
friction: 0.40
friction: 0.25
itemDrop: FloorTileItemArcadeBlue
heatCapacity: 10000
@@ -687,7 +668,7 @@
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
friction: 0.40
friction: 0.25
itemDrop: FloorTileItemArcadeBlue2
heatCapacity: 10000
@@ -702,7 +683,7 @@
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
friction: 0.40
friction: 0.25
itemDrop: FloorTileItemArcadeRed
heatCapacity: 10000
@@ -717,7 +698,7 @@
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
friction: 0.40
friction: 0.25
itemDrop: FloorTileItemEighties
heatCapacity: 10000
@@ -732,7 +713,7 @@
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
friction: 0.40
friction: 0.25
itemDrop: FloorTileItemCarpetClown
heatCapacity: 10000
@@ -747,7 +728,7 @@
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
friction: 0.40
friction: 0.25
itemDrop: FloorTileItemCarpetOffice
heatCapacity: 10000
@@ -762,7 +743,7 @@
canCrowbar: true
footstepSounds:
collection: FootstepFloor
friction: 0.40
friction: 0.25
itemDrop: FloorTileItemBoxing
heatCapacity: 10000
@@ -777,7 +758,7 @@
canCrowbar: true
footstepSounds:
collection: FootstepFloor
friction: 0.40
friction: 0.25
itemDrop: FloorTileItemGym
heatCapacity: 10000
@@ -1136,7 +1117,7 @@
footstepSounds:
collection: BarestepCarpet
itemDrop: FloorTileItemFlesh
friction: 0.20 #slippy
friction: 0.05 #slippy
heatCapacity: 10000
- type: tile

View File

@@ -6,7 +6,7 @@
isSubfloor: true
footstepSounds:
collection: FootstepPlating
friction: 0.5
friction: 0.3
heatCapacity: 10000
- type: tile
@@ -19,7 +19,7 @@
weather: true
footstepSounds:
collection: FootstepPlating
friction: 0.5
friction: 0.3
isSpace: true
itemDrop: PartRodMetal1
heatCapacity: 10000