Skip to content

Commit a8cb5a9

Browse files
authored
Space Wind Version 3 (#1537)
# Description I promised I would return to this code when I had gotten down the basics of Calculus, and so I have. This PR reworks Space Wind to be even more efficient, while also making it run significantly smoother. Previously, my last optimization to this system involved replacing the need to take the square root of a large float a few thousand times per tick by adding an early exit, cleverly rearranging the math so that it multiplies a few times instead of square rooting, and changing it to use the throwing system. That is no longer necessary, it now operates on the Derivative of said function with respect to time. It's no longer necessary to square anything. This new space wind is significantly smoother than before. <details><summary><h1>Media</h1></summary> <p> Final refinements of V3 courtesy of review by Mu Alpha Theta. https://github.com/user-attachments/assets/a48d43ae-7b79-4d83-81d5-028dd4e8c6c3 </p> </details> # Changelog :cl: - add: Added Space Wind Version 3. Smoother motion, better performance. - add: Monstermos rip tiles has returned as a default CVar. - tweak: Floor Tiles once again are embeddable projectiles.
1 parent cfc6e0e commit a8cb5a9

File tree

8 files changed

+149
-307
lines changed

8 files changed

+149
-307
lines changed

Content.Server/Atmos/EntitySystems/AtmosphereSystem.CVars.cs

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public sealed partial class AtmosphereSystem
1919
public bool MonstermosDepressurization { get; private set; }
2020
public bool MonstermosRipTiles { get; private set; }
2121
public float MonstermosRipTilesMinimumPressure { get; private set; }
22-
public float MonstermosRipTilesPressureOffset { get; private set; }
2322
public bool GridImpulse { get; private set; }
2423
public float SpacingEscapeRatio { get; private set; }
2524
public float SpacingMinGas { get; private set; }
@@ -54,7 +53,6 @@ private void InitializeCVars()
5453
Subs.CVar(_cfg, CCVars.MonstermosDepressurization, value => MonstermosDepressurization = value, true);
5554
Subs.CVar(_cfg, CCVars.MonstermosRipTiles, value => MonstermosRipTiles = value, true);
5655
Subs.CVar(_cfg, CCVars.MonstermosRipTilesMinimumPressure, value => MonstermosRipTilesMinimumPressure = value, true);
57-
Subs.CVar(_cfg, CCVars.MonstermosRipTilesPressureOffset, value => MonstermosRipTilesPressureOffset = value, true);
5856
Subs.CVar(_cfg, CCVars.AtmosGridImpulse, value => GridImpulse = value, true);
5957
Subs.CVar(_cfg, CCVars.AtmosSpacingEscapeRatio, value => SpacingEscapeRatio = value, true);
6058
Subs.CVar(_cfg, CCVars.AtmosSpacingMinGas, value => SpacingMinGas = value, true);

Content.Server/Atmos/EntitySystems/AtmosphereSystem.HighPressureDelta.cs

+132-184
Large diffs are not rendered by default.

Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -685,14 +685,14 @@ private void AdjustEqMovement(TileAtmosphere tile, AtmosDirection direction, flo
685685
adj.MonstermosInfo[idx.ToOppositeDir()] -= amount;
686686
}
687687

688-
private void HandleDecompressionFloorRip(MapGridComponent mapGrid, TileAtmosphere tile, float delta)
688+
private void HandleDecompressionFloorRip(MapGridComponent mapGrid, TileAtmosphere tile, float sum)
689689
{
690-
if (!mapGrid.TryGetTileRef(tile.GridIndices, out var tileRef))
690+
if (!MonstermosRipTiles)
691691
return;
692-
var tileref = tileRef.Tile;
693692

694-
var tileDef = (ContentTileDefinition) _tileDefinitionManager[tileref.TypeId];
695-
if (!tileDef.Reinforced && tileDef.TileRipResistance < delta * MonstermosRipTilesPressureOffset)
693+
var chance = MathHelper.Clamp(0.01f + sum / SpacingMaxWind * 0.3f, 0.003f, 0.3f);
694+
695+
if (sum > 20 && _robustRandom.Prob(chance))
696696
PryTile(mapGrid, tile.GridIndices);
697697
}
698698

Content.Server/Atmos/EntitySystems/AtmosphereSystem.Processing.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ private bool ProcessExcitedGroups(
381381
return true;
382382
}
383383

384-
private bool ProcessHighPressureDelta(Entity<GridAtmosphereComponent> ent)
384+
private bool ProcessHighPressureDelta(Entity<GridAtmosphereComponent> ent, float frameTime)
385385
{
386386
var atmosphere = ent.Comp;
387387
if (!atmosphere.ProcessingPaused)
@@ -397,7 +397,7 @@ private bool ProcessHighPressureDelta(Entity<GridAtmosphereComponent> ent)
397397

398398
while (atmosphere.CurrentRunTiles.TryDequeue(out var tile))
399399
{
400-
HighPressureMovements(ent, tile, bodies, xforms, pressureQuery, metas);
400+
HighPressureMovements(ent, tile, bodies, xforms, pressureQuery, metas, frameTime);
401401
tile.PressureDifference = 0f;
402402
tile.LastPressureDirection = tile.PressureDirection;
403403
tile.PressureDirection = AtmosDirection.Invalid;
@@ -647,7 +647,7 @@ private void UpdateProcessing(float frameTime)
647647
atmosphere.State = AtmosphereProcessingState.HighPressureDelta;
648648
continue;
649649
case AtmosphereProcessingState.HighPressureDelta:
650-
if (!ProcessHighPressureDelta((ent, ent)))
650+
if (!ProcessHighPressureDelta((ent, ent), frameTime))
651651
{
652652
atmosphere.ProcessingPaused = true;
653653
return;

Content.Shared/CCVar/CCVars.cs

+6-10
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,9 @@ public static readonly CVarDef<bool>
13611361
public static readonly CVarDef<bool> SpaceWind =
13621362
CVarDef.Create("atmos.space_wind", true, CVar.SERVERONLY);
13631363

1364+
public static readonly CVarDef<float> SpaceWindStrengthMultiplier =
1365+
CVarDef.Create("atmos.space_wind_strength_multiplier", 1f, CVar.SERVERONLY);
1366+
13641367
/// <summary>
13651368
/// Divisor from maxForce (pressureDifference * 2.25f) to force applied on objects.
13661369
/// </summary>
@@ -1396,7 +1399,7 @@ public static readonly CVarDef<bool>
13961399
/// And maybe do your part to fix that? :)
13971400
/// </remarks>
13981401
public static readonly CVarDef<float> SpaceWindMinimumCalculatedMass =
1399-
CVarDef.Create("atmos.space_wind_minimum_calculated_mass", 10f, CVar.SERVERONLY);
1402+
CVarDef.Create("atmos.space_wind_minimum_calculated_mass", 5f, CVar.SERVERONLY);
14001403

14011404
/// <summary>
14021405
/// Calculated as 1/Mass, where Mass is the physics.Mass of the desired threshold.
@@ -1433,14 +1436,7 @@ public static readonly CVarDef<bool>
14331436
/// This should be set by default to the cube of the game's lowest mass tile as defined in their prototypes, but can be increased for server performance reasons
14341437
/// </summary>
14351438
public static readonly CVarDef<float> MonstermosRipTilesMinimumPressure =
1436-
CVarDef.Create("atmos.monstermos_rip_tiles_min_pressure", 7500f, CVar.SERVERONLY);
1437-
1438-
/// <summary>
1439-
/// Taken after the minimum pressure is checked, the effective pressure is multiplied by this amount.
1440-
/// This allows server hosts to finely tune how likely floor tiles are to be ripped apart by air pressure
1441-
/// </summary>
1442-
public static readonly CVarDef<float> MonstermosRipTilesPressureOffset =
1443-
CVarDef.Create("atmos.monstermos_rip_tiles_pressure_offset", 0.44f, CVar.SERVERONLY);
1439+
CVarDef.Create("atmos.monstermos_rip_tiles_min_pressure", 20f, CVar.SERVERONLY);
14441440

14451441
/// <summary>
14461442
/// Whether explosive depressurization will cause the grid to gain an impulse.
@@ -1476,7 +1472,7 @@ public static readonly CVarDef<bool>
14761472
/// This solves the problem of objects being trapped in an infinite loop of slamming into a wall repeatedly.
14771473
/// </summary>
14781474
public static readonly CVarDef<bool> MonstermosUseExpensiveAirflow =
1479-
CVarDef.Create("atmos.mmos_expensive_airflow", true, CVar.SERVERONLY);
1475+
CVarDef.Create("atmos.mmos_expensive_airflow", false, CVar.SERVERONLY);
14801476

14811477
/// <summary>
14821478
/// Whether atmos superconduction is enabled.

Content.Shared/Damage/Systems/SharedDamageOtherOnHitSystem.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ private void OnItemToggleMapInit(EntityUid uid, ItemToggleDamageOtherOnHitCompon
9090

9191
private void OnDoHit(EntityUid uid, DamageOtherOnHitComponent component, ThrowDoHitEvent args)
9292
{
93-
if (component.HitQuantity >= component.MaxHitQuantity)
93+
if (TerminatingOrDeleted(args.Target)
94+
|| component.HitQuantity >= component.MaxHitQuantity)
9495
return;
9596

9697
var modifiedDamage = _damageable.TryChangeDamage(args.Target, GetDamage(uid, component, args.Component.Thrower),

Resources/Prototypes/Entities/Objects/Misc/tiles.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- type: Item
1010
sprite: Objects/Tiles/tile.rsi
1111
size: Normal
12+
- type: EmbeddableProjectile
1213
- type: DamageOtherOnHit
1314
damage:
1415
types:

0 commit comments

Comments
 (0)