Skip to content

Commit

Permalink
Revert Newtonian Singularity
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Mar 3, 2025
1 parent 990878b commit e7f6ccb
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 127 deletions.
32 changes: 7 additions & 25 deletions Content.Server/Singularity/Components/GravityWellComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,36 @@ namespace Content.Server.Singularity.Components;
/// The server-side version of <see cref="SharedGravityWellComponent"/>.
/// Primarily managed by <see cref="GravityWellSystem"/>.
/// </summary>
[RegisterComponent]
[RegisterComponent, AutoGenerateComponentPause]
public sealed partial class GravityWellComponent : Component
{
/// <summary>
/// The maximum range at which the gravity well can push/pull entities.
/// </summary>
[DataField("maxRange")]
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float MaxRange;

/// <summary>
/// The minimum range at which the gravity well can push/pull entities.
/// This is effectively hardfloored at <see cref="GravityWellSystem.MinGravPulseRange"/>.
/// </summary>
[DataField("minRange")]
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float MinRange = 0f;

/// <summary>
/// The acceleration entities will experience towards the gravity well at a distance of 1m.
/// Negative values accelerate entities away from the gravity well.
/// Actual acceleration scales with the inverse of the distance to the singularity.
/// </summary>
[DataField("baseRadialAcceleration")]
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float BaseRadialAcceleration = 0.0f;

/// <summary>
/// The acceleration entities will experience tangent to the gravity well at a distance of 1m.
/// Positive tangential acceleration is counter-clockwise.
/// Actual acceleration scales with the inverse of the distance to the singularity.
/// </summary>
[DataField("baseTangentialAcceleration")]
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float BaseTangentialAcceleration = 0.0f;

#region Update Timing
Expand All @@ -56,28 +52,14 @@ public sealed partial class GravityWellComponent : Component
/// <summary>
/// The next time at which this gravity well should pulse.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[Access(typeof(GravityWellSystem))]
[DataField, Access(typeof(GravityWellSystem)), AutoPausedField]
public TimeSpan NextPulseTime { get; internal set; } = default!;

/// <summary>
/// The last time this gravity well pulsed.
/// </summary>
[ViewVariables(VVAccess.ReadOnly)]
[Access(typeof(GravityWellSystem))]
public TimeSpan LastPulseTime { get; internal set; } = default!;

/// <summary>
/// Whether to also apply Newton's third law.
/// </summary>
[DataField]
public bool ApplyCounterforce;

/// <summary>
/// If <see cref="ApplyCounterforce"/> is true, how much to pull self to static objects. Does not pull static objects if null.
/// </summary>
[DataField]
public float? StaticAttraction = null;
public TimeSpan LastPulseTime => NextPulseTime - TargetPulsePeriod;

#endregion Update Timing
}
18 changes: 3 additions & 15 deletions Content.Server/Singularity/EntitySystems/EventHorizonSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public sealed class EventHorizonSystem : SharedEventHorizonSystem
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedTransformSystem _xformSystem = default!;
[Dependency] private readonly SharedMapSystem _mapSystem = default!;
[Dependency] private readonly TagSystem _tagSystem = default!;
#endregion Dependencies

private EntityQuery<PhysicsComponent> _physicsQuery;
private const float CosmicSpeedLimit = 20f;

public override void Initialize()
{
Expand Down Expand Up @@ -137,18 +137,6 @@ public void ConsumeEntity(EntityUid hungry, EntityUid morsel, EventHorizonCompon
}

EntityManager.QueueDeleteEntity(morsel);

if (eventHorizon.InheritMomentum && TryComp<PhysicsComponent>(hungry, out var thisPhysics) && TryComp<PhysicsComponent>(morsel, out var otherPhysics))
{
var impulse = (otherPhysics.LinearVelocity - thisPhysics.LinearVelocity)
* otherPhysics.FixturesMass
* thisPhysics.FixturesMass / (thisPhysics.FixturesMass + otherPhysics.FixturesMass); // Accounts for the expected mass change from consuming the object
if (impulse.Length() >= CosmicSpeedLimit) // Stop it from quantum tunneling through walls.
impulse = impulse.Normalized() * CosmicSpeedLimit;

_physics.ApplyLinearImpulse(hungry, impulse, body: thisPhysics);
}

var evSelf = new EntityConsumedByEventHorizonEvent(morsel, hungry, eventHorizon, outerContainer);
var evEaten = new EventHorizonConsumedEntityEvent(morsel, hungry, eventHorizon, outerContainer);
RaiseLocalEvent(hungry, ref evSelf);
Expand Down Expand Up @@ -270,7 +258,7 @@ public void ConsumeTiles(EntityUid hungry, List<(Vector2i, Tile)> tiles, EntityU

var ev = new TilesConsumedByEventHorizonEvent(tiles, gridId, grid, hungry, eventHorizon);
RaiseLocalEvent(hungry, ref ev);
grid.SetTiles(tiles);
_mapSystem.SetTiles(gridId, grid, tiles);
}

/// <summary>
Expand Down Expand Up @@ -323,7 +311,7 @@ public void ConsumeTilesInRange(EntityUid uid, float range, TransformComponent?
foreach (var grid in grids)
{
// TODO: Remover grid.Owner when this iterator returns entityuids as well.
AttemptConsumeTiles(uid, grid.Comp.GetTilesIntersecting(circle), grid, grid, eventHorizon);
AttemptConsumeTiles(uid, _mapSystem.GetTilesIntersecting(grid.Owner, grid.Comp, circle), grid, grid, eventHorizon);
}
}

Expand Down
Loading

0 comments on commit e7f6ccb

Please sign in to comment.