ItemComponent syncing fixes:

- Relay and lightcomponent states are synced (otherwise clients won't be notified if the state is, for example, toggled by a signal from a button).
- Clients don't play door sounds if a signal attempts to set the state to the same value as the predicted state, but DO play if a correction from the server changes the state from the predicted one.
- Clients are notified if a reactor receives a shutdown signal.
- Powercontainer updates are sent if the charge changes by 1%, not by 1 unit.
This commit is contained in:
Regalis
2017-04-11 20:36:52 +03:00
parent 347f549ac1
commit 9a36df0f52
5 changed files with 49 additions and 16 deletions
@@ -1,14 +1,14 @@
using System;
using Barotrauma.Networking;
using Lidgren.Network;
using System;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class RelayComponent : PowerTransfer
class RelayComponent : PowerTransfer, IServerSerializable
{
private float maxPower;
private float lastReceivedMessage;
[Editable, HasDefaultValue(1000.0f, true)]
public float MaxPower
{
@@ -75,19 +75,34 @@ namespace Barotrauma.Items.Components
}
else if (connection.Name == "toggle")
{
SetState(!IsOn);
SetState(!IsOn, false);
}
else if (connection.Name == "set_state")
{
SetState(signal != "0");
SetState(signal != "0", false);
}
}
public void SetState(bool on)
public void SetState(bool on, bool isNetworkMessage)
{
//if (GameMain.Client != null && !isNetworkMessage) return;
if (GameMain.Client != null && !isNetworkMessage) return;
if (on != IsOn && GameMain.Server != null)
{
item.CreateServerEvent(this);
}
IsOn = on;
}
public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
{
msg.Write(isOn);
}
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
SetState(msg.ReadBoolean(), true);
}
}
}