Remove redundant null checks for atmos (#2703)

* Remove redundant null checks for atmos

* Remove unnecessary nullability parameter from AtmosphereSystem.GetGridAtmosphere

* Remove more nullability markers

* Bring back null checks for gas tanks

* Remove null checks from GasMixture.Merge and TileAtmosphere.AssumeAir

Co-authored-by: Vera Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
DrSmugleaf
2020-12-08 12:17:13 +01:00
committed by GitHub
parent a78452c845
commit 074db878bb
6 changed files with 9 additions and 29 deletions

View File

@@ -11,7 +11,6 @@ using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.Serialization; using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
namespace Content.Server.Atmos namespace Content.Server.Atmos
@@ -42,7 +41,7 @@ namespace Content.Server.Atmos
public bool Immutable { get; private set; } public bool Immutable { get; private set; }
[ViewVariables] [ViewVariables]
public float LastShare { get; private set; } = 0; public float LastShare { get; private set; }
[ViewVariables] [ViewVariables]
public readonly Dictionary<GasReaction, float> ReactionResults = new() public readonly Dictionary<GasReaction, float> ReactionResults = new()
@@ -148,7 +147,7 @@ namespace Content.Server.Atmos
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Merge(GasMixture giver) public void Merge(GasMixture giver)
{ {
if (Immutable || giver == null) return; if (Immutable) return;
if (MathF.Abs(Temperature - giver.Temperature) > Atmospherics.MinimumTemperatureDeltaToConsider) if (MathF.Abs(Temperature - giver.Temperature) > Atmospherics.MinimumTemperatureDeltaToConsider)
{ {

View File

@@ -1121,7 +1121,7 @@ namespace Content.Server.Atmos
public bool AssumeAir(GasMixture giver) public bool AssumeAir(GasMixture giver)
{ {
if (giver == null || Air == null) return false; if (Air == null) return false;
Air.Merge(giver); Air.Merge(giver);

View File

@@ -5,6 +5,7 @@ using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform; using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Log;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -25,7 +26,7 @@ namespace Content.Server.GameObjects.Components.Atmos
[ViewVariables] [ViewVariables]
private int _currentAirBlockedDirection; private int _currentAirBlockedDirection;
private bool _airBlocked = true; private bool _airBlocked = true;
private bool _fixVacuum = false; private bool _fixVacuum;
[ViewVariables] [ViewVariables]
private bool _rotateAirBlocked = true; private bool _rotateAirBlocked = true;
@@ -141,7 +142,7 @@ namespace Content.Server.GameObjects.Components.Atmos
UpdatePosition(_lastPosition.Item1, _lastPosition.Item2); UpdatePosition(_lastPosition.Item1, _lastPosition.Item2);
if (_fixVacuum) if (_fixVacuum)
_atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1)?.FixVacuum(_lastPosition.Item2); _atmosphereSystem.GetGridAtmosphere(_lastPosition.Item1).FixVacuum(_lastPosition.Item2);
} }
private void OnTransformMove() private void OnTransformMove()
@@ -165,8 +166,6 @@ namespace Content.Server.GameObjects.Components.Atmos
{ {
var gridAtmos = _atmosphereSystem.GetGridAtmosphere(gridId); var gridAtmos = _atmosphereSystem.GetGridAtmosphere(gridId);
if (gridAtmos == null) return;
gridAtmos.UpdateAdjacentBits(pos); gridAtmos.UpdateAdjacentBits(pos);
gridAtmos.Invalidate(pos); gridAtmos.Invalidate(pos);
} }

View File

@@ -3,29 +3,23 @@ using System;
using Content.Server.Atmos; using Content.Server.Atmos;
using Content.Server.Explosions; using Content.Server.Explosions;
using Content.Server.GameObjects.Components.Body.Respiratory; using Content.Server.GameObjects.Components.Body.Respiratory;
using Content.Server.GameObjects.Components.GUI;
using Content.Server.Interfaces; using Content.Server.Interfaces;
using Content.Server.Utility; using Content.Server.Utility;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.GameObjects.Components.Atmos.GasTank; using Content.Shared.GameObjects.Components.Atmos.GasTank;
using Content.Shared.GameObjects.Components.Inventory;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.GameObjects.Verbs; using Content.Shared.GameObjects.Verbs;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
using Robust.Server.GameObjects.Components.UserInterface; using Robust.Server.GameObjects.Components.UserInterface;
using Robust.Server.GameObjects.EntitySystems; using Robust.Server.GameObjects.EntitySystems;
using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player; using Robust.Server.Interfaces.Player;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.EntitySystemMessages;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Utility; using Robust.Shared.Utility;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;

View File

@@ -2,7 +2,6 @@
using Content.Server.GameObjects.EntitySystems; using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems; using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Log;
namespace Content.Server.GameObjects.Components.Atmos.Piping namespace Content.Server.GameObjects.Components.Atmos.Piping
{ {
@@ -32,11 +31,6 @@ namespace Content.Server.GameObjects.Components.Atmos.Piping
{ {
var gridAtmos = EntitySystem.Get<AtmosphereSystem>() var gridAtmos = EntitySystem.Get<AtmosphereSystem>()
.GetGridAtmosphere(Owner.Transform.GridID); .GetGridAtmosphere(Owner.Transform.GridID);
if (gridAtmos == null)
{
Logger.Error($"{nameof(PipeNetDeviceComponent)} on entity {Owner.Uid} could not find an {nameof(IGridAtmosphereComponent)}.");
return;
}
JoinedGridAtmos = gridAtmos; JoinedGridAtmos = gridAtmos;
JoinedGridAtmos.AddPipeNetDevice(this); JoinedGridAtmos.AddPipeNetDevice(this);
} }

View File

@@ -106,7 +106,7 @@ namespace Content.Server.GameObjects.Components.Doors
/// <summary> /// <summary>
/// Whether something is currently using a welder on this so DoAfter isn't spammed. /// Whether something is currently using a welder on this so DoAfter isn't spammed.
/// </summary> /// </summary>
private bool _beingWelded = false; private bool _beingWelded;
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
private bool _canCrush = true; private bool _canCrush = true;
@@ -346,13 +346,10 @@ namespace Content.Server.GameObjects.Components.Doors
var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID); var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID);
if (gridAtmosphere == null)
return false;
var minMoles = float.MaxValue; var minMoles = float.MaxValue;
var maxMoles = 0f; var maxMoles = 0f;
foreach (var (direction, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices)) foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices))
{ {
var moles = adjacent.Air.TotalMoles; var moles = adjacent.Air.TotalMoles;
if (moles < minMoles) if (moles < minMoles)
@@ -376,10 +373,7 @@ namespace Content.Server.GameObjects.Components.Doors
var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID); var gridAtmosphere = atmosphereSystem.GetGridAtmosphere(Owner.Transform.GridID);
if (gridAtmosphere == null) foreach (var (_, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices))
return false;
foreach (var (direction, adjacent) in gridAtmosphere.GetAdjacentTiles(tileAtmos.GridIndices))
{ {
if (adjacent.Hotspot.Valid) if (adjacent.Hotspot.Valid)
return true; return true;