Optimization: Connection recipient caching, resetting cachedshadow data instead of creating a new one
This commit is contained in:
@@ -30,6 +30,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public readonly ushort[] wireId;
|
||||
|
||||
private List<Connection> recipients;
|
||||
|
||||
public bool IsPower
|
||||
{
|
||||
get;
|
||||
@@ -38,17 +40,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public List<Connection> Recipients
|
||||
{
|
||||
get
|
||||
{
|
||||
List<Connection> recipients = new List<Connection>();
|
||||
for (int i = 0; i<MaxLinked; i++)
|
||||
{
|
||||
if (Wires[i] == null) continue;
|
||||
Connection recipient = Wires[i].OtherConnection(this);
|
||||
if (recipient != null) recipients.Add(recipient);
|
||||
}
|
||||
return recipients;
|
||||
}
|
||||
get { return recipients; }
|
||||
}
|
||||
|
||||
public Item Item
|
||||
@@ -72,6 +64,8 @@ namespace Barotrauma.Items.Components
|
||||
//recipient = new Connection[MaxLinked];
|
||||
Wires = new Wire[MaxLinked];
|
||||
|
||||
recipients = new List<Connection>();
|
||||
|
||||
IsOutput = (element.Name.ToString() == "output");
|
||||
Name = ToolBox.GetAttributeString(element, "name", (IsOutput) ? "output" : "input");
|
||||
|
||||
@@ -140,6 +134,18 @@ namespace Barotrauma.Items.Components
|
||||
//linked[index] = connectedItem;
|
||||
//recipient[index] = otherConnection;
|
||||
Wires[index] = wire;
|
||||
UpdateRecipients();
|
||||
}
|
||||
|
||||
public void UpdateRecipients()
|
||||
{
|
||||
recipients.Clear();
|
||||
for (int i = 0; i < MaxLinked; i++)
|
||||
{
|
||||
if (Wires[i] == null) continue;
|
||||
Connection recipient = Wires[i].OtherConnection(this);
|
||||
if (recipient != null) recipients.Add(recipient);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendSignal(string signal, Item sender, float power)
|
||||
@@ -175,6 +181,8 @@ namespace Barotrauma.Items.Components
|
||||
Wires[i].RemoveConnection(this);
|
||||
Wires[i] = null;
|
||||
}
|
||||
|
||||
recipients.Clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -460,6 +468,8 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
UpdateRecipients();
|
||||
|
||||
//wireId = null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user