- server doesn't create a new EntityEvent if there's a duplicate event waiting to be sent

- hull, radar, steering & pump syncing
This commit is contained in:
Regalis
2016-11-14 16:58:21 +02:00
parent 44d87613b9
commit 0c9a55e9e0
10 changed files with 166 additions and 51 deletions

View File

@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Specialized;
@@ -7,15 +8,13 @@ using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
class Pump : Powered
class Pump : Powered, IServerSerializable, IClientSerializable
{
private float flowPercentage;
private float maxFlow;
private float? targetLevel;
private float lastUpdate;
public Hull hull1;
private GUITickBox isActiveTickBox;
@@ -75,6 +74,15 @@ namespace Barotrauma.Items.Components
IsActive = !IsActive;
if (!IsActive) currPowerConsumption = 0.0f;
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
}
else if (GameMain.Client != null)
{
item.CreateClientEvent(this);
}
return true;
};
@@ -83,6 +91,15 @@ namespace Barotrauma.Items.Components
{
FlowPercentage -= 10.0f;
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
}
else if (GameMain.Client != null)
{
item.CreateClientEvent(this);
}
return true;
};
@@ -91,6 +108,15 @@ namespace Barotrauma.Items.Components
{
FlowPercentage += 10.0f;
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
}
else if (GameMain.Client != null)
{
item.CreateClientEvent(this);
}
return true;
};
}

View File

@@ -1,4 +1,5 @@
using FarseerPhysics;
using Barotrauma.Networking;
using FarseerPhysics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -8,7 +9,7 @@ using Voronoi2;
namespace Barotrauma.Items.Components
{
class Radar : Powered
class Radar : Powered, IServerSerializable, IClientSerializable
{
private float range;
@@ -56,6 +57,14 @@ namespace Barotrauma.Items.Components
isActiveTickBox = new GUITickBox(new Rectangle(0, 0, 20, 20), "Sonar", Alignment.TopLeft, GuiFrame);
isActiveTickBox.OnSelected = (GUITickBox box) =>
{
if (GameMain.Server != null)
{
item.CreateServerEvent(this);
}
else if (GameMain.Client != null)
{
item.CreateClientEvent(this);
}
IsActive = box.Selected;
return true;
@@ -420,6 +429,8 @@ namespace Barotrauma.Items.Components
{
IsActive = msg.ReadBoolean();
isActiveTickBox.Selected = IsActive;
item.CreateServerEvent(this);
}
public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null)

View File

@@ -1,4 +1,5 @@
using FarseerPhysics;
using Barotrauma.Networking;
using FarseerPhysics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
@@ -11,7 +12,7 @@ using Voronoi2;
namespace Barotrauma.Items.Components
{
class Steering : Powered
class Steering : Powered, IServerSerializable, IClientSerializable
{
private const float AutopilotRayCastInterval = 0.5f;
@@ -30,7 +31,7 @@ namespace Barotrauma.Items.Components
private PathFinder pathFinder;
private float networkUpdateTimer;
private bool valueChanged;
private bool unsentChanges;
private float autopilotRayCastTimer;
@@ -112,7 +113,7 @@ namespace Barotrauma.Items.Components
autopilotTickBox.OnSelected = (GUITickBox box) =>
{
AutoPilot = box.Selected;
valueChanged = true;
unsentChanges = true;
return true;
};
@@ -139,13 +140,22 @@ namespace Barotrauma.Items.Components
public override void Update(float deltaTime, Camera cam)
{
if (valueChanged)
if (unsentChanges)
{
networkUpdateTimer -= deltaTime;
if (networkUpdateTimer <= 0.0f)
{
if (GameMain.Client != null)
{
item.CreateClientEvent(this);
}
else if (GameMain.Server != null)
{
item.CreateServerEvent(this);
}
networkUpdateTimer = 0.5f;
valueChanged = false;
unsentChanges = false;
}
}
@@ -219,7 +229,7 @@ namespace Barotrauma.Items.Components
TargetVelocity = PlayerInput.MousePosition - new Vector2(velRect.Center.X, velRect.Center.Y);
targetVelocity.Y = -targetVelocity.Y;
valueChanged = true;
unsentChanges = true;
}
}
}
@@ -389,7 +399,7 @@ namespace Barotrauma.Items.Components
private bool ToggleMaintainPosition(GUITickBox tickBox)
{
valueChanged = true;
unsentChanges = true;
levelStartTickBox.Selected = false;
levelEndTickBox.Selected = false;
@@ -410,7 +420,7 @@ namespace Barotrauma.Items.Components
private bool SelectDestination(GUITickBox tickBox)
{
valueChanged = true;
unsentChanges = true;
if (tickBox == levelStartTickBox)
{
@@ -501,6 +511,9 @@ namespace Barotrauma.Items.Components
}
}
}
//notify all clients of the changed state
unsentChanges = true;
}
public void ServerWrite(Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c, object[] extraData = null)