Reapply "OBT1.1.0 Merge branch 'dev_pte' into dev"
This reverts commit 046483b9da.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Barotrauma.Networking;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
@@ -13,7 +14,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
partial class WifiComponent : ItemComponent, IServerSerializable, IClientSerializable
|
||||
{
|
||||
private static readonly List<WifiComponent> list = new List<WifiComponent>();
|
||||
private static readonly ConcurrentDictionary<WifiComponent, byte> _wifiDict = new ConcurrentDictionary<WifiComponent, byte>();
|
||||
private static IEnumerable<WifiComponent> AllWifiComponents => _wifiDict.Keys;
|
||||
|
||||
const int ChannelMemorySize = 10;
|
||||
|
||||
@@ -114,7 +116,7 @@ namespace Barotrauma.Items.Components
|
||||
public WifiComponent(Item item, ContentXElement element)
|
||||
: base (item, element)
|
||||
{
|
||||
list.Add(this);
|
||||
_wifiDict.TryAdd(this, 0);
|
||||
IsActive = true;
|
||||
}
|
||||
|
||||
@@ -159,7 +161,7 @@ namespace Barotrauma.Items.Components
|
||||
/// </summary>
|
||||
public IEnumerable<WifiComponent> GetReceiversInRange()
|
||||
{
|
||||
return list.Where(w => w != this && w.CanReceive(this));
|
||||
return AllWifiComponents.Where(w => w != this && w.CanReceive(this));
|
||||
}
|
||||
|
||||
public bool CanReceive(WifiComponent sender)
|
||||
@@ -188,7 +190,7 @@ namespace Barotrauma.Items.Components
|
||||
/// </summary>
|
||||
public IEnumerable<WifiComponent> GetTransmittersInRange()
|
||||
{
|
||||
return list.Where(w => w != this && w.CanTransmit(this));
|
||||
return AllWifiComponents.Where(w => w != this && w.CanTransmit(this));
|
||||
}
|
||||
|
||||
public bool CanTransmit(WifiComponent sender)
|
||||
@@ -278,7 +280,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (signal.source != null)
|
||||
{
|
||||
foreach (Connection receiver in wifiComp.item.LastSentSignalRecipients)
|
||||
// Use ToList() snapshot for thread-safe iteration
|
||||
foreach (Connection receiver in wifiComp.item.LastSentSignalRecipients.ToList())
|
||||
{
|
||||
if (!signal.source.LastSentSignalRecipients.Contains(receiver))
|
||||
{
|
||||
@@ -369,7 +372,7 @@ namespace Barotrauma.Items.Components
|
||||
protected override void RemoveComponentSpecific()
|
||||
{
|
||||
base.RemoveComponentSpecific();
|
||||
list.Remove(this);
|
||||
_wifiDict.TryRemove(this, out _);
|
||||
}
|
||||
|
||||
public override XElement Save(XElement parentElement)
|
||||
|
||||
Reference in New Issue
Block a user