예제 #1
0
        /// <summary>
        /// Forces a time sync against the server time
        /// </summary>
        public void ForceTimeSync()
        {
            if (Enabled && !CurrentlyWarping && CanSyncTime && !WarpSystem.Singleton.WaitingSubspaceIdFromServer)
            {
                var targetTime   = WarpSystem.Singleton.CurrentSubspaceTime;
                var currentError = TimeUtil.SecondsToMilliseconds(CurrentErrorSec);

                LunaLog.LogWarning($"FORCING a time sync from: {Planetarium.GetUniversalTime()} to: {targetTime}. Error:{currentError}");
                ClockHandler.StepClock(targetTime);
            }
        }
예제 #2
0
 /// <summary>
 /// Routine that checks our time against the server time and adjust it if needed.
 /// If the error is too big this routine will adjust the clock with the planetarium instead of accelerating / decreasing the game time
 /// </summary>
 /// <returns></returns>
 private void SyncTime()
 {
     if (Enabled && !CurrentlyWarping && CanSyncTime && !SystemsContainer.Get <WarpSystem>().WaitingSubspaceIdFromServer)
     {
         var targetTime   = (int)SystemsContainer.Get <WarpSystem>().CurrentSubspaceTime;
         var currentError = TimeSpan.FromSeconds(CurrentErrorSec).TotalMilliseconds;
         if (targetTime != 0 && Math.Abs(currentError) > MaxClockErrorMs)
         {
             LunaLog.LogWarning($"[LMP] Adjusted time from: {Planetarium.GetUniversalTime()} to: {targetTime} due to error:{currentError}");
             ClockHandler.StepClock(targetTime);
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Routine that checks our time against the server time and adjust it if needed.
 /// If the error is too big this routine will adjust the clock with the planetarium instead of accelerating / decreasing the game time
 /// </summary>
 /// <returns></returns>
 private void SyncTime()
 {
     if (Enabled && !CurrentlyWarping && CanSyncTime && !WarpSystem.Singleton.WaitingSubspaceIdFromServer)
     {
         var targetTime   = WarpSystem.Singleton.CurrentSubspaceTime;
         var currentError = TimeUtil.SecondsToMilliseconds(CurrentErrorSec);
         if (targetTime != 0 && Math.Abs(currentError) > MaxClockErrorMs)
         {
             LunaLog.LogWarning($"[LMP] Adjusted time from: {Planetarium.GetUniversalTime()} to: {targetTime} due to error:{currentError}");
             ClockHandler.StepClock(targetTime);
         }
     }
 }
예제 #4
0
 /// <summary>
 /// Routine that checks our time against the server time and adjust it if needed.
 /// </summary>
 /// <returns></returns>
 private void SyncTime()
 {
     if (Enabled && Synced && !CurrentlyWarping && CanSyncTime() && !SystemsContainer.Get <WarpSystem>().WaitingSubspaceIdFromServer)
     {
         var targetTime   = SystemsContainer.Get <WarpSystem>().GetCurrentSubspaceTime();
         var currentError = TimeSpan.FromSeconds(GetCurrentError()).TotalMilliseconds;
         if (targetTime != 0 && Math.Abs(currentError) > MaxClockMsError)
         {
             if (Math.Abs(currentError) > MaxClockSkew)
             {
                 LunaLog.LogWarning($"[LMP] Adjusted time from: {Planetarium.GetUniversalTime()} to: {targetTime} due to error:{currentError}");
                 //TODO: This causes the throttle to reset when called.  This happens due to vessel unpacking resetting the throttle controls.
                 //TODO: Try to get Squad to change their code.
                 ClockHandler.StepClock(targetTime);
             }
             else
             {
                 SkewClock(currentError);
             }
         }
     }
 }
예제 #5
0
        /// <summary>
        /// Routine that checks our time against the server time and adjust it if needed.
        /// We only adjust the GAME time. And we will only do if the time error is between <see cref="MinPhisicsClockMsError"/> and <see cref="MaxPhisicsClockMsError"/>
        /// We cannot do it with more than <see cref="MaxPhisicsClockMsError"/> as then we would need a lot of time to catch up with the time error.
        /// For greater errors we just fix the time with the StepClock
        /// </summary>
        private void SyncTimeScale()
        {
            if (Enabled && !CurrentlyWarping && CanSyncTime && !WarpSystem.Singleton.WaitingSubspaceIdFromServer)
            {
                var targetTime   = WarpSystem.Singleton.CurrentSubspaceTime;
                var currentError = TimeUtil.SecondsToMilliseconds(CurrentErrorSec);

                if (Math.Abs(currentError) < MinPhisicsClockMsError)
                {
                    Time.timeScale = 1;
                }
                if (Math.Abs(currentError) > MinPhisicsClockMsError && Math.Abs(currentError) < MaxPhisicsClockMsError)
                {
                    //Time error is not so big so we can fix it adjusting the physics time
                    SkewClock();
                }
                else if (Math.Abs(currentError) > MaxPhisicsClockMsError)
                {
                    LunaLog.LogWarning($"[LMP] Adjusted time from: {UniversalTime} to: {targetTime} due to error: {currentError}");
                    ClockHandler.StepClock(targetTime);
                }
            }
        }