Beispiel #1
0
 public void unscheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target)
 {
     if (((selector != null) && (target != null)) && this.m_pHashForSelectors.ContainsKey(target))
     {
         tHashSelectorEntry element = this.m_pHashForSelectors[target];
         for (int i = 0; i < element.timers.Count; i++)
         {
             CCTimer timer = element.timers[i];
             if (selector == timer.m_pfnSelector)
             {
                 if ((timer == element.currentTimer) && !element.currentTimerSalvaged)
                 {
                     element.currentTimerSalvaged = true;
                 }
                 element.timers.RemoveAt(i);
                 if (element.timerIndex >= i)
                 {
                     element.timerIndex--;
                 }
                 if (element.timers.Count == 0)
                 {
                     if (this.m_pCurrentTarget == element)
                     {
                         this.m_bCurrentTargetSalvaged = true;
                         return;
                     }
                     this.removeHashElement(element);
                 }
                 return;
             }
         }
     }
 }
Beispiel #2
0
        /** The scheduled method will be called every 'interval' seconds.
         *   If paused is YES, then it won't be called until it is resumed.
         *   If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead.
         *   If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
         *
         *   @since v0.99.3
         */
        public void scheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target, float fInterval, bool bPaused)
        {
            if (selector == null)
            {
                throw (new ArgumentNullException("selector", "Schedule selector can not be null"));
            }
            if (target == null)
            {
                throw (new ArgumentNullException("target", "Schedule target must be set."));
            }

            tHashSelectorEntry element = null;

            if (!m_pHashForSelectors.ContainsKey(target))
            {
                element        = new tHashSelectorEntry();
                element.target = target;
                m_pHashForSelectors[target] = element;

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = bPaused;
            }
            else
            {
                element = m_pHashForSelectors[target];

                Debug.Assert(element.paused == bPaused);
            }

            if (element.timers == null)
            {
                element.timers = new List <CCTimer>();
            }
            else
            {
                foreach (CCTimer timer in element.timers)
                {
                    if (selector == timer.m_pfnSelector)
                    {
                        System.Diagnostics.Debug.WriteLine("CCSheduler#scheduleSelector. Selector already scheduled.");
                        timer.m_fInterval = fInterval;
                        return;
                    }
                }
            }

            CCTimer timer2 = new CCTimer();

            timer2.initWithTarget(target, selector, fInterval);
            element.timers.Add(timer2);
        }
Beispiel #3
0
        /** Unschedule a selector for a given target.
         *   If you want to unschedule the "update", use unscheudleUpdateForTarget.
         *   @since v0.99.3
         */
        public void unscheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target)
        {
            // explicity handle nil arguments when removing an object
            if (selector == null || target == null)
            {
                return;
            }

            if (m_pHashForSelectors.ContainsKey(target))
            {
                tHashSelectorEntry element = m_pHashForSelectors[target];

                for (int i = 0; i < element.timers.Count; i++)
                {
                    CCTimer timer = element.timers[i];

                    if (selector == timer.m_pfnSelector)
                    {
                        if (timer == element.currentTimer && (!element.currentTimerSalvaged))
                        {
                            element.currentTimerSalvaged = true;
                        }

                        element.timers.RemoveAt(i);

                        // update timerIndex in case we are in tick:, looping over the actions
                        if (element.timerIndex >= i)
                        {
                            element.timerIndex--;
                        }

                        if (element.timers.Count == 0)
                        {
                            if (m_pCurrentTarget == element)
                            {
                                m_bCurrentTargetSalvaged = true;
                            }
                            else
                            {
                                removeHashElement(element);
                            }
                        }

                        return;
                    }
                }
            }
        }
Beispiel #4
0
        public void scheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target, float fInterval, bool bPaused)
        {
            if (selector == null)
            {
                throw new ArgumentNullException("selector", "Schedule selector can not be null");
            }
            if (target == null)
            {
                throw new ArgumentNullException("target", "Schedule target must be set.");
            }
            tHashSelectorEntry entry = null;

            if (!this.m_pHashForSelectors.ContainsKey(target))
            {
                entry = new tHashSelectorEntry
                {
                    target = target
                };
                this.m_pHashForSelectors[target] = entry;
                entry.paused = bPaused;
            }
            else
            {
                entry = this.m_pHashForSelectors[target];
            }
            if (entry.timers == null)
            {
                entry.timers = new List <CCTimer>();
            }
            else
            {
                foreach (CCTimer timer in entry.timers)
                {
                    if (selector == timer.m_pfnSelector)
                    {
                        CCLog.Log("CCSheduler#scheduleSelector. Selector already scheduled.");
                        timer.m_fInterval = fInterval;
                        return;
                    }
                }
            }
            CCTimer item = new CCTimer();

            item.initWithTarget(target, selector, fInterval);
            entry.timers.Add(item);
        }
Beispiel #5
0
 public void update(float dt)
 {
     if (this.m_fElapsed != -1f)
     {
         CCTimer mFElapsed = this;
         mFElapsed.m_fElapsed = mFElapsed.m_fElapsed + dt;
     }
     else
     {
         this.m_fElapsed = 0f;
     }
     if (this.m_fElapsed >= this.m_fInterval && this.m_pfnSelector != null)
     {
         this.m_pfnSelector(this.m_fElapsed);
         this.m_fElapsed = 0f;
     }
 }
        /** The scheduled method will be called every 'interval' seconds.
         If paused is YES, then it won't be called until it is resumed.
         If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead.
         If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.

         @since v0.99.3
         */
        public void scheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target, float fInterval, bool bPaused)
        {
            Debug.Assert(selector != null);
            Debug.Assert(target != null);

            tHashSelectorEntry element = null;
            if (!m_pHashForSelectors.ContainsKey(target))
            {
                element = new tHashSelectorEntry();
                element.target = target;
                m_pHashForSelectors[target] = element;

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = bPaused;
            }
            else
            {
                element = m_pHashForSelectors[target];

                Debug.Assert(element.paused == bPaused);
            }

            if (element.timers == null)
            {
                element.timers = new List<CCTimer>();
            }
            else
            {
                foreach (CCTimer timer in element.timers)
                {
                    if (selector == timer.m_pfnSelector)
                    {
                        Debug.WriteLine("CCSheduler#scheduleSelector. Selector already scheduled.");
                        timer.m_fInterval = fInterval;
                        return;
                    }
                }
            }

            CCTimer timer2 = new CCTimer();
            timer2.initWithTarget(target, selector, fInterval);
            element.timers.Add(timer2);
        }
        /** The scheduled method will be called every 'interval' seconds.
	     If paused is YES, then it won't be called until it is resumed.
	     If 'interval' is 0, it will be called every frame, but if so, it recommened to use 'scheduleUpdateForTarget:' instead.
	     If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.

	     @since v0.99.3
	     */
        public void scheduleSelector(SEL_SCHEDULE selector, SelectorProtocol target, float fInterval, bool bPaused)
        {
            if (selector == null)
            {
                throw (new ArgumentNullException("selector", "Schedule selector can not be null"));
            }
            if (target == null)
        {
                throw (new ArgumentNullException("target", "Schedule target must be set."));
            }

            tHashSelectorEntry element = null;
            if (!m_pHashForSelectors.ContainsKey(target))
            {
                element = new tHashSelectorEntry();
                element.target = target;
                m_pHashForSelectors[target] = element;

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.paused = bPaused;
            }
            else
            {
                element = m_pHashForSelectors[target];

                Debug.Assert(element.paused == bPaused);
            }

            if (element.timers == null)
            {
                element.timers = new List<CCTimer>();
            }
            else
            {
                foreach (CCTimer timer in element.timers)
                {
                    if (selector == timer.m_pfnSelector)
                    {
                        CCLog.Log("CCSheduler#scheduleSelector. Selector already scheduled.");
                        timer.m_fInterval = fInterval;
                        return;
                    }
                }
            }

            CCTimer timer2 = new CCTimer();
            timer2.initWithTarget(target, selector, fInterval);
            element.timers.Add(timer2);
        }