Unstable 0.14.5.0

This commit is contained in:
Markus Isberg
2021-06-14 17:53:42 +03:00
parent 1f3e588fcd
commit 23a7c37eee
25 changed files with 254 additions and 259 deletions
@@ -783,7 +783,7 @@ namespace Barotrauma.Items.Components
case "set_fissionrate":
if (PowerOn && float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out float newFissionRate))
{
targetFissionRate = newFissionRate;
targetFissionRate = MathHelper.Clamp(newFissionRate, 0.0f, 100.0f);
if (GameMain.NetworkMember?.IsServer ?? false) { unsentChanges = true; }
#if CLIENT
FissionRateScrollBar.BarScroll = targetFissionRate / 100.0f;
@@ -793,7 +793,7 @@ namespace Barotrauma.Items.Components
case "set_turbineoutput":
if (PowerOn && float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out float newTurbineOutput))
{
targetTurbineOutput = newTurbineOutput;
targetTurbineOutput = MathHelper.Clamp(newTurbineOutput, 0.0f, 100.0f);
if (GameMain.NetworkMember?.IsServer ?? false) { unsentChanges = true; }
#if CLIENT
TurbineOutputScrollBar.BarScroll = targetTurbineOutput / 100.0f;
@@ -359,7 +359,7 @@ namespace Barotrauma.Items.Components
{
//other junction boxes don't need to receive the signal in the pass-through signal connections
//because we relay it straight to the connected items without going through the whole chain of junction boxes
if (ic is PowerTransfer && !(ic is RelayComponent) && connection.Name.Contains("signal")) { continue; }
if (ic is PowerTransfer && !(ic is RelayComponent)) { continue; }
ic.ReceiveSignal(signal, recipient);
}
@@ -19,5 +19,22 @@ namespace Barotrauma.Items.Components
this.power = power;
this.strength = strength;
}
internal Signal WithStepsTaken(int stepsTaken)
{
Signal retVal = this;
retVal.stepsTaken = stepsTaken;
return retVal;
}
public static bool operator==(Signal a, Signal b) =>
a.value == b.value &&
a.stepsTaken == b.stepsTaken &&
a.sender == b.sender &&
a.source == b.source &&
MathUtils.NearlyEqual(a.power, b.power) &&
MathUtils.NearlyEqual(a.strength, b.strength);
public static bool operator!=(Signal a, Signal b) => !(a == b);
}
}
@@ -64,6 +64,7 @@ namespace Barotrauma.Items.Components
public override void ReceiveSignal(Signal signal, Connection connection)
{
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out float value);
bool sendOutputImmediately = true;
switch (Function)
{
case FunctionType.Sin:
@@ -105,11 +106,13 @@ namespace Barotrauma.Items.Components
{
timeSinceReceived[0] = 0.0f;
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[0]);
sendOutputImmediately = false;
}
else if (connection.Name == "signal_in_y")
{
timeSinceReceived[1] = 0.0f;
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[1]);
sendOutputImmediately = false;
}
else
{
@@ -121,9 +124,11 @@ namespace Barotrauma.Items.Components
default:
throw new NotImplementedException($"Function {Function} has not been implemented.");
}
signal.value = value.ToString("G", CultureInfo.InvariantCulture);
item.SendSignal(signal, "signal_out");
if (sendOutputImmediately)
{
signal.value = value.ToString("G", CultureInfo.InvariantCulture);
item.SendSignal(signal, "signal_out");
}
}
}
}
@@ -2005,26 +2005,36 @@ namespace Barotrauma
SendSignal(signal, connection);
}
private readonly HashSet<(Signal Signal, Connection Connection)> delayedSignals = new HashSet<(Signal Signal, Connection Connection)>();
public void SendSignal(Signal signal, Connection connection)
{
LastSentSignalRecipients.Clear();
if (connections == null || connection == null) { return; }
signal.stepsTaken++;
//if the signal has been passed through this item multiple times already, interrupt it to prevent infinite loops
if (signal.stepsTaken > 5 && signal.source != null)
{
if (signal.source.LastSentSignalRecipients.AtLeast(3, recipient => recipient == connection))
{
return;
}
}
//use a coroutine to prevent infinite loops by creating a one
//frame delay if the "signal chain" gets too long
if (signal.stepsTaken > 10)
{
//if the signal has been passed through this item multiple times already, interrupt it to prevent infinite loops
if (signal.source != null)
//if there's an equal signal waiting to be sent
//to the same connection, don't add a new one
signal.stepsTaken = 0;
if (!delayedSignals.Contains((signal, connection)))
{
if (signal.source.LastSentSignalRecipients.Count(recipient => recipient == connection) > 2)
{
return;
}
delayedSignals.Add((signal, connection));
CoroutineManager.StartCoroutine(DelaySignal(signal, connection));
}
//use a coroutine to prevent infinite loops by creating a one
//frame delay if the "signal chain" gets too long
CoroutineManager.StartCoroutine(DelaySignal(signal, connection));
}
else
{
@@ -2045,7 +2055,8 @@ namespace Barotrauma
//wait one frame
yield return CoroutineStatus.Running;
signal.stepsTaken = 0;
delayedSignals.Remove((signal, connection));
signal.source = this;
connection.SendSignal(signal);