Revert "OBT1.1.0 Merge branch 'dev_pte' into dev"
This reverts commit177cf89756, reversing changes made to42ba733cd4.
This commit is contained in:
@@ -222,14 +222,13 @@ namespace Barotrauma.Items.Components
|
||||
public void SetRecipientsDirty()
|
||||
{
|
||||
recipientsDirty = true;
|
||||
if (IsPower) { Powered.MarkConnectionChanged(this); }
|
||||
if (IsPower) { Powered.ChangedConnections.Add(this); }
|
||||
}
|
||||
|
||||
private void RefreshRecipients()
|
||||
{
|
||||
recipients.Clear();
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (var wire in wires.ToArray())
|
||||
foreach (var wire in wires)
|
||||
{
|
||||
Connection recipient = wire.OtherConnection(this);
|
||||
if (recipient != null) { recipients.Add(recipient); }
|
||||
@@ -268,8 +267,8 @@ namespace Barotrauma.Items.Components
|
||||
//Check if both connections belong to a larger grid
|
||||
if (prevOtherConnection.recipients.Count > 1 && recipients.Count > 1)
|
||||
{
|
||||
Powered.MarkConnectionChanged(prevOtherConnection);
|
||||
Powered.MarkConnectionChanged(this);
|
||||
Powered.ChangedConnections.Add(prevOtherConnection);
|
||||
Powered.ChangedConnections.Add(this);
|
||||
}
|
||||
else if (recipients.Count > 1)
|
||||
{
|
||||
@@ -285,7 +284,7 @@ namespace Barotrauma.Items.Components
|
||||
else if (Grid.Connections.Count == 2)
|
||||
{
|
||||
//Delete the grid as these were the only 2 devices
|
||||
Powered.Grids.TryRemove(Grid.ID, out _);
|
||||
Powered.Grids.Remove(Grid.ID);
|
||||
Grid = null;
|
||||
prevOtherConnection.Grid = null;
|
||||
}
|
||||
@@ -326,8 +325,8 @@ namespace Barotrauma.Items.Components
|
||||
else
|
||||
{
|
||||
//Flag change so that proper grids can be formed
|
||||
Powered.MarkConnectionChanged(this);
|
||||
Powered.MarkConnectionChanged(otherConnection);
|
||||
Powered.ChangedConnections.Add(this);
|
||||
Powered.ChangedConnections.Add(otherConnection);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,8 +339,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
LastSentSignal = signal;
|
||||
enumeratingWires = true;
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (var wire in wires.ToArray())
|
||||
foreach (var wire in wires)
|
||||
{
|
||||
Connection recipient = wire.OtherConnection(this);
|
||||
if (recipient == null) { continue; }
|
||||
@@ -356,14 +354,14 @@ namespace Barotrauma.Items.Components
|
||||
GameMain.LuaCs.Hook.Call("signalReceived." + recipient.item.Prefab.Identifier, signal, recipient);
|
||||
}
|
||||
|
||||
foreach (CircuitBoxConnection connection in CircuitBoxConnections.ToArray())
|
||||
foreach (CircuitBoxConnection connection in CircuitBoxConnections)
|
||||
{
|
||||
connection.ReceiveSignal(signal);
|
||||
GameMain.LuaCs.Hook.Call("signalReceived", signal, connection.Connection);
|
||||
GameMain.LuaCs.Hook.Call("signalReceived." + connection.Connection.Item.Prefab.Identifier, signal, connection);
|
||||
}
|
||||
enumeratingWires = false;
|
||||
foreach (var removedWire in removedWires.ToArray())
|
||||
foreach (var removedWire in removedWires)
|
||||
{
|
||||
wires.Remove(removedWire);
|
||||
}
|
||||
@@ -374,16 +372,14 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
conn.LastReceivedSignal = signal;
|
||||
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (ItemComponent ic in conn.item.Components.ToArray())
|
||||
foreach (ItemComponent ic in conn.item.Components)
|
||||
{
|
||||
ic.ReceiveSignal(signal, conn);
|
||||
}
|
||||
|
||||
if (conn.Effects == null || signal.value == "0") { return; }
|
||||
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (StatusEffect effect in conn.Effects.ToArray())
|
||||
foreach (StatusEffect effect in conn.Effects)
|
||||
{
|
||||
conn.Item.ApplyStatusEffect(effect, ActionType.OnUse, (float)Timing.Step);
|
||||
}
|
||||
@@ -393,15 +389,13 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (IsPower && Grid != null)
|
||||
{
|
||||
Powered.MarkConnectionChanged(this);
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (Connection c in recipients.ToArray())
|
||||
Powered.ChangedConnections.Add(this);
|
||||
foreach (Connection c in recipients)
|
||||
{
|
||||
Powered.MarkConnectionChanged(c);
|
||||
Powered.ChangedConnections.Add(c);
|
||||
}
|
||||
}
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (var wire in wires.ToArray())
|
||||
foreach (var wire in wires)
|
||||
{
|
||||
wire.RemoveConnection(this);
|
||||
recipientsDirty = true;
|
||||
@@ -409,7 +403,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (enumeratingWires)
|
||||
{
|
||||
foreach (var wire in wires.ToArray())
|
||||
foreach (var wire in wires)
|
||||
{
|
||||
removedWires.Add(wire);
|
||||
}
|
||||
@@ -452,8 +446,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
XElement newElement = new XElement(IsOutput ? "output" : "input", new XAttribute("name", Name));
|
||||
|
||||
// Use ToArray() snapshot before OrderBy for thread-safe iteration
|
||||
foreach (var wire in wires.ToArray().OrderBy(w => w.Item.ID))
|
||||
foreach (var wire in wires.OrderBy(w => w.Item.ID))
|
||||
{
|
||||
newElement.Add(new XElement("link",
|
||||
new XAttribute("w", wire.Item.ID.ToString()),
|
||||
|
||||
+7
-13
@@ -148,16 +148,14 @@ namespace Barotrauma.Items.Components
|
||||
Vector2 wireNodeOffset = item.Submarine == null ? Vector2.Zero : item.Submarine.HiddenSubPosition + amount;
|
||||
foreach (Connection c in Connections)
|
||||
{
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (Wire wire in c.Wires.ToArray())
|
||||
foreach (Wire wire in c.Wires)
|
||||
{
|
||||
if (wire == null) { continue; }
|
||||
TryMoveWire(wire);
|
||||
}
|
||||
}
|
||||
|
||||
// Use ToList() snapshot for thread-safe iteration
|
||||
foreach (var wire in DisconnectedWires.ToList())
|
||||
foreach (var wire in DisconnectedWires)
|
||||
{
|
||||
TryMoveWire(wire);
|
||||
}
|
||||
@@ -389,7 +387,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
foreach (var connection in Connections)
|
||||
{
|
||||
Powered.UnmarkConnectionChanged(connection);
|
||||
Powered.ChangedConnections.Remove(connection);
|
||||
connection.Recipients.Clear();
|
||||
}
|
||||
Connections.Clear();
|
||||
@@ -414,19 +412,15 @@ namespace Barotrauma.Items.Components
|
||||
msg.WriteByte((byte)Connections.Count);
|
||||
foreach (Connection connection in Connections)
|
||||
{
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
var wiresSnapshot = connection.Wires.ToArray();
|
||||
msg.WriteVariableUInt32((uint)wiresSnapshot.Length);
|
||||
foreach (Wire wire in wiresSnapshot)
|
||||
msg.WriteVariableUInt32((uint)connection.Wires.Count);
|
||||
foreach (Wire wire in connection.Wires)
|
||||
{
|
||||
msg.WriteUInt16(wire?.Item == null ? (ushort)0 : wire.Item.ID);
|
||||
}
|
||||
}
|
||||
|
||||
// Use ToList() snapshot for thread-safe iteration
|
||||
var disconnectedSnapshot = DisconnectedWires.ToList();
|
||||
msg.WriteUInt16((ushort)disconnectedSnapshot.Count);
|
||||
foreach (Wire disconnectedWire in disconnectedSnapshot)
|
||||
msg.WriteUInt16((ushort)DisconnectedWires.Count);
|
||||
foreach (Wire disconnectedWire in DisconnectedWires)
|
||||
{
|
||||
msg.WriteUInt16(disconnectedWire.Item.ID);
|
||||
}
|
||||
|
||||
+11
-19
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Xna.Framework;
|
||||
namespace Barotrauma.Items.Components
|
||||
@@ -27,8 +25,7 @@ namespace Barotrauma.Items.Components
|
||||
private int signalQueueSize;
|
||||
private int delayTicks;
|
||||
|
||||
// Thread-safe queue for concurrent access
|
||||
private readonly ConcurrentQueue<DelayedSignal> signalQueue = new ConcurrentQueue<DelayedSignal>();
|
||||
private readonly Queue<DelayedSignal> signalQueue = new Queue<DelayedSignal>();
|
||||
|
||||
private DelayedSignal prevQueuedSignal;
|
||||
|
||||
@@ -43,8 +40,7 @@ namespace Barotrauma.Items.Components
|
||||
delay = value;
|
||||
delayTicks = (int)(delay / Timing.Step);
|
||||
signalQueueSize = Math.Max(delayTicks, 1) * 2;
|
||||
// ConcurrentQueue doesn't have Clear(), drain it instead
|
||||
while (signalQueue.TryDequeue(out _)) { }
|
||||
signalQueue.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,19 +66,19 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void Update(float deltaTime, Camera cam)
|
||||
{
|
||||
if (signalQueue.IsEmpty)
|
||||
if (signalQueue.Count == 0)
|
||||
{
|
||||
IsActive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (var val in signalQueue.ToArray())
|
||||
foreach (var val in signalQueue)
|
||||
{
|
||||
val.SendTimer -= 1;
|
||||
}
|
||||
while (signalQueue.TryPeek(out var signalOut) && signalOut.SendTimer <= 0)
|
||||
while (signalQueue.Count > 0 && signalQueue.Peek().SendTimer <= 0)
|
||||
{
|
||||
var signalOut = signalQueue.Peek();
|
||||
signalOut.SendDuration -= 1;
|
||||
item.SendSignal(new Signal(signalOut.Signal.value, sender: signalOut.Signal.sender, strength: signalOut.Signal.strength), "signal_out");
|
||||
if (signalOut.SendDuration <= 0)
|
||||
@@ -104,15 +100,11 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
case "signal_in":
|
||||
if (signalQueue.Count >= signalQueueSize) { return; }
|
||||
if (ResetWhenSignalReceived)
|
||||
{
|
||||
prevQueuedSignal = null;
|
||||
while (signalQueue.TryDequeue(out _)) { }
|
||||
}
|
||||
if (ResetWhenDifferentSignalReceived && signalQueue.TryPeek(out var peekSignal) && peekSignal.Signal.value != signal.value)
|
||||
if (ResetWhenSignalReceived) { prevQueuedSignal = null; signalQueue.Clear(); }
|
||||
if (ResetWhenDifferentSignalReceived && signalQueue.Count > 0 && signalQueue.Peek().Signal.value != signal.value)
|
||||
{
|
||||
prevQueuedSignal = null;
|
||||
while (signalQueue.TryDequeue(out _)) { }
|
||||
signalQueue.Clear();
|
||||
}
|
||||
|
||||
if (prevQueuedSignal != null &&
|
||||
@@ -135,10 +127,10 @@ namespace Barotrauma.Items.Components
|
||||
if (float.TryParse(signal.value, NumberStyles.Any, CultureInfo.InvariantCulture, out float newDelay))
|
||||
{
|
||||
newDelay = MathHelper.Clamp(newDelay, 0, 60);
|
||||
if (!signalQueue.IsEmpty && newDelay != Delay)
|
||||
if (signalQueue.Count > 0 && newDelay != Delay)
|
||||
{
|
||||
prevQueuedSignal = null;
|
||||
while (signalQueue.TryDequeue(out _)) { }
|
||||
signalQueue.Clear();
|
||||
}
|
||||
Delay = newDelay;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
@@ -32,8 +31,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private float thirdInverseMax = 0, loadEqnConstant = 0;
|
||||
|
||||
// Thread-safe immutable dictionary for connection pairs (read-only after initialization)
|
||||
private static readonly ImmutableDictionary<string, string> connectionPairs = new Dictionary<string, string>
|
||||
private static readonly Dictionary<string, string> connectionPairs = new Dictionary<string, string>
|
||||
{
|
||||
{ "power_in", "power_out"},
|
||||
{ "signal_in", "signal_out" },
|
||||
@@ -42,7 +40,7 @@ namespace Barotrauma.Items.Components
|
||||
{ "signal_in3", "signal_out3" },
|
||||
{ "signal_in4", "signal_out4" },
|
||||
{ "signal_in5", "signal_out5" }
|
||||
}.ToImmutableDictionary();
|
||||
};
|
||||
|
||||
protected override PowerPriority Priority { get { return PowerPriority.Relay; } }
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -11,8 +10,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class WifiComponent : ItemComponent, IServerSerializable, IClientSerializable
|
||||
{
|
||||
private static readonly ConcurrentDictionary<WifiComponent, byte> _wifiDict = new ConcurrentDictionary<WifiComponent, byte>();
|
||||
private static IEnumerable<WifiComponent> AllWifiComponents => _wifiDict.Keys;
|
||||
private static readonly List<WifiComponent> list = new List<WifiComponent>();
|
||||
|
||||
const int ChannelMemorySize = 10;
|
||||
|
||||
@@ -113,7 +111,7 @@ namespace Barotrauma.Items.Components
|
||||
public WifiComponent(Item item, ContentXElement element)
|
||||
: base (item, element)
|
||||
{
|
||||
_wifiDict.TryAdd(this, 0);
|
||||
list.Add(this);
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
@@ -158,7 +156,7 @@ namespace Barotrauma.Items.Components
|
||||
/// </summary>
|
||||
public IEnumerable<WifiComponent> GetReceiversInRange()
|
||||
{
|
||||
return AllWifiComponents.Where(w => w != this && w.CanReceive(this));
|
||||
return list.Where(w => w != this && w.CanReceive(this));
|
||||
}
|
||||
|
||||
public bool CanReceive(WifiComponent sender)
|
||||
@@ -187,7 +185,7 @@ namespace Barotrauma.Items.Components
|
||||
/// </summary>
|
||||
public IEnumerable<WifiComponent> GetTransmittersInRange()
|
||||
{
|
||||
return AllWifiComponents.Where(w => w != this && w.CanTransmit(this));
|
||||
return list.Where(w => w != this && w.CanTransmit(this));
|
||||
}
|
||||
|
||||
public bool CanTransmit(WifiComponent sender)
|
||||
@@ -277,8 +275,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (signal.source != null)
|
||||
{
|
||||
// Use ToList() snapshot for thread-safe iteration
|
||||
foreach (Connection receiver in wifiComp.item.LastSentSignalRecipients.ToList())
|
||||
foreach (Connection receiver in wifiComp.item.LastSentSignalRecipients)
|
||||
{
|
||||
if (!signal.source.LastSentSignalRecipients.Contains(receiver))
|
||||
{
|
||||
@@ -369,7 +366,7 @@ namespace Barotrauma.Items.Components
|
||||
protected override void RemoveComponentSpecific()
|
||||
{
|
||||
base.RemoveComponentSpecific();
|
||||
_wifiDict.TryRemove(this, out _);
|
||||
list.Remove(this);
|
||||
}
|
||||
|
||||
public override XElement Save(XElement parentElement)
|
||||
|
||||
@@ -250,8 +250,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (connections[0] != null && connections[1] != null)
|
||||
{
|
||||
// Use ToArray() snapshot for thread-safe iteration
|
||||
foreach (ItemComponent ic in item.Components.ToArray())
|
||||
foreach (ItemComponent ic in item.Components)
|
||||
{
|
||||
if (ic == this) { continue; }
|
||||
|
||||
@@ -724,11 +723,11 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (item0 == null && item1 != null)
|
||||
{
|
||||
item0 = Item.ItemList.FirstOrDefault(it => it.GetComponent<ConnectionPanel>()?.DisconnectedWires.Contains(this) ?? false);
|
||||
item0 = Item.ItemList.Find(it => it.GetComponent<ConnectionPanel>()?.DisconnectedWires.Contains(this) ?? false);
|
||||
}
|
||||
else if (item0 != null && item1 == null)
|
||||
{
|
||||
item1 = Item.ItemList.FirstOrDefault(it => it.GetComponent<ConnectionPanel>()?.DisconnectedWires.Contains(this) ?? false);
|
||||
item1 = Item.ItemList.Find(it => it.GetComponent<ConnectionPanel>()?.DisconnectedWires.Contains(this) ?? false);
|
||||
}
|
||||
|
||||
if (item0 == null || item1 == null || nodes.Count == 0) { return; }
|
||||
|
||||
Reference in New Issue
Block a user