Esempio n. 1
0
        public void UpdateScheduledEvents()
        {
            try
            {
                m_TransactionMode = true;

                // TODO: On a GAME Panel game time should be per frame and not change during a frame.
                // TODO: On an Editor Panel time should be real time
                long currentTime = Panel.TimeSinceStartupMs();

                int itemsCount = m_ScheduledItems.Count;

                const long maxMsPerUpdate = 20;
                long       maxTime        = currentTime + maxMsPerUpdate;

                int startIndex = m_LastUpdatedIndex + 1;
                if (startIndex >= itemsCount)
                {
                    startIndex = 0;
                }


                for (int i = 0; i < itemsCount; i++)
                {
                    currentTime = Panel.TimeSinceStartupMs();

                    if (!disableThrottling && currentTime >= maxTime)
                    {
                        //We spent too much time on this frame updating items, we break for now, we'll resume next frame
                        break;
                    }
                    int index = startIndex + i;
                    if (index >= itemsCount)
                    {
                        index -= itemsCount;
                    }

                    ScheduledItem scheduledItem = m_ScheduledItems[index];

                    bool unscheduleItem = false;

                    if (currentTime - scheduledItem.delayMs >= scheduledItem.startMs)
                    {
                        TimerState timerState = new TimerState {
                            start = scheduledItem.startMs, now = currentTime
                        };

                        if (!m_UnscheduleTransactions.Contains(scheduledItem)) // Don't execute items that have been marked for future removal
                        {
                            scheduledItem.PerformTimerUpdate(timerState);
                        }

                        scheduledItem.startMs = currentTime;
                        scheduledItem.delayMs = scheduledItem.intervalMs;

                        if (scheduledItem.ShouldUnschedule())
                        {
                            unscheduleItem = true;
                        }
                    }

                    if (unscheduleItem || (scheduledItem.endTimeMs > 0 && currentTime > scheduledItem.endTimeMs))
                    {
                        // if the scheduledItem has been unscheduled explicitly in PerformTimerUpdate then
                        // it will be in m_UnscheduleTransactions and we shouldn't unschedule it again
                        if (!m_UnscheduleTransactions.Contains(scheduledItem))
                        {
                            Unschedule(scheduledItem);
                        }
                    }

                    m_LastUpdatedIndex = index;
                }
            }
            finally
            {
                m_TransactionMode = false;

                // Rule: remove unscheduled transactions first
                foreach (var item in m_UnscheduleTransactions)
                {
                    PrivateUnSchedule(item);
                }
                m_UnscheduleTransactions.Clear();

                // Then add scheduled transactions
                foreach (var item in m_ScheduleTransactions)
                {
                    Schedule(item);
                }
                m_ScheduleTransactions.Clear();
            }
        }
Esempio n. 2
0
 public abstract void PerformTimerUpdate(TimerState state);
Esempio n. 3
0
 public override void PerformTimerUpdate(TimerState state)
 {
     m_TimerUpdateEvent?.Invoke(state);
 }
 public void UpdateScheduledEvents()
 {
     try
     {
         this.m_TransactionMode = true;
         long num   = Panel.TimeSinceStartupMs();
         int  count = this.m_ScheduledItems.Count;
         long num2  = num + 20L;
         int  num3  = this.m_LastUpdatedIndex + 1;
         bool flag  = num3 >= count;
         if (flag)
         {
             num3 = 0;
         }
         for (int i = 0; i < count; i++)
         {
             num = Panel.TimeSinceStartupMs();
             bool flag2 = !this.disableThrottling && num >= num2;
             if (flag2)
             {
                 break;
             }
             int  num4  = num3 + i;
             bool flag3 = num4 >= count;
             if (flag3)
             {
                 num4 -= count;
             }
             ScheduledItem scheduledItem = this.m_ScheduledItems[num4];
             bool          flag4         = false;
             bool          flag5         = num - scheduledItem.delayMs >= scheduledItem.startMs;
             if (flag5)
             {
                 TimerState state = new TimerState
                 {
                     start = scheduledItem.startMs,
                     now   = num
                 };
                 bool flag6 = !this.m_UnscheduleTransactions.Contains(scheduledItem);
                 if (flag6)
                 {
                     scheduledItem.PerformTimerUpdate(state);
                 }
                 scheduledItem.startMs = num;
                 scheduledItem.delayMs = scheduledItem.intervalMs;
                 bool flag7 = scheduledItem.ShouldUnschedule();
                 if (flag7)
                 {
                     flag4 = true;
                 }
             }
             bool flag8 = flag4 || (scheduledItem.endTimeMs > 0L && num > scheduledItem.endTimeMs);
             if (flag8)
             {
                 bool flag9 = !this.m_UnscheduleTransactions.Contains(scheduledItem);
                 if (flag9)
                 {
                     this.Unschedule(scheduledItem);
                 }
             }
             this.m_LastUpdatedIndex = num4;
         }
     }
     finally
     {
         this.m_TransactionMode = false;
         foreach (ScheduledItem current in this.m_UnscheduleTransactions)
         {
             this.PrivateUnSchedule(current);
         }
         this.m_UnscheduleTransactions.Clear();
         foreach (ScheduledItem current2 in this.m_ScheduleTransactions)
         {
             this.Schedule(current2);
         }
         this.m_ScheduleTransactions.Clear();
     }
 }