Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Revert "Эксперименты (#296)"
Browse files Browse the repository at this point in the history
This reverts commit b2bcdea.
  • Loading branch information
Vonsant authored Jun 19, 2024
1 parent 04315aa commit a8f1bb3
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 264 deletions.
10 changes: 0 additions & 10 deletions Content.Server/Atmos/EntitySystems/AtmosphereSystem.CVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,9 @@ public sealed partial class AtmosphereSystem
public float SpaceWindPressureForceDivisorPush { get; private set; }
public float SpaceWindMaxVelocity { get; private set; }
public float SpaceWindMaxPushForce { get; private set; }
public float SpaceWindMinimumCalculatedMass { get; private set; }
public float SpaceWindMaximumCalculatedInverseMass { get; private set; }
public bool MonstermosUseExpensiveAirflow { get; private set; }
public bool MonstermosEqualization { get; private set; }
public bool MonstermosDepressurization { get; private set; }
public bool MonstermosRipTiles { get; private set; }
public float MonstermosRipTilesMinimumPressure { get; private set; }
public float MonstermosRipTilesPressureOffset { get; private set; }
public bool GridImpulse { get; private set; }
public float SpacingEscapeRatio { get; private set; }
public float SpacingMinGas { get; private set; }
Expand All @@ -46,14 +41,9 @@ private void InitializeCVars()
Subs.CVar(_cfg, CCVars.SpaceWindPressureForceDivisorPush, value => SpaceWindPressureForceDivisorPush = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMaxVelocity, value => SpaceWindMaxVelocity = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMaxPushForce, value => SpaceWindMaxPushForce = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMinimumCalculatedMass, value => SpaceWindMinimumCalculatedMass = value, true);
Subs.CVar(_cfg, CCVars.SpaceWindMaximumCalculatedInverseMass, value => SpaceWindMaximumCalculatedInverseMass = value, true);
Subs.CVar(_cfg, CCVars.MonstermosUseExpensiveAirflow, value => MonstermosUseExpensiveAirflow = value, true);
Subs.CVar(_cfg, CCVars.MonstermosEqualization, value => MonstermosEqualization = value, true);
Subs.CVar(_cfg, CCVars.MonstermosDepressurization, value => MonstermosDepressurization = value, true);
Subs.CVar(_cfg, CCVars.MonstermosRipTiles, value => MonstermosRipTiles = value, true);
Subs.CVar(_cfg, CCVars.MonstermosRipTilesMinimumPressure, value => MonstermosRipTilesMinimumPressure = value, true);
Subs.CVar(_cfg, CCVars.MonstermosRipTilesPressureOffset, value => MonstermosRipTilesPressureOffset = value, true);
Subs.CVar(_cfg, CCVars.AtmosGridImpulse, value => GridImpulse = value, true);
Subs.CVar(_cfg, CCVars.AtmosSpacingEscapeRatio, value => SpacingEscapeRatio = value, true);
Subs.CVar(_cfg, CCVars.AtmosSpacingMinGas, value => SpacingMinGas = value, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ private void UpdateHighPressure(float frameTime)
comp.Accumulator = 0f;
toRemove.Add(ent);

if (TryComp<PhysicsComponent>(uid, out var body))
if (HasComp<MobStateComponent>(uid) &&
TryComp<PhysicsComponent>(uid, out var body))
{
_physics.SetBodyStatus(uid, body, BodyStatus.OnGround);
}
Expand All @@ -69,7 +70,7 @@ private void UpdateHighPressure(float frameTime)
}
}

private void AddMovedByPressure(EntityUid uid, MovedByPressureComponent component, PhysicsComponent body)
private void AddMobMovedByPressure(EntityUid uid, MovedByPressureComponent component, PhysicsComponent body)
{
if (!TryComp<FixturesComponent>(uid, out var fixtures))
return;
Expand All @@ -90,9 +91,6 @@ private void AddMovedByPressure(EntityUid uid, MovedByPressureComponent componen

private void HighPressureMovements(Entity<GridAtmosphereComponent> gridAtmosphere, TileAtmosphere tile, EntityQuery<PhysicsComponent> bodies, EntityQuery<TransformComponent> xforms, EntityQuery<MovedByPressureComponent> pressureQuery, EntityQuery<MetaDataComponent> metas)
{
//!MAGIC EXIT CONDITION THAT MAKES ALMOST 200 LINES RUN 1/100TH AS OFTEN.
if (tile.PressureDifference < SpaceWindMinimumCalculatedMass * SpaceWindMinimumCalculatedMass)
return;
// TODO ATMOS finish this

// Don't play the space wind sound on tiles that are on fire...
Expand Down Expand Up @@ -122,8 +120,7 @@ private void HighPressureMovements(Entity<GridAtmosphereComponent> gridAtmospher
var gridWorldRotation = xforms.GetComponent(gridAtmosphere).WorldRotation;

// If we're using monstermos, smooth out the yeet direction to follow the flow
//WTF:This is bad, don't run this. It just makes the throws worse by somehow rounding them to orthogonal
if (!MonstermosEqualization)
if (MonstermosEqualization)
{
// We step through tiles according to the pressure direction on the current tile.
// The goal is to get a general direction of the airflow in the area.
Expand Down Expand Up @@ -163,7 +160,7 @@ private void HighPressureMovements(Entity<GridAtmosphereComponent> gridAtmospher
(entity, pressureMovements),
gridAtmosphere.Comp.UpdateCounter,
tile.PressureDifference,
tile.PressureDirection,
tile.PressureDirection, 0,
tile.PressureSpecificTarget != null ? _mapSystem.ToCenterCoordinates(tile.GridIndex, tile.PressureSpecificTarget.GridIndices) : EntityCoordinates.Invalid,
gridWorldRotation,
xforms.GetComponent(entity),
Expand All @@ -184,37 +181,12 @@ private void ConsiderPressureDifference(GridAtmosphereComponent gridAtmosphere,
tile.PressureDirection = differenceDirection;
}

//INFO:The EE version of this function drops pressureResistanceProbDelta, since it's not needed. If you are for whatever reason calling this function
//INFO:And it isn't working, you've probably still got the pressureResistanceProbDelta line included.
/// <notes>
/// EXPLANATION:
/// pressureDifference = Force of Air Flow on a given tile
/// physics.Mass = Mass of the object potentially being thrown
/// physics.InvMass = 1 divided by said Mass. More CPU efficient way to do division.
///
/// Objects can only be thrown if the force of air flow is greater than the SQUARE of their mass or {SpaceWindMinimumCalculatedMass}, whichever is heavier
/// This means that the heavier an object is, the exponentially more force is required to move it
/// The force of a throw is equal to the force of air pressure, divided by an object's mass. So not only are heavier objects
/// less likely to be thrown, they are also harder to throw,
/// while lighter objects are yeeted easily, and from great distance.
///
/// For a human sized entity with a standard weight of 80kg and a spacing between a hard vacuum and a room pressurized at 101kpa,
/// The human shall only be moved if he is either very close to the hole, or is standing in a region of high airflow
/// </notes>
/// <param name="ent"></param>
/// <param name="cycle"></param>
/// <param name="pressureDifference"></param>
/// <param name="direction"></param>
/// <param name="throwTarget"></param>
/// <param name="gridWorldRotation"></param>
/// <param name="xform"></param>
/// <param name="physics"></param>

public void ExperiencePressureDifference(
Entity<MovedByPressureComponent> ent,
int cycle,
float pressureDifference,
AtmosDirection direction,
float pressureResistanceProbDelta,
EntityCoordinates throwTarget,
Angle gridWorldRotation,
TransformComponent? xform = null,
Expand All @@ -227,28 +199,50 @@ public void ExperiencePressureDifference(
if (!Resolve(uid, ref xform))
return;

// TODO ATMOS stuns?

var maxForce = MathF.Sqrt(pressureDifference) * 2.25f;
var moveProb = 100f;

if (physics.BodyType != BodyType.Static
&& !float.IsPositiveInfinity(component.MoveResist))
if (component.PressureResistance > 0)
moveProb = MathF.Abs((pressureDifference / component.PressureResistance * MovedByPressureComponent.ProbabilityBasePercent) -
MovedByPressureComponent.ProbabilityOffset);

// Can we yeet the thing (due to probability, strength, etc.)
if (moveProb > MovedByPressureComponent.ProbabilityOffset && _robustRandom.Prob(MathF.Min(moveProb / 100f, 1f))
&& !float.IsPositiveInfinity(component.MoveResist)
&& (physics.BodyType != BodyType.Static
&& (maxForce >= (component.MoveResist * MovedByPressureComponent.MoveForcePushRatio)))
|| (physics.BodyType == BodyType.Static && (maxForce >= (component.MoveResist * MovedByPressureComponent.MoveForceForcePushRatio))))
{
var moveForce = pressureDifference * MathF.Max(physics.InvMass, SpaceWindMaximumCalculatedInverseMass);
if (moveForce > physics.Mass)
if (HasComp<MobStateComponent>(uid))
{
AddMobMovedByPressure(uid, component, physics);
}

if (maxForce > MovedByPressureComponent.ThrowForce)
{
var moveForce = maxForce;
moveForce /= (throwTarget != EntityCoordinates.Invalid) ? SpaceWindPressureForceDivisorThrow : SpaceWindPressureForceDivisorPush;
moveForce *= MathHelper.Clamp(moveProb, 0, 100);

// Apply a sanity clamp to prevent being thrown through objects.
var maxSafeForceForObject = SpaceWindMaxVelocity * physics.Mass;
moveForce = MathF.Min(moveForce, maxSafeForceForObject);
AddMovedByPressure(uid, component, physics);

// Grid-rotation adjusted direction
var dirVec = (direction.ToAngle() + gridWorldRotation).ToWorldVec();

// TODO: Consider replacing throw target with proper trigonometry angles.
// TODO: Technically these directions won't be correct but uhh I'm just here for optimisations buddy not to fix my old bugs.
if (throwTarget != EntityCoordinates.Invalid)
{
var pos = throwTarget.ToMap(EntityManager, _transformSystem).Position - xform.WorldPosition + dirVec;
_physics.ApplyLinearImpulse(uid, pos.Normalized() * moveForce, body: physics);
var pos = ((throwTarget.ToMap(EntityManager, _transformSystem).Position - xform.WorldPosition).Normalized() + dirVec).Normalized();
_physics.ApplyLinearImpulse(uid, pos * moveForce, body: physics);
}
else
{
_physics.ApplyLinearImpulse(uid, dirVec.Normalized() * moveForce, body: physics);
moveForce = MathF.Min(moveForce, SpaceWindMaxPushForce);
_physics.ApplyLinearImpulse(uid, dirVec * moveForce, body: physics);
}

component.LastHighPressureMovementAirCycle = cycle;
Expand Down
21 changes: 8 additions & 13 deletions Content.Server/Atmos/EntitySystems/AtmosphereSystem.Monstermos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
using Content.Shared.Atmos;
using Content.Shared.Atmos.Components;
using Content.Shared.Database;
using Content.Shared.Maps;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;

namespace Content.Server.Atmos.EntitySystems
{
public sealed partial class AtmosphereSystem
Expand Down Expand Up @@ -139,7 +137,7 @@ private void EqualizePressureInZone(
var logN = MathF.Log2(tileCount);

// Optimization - try to spread gases using an O(n log n) algorithm that has a chance of not working first to avoid O(n^2)
if (!MonstermosUseExpensiveAirflow && giverTilesLength > logN && takerTilesLength > logN)
if (giverTilesLength > logN && takerTilesLength > logN)
{
// Even if it fails, it will speed up the next part.
Array.Sort(_equalizeTiles, 0, tileCount, _monstermosComparer);
Expand Down Expand Up @@ -552,8 +550,7 @@ private void ExplosivelyDepressurize(
}

InvalidateVisuals(ent, otherTile);
if (MonstermosRipTiles && otherTile.PressureDifference > MonstermosRipTilesMinimumPressure)
HandleDecompressionFloorRip(mapGrid, otherTile, otherTile.PressureDifference);
HandleDecompressionFloorRip(mapGrid, otherTile, otherTile.MonstermosInfo.CurrentTransferAmount);
}

if (GridImpulse && tileCount > 0)
Expand Down Expand Up @@ -685,17 +682,15 @@ private void AdjustEqMovement(TileAtmosphere tile, AtmosDirection direction, flo
adj.MonstermosInfo[idx.ToOppositeDir()] -= amount;
}

private void HandleDecompressionFloorRip(MapGridComponent mapGrid, TileAtmosphere tile, float delta)
private void HandleDecompressionFloorRip(MapGridComponent mapGrid, TileAtmosphere tile, float sum)
{
if (!mapGrid.TryGetTileRef(tile.GridIndices, out var tileRef))
if (!MonstermosRipTiles)
return;
var tileref = tileRef.Tile;

var tileDef = (ContentTileDefinition) _tileDefinitionManager[tileref.TypeId];
if (!tileDef.Reinforced && tileDef.TileRipResistance < delta * MonstermosRipTilesPressureOffset)
{
var chance = MathHelper.Clamp(0.01f + (sum / SpacingMaxWind) * 0.3f, 0.003f, 0.3f);

if (sum > 20 && _robustRandom.Prob(chance))
PryTile(mapGrid, tile.GridIndices);
}
}

private sealed class TileAtmosphereComparer : IComparer<TileAtmosphere?>
Expand Down
7 changes: 2 additions & 5 deletions Content.Server/Temperature/Systems/TemperatureSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Content.Shared.Inventory;
using Content.Shared.Rejuvenate;
using Content.Shared.Temperature;
using Robust.Server.GameObjects;
using Robust.Shared.Physics.Components;

namespace Content.Server.Temperature.Systems;
Expand All @@ -22,7 +21,6 @@ public sealed class TemperatureSystem : EntitySystem
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] private readonly DamageableSystem _damageable = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly TransformSystem _transform = default!;

/// <summary>
/// All the components that will have their damage updated at the end of the tick.
Expand Down Expand Up @@ -163,9 +161,8 @@ public float GetHeatCapacity(EntityUid uid, TemperatureComponent? comp = null, P
{
return Atmospherics.MinimumHeatCapacity;
}
if (physics.Mass < 1)
return comp.SpecificHeat;
else return comp.SpecificHeat * physics.FixturesMass;

return comp.SpecificHeat * physics.FixturesMass;
}

private void OnInit(EntityUid uid, InternalTemperatureComponent comp, MapInitEvent args)
Expand Down
46 changes: 3 additions & 43 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,33 +1026,14 @@ public static readonly CVarDef<bool>
/// Useful to prevent clipping through objects.
/// </summary>
public static readonly CVarDef<float> SpaceWindMaxVelocity =
CVarDef.Create("atmos.space_wind_max_velocity", 15f, CVar.SERVERONLY);
CVarDef.Create("atmos.space_wind_max_velocity", 30f, CVar.SERVERONLY);

/// <summary>
/// The maximum force that may be applied to an object by pushing (i.e. not throwing) atmospheric pressure differences.
/// A "throwing" atmospheric pressure difference ignores this limit, but not the max. velocity limit.
/// </summary>
public static readonly CVarDef<float> SpaceWindMaxPushForce =
CVarDef.Create("atmos.space_wind_max_push_force", 20f, CVar.SERVERONLY);

/// <summary>
/// If an object's mass is below this number, then this number is used in place of mass to determine whether air pressure can throw an object.
/// This has nothing to do with throwing force, only acting as a way of reducing the odds of tiny 5 gram objects from being yeeted by people's breath
/// </summary>
/// <remarks>
/// If you are reading this because you want to change it, consider looking into why almost every item in the game weighs only 5 grams
/// And maybe do your part to fix that? :)
/// </remarks>
public static readonly CVarDef<float> SpaceWindMinimumCalculatedMass =
CVarDef.Create("atmos.space_wind_minimum_calculated_mass", 10f, CVar.SERVERONLY);

/// <summary>
/// Calculated as 1/Mass, where Mass is the physics.Mass of the desired threshold.
/// If an object's inverse mass is lower than this, it is capped at this. Basically, an upper limit to how heavy an object can be
/// before it stops resisting space wind more.
/// </summary>
public static readonly CVarDef<float> SpaceWindMaximumCalculatedInverseMass =
CVarDef.Create("atmos.space_wind_maximum_calculated_inverse_mass", 0.04f, CVar.SERVERONLY);
CVarDef.Create("atmos.space_wind_max_push_force", 25f, CVar.SERVERONLY);

/// <summary>
/// Whether monstermos tile equalization is enabled.
Expand All @@ -1075,21 +1056,7 @@ public static readonly CVarDef<bool>
/// Also looks weird on slow spacing for unrelated reasons. If you do want to enable this, you should probably turn on instaspacing.
/// </summary>
public static readonly CVarDef<bool> MonstermosRipTiles =
CVarDef.Create("atmos.monstermos_rip_tiles", true, CVar.SERVERONLY);

/// <summary>
/// Taken as the cube of a tile's mass, this acts as a minimum threshold of mass for which air pressure calculates whether or not to rip a tile from the floor
/// This should be set by default to the cube of the game's lowest mass tile as defined in .yml prototypes, but can be increased for server performance reasons
/// </summary>
public static readonly CVarDef<float> MonstermosRipTilesMinimumPressure =
CVarDef.Create("atmos.monstermos_rip_tiles_min_pressure", 7500f, CVar.SERVERONLY);

/// <summary>
/// Taken after the minimum pressure is checked, the effective pressure is multiplied by this amount. This allows server hosts to
/// finely tune how likely floor tiles are to be ripped apart by air pressure
/// </summary>
public static readonly CVarDef<float> MonstermosRipTilesPressureOffset =
CVarDef.Create("atmos.monstermos_rip_tiles_pressure_offset", 0.44f, CVar.SERVERONLY);
CVarDef.Create("atmos.monstermos_rip_tiles", false, CVar.SERVERONLY);

/// <summary>
/// Whether explosive depressurization will cause the grid to gain an impulse.
Expand Down Expand Up @@ -1120,13 +1087,6 @@ public static readonly CVarDef<bool>
public static readonly CVarDef<float> AtmosSpacingMaxWind =
CVarDef.Create("atmos.mmos_max_wind", 500f, CVar.SERVERONLY);

/// <summary>
/// Increases default airflow calculations to O(n^2) complexity, for use with heavy space wind optimizations. Potato servers BEWARE
/// This solves the problem of objects being trapped in an infinite loop of slamming into a wall repeatedly.
/// </summary>
public static readonly CVarDef<bool> MonstermosUseExpensiveAirflow =
CVarDef.Create("atmos.mmos_expensive_airflow", true, CVar.SERVERONLY);

/// <summary>
/// Whether atmos superconduction is enabled.
/// </summary>
Expand Down
Loading

0 comments on commit a8f1bb3

Please sign in to comment.