/// <summary> /// This method adjust the extra interpolation duration in case we are lagging or too advanced. /// The idea is that we replay the message at the correct time that is GameTimeWhenMessageWasSent+InterpolationOffset /// In order to adjust we increase or decrease the interpolation duration so next packet matches the time more perfectly /// </summary> public void AdjustExtraInterpolationTimes() { TimeDifference = TimeSyncSystem.UniversalTime - GameTimeStamp - VesselCommon.PositionAndFlightStateMessageOffsetSec(PingSec); if (WarpSystem.Singleton.CurrentlyWarping || SubspaceId == -1) { //This is the case when the message was received while warping or we are warping. /* We are warping: * While WE warp if we receive a message that is from before our time, we want to skip it as fast as possible! * If the packet is in the future then we must interpolate towards it * * Player was warping: * The message was received when HE was warping. We don't know his final subspace time BUT if the message was sent * in a time BEFORE ours, we can skip it as fast as possible. * If the packet is in the future then we must interpolate towards it * * Bear in mind that even if the interpolation against the future packet is long because he is in the future, * when we stop warping this method will be called * * Also, we don't remove messages if we are close to the min recommended value * */ if (TimeDifference > 0) { //This means that we are behind and we must consume the message fast CurrentFrame = float.MaxValue; } else { ExtraInterpolationTime = GetInterpolationFixFactor(); } } else { //This is the easiest case, the message comes from the same or a past subspace //IN past or same subspaces we want to be SettingsSystem.CurrentSettings.InterpolationOffset seconds BEHIND the player position if (WarpSystem.Singleton.SubspaceIsInThePast(SubspaceId)) { /* The subspace is in the past so REMOVE the difference to normalize it * Example: P1 subspace is +7 seconds. Your subspace is + 30 seconds * Packet TimeDifference will be 23 seconds but in reality it should be 0 * So, we remove the time difference between subspaces (30 - 7 = 23) * And now the TimeDifference - 23 = 0 */ var timeToAdd = Math.Abs(WarpSystem.Singleton.GetTimeDifferenceWithGivenSubspace(SubspaceId)); TimeDifference -= timeToAdd; } ExtraInterpolationTime = (TimeDifference > 0 ? -1 : 1) * GetInterpolationFixFactor(); } }
private static bool PositionUpdateIsTooOld(VesselPositionUpdate update) { return(update.GameTimeStamp < TimeSyncSystem.UniversalTime - VesselCommon.PositionAndFlightStateMessageOffsetSec(update.PingMs)); }