EntityEventManagers wait for 1.5*roundtriptime before resending messages (less unnecessary resends), skipping to the next event in a packet if an exception is thrown while reading an event

This commit is contained in:
Regalis
2016-12-09 20:00:41 +02:00
parent 63ca7254b2
commit 9192dad6ea
3 changed files with 18 additions and 3 deletions
@@ -59,7 +59,8 @@ namespace Barotrauma.Networking
float lastSent = 0; float lastSent = 0;
eventLastSent.TryGetValue(events[i].ID, out lastSent); eventLastSent.TryGetValue(events[i].ID, out lastSent);
if (lastSent > NetTime.Now - serverConnection.AverageRoundtripTime) //wait for 1.5f * roundtriptime until resending
if (lastSent > NetTime.Now - serverConnection.AverageRoundtripTime * 1.5f)
{ {
break; break;
} }
@@ -73,9 +73,22 @@ namespace Barotrauma.Networking
} }
else else
{ {
long msgPosition = msg.Position;
DebugConsole.NewMessage("received msg "+thisEventID, Microsoft.Xna.Framework.Color.Green); DebugConsole.NewMessage("received msg "+thisEventID, Microsoft.Xna.Framework.Color.Green);
lastReceivedID++; lastReceivedID++;
ReadEvent(msg, entity, sendingTime, sender); try
{
ReadEvent(msg, entity, sendingTime, sender);
}
catch (Exception e)
{
#if DEBUG
DebugConsole.ThrowError("Failed to read event for entity \""+entity.ToString()+"\"!", e);
#endif
msg.Position = msgPosition + msgLength * 8;
}
} }
msg.ReadPadBits(); msg.ReadPadBits();
} }
@@ -58,7 +58,8 @@ namespace Barotrauma.Networking
float lastSent = 0; float lastSent = 0;
client.entityEventLastSent.TryGetValue(events[i].ID, out lastSent); client.entityEventLastSent.TryGetValue(events[i].ID, out lastSent);
if (lastSent > NetTime.Now - client.Connection.AverageRoundtripTime) //wait for 1.5f * roundtriptime until resending
if (lastSent > NetTime.Now - client.Connection.AverageRoundtripTime * 1.5f)
{ {
break; break;
} }