Unstable 0.17.1.0

This commit is contained in:
Markus Isberg
2022-03-17 01:25:04 +09:00
parent 3974067915
commit 6d410cc1b7
302 changed files with 5878 additions and 3317 deletions
@@ -15,6 +15,8 @@ namespace Barotrauma.Items.Components
//the output is sent if both inputs have received a signal within the timeframe
protected float timeFrame;
protected readonly Character[] signalSender = new Character[2];
[Serialize(999999.0f, IsPropertySaveable.Yes, description: "The output of the item is restricted below this value.", alwaysUseInstanceValues: true),
InGameEditable(MinValueFloat = -999999.0f, MaxValueFloat = 999999.0f)]
public float ClampMax
@@ -33,7 +35,7 @@ namespace Barotrauma.Items.Components
[InGameEditable(DecimalCount = 2),
Serialize(0.0f, IsPropertySaveable.Yes, description: "The item must have received signals to both inputs within this timeframe to output the result." +
" If set to 0, the inputs must be received at the same time.", alwaysUseInstanceValues: true)]
" If set to 0, the inputs must be received at the same time.", alwaysUseInstanceValues: true, translationTextTag: "sp.")]
public float TimeFrame
{
get { return timeFrame; }
@@ -71,7 +73,7 @@ namespace Barotrauma.Items.Components
float output = Calculate(receivedSignal[0], receivedSignal[1]);
if (MathUtils.IsValid(output))
{
item.SendSignal(MathHelper.Clamp(output, ClampMin, ClampMax).ToString("G", CultureInfo.InvariantCulture), "signal_out");
item.SendSignal(new Signal(MathHelper.Clamp(output, ClampMin, ClampMax).ToString("G", CultureInfo.InvariantCulture), sender: signalSender[0] ?? signalSender[1]), "signal_out");
}
}
@@ -83,11 +85,13 @@ namespace Barotrauma.Items.Components
{
case "signal_in1":
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[0]);
signalSender[0] = signal.sender;
timeSinceReceived[0] = 0.0f;
IsActive = true;
break;
case "signal_in2":
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out receivedSignal[1]);
signalSender[1] = signal.sender;
timeSinceReceived[1] = 0.0f;
IsActive = true;
break;
@@ -109,10 +109,23 @@ namespace Barotrauma.Items.Components
return true;
}
private void Write(IWriteMessage msg, object[] extraData)
private readonly struct EventData : IEventData
{
if (extraData == null || extraData.Length < 3) { return; }
msg.WriteRangedInteger((int)extraData[2], 0, Signals.Length - 1);
public readonly int SignalIndex;
public EventData(int signalIndex)
{
SignalIndex = signalIndex;
}
}
public override bool ValidateEventData(NetEntityEvent.IData data)
=> TryExtractEventData<EventData>(data, out _);
private void Write(IWriteMessage msg, NetEntityEvent.IData extraData)
{
var eventData = ExtractEventData<EventData>(extraData);
msg.WriteRangedInteger(eventData.SignalIndex, 0, Signals.Length - 1);
}
}
}
@@ -400,7 +400,7 @@ namespace Barotrauma.Items.Components
}
public void ClientWrite(IWriteMessage msg, object[] extraData = null)
public void ClientEventWrite(IWriteMessage msg, NetEntityEvent.IData extraData = null)
{
#if CLIENT
TriggerRewiringSound();
@@ -8,6 +8,16 @@ namespace Barotrauma.Items.Components
{
partial class CustomInterface : ItemComponent, IClientSerializable, IServerSerializable
{
private readonly struct EventData : IEventData
{
public readonly CustomInterfaceElement BtnElement;
public EventData(CustomInterfaceElement btnElement)
{
BtnElement = btnElement;
}
}
class CustomInterfaceElement : ISerializableEntity
{
public bool ContinuousSignal;
@@ -1,7 +1,6 @@
using FarseerPhysics;
using Microsoft.Xna.Framework;
using System;
using System.Linq;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
@@ -1,13 +1,11 @@
using System.Xml.Linq;
namespace Barotrauma.Items.Components
namespace Barotrauma.Items.Components
{
class NotComponent : ItemComponent
{
private bool signalReceived;
private bool continuousOutput;
[Editable, Serialize(false, IsPropertySaveable.Yes, description: "When enabled, the component continuously outputs \"1\" when it's not receiving a signal.", alwaysUseInstanceValues: true)]
[InGameEditable, Serialize(false, IsPropertySaveable.Yes, description: "When enabled, the component continuously outputs \"1\" when it's not receiving a signal.", alwaysUseInstanceValues: true)]
public bool ContinuousOutput
{
get { return continuousOutput; }
@@ -372,12 +372,12 @@ namespace Barotrauma.Items.Components
IsOn = on;
}
public void ServerWrite(IWriteMessage msg, Client c, object[] extraData = null)
public void ServerEventWrite(IWriteMessage msg, Client c, NetEntityEvent.IData extraData = null)
{
msg.Write(isOn);
}
public void ClientRead(ServerNetObject type, IReadMessage msg, float _)
public void ClientEventRead(IReadMessage msg, float sendingTime)
{
SetState(msg.ReadBoolean(), true);
}
@@ -68,7 +68,7 @@ namespace Barotrauma.Items.Components
{
foreach (FireSource fireSource in hull.FireSources)
{
if (fireSource.IsInDamageRange(item.WorldPosition, fireSource.DamageRange * 2.0f)) { return true; }
if (fireSource.IsInDamageRange(item.WorldPosition, Math.Max(fireSource.DamageRange * 2.0f, 500.0f))) { return true; }
}
}
@@ -1,7 +1,4 @@
using Microsoft.Xna.Framework;
using System;
using System.Globalization;
using System.Xml.Linq;
using System;
namespace Barotrauma.Items.Components
{
@@ -20,6 +20,8 @@ namespace Barotrauma.Items.Components
private readonly float[] receivedSignal = new float[2];
private readonly float[] timeSinceReceived = new float[2];
protected Character signalSender;
[Serialize(FunctionType.Sin, IsPropertySaveable.No, description: "Which kind of function to run the input through.", alwaysUseInstanceValues: true)]
public FunctionType Function
{
@@ -56,7 +58,7 @@ namespace Barotrauma.Items.Components
{
float angle = (float)Math.Atan2(receivedSignal[1], receivedSignal[0]);
if (!UseRadians) { angle = MathHelper.ToDegrees(angle); }
item.SendSignal(angle.ToString("G", CultureInfo.InvariantCulture), "signal_out");
item.SendSignal(new Signal(angle.ToString("G", CultureInfo.InvariantCulture), sender: signalSender), "signal_out");
}
}
}
@@ -65,6 +67,7 @@ namespace Barotrauma.Items.Components
{
float.TryParse(signal.value, NumberStyles.Float, CultureInfo.InvariantCulture, out float value);
bool sendOutputImmediately = true;
signalSender = signal.sender;
switch (Function)
{
case FunctionType.Sin:
@@ -455,12 +455,7 @@ namespace Barotrauma.Items.Components
#if CLIENT
if (GameMain.NetworkMember != null)
{
GameMain.Client.CreateEntityEvent(item, new object[]
{
NetEntityEvent.Type.ComponentState,
item.GetComponentIndex(this),
nodes.Count
});
item.CreateClientEvent(this, new ClientEventData(nodes.Count));
}
#endif
}
@@ -482,12 +477,7 @@ namespace Barotrauma.Items.Components
#if CLIENT
if (GameMain.NetworkMember != null)
{
GameMain.Client.CreateEntityEvent(item, new object[]
{
NetEntityEvent.Type.ComponentState,
item.GetComponentIndex(this),
nodes.Count
});
item.CreateClientEvent(this, new ClientEventData(nodes.Count));
}
#endif
}