Esempio n. 1
0
 public void GetExpired(double now, Queue <Timer.TimerInstance> queue)
 {
     for (Timer.TimerInstance i = this.FirstInstance; i != null && (double)i.ExpiresAt <= now; i = i.NextInstance)
     {
         queue.Enqueue(i);
     }
 }
Esempio n. 2
0
 internal void Remove()
 {
     Timer.TimeSlot timeSlot = this.TimeSlot;
     if (timeSlot == null)
     {
         return;
     }
     timeSlot.Count--;
     Timer.Count = Timer.Count - 1;
     Timer.TimerInstance previousInstance = this.PreviousInstance;
     Timer.TimerInstance nextInstance     = this.NextInstance;
     if (nextInstance != null)
     {
         nextInstance.PreviousInstance = previousInstance;
     }
     else
     {
         timeSlot.LastInstance = previousInstance;
     }
     if (previousInstance != null)
     {
         previousInstance.NextInstance = nextInstance;
     }
     else
     {
         timeSlot.FirstInstance = nextInstance;
     }
     this.TimeSlot         = null;
     this.PreviousInstance = null;
     this.NextInstance     = null;
 }
Esempio n. 3
0
 internal Timer.TimerInstance AddTimer(int repetitions, float delay, Action callback, Plugin owner = null)
 {
     Timer.TimerInstance timerInstance;
     Timer.TimerInstance timerInstance1;
     lock (Timer.Lock)
     {
         Queue <Timer.TimerInstance> pool = Timer.TimerInstance.Pool;
         if (pool.Count <= 0)
         {
             timerInstance = new Timer.TimerInstance(this, repetitions, delay, callback, owner);
         }
         else
         {
             timerInstance = pool.Dequeue();
             timerInstance.Load(this, repetitions, delay, callback, owner);
         }
         this.InsertTimer(timerInstance, timerInstance.ExpiresAt < Timer.Oxide.Now);
         timerInstance1 = timerInstance;
     }
     return(timerInstance1);
 }
Esempio n. 4
0
        public void Update(float delta)
        {
            float now = Timer.Oxide.Now;

            Timer.TimeSlot[]            timeSlotArray  = this.timeSlots;
            Queue <Timer.TimerInstance> timerInstances = this.expiredInstanceQueue;
            int num = 0;

            lock (Timer.Lock)
            {
                int    num1 = this.currentSlot;
                double num2 = this.nextSlotAt;
                while (true)
                {
                    timeSlotArray[num1].GetExpired((num2 > (double)now ? (double)now : num2), timerInstances);
                    if ((double)now <= num2)
                    {
                        break;
                    }
                    num++;
                    num1  = (num1 < 511 ? num1 + 1 : 0);
                    num2 += 0.00999999977648258;
                }
                if (num > 0)
                {
                    this.currentSlot = num1;
                    this.nextSlotAt  = num2;
                }
                int count = timerInstances.Count;
                for (int i = 0; i < count; i++)
                {
                    Timer.TimerInstance timerInstance = timerInstances.Dequeue();
                    if (!timerInstance.Destroyed)
                    {
                        timerInstance.Invoke(now);
                    }
                }
            }
        }
Esempio n. 5
0
 private void InsertTimer(Timer.TimerInstance timer, bool in_past = false)
 {
     this.timeSlots[(in_past ? this.currentSlot : (int)(timer.ExpiresAt / 0.01f) & 511)].InsertTimer(timer);
 }
Esempio n. 6
0
            public void InsertTimer(Timer.TimerInstance timer)
            {
                float expiresAt = timer.ExpiresAt;

                Timer.TimerInstance firstInstance = this.FirstInstance;
                Timer.TimerInstance lastInstance  = this.LastInstance;
                Timer.TimerInstance nextInstance  = firstInstance;
                if (firstInstance != null)
                {
                    float single     = firstInstance.ExpiresAt;
                    float expiresAt1 = lastInstance.ExpiresAt;
                    if (expiresAt <= single)
                    {
                        nextInstance = firstInstance;
                    }
                    else if (expiresAt >= expiresAt1)
                    {
                        nextInstance = null;
                    }
                    else if (expiresAt1 - expiresAt >= expiresAt - single)
                    {
                        while (nextInstance != null && nextInstance.ExpiresAt <= expiresAt)
                        {
                            nextInstance = nextInstance.NextInstance;
                        }
                    }
                    else
                    {
                        nextInstance = lastInstance;
                        for (Timer.TimerInstance i = nextInstance; i != null; i = i.PreviousInstance)
                        {
                            if (i.ExpiresAt <= expiresAt)
                            {
                                goto Label0;
                            }
                            nextInstance = i;
                        }
                    }
                }
Label0:
                if (nextInstance != null)
                {
                    Timer.TimerInstance previousInstance = nextInstance.PreviousInstance;
                    if (previousInstance != null)
                    {
                        previousInstance.NextInstance = timer;
                    }
                    else
                    {
                        this.FirstInstance = timer;
                    }
                    nextInstance.PreviousInstance = timer;
                    timer.PreviousInstance        = previousInstance;
                    timer.NextInstance            = nextInstance;
                }
                else
                {
                    timer.NextInstance = null;
                    if (lastInstance != null)
                    {
                        lastInstance.NextInstance = timer;
                        timer.PreviousInstance    = lastInstance;
                        this.LastInstance         = timer;
                    }
                    else
                    {
                        this.FirstInstance = timer;
                        this.LastInstance  = timer;
                    }
                }
                timer.Added(this);
            }