Fix the timestep jank threshold.

This commit is contained in:
Paul Chote
2014-03-13 10:57:29 +13:00
committed by Matthias Mailänder
parent d5edbc2bc7
commit 7e9793fa90

View File

@@ -74,9 +74,8 @@ namespace OpenRA
public static int NetFrameNumber { get { return orderManager.NetFrameNumber; } } public static int NetFrameNumber { get { return orderManager.NetFrameNumber; } }
public static int LocalTick { get { return orderManager.LocalFrameNumber; } } public static int LocalTick { get { return orderManager.LocalFrameNumber; } }
public const int NetTickScale = 3; // 120 ms net tick for 40 ms local tick public const int NetTickScale = 3; // 120 ms net tick for 40 ms local tick
public const int MinTick = 1;
public const int MaxTick = 10;
public const int Timestep = 40; public const int Timestep = 40;
public const int TimestepJankThreshold = 250; // Don't catch up for delays larger than 250ms
public static event Action<OrderManager> ConnectionStateChanged = _ => { }; public static event Action<OrderManager> ConnectionStateChanged = _ => { };
static ConnectionState lastConnectionState = ConnectionState.PreConnecting; static ConnectionState lastConnectionState = ConnectionState.PreConnecting;
@@ -181,9 +180,13 @@ namespace OpenRA
if (worldTimestep != 0 && worldTickDelta >= worldTimestep) if (worldTimestep != 0 && worldTickDelta >= worldTimestep)
using (new PerfSample("tick_time")) using (new PerfSample("tick_time"))
{ {
var relativeTickDelta = (worldTickDelta / worldTimestep) * worldTimestep; // Tick the world to advance the world time to match real time:
var tickIntervall = relativeTickDelta > MinTick && relativeTickDelta < MaxTick ? MinTick : relativeTickDelta; // If dt < TickJankThreshold then we should try and catch up by repeatedly ticking
orderManager.LastTickTime += tickIntervall; // If dt >= TickJankThreshold then we should accept the jank and progress at the normal rate
// dt is rounded down to an integer tick count in order to preserve fractional tick components.
var integralTickTimestep = (worldTickDelta / worldTimestep) * worldTimestep;
orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep;
if (orderManager.GameStarted) if (orderManager.GameStarted)
++Viewport.TicksSinceLastMove; ++Viewport.TicksSinceLastMove;