* 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

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
@@ -13,6 +14,8 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{
IReadOnlyList<Node> Nodes { get; }
void Initialize(Node sourceNode);
void AddNode(Node node);
void RemoveNode(Node node);
@@ -34,6 +37,13 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
public static readonly INodeGroup NullGroup = new NullNodeGroup();
protected GridId GridId { get; private set;}
public virtual void Initialize(Node sourceNode)
{
GridId = sourceNode.Owner.Transform.GridID;
}
public void AddNode(Node node)
{
_nodes.Add(node);
@@ -54,6 +64,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
newGroup.CombineGroup(this);
return;
}
OnGivingNodesForCombine(newGroup);
foreach (var node in Nodes)
{
node.NodeGroup = newGroup;
@@ -70,23 +81,31 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{
node.ClearNodeGroup();
}
var newGroups = new List<INodeGroup>();
foreach (var node in Nodes)
{
if (node.TryAssignGroupIfNeeded())
{
node.SpreadGroup();
newGroups.Add(node.NodeGroup);
}
}
AfterRemake(newGroups);
}
protected virtual void OnAddNode(Node node) { }
protected virtual void OnRemoveNode(Node node) { }
protected virtual void OnGivingNodesForCombine(INodeGroup newGroup) { }
protected virtual void AfterRemake(IEnumerable<INodeGroup> newGroups) { }
private class NullNodeGroup : INodeGroup
{
public IReadOnlyList<Node> Nodes => _nodes;
private readonly List<Node> _nodes = new List<Node>();
public void Initialize(Node sourceNode) { }
public void AddNode(Node node) { }
public void CombineGroup(INodeGroup newGroup) { }
public void RemoveNode(Node node) { }

View File

@@ -0,0 +1,100 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.ViewVariables;
using System.Collections.Generic;
namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{
public interface IPipeNet : IGasMixtureHolder
{
/// <summary>
/// Causes gas in the PipeNet to react.
/// </summary>
void Update();
}
[NodeGroup(NodeGroupID.Pipe)]
public class PipeNet : BaseNodeGroup, IPipeNet
{
[ViewVariables]
public GasMixture Air { get; set; } = new GasMixture();
public static readonly IPipeNet NullNet = new NullPipeNet();
[ViewVariables]
private readonly List<PipeNode> _pipes = new List<PipeNode>();
[ViewVariables]
private IGridAtmosphereComponent _gridAtmos;
public override void Initialize(Node sourceNode)
{
base.Initialize(sourceNode);
_gridAtmos = EntitySystem.Get<AtmosphereSystem>()
.GetGridAtmosphere(GridId);
_gridAtmos?.AddPipeNet(this);
}
public void Update()
{
Air.React(this);
}
protected override void OnAddNode(Node node)
{
if (!(node is PipeNode pipeNode))
return;
_pipes.Add(pipeNode);
pipeNode.JoinPipeNet(this);
Air.Volume += pipeNode.Volume;
Air.Merge(pipeNode.LocalAir);
pipeNode.LocalAir.Clear();
}
protected override void OnRemoveNode(Node node)
{
RemoveFromGridAtmos();
if (!(node is PipeNode pipeNode))
return;
var pipeAir = pipeNode.LocalAir;
pipeAir.Merge(Air);
pipeAir.Multiply(pipeNode.Volume / Air.Volume);
_pipes.Remove(pipeNode);
}
protected override void OnGivingNodesForCombine(INodeGroup newGroup)
{
if (!(newGroup is IPipeNet newPipeNet))
return;
newPipeNet.Air.Merge(Air);
Air.Clear();
}
protected override void AfterRemake(IEnumerable<INodeGroup> newGroups)
{
foreach (var newGroup in newGroups)
{
if (!(newGroup is IPipeNet newPipeNet))
continue;
newPipeNet.Air.Merge(Air);
var newPipeNetGas = newPipeNet.Air;
newPipeNetGas.Multiply(newPipeNetGas.Volume / Air.Volume);
}
RemoveFromGridAtmos();
}
private void RemoveFromGridAtmos()
{
_gridAtmos.RemovePipeNet(this);
}
private class NullPipeNet : IPipeNet
{
GasMixture IGasMixtureHolder.Air { get; set; } = new GasMixture();
public void Update() { }
}
}
}

View File

@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Content.Server.GameObjects.Components.NodeContainer.Nodes;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.IoC;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
{
@@ -17,7 +18,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
/// <summary>
/// Returns a new <see cref="INodeGroup"/> instance.
/// </summary>
INodeGroup MakeNodeGroup(NodeGroupID nodeGroupType);
INodeGroup MakeNodeGroup(Node sourceNode);
}
public class NodeGroupFactory : INodeGroupFactory
@@ -29,7 +30,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
public void Initialize()
{
var nodeGroupTypes = _reflectionManager.GetAllChildren<BaseNodeGroup>();
var nodeGroupTypes = _reflectionManager.GetAllChildren<INodeGroup>();
foreach (var nodeGroupType in nodeGroupTypes)
{
var att = nodeGroupType.GetCustomAttribute<NodeGroupAttribute>();
@@ -43,13 +44,15 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
}
}
public INodeGroup MakeNodeGroup(NodeGroupID nodeGroupType)
public INodeGroup MakeNodeGroup(Node sourceNode)
{
if (_groupTypes.TryGetValue(nodeGroupType, out var type))
if (_groupTypes.TryGetValue(sourceNode.NodeGroupID, out var type))
{
return _typeFactory.CreateInstance<INodeGroup>(type);
var nodeGroup = _typeFactory.CreateInstance<INodeGroup>(type);
nodeGroup.Initialize(sourceNode);
return nodeGroup;
}
throw new ArgumentException($"{nodeGroupType} did not have an associated {nameof(INodeGroup)}.");
throw new ArgumentException($"{sourceNode.NodeGroupID} did not have an associated {nameof(INodeGroup)}.");
}
}
@@ -59,5 +62,6 @@ namespace Content.Server.GameObjects.Components.NodeContainer.NodeGroups
HVPower,
MVPower,
Apc,
Pipe,
}
}

View File

@@ -53,7 +53,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
serializer.DataField(this, x => NodeGroupID, "nodeGroupID", NodeGroupID.Default);
}
public void Initialize(IEntity owner)
public virtual void Initialize(IEntity owner)
{
Owner = owner;
_nodeGroupFactory = IoCManager.Resolve<INodeGroupFactory>();
@@ -143,7 +143,7 @@ namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
private INodeGroup MakeNewGroup()
{
return _nodeGroupFactory.MakeNodeGroup(NodeGroupID);
return _nodeGroupFactory.MakeNodeGroup(this);
}
private void AnchorUpdate()

View File

@@ -0,0 +1,171 @@
using Content.Server.Atmos;
using Content.Server.GameObjects.Components.NodeContainer.NodeGroups;
using Content.Server.Interfaces;
using Content.Shared.Atmos;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Content.Server.GameObjects.Components.NodeContainer.Nodes
{
/// <summary>
/// Connects with other <see cref="PipeNode"/>s whose <see cref="PipeNode.PipeDirection"/>
/// correctly correspond.
/// </summary>
public class PipeNode : Node, IGasMixtureHolder
{
[ViewVariables]
public PipeDirection PipeDirection => _pipeDirection;
private PipeDirection _pipeDirection;
[ViewVariables]
private IPipeNet _pipeNet = PipeNet.NullNet;
[ViewVariables]
private bool _needsPipeNet = true;
/// <summary>
/// The gases in this pipe.
/// </summary>
[ViewVariables]
public GasMixture Air
{
get => _needsPipeNet ? LocalAir : _pipeNet.Air;
set
{
if (_needsPipeNet)
LocalAir = value;
else
_pipeNet.Air = value;
}
}
/// <summary>
/// Stores gas in this pipe when disconnected from a <see cref="IPipeNet"/>.
/// Only for usage by <see cref="IPipeNet"/>s.
/// </summary>
[ViewVariables]
public GasMixture LocalAir { get; set; }
[ViewVariables]
public float Volume { get; private set; }
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _pipeDirection, "pipeDirection", PipeDirection.None);
serializer.DataField(this, x => Volume, "volume", 10);
}
public override void Initialize(IEntity owner)
{
base.Initialize(owner);
LocalAir = new GasMixture(Volume);
}
public void JoinPipeNet(IPipeNet pipeNet)
{
_pipeNet = pipeNet;
_needsPipeNet = false;
}
public void ClearPipeNet()
{
_pipeNet = PipeNet.NullNet;
_needsPipeNet = true;
}
protected override IEnumerable<Node> GetReachableNodes()
{
foreach (CardinalDirection direction in Enum.GetValues(typeof(CardinalDirection)))
{
PipeDirectionFromCardinal(direction, out var ownNeededConnection, out var theirNeededConnection);
if ((_pipeDirection & ownNeededConnection) == PipeDirection.None)
{
continue;
}
var pipeNodesInDirection = Owner.GetComponent<SnapGridComponent>()
.GetInDir((Direction) direction)
.Select(entity => entity.TryGetComponent<NodeContainerComponent>(out var container) ? container : null)
.Where(container => container != null)
.SelectMany(container => container.Nodes)
.OfType<PipeNode>()
.Where(pipeNode => (pipeNode._pipeDirection & theirNeededConnection) != PipeDirection.None);
foreach (var pipeNode in pipeNodesInDirection)
{
yield return pipeNode;
}
}
}
private void PipeDirectionFromCardinal(CardinalDirection direction, out PipeDirection sameDir, out PipeDirection oppDir)
{
switch (direction)
{
case CardinalDirection.North:
sameDir = PipeDirection.North;
oppDir = PipeDirection.South;
break;
case CardinalDirection.South:
sameDir = PipeDirection.South;
oppDir = PipeDirection.North;
break;
case CardinalDirection.East:
sameDir = PipeDirection.East;
oppDir = PipeDirection.West;
break;
case CardinalDirection.West:
sameDir = PipeDirection.West;
oppDir = PipeDirection.East;
break;
default:
throw new ArgumentException("Invalid Direction.");
}
}
private enum CardinalDirection
{
North = Direction.North,
South = Direction.South,
East = Direction.East,
West = Direction.West,
}
}
public enum PipeDirection
{
None = 0,
//Half of a pipe in a direction
North = 1 << 0,
South = 1 << 1,
West = 1 << 2,
East = 1 << 3,
//Straight pipes
Longitudinal = North | South,
Lateral = West | East,
//Bends
NWBend = North | West,
NEBend = North | East,
SWBend = South | West,
SEBend = South | East,
//T-Junctions
TNorth = North | Lateral,
TSouth = South | Lateral,
TWest = West | Longitudinal,
TEast = East | Longitudinal,
//Four way
FourWay = North | South | East | West,
All = -1,
}
}