public static bool Matches(ScheduledItem item, ActionType updateEvent)
            {
                VisualElementScheduledItem <ActionType> vItem = item as VisualElementScheduledItem <ActionType>;

                if (vItem != null)
                {
                    return(EqualityComparer <ActionType> .Default.Equals(vItem.updateEvent, updateEvent));
                }
                return(false);
            }
Example #2
0
        public void Schedule(ScheduledItem item)
        {
            if (item == null)
            {
                return;
            }

            ScheduledItem scheduledItem = item as ScheduledItem;

            if (scheduledItem == null)
            {
                throw new NotSupportedException("Scheduled Item type is not supported by this scheduler");
            }

            if (m_TransactionMode)
            {
                if (m_UnscheduleTransactions.Remove(scheduledItem))
                {
                    // The item was unscheduled then rescheduled in the same transaction.
                }
                else if (m_ScheduledItems.Contains(scheduledItem) || m_ScheduleTransactions.Contains(scheduledItem))
                {
                    throw new ArgumentException(string.Concat("Cannot schedule function ", scheduledItem, " more than once"));
                }
                else
                {
                    m_ScheduleTransactions.Add(scheduledItem);
                }
            }
            else
            {
                if (m_ScheduledItems.Contains(scheduledItem))
                {
                    throw new ArgumentException(string.Concat("Cannot schedule function ", scheduledItem, " more than once"));
                }
                else
                {
                    m_ScheduledItems.Add(scheduledItem);
                }
            }
        }
Example #3
0
        public void Unschedule(ScheduledItem item)
        {
            ScheduledItem sItem = item as ScheduledItem;

            if (sItem != null)
            {
                if (m_TransactionMode)
                {
                    if (m_UnscheduleTransactions.Contains(sItem))
                    {
                        throw new ArgumentException("Cannot unschedule scheduled function twice" + sItem);
                    }
                    else if (m_ScheduleTransactions.Remove(sItem))
                    {
                        // A item has been scheduled then unscheduled in the same transaction. which is valid.
                    }
                    else if (m_ScheduledItems.Contains(sItem))
                    {
                        // Only add it to m_UnscheduleTransactions if it is in m_ScheduledItems.
                        // if it was successfully removed from m_ScheduleTransaction we are fine.
                        m_UnscheduleTransactions.Add(sItem);
                    }
                    else
                    {
                        throw new ArgumentException("Cannot unschedule unknown scheduled function " + sItem);
                    }
                }
                else
                {
                    if (!PrivateUnSchedule(sItem))
                    {
                        throw new ArgumentException("Cannot unschedule unknown scheduled function " + sItem);
                    }
                }

                sItem.OnItemUnscheduled(); // Call OnItemUnscheduled immediately after successful removal even if we are in transaction mode
            }
        }
        public void Schedule(ScheduledItem item)
        {
            bool flag = item == null;

            if (!flag)
            {
                bool flag2 = item == null;
                if (flag2)
                {
                    throw new NotSupportedException("Scheduled Item type is not supported by this scheduler");
                }
                bool transactionMode = this.m_TransactionMode;
                if (transactionMode)
                {
                    bool flag3 = this.m_UnscheduleTransactions.Remove(item);
                    if (!flag3)
                    {
                        bool flag4 = this.m_ScheduledItems.Contains(item) || this.m_ScheduleTransactions.Contains(item);
                        if (flag4)
                        {
                            throw new ArgumentException("Cannot schedule function " + item + " more than once");
                        }
                        this.m_ScheduleTransactions.Add(item);
                    }
                }
                else
                {
                    bool flag5 = this.m_ScheduledItems.Contains(item);
                    if (flag5)
                    {
                        throw new ArgumentException("Cannot schedule function " + item + " more than once");
                    }
                    this.m_ScheduledItems.Add(item);
                }
            }
        }
        public void Unschedule(ScheduledItem item)
        {
            bool flag = item != null;

            if (flag)
            {
                bool transactionMode = this.m_TransactionMode;
                if (transactionMode)
                {
                    bool flag2 = this.m_UnscheduleTransactions.Contains(item);
                    if (flag2)
                    {
                        throw new ArgumentException("Cannot unschedule scheduled function twice" + ((item != null) ? item.ToString() : null));
                    }
                    bool flag3 = this.m_ScheduleTransactions.Remove(item);
                    if (!flag3)
                    {
                        bool flag4 = this.m_ScheduledItems.Contains(item);
                        if (!flag4)
                        {
                            throw new ArgumentException("Cannot unschedule unknown scheduled function " + ((item != null) ? item.ToString() : null));
                        }
                        this.m_UnscheduleTransactions.Add(item);
                    }
                }
                else
                {
                    bool flag5 = !this.PrivateUnSchedule(item);
                    if (flag5)
                    {
                        throw new ArgumentException("Cannot unschedule unknown scheduled function " + ((item != null) ? item.ToString() : null));
                    }
                }
                item.OnItemUnscheduled();
            }
        }
Example #6
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();
            }
        }
Example #7
0
 bool PrivateUnSchedule(ScheduledItem sItem)
 {
     return(m_ScheduleTransactions.Remove(sItem) || RemovedScheduledItemAt(m_ScheduledItems.IndexOf(sItem)));
 }
 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();
     }
 }