コード例 #1
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        /** Unschedules all selectors for a given target.
         *   This also includes the "update" selector.
         *   @since v0.99.3
         */

        public void UnscheduleAllForTarget(ICCSelectorProtocol target)
        {
            // explicit NULL handling
            if (target == null)
            {
                return;
            }

            // custom selectors
            HashTimeEntry element;

            if (m_pHashForTimers.TryGetValue(target, out element))
            {
                if (element.Timers.Contains(element.CurrentTimer))
                {
                    element.CurrentTimerSalvaged = true;
                }
                element.Timers.Clear();

                if (m_pCurrentTarget == element)
                {
                    m_bCurrentTargetSalvaged = true;
                }
                else
                {
                    RemoveHashElement(element);
                }
            }

            // update selector
            UnscheduleUpdateForTarget(target);
        }
コード例 #2
0
        /// <summary>
        ///  creates a menu item from a string and atlas. Use it with MenuItemToggle
        /// </summary>
        public static CCMenuItemAtlasFont ItemFromString(string value, string charMapFile, int itemWidth, int itemHeight, char startCharMap,
		                                                 ICCSelectorProtocol target, Action<object> selector)
        {
            var pRet = new CCMenuItemAtlasFont();
            pRet.InitFromString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
            return pRet;
        }
コード例 #3
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        /** Schedules the 'update' selector for a given target with a given priority.
         *   The 'update' selector will be called every frame.
         *   The lower the priority, the earlier it is called.
         *   @since v0.99.3
         */

        public void ScheduleUpdateForTarget(ICCSelectorProtocol targt, int priority, bool paused)
        {
            HashUpdateEntry element;

            if (m_pHashForUpdates.TryGetValue(targt, out element))
            {
                Debug.Assert(element.Entry.MarkedForDeletion);

                // TODO: check if priority has changed!
                element.Entry.MarkedForDeletion = false;

                return;
            }

            // most of the updates are going to be 0, that's way there
            // is an special list for updates with priority 0
            if (priority == 0)
            {
                AppendIn(m_pUpdates0List, targt, paused);
            }
            else if (priority < 0)
            {
                PriorityIn(m_pUpdatesNegList, targt, priority, paused);
            }
            else
            {
                PriorityIn(m_pUpdatesPosList, targt, priority, paused);
            }
        }
コード例 #4
0
        /// <summary>
        /// initializes a menu item from a string and atlas with a target/selector
        /// </summary>
        public bool InitFromString(string value, string charMapFile, int itemWidth, int itemHeight, char startCharMap, ICCSelectorProtocol target,
		                           Action<object> selector)
        {
            // CCAssert( value != NULL && strlen(value) != 0, "value length must be greater than 0");
            var label = new CCLabelAtlas(value, charMapFile, itemWidth, itemHeight, startCharMap);
            base.InitWithLabel(label, selector);
            return true;
        }
コード例 #5
0
        /// <summary>
        ///  creates a menu item from a string and atlas. Use it with MenuItemToggle
        /// </summary>
        public static CCMenuItemAtlasFont ItemFromString(string value, string charMapFile, int itemWidth, int itemHeight, char startCharMap,
                                                         ICCSelectorProtocol target, Action <CCMenuItem> selector)
        {
            var pRet = new CCMenuItemAtlasFont();

            pRet.InitFromString(value, charMapFile, itemWidth, itemHeight, startCharMap, target, selector);
            return(pRet);
        }
コード例 #6
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        /** 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's recommended to use 'scheduleUpdateForTarget:' instead.
         * If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
         * repeat let the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
         * delay is the amount of time the action will wait before it'll start
         *
         * @since v0.99.3, repeat and delay added in v1.1
         */

        public void ScheduleSelector(Action <float> selector, ICCSelectorProtocol target, float interval, uint repeat,
                                     float delay, bool paused)
        {
            Debug.Assert(selector != null);
            Debug.Assert(target != null);

            HashTimeEntry element;

            lock (m_pHashForTimers)
            {
                if (!m_pHashForTimers.TryGetValue(target, out element))
                {
                    element = new HashTimeEntry {
                        Target = target
                    };
                    m_pHashForTimers[target] = element;

                    // Is this the 1st element ? Then set the pause level to all the selectors of this target
                    element.Paused = paused;
                }
                else
                {
                    if (element != null)
                    {
                        Debug.Assert(element.Paused == paused);
                    }
                }
                if (element != null)
                {
                    if (element.Timers == null)
                    {
                        element.Timers = new List <CCTimer>();
                    }
                    else
                    {
                        CCTimer[] timers = element.Timers.ToArray();
                        foreach (var timer in timers)
                        {
                            if (timer == null)
                            {
                                continue;
                            }
                            if (selector == timer.Selector)
                            {
                                CCLog.Log(
                                    "CCSheduler#scheduleSelector. Selector already scheduled. Updating interval from: {0} to {1}",
                                    timer.Interval, interval);
                                timer.Interval = interval;
                                return;
                            }
                        }
                    }

                    element.Timers.Add(new CCTimer(this, target, selector, interval, repeat, delay));
                }
            }
        }
コード例 #7
0
ファイル: CCScheduler.cs プロジェクト: pekayatt/cocos2d-xna
 public CCTimer(CCScheduler scheduler, ICCSelectorProtocol target, Action<float> selector, float seconds, uint repeat, float delay)
 {
     _scheduler = scheduler;
     Target = target;
     Selector = selector;
     Elapsed = -1;
     OriginalInterval = seconds;
     Interval = seconds;
     m_fDelay = delay;
     m_bUseDelay = delay > 0f;
     m_nRepeat = repeat;
     m_bRunForever = m_nRepeat == uint.MaxValue;
 }
コード例 #8
0
 public CCTimer(CCScheduler scheduler, ICCSelectorProtocol target, Action <float> selector, float seconds, uint repeat, float delay)
 {
     _scheduler       = scheduler;
     Target           = target;
     Selector         = selector;
     Elapsed          = -1;
     OriginalInterval = seconds;
     Interval         = seconds;
     m_fDelay         = delay;
     m_bUseDelay      = delay > 0f;
     m_nRepeat        = repeat;
     m_bRunForever    = m_nRepeat == uint.MaxValue;
 }
コード例 #9
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        /** Unschedule a selector for a given target.
         *   If you want to unschedule the "update", use unscheudleUpdateForTarget.
         *   @since v0.99.3
         */

        public void UnscheduleSelector(Action <float> selector, ICCSelectorProtocol target)
        {
            // explicity handle nil arguments when removing an object
            if (selector == null || target == null)
            {
                return;
            }

            HashTimeEntry element;

            if (m_pHashForTimers.TryGetValue(target, out element))
            {
                for (int i = 0; i < element.Timers.Count; i++)
                {
                    var timer = element.Timers[i];
                    if (timer == null)
                    {
                        continue;
                    }
                    if (selector == timer.Selector)
                    {
                        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;
                    }
                }
            }
        }
コード例 #10
0
        public bool IsTargetPaused(ICCSelectorProtocol target)
        {
            Debug.Assert(target != null, "target must be non nil");

            // Custom selectors
            HashSelectorEntry element;

            if (m_pHashForSelectors.TryGetValue(target, out element))
            {
                return(element.Paused);
            }

            return(false); // should never get here
        }
コード例 #11
0
ファイル: CCScheduler.cs プロジェクト: liwq-net/UIFactory
 public CCTimer(CCScheduler scheduler, ICCSelectorProtocol target, Action<float> selector, float seconds,
                uint repeat, float delay)
 {
     _scheduler = scheduler;
     m_pTarget = target;
     Selector = selector;
     m_fElapsed = -1;
     OriginalInterval = seconds;
     Interval = seconds;
     m_fDelay = delay;
     m_bUseDelay = delay > 0f;
     m_uRepeat = repeat;
     m_bRunForever = (m_uRepeat == CCScheduler.kCCRepeatForever);
 }
コード例 #12
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
 public CCTimer(CCScheduler scheduler, ICCSelectorProtocol target, Action <float> selector, float seconds,
                uint repeat, float delay)
 {
     _scheduler       = scheduler;
     m_pTarget        = target;
     Selector         = selector;
     m_fElapsed       = -1;
     OriginalInterval = seconds;
     Interval         = seconds;
     m_fDelay         = delay;
     m_bUseDelay      = delay > 0f;
     m_uRepeat        = repeat;
     m_bRunForever    = (m_uRepeat == CCScheduler.kCCRepeatForever);
 }
コード例 #13
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        private void UpdateTarget(ICCSelectorProtocol target, float dt)
        {
            if (OnUnhandledException == null)
            {
                target.Update(dt);
                return;
            }

            try
            {
                target.Update(dt);
            }
            catch (Exception exception)
            {
                OnUnhandledException(exception);
            }
        }
コード例 #14
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        private void PriorityIn(LinkedList <ListEntry> list, ICCSelectorProtocol target, int priority, bool paused)
        {
            var listElement = new ListEntry
            {
                Target            = target,
                Priority          = priority,
                Paused            = paused,
                MarkedForDeletion = false
            };

            if (list.First == null)
            {
                list.AddFirst(listElement);
            }
            else
            {
                bool added = false;
                for (LinkedListNode <ListEntry> node = list.First; node != null; node = node.Next)
                {
                    if (priority < node.Value.Priority)
                    {
                        list.AddBefore(node, listElement);
                        added = true;
                        break;
                    }
                }

                if (!added)
                {
                    list.AddLast(listElement);
                }
            }

            // update hash entry for quick access
            var hashElement = new HashUpdateEntry
            {
                Target = target,
                List   = list,
                Entry  = listElement
            };

            m_pHashForUpdates.Add(target, hashElement);
        }
コード例 #15
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        public void ResumeTarget(ICCSelectorProtocol target)
        {
            Debug.Assert(target != null);

            // custom selectors
            HashTimeEntry element;

            if (m_pHashForTimers.TryGetValue(target, out element))
            {
                element.Paused = false;
            }

            // Update selector
            HashUpdateEntry elementUpdate;

            if (m_pHashForUpdates.TryGetValue(target, out elementUpdate))
            {
                elementUpdate.Entry.Paused = false;
            }
        }
コード例 #16
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        public void PauseTarget(ICCSelectorProtocol target)
        {
            Debug.Assert(target != null);

            // custom selectors
            HashTimeEntry entry;

            if (m_pHashForTimers.TryGetValue(target, out entry))
            {
                entry.Paused = true;
            }

            // Update selector
            HashUpdateEntry updateEntry;

            if (m_pHashForUpdates.TryGetValue(target, out updateEntry))
            {
                updateEntry.Entry.Paused = true;
            }
        }
コード例 #17
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        /*
         * unsigned int CCScheduler::scheduleScriptFunc(unsigned int nHandler, float fInterval, bool bPaused)
         * {
         *  CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::create(nHandler, fInterval, bPaused);
         *  if (!m_pScriptHandlerEntries)
         *  {
         *      m_pScriptHandlerEntries = CCArray::create(20);
         *      m_pScriptHandlerEntries->retain();
         *  }
         *  m_pScriptHandlerEntries->addObject(pEntry);
         *  return pEntry->getEntryId();
         * }
         *
         * void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID)
         * {
         *  for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--)
         *  {
         *      CCSchedulerScriptHandlerEntry* pEntry = static_cast<CCSchedulerScriptHandlerEntry*>(m_pScriptHandlerEntries->objectAtIndex(i));
         *      if (pEntry->getEntryId() == uScheduleScriptEntryID)
         *      {
         *          pEntry->markedForDeletion();
         *          break;
         *      }
         *  }
         * }
         */

        public void UnscheduleUpdateForTarget(ICCSelectorProtocol target)
        {
            if (target == null)
            {
                return;
            }

            HashUpdateEntry element;

            if (m_pHashForUpdates.TryGetValue(target, out element))
            {
                if (m_bUpdateHashLocked)
                {
                    element.Entry.MarkedForDeletion = true;
                }
                else
                {
                    RemoveUpdateFromHash(element.Entry);
                }
            }
        }
コード例 #18
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        private void AppendIn(LinkedList <ListEntry> list, ICCSelectorProtocol target, bool paused)
        {
            var listElement = new ListEntry
            {
                Target            = target,
                Paused            = paused,
                MarkedForDeletion = false
            };

            list.AddLast(listElement);

            // update hash entry for quicker access
            var hashElement = new HashUpdateEntry
            {
                Target = target,
                List   = list,
                Entry  = listElement
            };

            m_pHashForUpdates.Add(target, hashElement);
        }
コード例 #19
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        public bool IsTargetPaused(ICCSelectorProtocol target)
        {
            Debug.Assert(target != null, "target must be non nil");

            // Custom selectors
            HashTimeEntry element;

            if (m_pHashForTimers.TryGetValue(target, out element))
            {
                return(element.Paused);
            }

            // We should check update selectors if target does not have custom selectors
            HashUpdateEntry elementUpdate;

            if (m_pHashForUpdates.TryGetValue(target, out elementUpdate))
            {
                return(elementUpdate.Entry.Paused);
            }

            return(false); // should never get here
        }
コード例 #20
0
        /// <summary>
        /// initializes a menu item from a string and atlas with a target/selector
        /// </summary>
        public bool InitFromString(string value, string charMapFile, int itemWidth, int itemHeight, char startCharMap, ICCSelectorProtocol target,
                                   Action <CCMenuItem> selector)
        {
            // CCAssert( value != NULL && strlen(value) != 0, "value length must be greater than 0");
            var label = new CCLabelAtlas(value, charMapFile, itemWidth, itemHeight, startCharMap);

            base.InitWithLabel(label, selector);
            return(true);
        }
コード例 #21
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        private void AppendIn(LinkedList<ListEntry> list, ICCSelectorProtocol target, bool paused)
        {
            var listElement = new ListEntry
                {
                    Target = target,
                    Paused = paused,
                    MarkedForDeletion = false
                };

            list.AddLast(listElement);

            // update hash entry for quicker access
            var hashElement = new HashUpdateEntry
                {
                    Target = target,
                    List = list,
                    Entry = listElement
                };

            m_pHashForUpdates.Add(target, hashElement);
        }
コード例 #22
0
ファイル: CCScheduler.cs プロジェクト: pekayatt/cocos2d-xna
        public bool IsTargetPaused(ICCSelectorProtocol target)
        {
            Debug.Assert(target != null, "target must be non nil");

            // Custom selectors
            HashSelectorEntry element;
            if (m_pHashForSelectors.TryGetValue(target, out element))
            {
                return element.Paused;
            }

            return false; // should never get here
        }
コード例 #23
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        public bool IsTargetPaused(ICCSelectorProtocol target)
        {
            Debug.Assert(target != null, "target must be non nil");

            // Custom selectors
            HashTimeEntry element;
            if (m_pHashForTimers.TryGetValue(target, out element))
            {
                return element.Paused;
            }

            // We should check update selectors if target does not have custom selectors
            HashUpdateEntry elementUpdate;
            if (m_pHashForUpdates.TryGetValue(target, out elementUpdate))
            {
                return elementUpdate.Entry.Paused;
            }

            return false; // should never get here
        }
コード例 #24
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        private void PriorityIn(LinkedList<ListEntry> list, ICCSelectorProtocol target, int priority, bool paused)
        {
            var listElement = new ListEntry
                {
                    Target = target,
                    Priority = priority,
                    Paused = paused,
                    MarkedForDeletion = false
                };

            if (list.First == null)
            {
                list.AddFirst(listElement);
            }
            else
            {
                bool added = false;
                for (LinkedListNode<ListEntry> node = list.First; node != null; node = node.Next)
                {
                    if (priority < node.Value.Priority)
                    {
                        list.AddBefore(node, listElement);
                        added = true;
                        break;
                    }
                }

                if (!added)
                {
                    list.AddLast(listElement);
                }
            }

            // update hash entry for quick access
            var hashElement = new HashUpdateEntry
                {
                    Target = target,
                    List = list,
                    Entry = listElement
                };

            m_pHashForUpdates.Add(target, hashElement);
        }
コード例 #25
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        public void PauseTarget(ICCSelectorProtocol target)
        {
            Debug.Assert(target != null);

            // custom selectors
            HashTimeEntry entry;
            if (m_pHashForTimers.TryGetValue(target, out entry))
            {
                entry.Paused = true;
            }

            // Update selector
            HashUpdateEntry updateEntry;
            if (m_pHashForUpdates.TryGetValue(target, out updateEntry))
            {
                updateEntry.Entry.Paused = true;
            }
        }
コード例 #26
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        public void ResumeTarget(ICCSelectorProtocol target)
        {
            Debug.Assert(target != null);

            // custom selectors
            HashTimeEntry element;
            if (m_pHashForTimers.TryGetValue(target, out element))
            {
                element.Paused = false;
            }

            // Update selector
            HashUpdateEntry elementUpdate;
            if (m_pHashForUpdates.TryGetValue(target, out elementUpdate))
            {
                elementUpdate.Entry.Paused = false;
            }
        }
コード例 #27
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        /** Unschedules all selectors for a given target.
    	     This also includes the "update" selector.
    	     @since v0.99.3
    	     */

        public void UnscheduleAllForTarget(ICCSelectorProtocol target)
        {
            // explicit NULL handling
            if (target == null)
            {
                return;
            }

            // custom selectors           
            HashTimeEntry element;

            if (m_pHashForTimers.TryGetValue(target, out element))
            {
                if (element.Timers.Contains(element.CurrentTimer))
                {
                    element.CurrentTimerSalvaged = true;
                }
                element.Timers.Clear();

                if (m_pCurrentTarget == element)
                {
                    m_bCurrentTargetSalvaged = true;
                }
                else
                {
                    RemoveHashElement(element);
                }
            }

            // update selector
            UnscheduleUpdateForTarget(target);
        }
コード例 #28
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        /*
        unsigned int CCScheduler::scheduleScriptFunc(unsigned int nHandler, float fInterval, bool bPaused)
        {
            CCSchedulerScriptHandlerEntry* pEntry = CCSchedulerScriptHandlerEntry::create(nHandler, fInterval, bPaused);
            if (!m_pScriptHandlerEntries)
            {
                m_pScriptHandlerEntries = CCArray::create(20);
                m_pScriptHandlerEntries->retain();
            }
            m_pScriptHandlerEntries->addObject(pEntry);
            return pEntry->getEntryId();
        }

        void CCScheduler::unscheduleScriptEntry(unsigned int uScheduleScriptEntryID)
        {
            for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--)
            {
                CCSchedulerScriptHandlerEntry* pEntry = static_cast<CCSchedulerScriptHandlerEntry*>(m_pScriptHandlerEntries->objectAtIndex(i));
                if (pEntry->getEntryId() == uScheduleScriptEntryID)
                {
                    pEntry->markedForDeletion();
                    break;
                }
            }
        }
        */

        public void UnscheduleUpdateForTarget(ICCSelectorProtocol target)
        {
            if (target == null)
            {
                return;
            }

            HashUpdateEntry element;
            if (m_pHashForUpdates.TryGetValue(target, out element))
            {
                if (m_bUpdateHashLocked)
                {
                    element.Entry.MarkedForDeletion = true;
                }
                else
                {
                    RemoveUpdateFromHash(element.Entry);
                }
            }
        }
コード例 #29
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        /** Unschedule a selector for a given target.
    	     If you want to unschedule the "update", use unscheudleUpdateForTarget.
    	     @since v0.99.3
    	     */

        public void UnscheduleSelector(Action<float> selector, ICCSelectorProtocol target)
        {
            // explicity handle nil arguments when removing an object
            if (selector == null || target == null)
            {
                return;
            }

            HashTimeEntry element;
            if (m_pHashForTimers.TryGetValue(target, out element))
            {
                for (int i = 0; i < element.Timers.Count; i++)
                {
                    var timer = element.Timers[i];

                    if (selector == timer.Selector)
                    {
                        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;
                    }
                }
            }
        }
コード例 #30
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        /** Initializes a timer with a target, a selector and an interval in seconds. 
         *  Target is not needed in c#, it is just for compatibility.
         */

        public CCTimer(CCScheduler scheduler, ICCSelectorProtocol target, Action<float> selector, float seconds)
            : this(scheduler, target, selector, seconds, 0, 0)
        {
        }
コード例 #31
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        /** Schedules the 'update' selector for a given target with a given priority.
    	     The 'update' selector will be called every frame.
    	     The lower the priority, the earlier it is called.
    	     @since v0.99.3
    	     */

        public void ScheduleUpdateForTarget(ICCSelectorProtocol targt, int priority, bool paused)
        {
            HashUpdateEntry element;

            if (m_pHashForUpdates.TryGetValue(targt, out element))
            {
                Debug.Assert(element.Entry.MarkedForDeletion);

                // TODO: check if priority has changed!
                element.Entry.MarkedForDeletion = false;

                return;
            }

            // most of the updates are going to be 0, that's way there
            // is an special list for updates with priority 0
            if (priority == 0)
            {
                AppendIn(m_pUpdates0List, targt, paused);
            }
            else if (priority < 0)
            {
                PriorityIn(m_pUpdatesNegList, targt, priority, paused);
            }
            else
            {
                PriorityIn(m_pUpdatesPosList, targt, priority, paused);
            }
        }
コード例 #32
0
ファイル: CCScheduler.cs プロジェクト: rtabbara/cocos2d-xna
        /** 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's recommended to use 'scheduleUpdateForTarget:' instead.
         If the selector is already scheduled, then only the interval parameter will be updated without re-scheduling it again.
         repeat let the action be repeated repeat + 1 times, use kCCRepeatForever to let the action run continuously
         delay is the amount of time the action will wait before it'll start

         @since v0.99.3, repeat and delay added in v1.1
         */

        public void ScheduleSelector(Action<float> selector, ICCSelectorProtocol target, float interval, uint repeat,
                                     float delay, bool paused)
        {
            Debug.Assert(selector != null);
            Debug.Assert(target != null);

            HashTimeEntry element;

            if (!m_pHashForTimers.TryGetValue(target, out element))
            {
                element = new HashTimeEntry {Target = target};
                m_pHashForTimers[target] = element;

                // Is this the 1st element ? Then set the pause level to all the selectors of this target
                element.Paused = paused;
            }
            else
            {
                Debug.Assert(element.Paused == paused);
            }

            if (element.Timers == null)
            {
                element.Timers = new List<CCTimer>();
            }
            else
            {
                foreach (var timer in element.Timers)
                {
                    if (selector == timer.Selector)
                    {
                        Debug.WriteLine(
                            "CCSheduler#scheduleSelector. Selector already scheduled. Updating interval from: {0} to {1}",
                            timer.Interval, interval);
                        timer.Interval = interval;
                        return;
                    }
                }
            }

            element.Timers.Add(new CCTimer(this, target, selector, interval, repeat, delay));
        }
コード例 #33
0
ファイル: CCScheduler.cs プロジェクト: liwq-net/UIFactory
        private void UpdateTarget(ICCSelectorProtocol target, float dt)
        {
            if (OnUnhandledException == null)
            {
                target.Update(dt);
                return;
            }

            try
            {
                target.Update(dt);
            }
            catch (Exception exception)
            {
                OnUnhandledException(exception);
            }
        }
コード例 #34
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        internal void update(float dt)
        {
            m_bUpdateHashLocked = true;

            try
            {
                if (TimeScale != 1.0f)
                {
                    dt *= TimeScale;
                }

                LinkedListNode <ListEntry> next;

                // updates with priority < 0
                //foreach (ListEntry entry in _updatesNegList)
                for (LinkedListNode <ListEntry> node = m_pUpdatesNegList.First; node != null; node = next)
                {
                    next = node.Next;
                    if (!node.Value.Paused && !node.Value.MarkedForDeletion)
                    {
                        UpdateTarget(node.Value.Target, dt);
                    }
                }

                // updates with priority == 0
                //foreach (ListEntry entry in _updates0List)
                for (LinkedListNode <ListEntry> node = m_pUpdates0List.First; node != null; node = next)
                {
                    next = node.Next;
                    if (!node.Value.Paused && !node.Value.MarkedForDeletion)
                    {
                        UpdateTarget(node.Value.Target, dt);
                    }
                }

                // updates with priority > 0
                for (LinkedListNode <ListEntry> node = m_pUpdatesPosList.First; node != null; node = next)
                {
                    next = node.Next;
                    if (!node.Value.Paused && !node.Value.MarkedForDeletion)
                    {
                        UpdateTarget(node.Value.Target, dt);
                    }
                }

                // Iterate over all the custom selectors
                var count = m_pHashForTimers.Keys.Count;
                if (s_pTmpSelectorArray.Length < count)
                {
                    s_pTmpSelectorArray = new ICCSelectorProtocol[s_pTmpSelectorArray.Length * 2];
                }
                m_pHashForTimers.Keys.CopyTo(s_pTmpSelectorArray, 0);

                for (int i = 0; i < count; i++)
                {
                    ICCSelectorProtocol key = s_pTmpSelectorArray[i];
                    if (key == null || !m_pHashForTimers.ContainsKey(key))
                    {
                        continue;
                    }
                    HashTimeEntry elt = m_pHashForTimers[key];

                    m_pCurrentTarget         = elt;
                    m_bCurrentTargetSalvaged = false;

                    if (elt != null && !m_pCurrentTarget.Paused)
                    {
                        // The 'timers' array may change while inside this loop
                        for (elt.TimerIndex = 0; elt.TimerIndex < elt.Timers.Count; ++elt.TimerIndex)
                        {
                            elt.CurrentTimer = elt.Timers[elt.TimerIndex];
                            if (elt.CurrentTimer != null)
                            {
                                elt.CurrentTimerSalvaged = false;
                                UpdateTarget(elt.CurrentTimer, dt);
                                elt.CurrentTimer = null;
                            }
                        }
                    }

                    // only delete currentTarget if no actions were scheduled during the cycle (issue #481)
                    if (m_bCurrentTargetSalvaged && m_pCurrentTarget.Timers.Count == 0)
                    {
                        RemoveHashElement(m_pCurrentTarget);
                    }
                }

                /*
                 * // Iterate over all the script callbacks
                 * if (m_pScriptHandlerEntries)
                 * {
                 *  for (int i = m_pScriptHandlerEntries->count() - 1; i >= 0; i--)
                 *  {
                 *      CCSchedulerScriptHandlerEntry* pEntry = static_cast<CCSchedulerScriptHandlerEntry*>(m_pScriptHandlerEntries->objectAtIndex(i));
                 *      if (pEntry->isMarkedForDeletion())
                 *      {
                 *          m_pScriptHandlerEntries->removeObjectAtIndex(i);
                 *      }
                 *      else if (!pEntry->isPaused())
                 *      {
                 *          pEntry->getTimer()->update(dt);
                 *      }
                 *  }
                 * }
                 */

                // delete all updates that are marked for deletion
                // updates with priority < 0
                for (LinkedListNode <ListEntry> node = m_pUpdatesNegList.First; node != null; node = next)
                {
                    next = node.Next;
                    if (node.Value.MarkedForDeletion)
                    {
                        m_pUpdatesNegList.Remove(node);
                        RemoveUpdateFromHash(node.Value);
                    }
                }

                // updates with priority == 0
                for (LinkedListNode <ListEntry> node = m_pUpdates0List.First; node != null; node = next)
                {
                    next = node.Next;
                    if (node.Value.MarkedForDeletion)
                    {
                        m_pUpdates0List.Remove(node);
                        RemoveUpdateFromHash(node.Value);
                    }
                }

                // updates with priority > 0
                for (LinkedListNode <ListEntry> node = m_pUpdatesPosList.First; node != null; node = next)
                {
                    next = node.Next;
                    if (node.Value.MarkedForDeletion)
                    {
                        m_pUpdatesPosList.Remove(node);
                        RemoveUpdateFromHash(node.Value);
                    }
                }
            }
            finally
            {
                // Always do this just in case there is a problem

                m_bUpdateHashLocked = false;
                m_pCurrentTarget    = null;
            }
        }
コード例 #35
0
ファイル: CCScheduler.cs プロジェクト: krashman/cocos2d-xna
        /** Initializes a timer with a target, a selector and an interval in seconds.
         *  Target is not needed in c#, it is just for compatibility.
         */

        public CCTimer(CCScheduler scheduler, ICCSelectorProtocol target, Action <float> selector, float seconds)
            : this(scheduler, target, selector, seconds, 0, 0)
        {
        }