Example #1
0
        public void Schedule(IScheduledItem 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)
            {
                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 #2
0
 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;
         if (num3 >= count)
         {
             num3 = 0;
         }
         for (int i = 0; i < count; i++)
         {
             num = Panel.TimeSinceStartupMs();
             if (!this.disableThrottling && num >= num2)
             {
                 break;
             }
             int num4 = num3 + i;
             if (num4 >= count)
             {
                 num4 -= count;
             }
             ScheduledItem scheduledItem = this.m_ScheduledItems[num4];
             if (num - scheduledItem.delayMs >= scheduledItem.startMs)
             {
                 TimerState state = new TimerState
                 {
                     start = scheduledItem.startMs,
                     now   = num
                 };
                 scheduledItem.PerformTimerUpdate(state);
                 scheduledItem.startMs = num;
                 scheduledItem.delayMs = scheduledItem.intervalMs;
                 if (scheduledItem.ShouldUnschedule())
                 {
                     this.Unschedule(scheduledItem);
                 }
             }
             this.m_LastUpdatedIndex = num4;
         }
     }
     finally
     {
         this.m_TransactionMode = false;
         for (int j = 0; j < this.m_UnscheduleTransactions.Count; j++)
         {
             this.Unschedule(this.m_UnscheduleTransactions[j]);
         }
         this.m_UnscheduleTransactions.Clear();
         for (int k = 0; k < this.m_ScheduleTransactions.Count; k++)
         {
             this.Schedule(this.m_ScheduleTransactions[k]);
         }
         this.m_ScheduleTransactions.Clear();
     }
 }
Example #3
0
 public ScheduleBuilder Until(Func <bool> condition)
 {
     if (this.m_ScheduledItem != null)
     {
         ScheduledItem expr_12 = this.m_ScheduledItem;
         expr_12.timerUpdateStopCondition = (Func <bool>)Delegate.Combine(expr_12.timerUpdateStopCondition, condition);
     }
     return(this);
 }
Example #4
0
            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);
            }
 private void Schedule(ScheduledItem scheduleItem)
 {
     if (this.m_ScheduledItems.Contains(scheduleItem))
     {
         Debug.LogError("Cannot schedule function " + scheduleItem.timerUpdateEvent + " more than once");
     }
     else
     {
         this.m_ScheduledItems.Add(scheduleItem);
     }
 }
Example #6
0
 public void UpdateScheduledEvents()
 {
     try
     {
         this.m_TransactionMode = true;
         long num   = (long)(Time.realtimeSinceStartup * 1000f);
         int  count = this.m_ScheduledItems.Count;
         int  num2  = this.m_LastUpdatedIndex + 1;
         if (num2 >= count)
         {
             num2 = 0;
         }
         for (int i = 0; i < count; i++)
         {
             int num3 = num2 + i;
             if (num3 >= count)
             {
                 num3 -= count;
             }
             ScheduledItem scheduledItem = this.m_ScheduledItems[num3];
             if (num - scheduledItem.delayMs >= scheduledItem.startMs)
             {
                 TimerState state = new TimerState
                 {
                     start = scheduledItem.startMs,
                     now   = num
                 };
                 scheduledItem.PerformTimerUpdate(state);
                 scheduledItem.startMs = num;
                 scheduledItem.delayMs = scheduledItem.intervalMs;
                 if (scheduledItem.ShouldUnschedule())
                 {
                     this.Unschedule(scheduledItem);
                 }
             }
             this.m_LastUpdatedIndex = num3;
         }
     }
     finally
     {
         this.m_TransactionMode = false;
         for (int j = 0; j < this.m_UnscheduleTransactions.Count; j++)
         {
             this.Unschedule(this.m_UnscheduleTransactions[j]);
         }
         this.m_UnscheduleTransactions.Clear();
         for (int k = 0; k < this.m_ScheduleTransactions.Count; k++)
         {
             this.Schedule(this.m_ScheduleTransactions[k]);
         }
         this.m_ScheduleTransactions.Clear();
     }
 }
 public void UpdateScheduledEvents()
 {
     try
     {
         this.m_TransactionMode = true;
         long num = (long)(Time.realtimeSinceStartup * 1000f);
         for (int i = 0; i < this.m_ScheduledItems.Count; i++)
         {
             ScheduledItem scheduledItem = this.m_ScheduledItems[i];
             if (scheduledItem.handler.panel == null)
             {
                 Debug.Log("Will unschedule action of " + scheduledItem.handler + " because it has no panel");
                 this.Unschedule(scheduledItem.timerUpdateEvent);
             }
             else if (scheduledItem.IsUpdatable())
             {
                 TimerState obj = new TimerState
                 {
                     start = scheduledItem.start,
                     now   = num
                 };
                 if (num - scheduledItem.delay > scheduledItem.start)
                 {
                     if (scheduledItem.timerUpdateEvent != null)
                     {
                         scheduledItem.timerUpdateEvent(obj);
                     }
                     scheduledItem.start = num;
                     scheduledItem.delay = scheduledItem.interval;
                     if (scheduledItem.timerUpdateStopCondition != null && scheduledItem.timerUpdateStopCondition())
                     {
                         this.Unschedule(scheduledItem.timerUpdateEvent);
                     }
                 }
             }
         }
     }
     finally
     {
         this.m_TransactionMode = false;
         for (int j = 0; j < this.m_UnscheduleTransactions.Count; j++)
         {
             this.Unschedule(this.m_UnscheduleTransactions[j]);
         }
         this.m_UnscheduleTransactions.Clear();
         for (int k = 0; k < this.m_ScheduleTansactions.Count; k++)
         {
             this.Schedule(this.m_ScheduleTansactions[k]);
         }
         this.m_ScheduleTansactions.Clear();
     }
 }
        public ScheduleBuilder Schedule(Action <TimerState> timerUpdateEvent, IEventHandler handler)
        {
            ScheduledItem scheduledItem = new ScheduledItem(timerUpdateEvent, handler);

            if (this.m_TransactionMode)
            {
                this.m_ScheduleTansactions.Add(scheduledItem);
            }
            else
            {
                this.Schedule(scheduledItem);
            }
            return(new ScheduleBuilder(scheduledItem));
        }
Example #9
0
        public void Unschedule(IScheduledItem item)
        {
            ScheduledItem scheduledItem = item as ScheduledItem;

            if (scheduledItem != null)
            {
                if (this.m_TransactionMode)
                {
                    this.m_UnscheduleTransactions.Add(scheduledItem);
                }
                else if (!this.RemovedScheduledItemAt(this.m_ScheduledItems.IndexOf(scheduledItem)))
                {
                    throw new ArgumentException("Cannot unschedule unknown scheduled function " + scheduledItem);
                }
            }
        }
Example #10
0
        private bool RemovedScheduledItemAt(int index)
        {
            bool result;

            if (index >= 0)
            {
                ScheduledItem scheduledItem = this.m_ScheduledItems[index];
                this.m_ScheduledItems.RemoveAt(index);
                scheduledItem.OnItemUnscheduled();
                result = true;
            }
            else
            {
                result = false;
            }
            return(result);
        }
 public void Unschedule(Action <TimerState> timerUpdateEvent)
 {
     if (this.m_TransactionMode)
     {
         this.m_UnscheduleTransactions.Add(timerUpdateEvent);
     }
     else
     {
         ScheduledItem scheduledItem = this.m_ScheduledItems.Find((ScheduledItem t) => t.timerUpdateEvent == timerUpdateEvent);
         if (scheduledItem != null)
         {
             this.m_ScheduledItems.Remove(scheduledItem);
         }
         else
         {
             Debug.LogError("Cannot unschedule unknown scheduled function " + timerUpdateEvent);
         }
     }
 }
Example #12
0
        public void Unschedule(IScheduledItem item)
        {
            ScheduledItem sItem = item as ScheduledItem;

            if (sItem != null)
            {
                if (m_TransactionMode)
                {
                    m_UnscheduleTransactions.Add(sItem);   //TODO: optimize this, we lose the item and need to re-search
                }
                else
                {
                    if (!RemovedScheduledItemAt(m_ScheduledItems.IndexOf(sItem)))
                    {
                        throw new ArgumentException("Cannot unschedule unknown scheduled function " + sItem);
                    }
                }
            }
        }
Example #13
0
        public void Unschedule(IScheduledItem 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
            }
        }
Example #14
0
 public void Schedule(IScheduledItem item)
 {
     if (item != null)
     {
         ScheduledItem scheduledItem = item as ScheduledItem;
         if (scheduledItem == null)
         {
             throw new NotSupportedException("Scheduled Item type is not supported by this scheduler");
         }
         if (this.m_TransactionMode)
         {
             this.m_ScheduleTransactions.Add(scheduledItem);
         }
         else
         {
             if (this.m_ScheduledItems.Contains(scheduledItem))
             {
                 throw new ArgumentException("Cannot schedule function " + scheduledItem + " more than once");
             }
             this.m_ScheduledItems.Add(scheduledItem);
         }
     }
 }
Example #15
0
 internal ScheduleBuilder(ScheduledItem scheduledItem)
 {
     this.m_ScheduledItem = scheduledItem;
 }
Example #16
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];

                    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 amrker for future removal
                        {
                            scheduledItem.PerformTimerUpdate(timerState);
                        }

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

                        if (scheduledItem.ShouldUnschedule() && !m_UnscheduleTransactions.Contains(scheduledItem))
                        // if the scheduledItem has been unscheduled explicitly in PerformTimerUpdate then it will be in m_UnscheduleTransactions and we shouldn't
                        // unschedule it again
                        {
                            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 #17
0
 bool PrivateUnSchedule(ScheduledItem sItem)
 {
     return(m_ScheduleTransactions.Remove(sItem) || RemovedScheduledItemAt(m_ScheduledItems.IndexOf(sItem)));
 }
Example #18
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];

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

                        scheduledItem.PerformTimerUpdate(timerState);

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

                        if (scheduledItem.ShouldUnschedule())
                        {
                            Unschedule(scheduledItem);
                        }
                    }

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

                // Rule: remove unscheduled transactions first
                for (int s = 0; s < m_UnscheduleTransactions.Count; s++)
                {
                    Unschedule(m_UnscheduleTransactions[s]);
                }
                m_UnscheduleTransactions.Clear();

                // Then add scheduled transactions
                for (int s = 0; s < m_ScheduleTransactions.Count; s++)
                {
                    Schedule(m_ScheduleTransactions[s]);
                }
                m_ScheduleTransactions.Clear();
            }
        }