Skip to content

Commit

Permalink
slothie poo
Browse files Browse the repository at this point in the history
  • Loading branch information
EmoGarbage404 committed Jun 29, 2024
1 parent bab95d5 commit ec9169e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Robust.LoaderApi
6 changes: 0 additions & 6 deletions Robust.Shared/Physics/Components/PhysicsComponent.Physics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,6 @@ public sealed partial class PhysicsComponent : Component
Other = AccessPermissions.Read)]
public float LinearDamping = 0.2f;

/// <summary>
/// This is a set amount that the body's linear velocity is reduced by every tick when the body is off-grid.
/// </summary>
[DataField, Access(typeof(SharedPhysicsSystem), Friend = AccessPermissions.ReadWriteExecute, Other = AccessPermissions.Read)]
public float OffGridLinearDamping = 0.05f;

/// <summary>
/// This is a set amount that the body's angular velocity is reduced every tick.
/// Combined with the tile friction.
Expand Down
21 changes: 16 additions & 5 deletions Robust.Shared/Physics/Systems/SharedPhysicsSystem.Island.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ internal record struct IslandData(
private const int VelocityConstraintsPerThread = 16;
private const int PositionConstraintsPerThread = 16;

[ByRefEvent]
public struct GetLinearDampingOverrideEvent
{
public float? LinearDampingOverride;
}

public delegate void LinearDampingOverrideHandler(ref GetLinearDampingOverrideEvent ev);

/// <summary>
/// Invoked to allow content to override linear damping for objects.
/// </summary>
public event LinearDampingOverrideHandler? OnGetLinearDampingOverride;

#region Setup

private void InitializeIsland()
Expand Down Expand Up @@ -717,7 +730,6 @@ private void SolveIsland(
var angles = ArrayPool<float>.Shared.Rent(bodyCount);
var offset = island.Offset;
var xformQuery = GetEntityQuery<TransformComponent>();
var mapGridQuery = GetEntityQuery<MapGridComponent>();

for (var i = 0; i < island.Bodies.Count; i++)
{
Expand Down Expand Up @@ -747,10 +759,9 @@ private void SolveIsland(

angularVelocity += body.InvI * body.Torque * data.FrameTime;

var onGrid = xform.GridUid != null || mapGridQuery.HasComp(xform.MapUid);
var linearDamping = onGrid
? body.LinearDamping
: body.OffGridLinearDamping;
var ev = new GetLinearDampingOverrideEvent();
OnGetLinearDampingOverride?.Invoke(ref ev);
var linearDamping = ev.LinearDampingOverride ?? body.LinearDamping;

linearVelocity *= Math.Clamp(1.0f - data.FrameTime * linearDamping, 0.0f, 1.0f);
angularVelocity *= Math.Clamp(1.0f - data.FrameTime * body.AngularDamping, 0.0f, 1.0f);
Expand Down

0 comments on commit ec9169e

Please sign in to comment.