ServerEntityEventManager doesn't process received events until the character inputs of the client for the corresponding frame have been processed (fixes character movement lagging behind EntityEvents at the servers side)

+ split character networking logic into a separate file, characters drop items at the position of their collider instead of hands
This commit is contained in:
Regalis
2017-02-09 18:56:28 +02:00
parent 1f16bef01c
commit 52bf73722f
29 changed files with 959 additions and 827 deletions
@@ -333,9 +333,9 @@ namespace Barotrauma.Items.Components
powerConnection.TryAddLink(wire);
wire.Connect(powerConnection, false);
wire.Connect(powerConnection, false, false);
recipient.TryAddLink(wire);
wire.Connect(recipient, false);
wire.Connect(recipient, false, false);
}
private void CreateDoorBody()
@@ -756,7 +756,7 @@ namespace Barotrauma.Items.Components
}
}
public void ClientRead(ServerNetObject type, Lidgren.Network.NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
{
bool isDocked = msg.ReadBoolean();
+1 -1
View File
@@ -536,7 +536,7 @@ namespace Barotrauma.Items.Components
msg.WriteRangedSingle(stuck, 0.0f, 100.0f, 8);
}
public void ClientRead(ServerNetObject type, Lidgren.Network.NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
{
SetState(msg.ReadBoolean(), true);
Stuck = msg.ReadRangedSingle(0.0f, 100.0f, 8);
@@ -121,13 +121,16 @@ namespace Barotrauma.Items.Components
{
if (dropper == null) return;
picker = dropper;
}
if (picker.Inventory == null) return;
item.Submarine = picker.Submarine;
//item.Unequip();
if (item.body != null)
{
item.body.ResetDynamics();
item.SetTransform(picker.SimPosition, 0.0f);
}
picker.DeselectItem(item);
picker.Inventory.RemoveItem(item);
@@ -191,21 +191,15 @@ namespace Barotrauma.Items.Components
DropConnectedWires(picker);
item.Submarine = picker.Submarine;
Limb rightHand = picker.AnimController.GetLimb(LimbType.RightHand);
bodyDropPos = rightHand.SimPosition;
if (item.body != null)
{
item.body.ResetDynamics();
}
bodyDropPos = picker.SimPosition;
picker.Inventory.RemoveItem(item);
picker = null;
}
if (item.body != null && !item.body.Enabled)
{
item.body.ResetDynamics();
item.SetTransform(bodyDropPos, 0.0f);
item.body.Enabled = true;
}
@@ -147,7 +147,7 @@ namespace Barotrauma.Items.Components
msg.Write(IsActive);
}
public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c)
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
{
bool active = msg.ReadBoolean();
@@ -164,7 +164,7 @@ namespace Barotrauma.Items.Components
msg.Write(IsActive);
}
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
SetActive(msg.ReadBoolean());
}
@@ -453,7 +453,7 @@ namespace Barotrauma.Items.Components
msg.WriteRangedInteger(-1, fabricableItems.Count - 1, itemIndex);
}
public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c)
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
{
int itemIndex = msg.ReadRangedInteger(-1, fabricableItems.Count - 1);
@@ -482,7 +482,7 @@ namespace Barotrauma.Items.Components
msg.WriteRangedInteger(-1, fabricableItems.Count - 1, itemIndex);
}
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
int itemIndex = msg.ReadRangedInteger(-1, fabricableItems.Count - 1);
@@ -234,7 +234,7 @@ namespace Barotrauma.Items.Components
msg.Write(IsActive);
}
public void ServerRead(ClientNetObject type, Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c)
public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
{
float flowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
bool isActive = msg.ReadBoolean();
@@ -252,7 +252,7 @@ namespace Barotrauma.Items.Components
msg.Write(IsActive);
}
public void ClientRead(ServerNetObject type, Lidgren.Network.NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
{
FlowPercentage = msg.ReadRangedInteger(-10, 10) * 10.0f;
IsActive = msg.ReadBoolean();
@@ -431,7 +431,7 @@ namespace Barotrauma.Items.Components
msg.Write(IsActive);
}
public void ServerRead(ClientNetObject type, Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c)
public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
{
bool isActive = msg.ReadBoolean();
@@ -448,7 +448,7 @@ namespace Barotrauma.Items.Components
msg.Write(IsActive);
}
public void ClientRead(ServerNetObject type, Lidgren.Network.NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
{
IsActive = msg.ReadBoolean();
isActiveTickBox.Selected = IsActive;
@@ -561,7 +561,7 @@ namespace Barotrauma.Items.Components
msg.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8);
}
public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c)
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
{
bool autoTemp = msg.ReadBoolean();
float shutDownTemp = msg.ReadRangedSingle(0.0f, 10000.0f, 8);
@@ -591,7 +591,7 @@ namespace Barotrauma.Items.Components
msg.WriteRangedSingle(fissionRate, 0.0f, 100.0f, 8);
}
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
Temperature = msg.ReadRangedSingle(0.0f, 10000.0f, 16);
@@ -486,7 +486,7 @@ namespace Barotrauma.Items.Components
}
}
public void ServerRead(ClientNetObject type, Lidgren.Network.NetIncomingMessage msg, Barotrauma.Networking.Client c)
public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
{
bool autoPilot = msg.ReadBoolean();
Vector2 newTargetVelocity = targetVelocity;
@@ -569,7 +569,7 @@ namespace Barotrauma.Items.Components
}
}
public void ClientRead(ServerNetObject type, Lidgren.Network.NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
{
bool autoPilot = msg.ReadBoolean();
Vector2 newTargetVelocity = targetVelocity;
@@ -348,7 +348,7 @@ namespace Barotrauma.Items.Components
draggingConnected.RemoveConnection(item);
if (draggingConnected.Connect(this, !alreadyConnected)) Wires[index] = draggingConnected;
if (draggingConnected.Connect(this, !alreadyConnected, true)) Wires[index] = draggingConnected;
}
}
}
@@ -477,7 +477,7 @@ namespace Barotrauma.Items.Components
if (Wires[i] != null)
{
if (Wires[i].Item.body != null) Wires[i].Item.body.Enabled = false;
Wires[i].Connect(this, false, true);
Wires[i].Connect(this, false, false);
}
}
}
@@ -173,7 +173,7 @@ namespace Barotrauma.Items.Components
}
}
public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c)
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
{
int[] wireCounts = new int[Connections.Count];
Wire[,] wires = new Wire[Connections.Count, Connection.MaxLinked];
@@ -244,7 +244,7 @@ namespace Barotrauma.Items.Components
ClientWrite(msg, extraData);
}
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
foreach (Connection connection in Connections)
{
@@ -133,7 +133,7 @@ namespace Barotrauma.Items.Components
if (connection == connections[1]) connections[1] = null;
}
public bool Connect(Connection newConnection, bool addNode = true, bool loading = false)
public bool Connect(Connection newConnection, bool addNode = true, bool sendNetworkEvent = false)
{
for (int i = 0; i < 2; i++)
{
@@ -196,7 +196,7 @@ namespace Barotrauma.Items.Components
CleanNodes();
}
if (!loading)
if (sendNetworkEvent)
{
if (GameMain.Server != null)
{
@@ -726,7 +726,7 @@ namespace Barotrauma.Items.Components
}
}
public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c)
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
{
nodes.Clear();
@@ -752,7 +752,7 @@ namespace Barotrauma.Items.Components
ClientWrite(msg, extraData);
}
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
nodes.Clear();
+3 -3
View File
@@ -546,7 +546,7 @@ namespace Barotrauma
syncItemsDelay = 1.0f;
}
public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Barotrauma.Networking.Client c)
public void ServerRead(ClientNetObject type, NetBuffer msg, Barotrauma.Networking.Client c)
{
List<Item> prevItems = new List<Item>(Items);
ushort[] newItemIDs = new ushort[capacity];
@@ -565,7 +565,7 @@ namespace Barotrauma
{
if (newItemIDs[i] == 0)
{
if (Items[i] != null) Items[i].Drop();
if (Items[i] != null) Items[i].Drop(c.Character);
System.Diagnostics.Debug.Assert(Items[i]==null);
}
else
@@ -609,7 +609,7 @@ namespace Barotrauma
}
}
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
receivedItemIDs = new ushort[capacity];
+5 -5
View File
@@ -1733,7 +1733,7 @@ namespace Barotrauma
}
}
public void ClientRead(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
{
if (type == ServerNetObject.ENTITY_POSITION)
{
@@ -1822,7 +1822,7 @@ namespace Barotrauma
}
}
public void ServerRead(ClientNetObject type, NetIncomingMessage msg, Client c)
public void ServerRead(ClientNetObject type, NetBuffer msg, Client c)
{
NetEntityEvent.Type eventType =
(NetEntityEvent.Type)msg.ReadRangedInteger(0, Enum.GetValues(typeof(NetEntityEvent.Type)).Length - 1);
@@ -1898,7 +1898,7 @@ namespace Barotrauma
}
}
private void ReadPropertyChange(NetIncomingMessage msg)
private void ReadPropertyChange(NetBuffer msg)
{
var allProperties = GetProperties<InGameEditable>();
if (allProperties.Count == 0) return;
@@ -1965,7 +1965,7 @@ namespace Barotrauma
if (Name == "ID Card") msg.Write(Tags);
}
public static Item ReadSpawnData(NetIncomingMessage msg, bool spawn = true)
public static Item ReadSpawnData(NetBuffer msg, bool spawn = true)
{
if (GameMain.Server != null) return null;
@@ -2090,7 +2090,7 @@ namespace Barotrauma
lastSentPos = SimPosition;
}
public void ClientReadPosition(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
public void ClientReadPosition(ServerNetObject type, NetBuffer msg, float sendingTime)
{
body.TargetPosition = new Vector2(