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;
|
||||
}
|
||||
|
||||
|
||||
@@ -162,6 +162,7 @@ namespace Barotrauma.Items.Components
|
||||
c.Wires[i] = wireComponent;
|
||||
wireComponent.Connect(c, false);
|
||||
}
|
||||
c.UpdateRecipients();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void Move(Vector2 amount)
|
||||
{
|
||||
for (int i = 0; i < Nodes.Count; i++)
|
||||
{
|
||||
Nodes[i] += amount;
|
||||
}
|
||||
//for (int i = 0; i < Nodes.Count; i++)
|
||||
//{
|
||||
// Nodes[i] += amount;
|
||||
//}
|
||||
}
|
||||
|
||||
public Connection OtherConnection(Connection connection)
|
||||
@@ -64,7 +64,10 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
for (int n = 0; n< connections[i].Wires.Length; n++)
|
||||
{
|
||||
if (connections[i].Wires[n] == this) connections[i].Wires[n] = null;
|
||||
if (connections[i].Wires[n] != this) continue;
|
||||
|
||||
connections[i].Wires[n] = null;
|
||||
connections[i].UpdateRecipients();
|
||||
}
|
||||
connections[i] = null;
|
||||
}
|
||||
@@ -290,7 +293,7 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
|
||||
|
||||
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, bool editing)
|
||||
public override void Draw(SpriteBatch spriteBatch, bool editing)
|
||||
{
|
||||
if (Nodes.Count == 0) return;
|
||||
|
||||
@@ -369,8 +372,8 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
if (item.Submarine!=null)
|
||||
{
|
||||
start += item.Submarine.DrawPosition;
|
||||
end += item.Submarine.DrawPosition;
|
||||
start += item.Submarine.DrawPosition+Submarine.HiddenSubPosition;
|
||||
end += item.Submarine.DrawPosition+Submarine.HiddenSubPosition;
|
||||
}
|
||||
|
||||
start.Y = -start.Y;
|
||||
|
||||
Reference in New Issue
Block a user