* PipeNode

* Pipe prototypes

* Fixes Default NodeGroup not being registered by NodeGroupFactory

* GasNet

* PumpComponent

* IPipeNet

* PipeComponent

* misc naming, yaml

* PipeComponent rework

* PipeNet gas transfer from pipes

* PipeNet correctly combines gas on combining with other group

* Client ignores piping components

* AfterRemake

* PipeNet remake simplification

* IGasMixtureHolder on PipeComponent, IPipeNet

* PipeContainerComponent

* BasePump

* DebugPump

* IgnoredComponent fix

* Pipe LocalAir and Air

* comments

* Pump fix

* PipeNet fix

* name simplification

* PipeDirection name changes

* BaseVentComponent and DebugVentComponent

* Moves Pipe to own file

* DebugVentComponent moved to own file

* BaseScrubberComponent

* DebugScrubberComponent

* IgnoredComponents update

* scrubber prototype

* vent prototype fix

* comments

* Removes vent and scrubber PipeDirection check

* PipeContainer, Pipe, and PipeNode refactor

* Yaml cleanup

* pump prototype fix

* Removes AssumeAir usage from old IGasMixtureHolders

* Simplfies Vent & Scrubber to use AtmosHelper methods

* Vents and scrubbers invalidate the coordinate they changed the gas of

* UpdatedPipingComponent

* ScrubberComponent renamed to SiphonComponent

* Removes PumpSystem

* Removes framTime from UpdatedPiping

* PipeNetDevices

* PipeNetDevice updated by GridAtmosphereComponent

* PipeNets react from update in GridAtmosphereComponent

* GridAtmosphereComponent stores PipeNets/PipeNetDevices to be updated in queue

* diff fix

* Removes debug gas starting in pipes

* type safety in IPipeNet when combining groups

* null checks

* GridAtmos stores PipeNets and PipeNetDevices in List

* comments

* rogue curly bracket

* ProcessPipeNets update fix

* RemovePipeNet fix

* PipeNet update() unique index

* fix diff

* Integration test fixes

* Error Logging

* error fix

Co-authored-by: py01 <pyronetics01@gmail.com>
This commit is contained in:
py01
2020-08-27 09:45:27 -06:00
committed by GitHub
parent 548ef3dedb
commit 7b12d4e08c
19 changed files with 833 additions and 11 deletions

View File

@@ -5,6 +5,8 @@ using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.Atmos.Piping;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Shared.Atmos;
using Content.Shared.Maps;
using Robust.Server.Interfaces.GameObjects;
@@ -73,6 +75,22 @@ namespace Content.Server.GameObjects.Components.Atmos
[ViewVariables]
private HashSet<TileAtmosphere> _highPressureDelta = new HashSet<TileAtmosphere>(1000);
[ViewVariables]
private readonly List<IPipeNet> _pipeNets = new List<IPipeNet>();
/// <summary>
/// Index of most recently updated <see cref="IPipeNet"/>.
/// </summary>
private int _pipeNetIndex = 0;
[ViewVariables]
private readonly List<PipeNetDeviceComponent> _pipeNetDevices = new List<PipeNetDeviceComponent>();
/// <summary>
/// Index of most recently updated <see cref="PipeNetDeviceComponent"/>.
/// </summary>
private int _deviceIndex = 0;
[ViewVariables]
private ProcessState _state = ProcessState.TileEqualize;
@@ -84,6 +102,8 @@ namespace Content.Server.GameObjects.Components.Atmos
HighPressureDelta,
Hotspots,
Superconductivity,
PipeNet,
PipeNetDevices,
}
/// <inheritdoc />
@@ -296,6 +316,28 @@ namespace Content.Server.GameObjects.Components.Atmos
_excitedGroups.Remove(excitedGroup);
}
public void AddPipeNet(IPipeNet pipeNet)
{
_pipeNets.Add(pipeNet);
}
public void RemovePipeNet(IPipeNet pipeNet)
{
_pipeNets.Remove(pipeNet);
_deviceIndex = 0;
}
public void AddPipeNetDevice(PipeNetDeviceComponent pipeNetDevice)
{
_pipeNetDevices.Add(pipeNetDevice);
}
public void RemovePipeNetDevice(PipeNetDeviceComponent pipeNetDevice)
{
_pipeNetDevices.Remove(pipeNetDevice);
_deviceIndex = 0;
}
/// <inheritdoc />
public TileAtmosphere? GetTile(GridCoordinates coordinates)
{
@@ -401,6 +443,14 @@ namespace Content.Server.GameObjects.Components.Atmos
break;
case ProcessState.Superconductivity:
ProcessSuperconductivity();
_state = ProcessState.PipeNet;
break;
case ProcessState.PipeNet:
ProcessPipeNets();
_state = ProcessState.PipeNetDevices;
break;
case ProcessState.PipeNetDevices:
ProcessPipeNetDevices();
_state = ProcessState.TileEqualize;
break;
}
@@ -520,6 +570,45 @@ namespace Content.Server.GameObjects.Components.Atmos
}
}
private void ProcessPipeNets()
{
_stopwatch.Restart();
var number = 0;
var pipeNets = _pipeNets.ToArray();
var netCount = pipeNets.Count();
for ( ; _pipeNetIndex < netCount; _pipeNetIndex++)
{
pipeNets[_pipeNetIndex].Update();
if (number++ < LagCheckIterations) continue;
number = 0;
// Process the rest next time.
if (_stopwatch.Elapsed.TotalMilliseconds >= LagCheckMaxMilliseconds)
return;
}
_pipeNetIndex = 0;
}
private void ProcessPipeNetDevices()
{
_stopwatch.Restart();
var number = 0;
var pipeNetDevices = _pipeNetDevices.ToArray();
var deviceCount = pipeNetDevices.Count();
for ( ; _deviceIndex < deviceCount; _deviceIndex++)
{
pipeNetDevices[_deviceIndex].Update();
if (number++ < LagCheckIterations) continue;
number = 0;
// Process the rest next time.
if (_stopwatch.Elapsed.TotalMilliseconds >= LagCheckMaxMilliseconds)
return;
}
_deviceIndex = 0;
}
private AirtightComponent? GetObstructingComponent(MapIndices indices)
{
if (!Owner.TryGetComponent(out IMapGridComponent? mapGrid)) return default;

View File

@@ -0,0 +1,50 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Log;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Adds itself to a <see cref="IGridAtmosphereComponent"/> to be updated by.
/// TODO: Make compatible with unanchoring/anchoring. Currently assumes that the Owner does not move.
/// </summary>
public abstract class PipeNetDeviceComponent : Component
{
public abstract void Update();
protected IGridAtmosphereComponent JoinedGridAtmos { get; private set; }
public override void Initialize()
{
base.Initialize();
JoinGridAtmos();
}
public override void OnRemove()
{
base.OnRemove();
LeaveGridAtmos();
}
private void JoinGridAtmos()
{
var gridAtmos = EntitySystem.Get<AtmosphereSystem>()
.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.AddPipeNetDevice(this);
}
private void LeaveGridAtmos()
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
JoinedGridAtmos = null;
}
}
}

View File

@@ -0,0 +1,68 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Robust.Shared.Log;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System.Linq;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Transfer gas from one <see cref="PipeNode"/> to another.
/// </summary>
public abstract class BasePumpComponent : PipeNetDeviceComponent
{
/// <summary>
/// Needs to be same <see cref="PipeDirection"/> as that of a <see cref="Pipe"/> on this entity.
/// </summary>
[ViewVariables]
private PipeDirection _inletDirection;
/// <summary>
/// Needs to be same <see cref="PipeDirection"/> as that of a <see cref="Pipe"/> on this entity.
/// </summary>
[ViewVariables]
private PipeDirection _outletDirection;
[ViewVariables]
private PipeNode _inletPipe;
[ViewVariables]
private PipeNode _outletPipe;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _inletDirection, "inletDirection", PipeDirection.None);
serializer.DataField(ref _outletDirection, "outletDirection", PipeDirection.None);
}
public override void Initialize()
{
base.Initialize();
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(BasePumpComponent)} on entity {Owner.Uid} did not have a {nameof(NodeContainerComponent)}.");
return;
}
var pipeNodes = container.Nodes.OfType<PipeNode>();
_inletPipe = pipeNodes.Where(pipe => pipe.PipeDirection == _inletDirection).FirstOrDefault();
_outletPipe = pipeNodes.Where(pipe => pipe.PipeDirection == _outletDirection).FirstOrDefault();
if (_inletPipe == null | _outletPipe == null)
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(BasePumpComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return;
}
}
public override void Update()
{
PumpGas(_inletPipe.Air, _outletPipe.Air);
}
protected abstract void PumpGas(GasMixture inletGas, GasMixture outletGas);
}
}

View File

@@ -0,0 +1,21 @@
using Content.Server.Atmos;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Placeholder example of pump functionality.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(BasePumpComponent))]
public class DebugPumpComponent : BasePumpComponent
{
public override string Name => "DebugPump";
protected override void PumpGas(GasMixture inletGas, GasMixture outletGas)
{
outletGas.Merge(inletGas);
inletGas.Clear();
}
}
}

View File

@@ -0,0 +1,52 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
using System.Linq;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Transfers gas from the tile it is on to a <see cref="PipeNode"/>.
/// </summary>
public abstract class BaseSiphonComponent : PipeNetDeviceComponent
{
[ViewVariables]
private PipeNode _scrubberOutlet;
private AtmosphereSystem _atmosSystem;
public override void Initialize()
{
base.Initialize();
_atmosSystem = EntitySystem.Get<AtmosphereSystem>();
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(BaseSiphonComponent)} on entity {Owner.Uid} did not have a {nameof(NodeContainerComponent)}.");
return;
}
_scrubberOutlet = container.Nodes.OfType<PipeNode>().FirstOrDefault();
if (_scrubberOutlet == null)
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(BaseSiphonComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return;
}
}
public override void Update()
{
var tileAtmos = AtmosHelpers.GetTileAtmosphere(Owner.Transform.GridPosition);
if (tileAtmos == null)
return;
ScrubGas(tileAtmos.Air, _scrubberOutlet.Air);
_atmosSystem.GetGridAtmosphere(Owner.Transform.GridID).Invalidate(tileAtmos.GridIndices);
}
protected abstract void ScrubGas(GasMixture inletGas, GasMixture outletGas);
}
}

View File

@@ -0,0 +1,21 @@
using Content.Server.Atmos;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Placeholder example of scrubber functionality.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(BaseSiphonComponent))]
public class DebugSiphonComponent : BaseSiphonComponent
{
public override string Name => "DebugSiphon";
protected override void ScrubGas(GasMixture inletGas, GasMixture outletGas)
{
outletGas.Merge(inletGas);
inletGas.Clear();
}
}
}

View File

@@ -0,0 +1,54 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Log;
using Robust.Shared.ViewVariables;
using System.Linq;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Transfers gas from a <see cref="PipeNode"/> to the tile it is on.
/// </summary>
public abstract class BaseVentComponent : PipeNetDeviceComponent
{
[ViewVariables]
private PipeNode _ventInlet;
private AtmosphereSystem _atmosSystem;
public override void Initialize()
{
base.Initialize();
_atmosSystem = EntitySystem.Get<AtmosphereSystem>();
if (!Owner.TryGetComponent<NodeContainerComponent>(out var container))
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(BaseVentComponent)} on entity {Owner.Uid} did not have a {nameof(NodeContainerComponent)}.");
return;
}
_ventInlet = container.Nodes.OfType<PipeNode>().FirstOrDefault();
if (_ventInlet == null)
{
JoinedGridAtmos?.RemovePipeNetDevice(this);
Logger.Error($"{typeof(BaseVentComponent)} on entity {Owner.Uid} could not find compatible {nameof(PipeNode)}s on its {nameof(NodeContainerComponent)}.");
return;
}
}
public override void Update()
{
var tileAtmos = AtmosHelpers.GetTileAtmosphere(Owner.Transform.GridPosition);
if (tileAtmos == null)
return;
VentGas(_ventInlet.Air, tileAtmos.Air);
_atmosSystem.GetGridAtmosphere(Owner.Transform.GridID).Invalidate(tileAtmos.GridIndices);
}
protected abstract void VentGas(GasMixture inletGas, GasMixture outletGas);
}
}

View File

@@ -0,0 +1,21 @@
using Content.Server.Atmos;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Atmos.Piping
{
/// <summary>
/// Placeholder example of vent functionality.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(BaseVentComponent))]
public class DebugVentComponent : BaseVentComponent
{
public override string Name => "DebugVent";
protected override void VentGas(GasMixture inletGas, GasMixture outletGas)
{
outletGas.Merge(inletGas);
inletGas.Clear();
}
}
}