Pulling rework (#20906)

* Pulling rework

Fixing up the FOUR systems managing pulling, all the shitcode, and also making it nicer ingame.

* More pulling cleanup

* stats

* More cleanup

* First draft

* More pulling

* weh

* Fix puller

* Pulling working

* Fix merge

* Dunked

* Self-merge time
This commit is contained in:
metalgearsloth
2024-02-03 14:36:09 +11:00
committed by GitHub
parent 79e3a6630d
commit 0d8254b2a2
53 changed files with 764 additions and 1359 deletions

View File

@@ -2,8 +2,8 @@ using System.Numerics;
using Content.Shared.CCVar;
using Content.Shared.Gravity;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Systems;
using Content.Shared.Pulling.Components;
using JetBrains.Annotations;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
@@ -23,6 +23,12 @@ namespace Content.Shared.Friction
[Dependency] private readonly SharedMoverController _mover = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
private EntityQuery<TileFrictionModifierComponent> _frictionQuery;
private EntityQuery<TransformComponent> _xformQuery;
private EntityQuery<PullerComponent> _pullerQuery;
private EntityQuery<PullableComponent> _pullableQuery;
private EntityQuery<MapGridComponent> _gridQuery;
private float _stopSpeed;
private float _frictionModifier;
public const float DefaultFriction = 0.3f;
@@ -31,6 +37,12 @@ namespace Content.Shared.Friction
{
base.Initialize();
_frictionQuery = GetEntityQuery<TileFrictionModifierComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
_pullerQuery = GetEntityQuery<PullerComponent>();
_pullableQuery = GetEntityQuery<PullableComponent>();
_gridQuery = GetEntityQuery<MapGridComponent>();
_configManager.OnValueChanged(CCVars.TileFrictionModifier, SetFrictionModifier, true);
_configManager.OnValueChanged(CCVars.StopSpeed, SetStopSpeed, true);
}
@@ -51,12 +63,6 @@ namespace Content.Shared.Friction
{
base.UpdateBeforeMapSolve(prediction, mapComponent, frameTime);
var frictionQuery = GetEntityQuery<TileFrictionModifierComponent>();
var xformQuery = GetEntityQuery<TransformComponent>();
var pullerQuery = GetEntityQuery<SharedPullerComponent>();
var pullableQuery = GetEntityQuery<SharedPullableComponent>();
var gridQuery = GetEntityQuery<MapGridComponent>();
foreach (var body in mapComponent.AwakeBodies)
{
var uid = body.Owner;
@@ -72,16 +78,16 @@ namespace Content.Shared.Friction
if (body.LinearVelocity.Equals(Vector2.Zero) && body.AngularVelocity.Equals(0f))
continue;
if (!xformQuery.TryGetComponent(uid, out var xform))
if (!_xformQuery.TryGetComponent(uid, out var xform))
{
Log.Error($"Unable to get transform for {ToPrettyString(uid)} in tilefrictioncontroller");
continue;
}
var surfaceFriction = GetTileFriction(uid, body, xform, gridQuery, frictionQuery);
var surfaceFriction = GetTileFriction(uid, body, xform);
var bodyModifier = 1f;
if (frictionQuery.TryGetComponent(uid, out var frictionComp))
if (_frictionQuery.TryGetComponent(uid, out var frictionComp))
{
bodyModifier = frictionComp.Modifier;
}
@@ -94,8 +100,8 @@ namespace Content.Shared.Friction
// If we're sandwiched between 2 pullers reduce friction
// Might be better to make this dynamic and check how many are in the pull chain?
// Either way should be much faster for now.
if (pullerQuery.TryGetComponent(uid, out var puller) && puller.Pulling != null &&
pullableQuery.TryGetComponent(uid, out var pullable) && pullable.BeingPulled)
if (_pullerQuery.TryGetComponent(uid, out var puller) && puller.Pulling != null &&
_pullableQuery.TryGetComponent(uid, out var pullable) && pullable.BeingPulled)
{
bodyModifier *= 0.2f;
}
@@ -175,9 +181,7 @@ namespace Content.Shared.Friction
private float GetTileFriction(
EntityUid uid,
PhysicsComponent body,
TransformComponent xform,
EntityQuery<MapGridComponent> gridQuery,
EntityQuery<TileFrictionModifierComponent> frictionQuery)
TransformComponent xform)
{
// TODO: Make IsWeightless event-based; we already have grid traversals tracked so just raise events
if (_gravity.IsWeightless(uid, body, xform))
@@ -187,9 +191,9 @@ namespace Content.Shared.Friction
return 0.0f;
// If not on a grid then return the map's friction.
if (!gridQuery.TryGetComponent(xform.GridUid, out var grid))
if (!_gridQuery.TryGetComponent(xform.GridUid, out var grid))
{
return frictionQuery.TryGetComponent(xform.MapUid, out var friction)
return _frictionQuery.TryGetComponent(xform.MapUid, out var friction)
? friction.Modifier
: DefaultFriction;
}
@@ -209,7 +213,7 @@ namespace Content.Shared.Friction
while (anc.MoveNext(out var tileEnt))
{
if (frictionQuery.TryGetComponent(tileEnt, out var friction))
if (_frictionQuery.TryGetComponent(tileEnt, out var friction))
return friction.Modifier;
}