Пример #1
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);
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Inserts a new object into the queue.
        /// </summary>
        public void Add(Time time, ClockHandler h)
        {
            int    i = list.IndexOfKey(time);
            object o = new HandlerWrapper(h);

            if (i < 0)
            {
                ArrayList a = new ArrayList(arrayCapacity);
                a.Add(o);
                list.Add(time, a);
                i = list.IndexOfKey(time);
            }
            else
            {
                ((ArrayList)list.GetByIndex(i)).Add(o);
            }
            if (i < prevIndex)
            {
                prevIndex++;
            }
            count++;
        }
Пример #3
0
        private void setClockHandlers()
        {
            //long today_h = TimeLength.pastMinutesToday().totalMinutes;
            long today_h = clock.hour;
            long today_m = today_h * Time.HOUR + clock.minutes;

            // MajorEvent occures both day and night. Generate trend making events.
            if (MajorUpdateEvent != null)
            {
                clock.unregister(MajorUpdateEvent);
            }
            MajorUpdateEvent = new ClockHandler(onMajorUpdate);
            long major = MajorUpdateStartingHour;

            while (major < today_h)
            {
                major += MajorUpdateIntervalHours;
            }
            clock.registerRepeated(MajorUpdateEvent,
                                   TimeLength.fromMinutes(major * Time.HOUR - today_m),
                                   TimeLength.fromHours(MajorUpdateIntervalHours));

            // MinorEvent dispached only in the business hours. Progresses trend only.
            if (MinorUpdateEvent != null)
            {
                clock.unregister(MinorUpdateEvent);
            }
            MinorUpdateEvent = new ClockHandler(onMinorUpdate);
            long minor = MinorUpdateStartingHour;

            while (minor < today_h)
            {
                minor += MinorUpdateIntervalHours;
            }
            clock.registerRepeated(MinorUpdateEvent,
                                   TimeLength.fromMinutes(minor * Time.HOUR - today_m),
                                   TimeLength.fromHours(MinorUpdateIntervalHours));
        }
Пример #4
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);
                }
            }
        }
Пример #5
0
        protected void Remove(ClockHandler h, int index)
        {
            ArrayList a = list.GetByIndex(index) as ArrayList;

            if (a != null)
            {
                for (int i = 0; i < a.Count; i++)
                {
                    HandlerWrapper hw = a[i] as HandlerWrapper;
                    if (hw.o.Equals(h))
                    {
                        a.RemoveAt(i);
                    }
                }
                if (a.Count == 0)
                {
                    list.Remove(index);
                    if (index < prevIndex)
                    {
                        prevIndex--;
                    }
                }
            }
        }
Пример #6
0
 // Use this for initialization
 public void Start()
 {
     if (isServer)
     {
         if (clockHandler == null)
         {
             clockHandler  = this;
             isMasterClock = true;
             actualTime    = 0;
             seconds       = 0;
             minuts        = 20;
             fixedTimeUnit = 0.1f;
         }
         if (isLocalPlayer)
         {
             //isMasterClock = true;
             fasterBtn.gameObject.SetActive(true);
             slowerBtn.gameObject.SetActive(true);
         }
         if (gameObject.tag == "player" && !isLocalPlayer)
         {
             isMasterClock = false;
         }
     }
     else
     {
         SetClockReference();
     }
     if (!playerId.isLocalPlayer)
     {
         if (gameObject.tag == "player")
         {
             clockText.gameObject.SetActive(false);
         }
     }
 }
Пример #7
0
 /// <summary>
 /// Unregisters a yearly repeated timer.
 /// </summary>
 public void UnregisterYearlyHandler(ClockHandler handler, Time time)
 {
     yearlyQueue.Remove(new Time(time.Ticks % YEAR), handler);
 }
Пример #8
0
 /// <summary>
 /// Unregisters a repeated timer.
 /// </summary>
 public void unregister(ClockHandler handler)
 {
     queue.remove(handler);
 }
Пример #9
0
 /// <summary>
 /// Registers an one-shot timer, which will be fired at
 /// the specified time.
 /// </summary>
 public void registerOneShot(ClockHandler handler, Time time)
 {
     registerOneShot(handler, time - World.world.clock);
 }
Пример #10
0
 /// <summary>
 /// Registers an one-shot timer, which will be fired at
 /// the specified time.
 /// </summary>
 public void registerOneShot(ClockHandler handler, Time time)
 {
     registerOneShot(handler, time - WorldDefinition.World.Clock);
 }
Пример #11
0
 /// <summary>
 /// Registers a repeated-timer, which will be fired
 /// periodically for every specified interval.
 ///
 /// The first clock notification will be sent also after the
 /// specified minutes.
 /// </summary>
 /// <returns>
 /// The cookie, which shall be then used to unregister the timer.
 /// </returns>
 public ClockHandler registerRepeated(ClockHandler handler, TimeLength time)
 {
     return(registerRepeated(handler, time, time));
 }
Пример #12
0
 /// <summary>
 /// Registers a daily-timer, which will be fired
 /// everyday at specified time.
 /// the value second of the 'time' is ignored.
 /// </summary>
 public void RegisterDailyHandler(ClockHandler handler, TimeOfDay time)
 {
     Debug.Assert(time.Ticks >= 0);
     dailyQueue.Add(time, handler);
 }
Пример #13
0
 /// <summary>
 /// Registers an one-shot timer, which will be fired after
 /// the specified time span.
 /// </summary>
 public void registerOneShot(ClockHandler handler, TimeLength time)
 {
     Debug.Assert(time.totalMinutes > 0);
     queue.insert(currentTime + time.totalMinutes, handler);
 }
Пример #14
0
 /// <summary>
 /// Registers an one-shot timer, which will be fired at
 /// the specified time.
 /// </summary>
 public void RegisterOneShot(ClockHandler handler, Time time)
 {
     Debug.Assert(this < time);
     oneshotQueue.Add(time, handler);
 }
Пример #15
0
 /// <summary>
 /// Registers an one-shot timer, which will be fired at
 /// the specified time.
 /// </summary>
 public void RegisterOneShot(ClockHandler handler, TimeOfDay time)
 {
     RegisterOneShot(handler, UntilTheTime(time));
 }
Пример #16
0
 public HandlerWrapper(ClockHandler h)
 {
     o = h;
 }
Пример #17
0
 /// <summary>
 /// Registers an one-shot timer, which will be fired after
 /// the specified time span.
 /// </summary>
 public void RegisterOneShot(ClockHandler handler, TimeLength time)
 {
     Debug.Assert(time.TotalSeconds > 0);
     oneshotQueue.Add(this + time, handler);
 }
Пример #18
0
 /// <summary>
 /// Unregisters a weekly repeated timer.
 /// </summary>
 public void UnregisterWeeklyHandler(ClockHandler handler, DayOfWeek week, TimeOfDay time)
 {
     weeklyQueue[(int)week].Remove(time, handler);
 }
Пример #19
0
 /// <summary>
 /// Unregisters a daily repeated timer.
 /// </summary>
 public void UnregisterDailyHandler(ClockHandler handler, TimeOfDay time)
 {
     dailyQueue.Remove(time, handler);
 }
Пример #20
0
 /// <summary>
 /// Registers a yearly-timer, which will be fired
 /// everyyear at specified time.
 /// the value second and year of the 'time' is ignored.
 /// </summary>
 public void RegisterYearlyHandler(ClockHandler handler, Time time)
 {
     Debug.Assert(time.Ticks >= 0);
     yearlyQueue.Add(new Time(time.Ticks % YEAR), handler);
 }
Пример #21
0
 /// <summary>
 /// Registers a weekly-timer, which will be fired
 /// everyweek at specified time.
 /// the value second of the 'time' is ignored.
 /// </summary>
 public void RegisterWeeklyHandler(ClockHandler handler, DayOfWeek week, TimeOfDay time)
 {
     Debug.Assert(time.Ticks >= 0);
     weeklyQueue[(int)week].Add(time, handler);
 }
Пример #22
0
 /// <summary>
 /// Subscribe to the ClockEvent
 /// </summary>
 /// <param name="iCO"></param>
 public void Unsubscribe(IClockObserver iCO)
 {
     TimeHandler -= new ClockHandler <CombatTime>(iCO.ClockTimeChangedEvent);
 }