Reactors, sonars, nav terminals, pumps and batteries use similar delayed correction logic as doors and inventories.

I.e. the clients delay correcting the state of the item until the local player stops manipulating the state (atm the delay is 1 sec). Prevents pumping speeds, steering directions and whatnot from switching to an old state and back - now the corrections should not be visible to the players unless the client predicts the state wrong.
This commit is contained in:
Regalis
2017-04-11 00:41:12 +03:00
parent fac31b4892
commit 347f549ac1
8 changed files with 114 additions and 25 deletions
@@ -80,6 +80,7 @@ namespace Barotrauma.Items.Components
}
else if (GameMain.Client != null)
{
correctionTimer = CorrectionDelay;
item.CreateClientEvent(this);
}
@@ -97,6 +98,7 @@ namespace Barotrauma.Items.Components
}
else if (GameMain.Client != null)
{
correctionTimer = CorrectionDelay;
item.CreateClientEvent(this);
}
@@ -114,6 +116,7 @@ namespace Barotrauma.Items.Components
}
else if (GameMain.Client != null)
{
correctionTimer = CorrectionDelay;
item.CreateClientEvent(this);
}
@@ -234,7 +237,7 @@ namespace Barotrauma.Items.Components
msg.Write(IsActive);
}
public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Client c)
{
float flowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
bool isActive = msg.ReadBoolean();
@@ -243,9 +246,12 @@ namespace Barotrauma.Items.Components
FlowPercentage = flowPercentage;
IsActive = isActive;
//notify all clients of the changed state
item.CreateServerEvent(this);
}
public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null)
public void ServerWrite(Lidgren.Network.NetBuffer msg, Client c, object[] extraData = null)
{
//flowpercentage can only be adjusted at 10% intervals -> no need for more accuracy than this
msg.WriteRangedInteger(-10, 10, (int)(flowPercentage / 10.0f));
@@ -254,6 +260,12 @@ namespace Barotrauma.Items.Components
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
{
if (correctionTimer > 0.0f)
{
StartDelayedCorrection(type, msg.ExtractBits(5 + 1), sendingTime);
return;
}
FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
IsActive = msg.ReadBoolean();
}