Example #1
0
        // update specific

        private void priorityIn(List <tListEntry> list, SelectorProtocol target, int nPriority, bool bPaused)
        {
            tListEntry listElement = new tListEntry();

            listElement.target            = target;
            listElement.priority          = nPriority;
            listElement.paused            = bPaused;
            listElement.markedForDeletion = false;

            // list will not be empty, because it is new in init()
            int index = 0;

            foreach (tListEntry element in list)
            {
                if (nPriority < element.priority)
                {
                    break;
                }

                ++index;
            }

            // Can not throw exception, because index in [0, count]
            list.Insert(index, listElement);

            // update hash entry for quick access
            tHashUpdateEntry hashElement = new tHashUpdateEntry();

            hashElement.target = target;
            hashElement.list   = list;
            hashElement.entry  = listElement;
            m_pHashForUpdates.Add(target, hashElement);
        }
Example #2
0
        private void appendIn(List <tListEntry> list, SelectorProtocol target, bool bPaused)
        {
            tListEntry listElement = new tListEntry();

            listElement.target            = target;
            listElement.paused            = bPaused;
            listElement.markedForDeletion = false;

            list.Add(listElement);

            // update hash entry for quicker access
            tHashUpdateEntry hashElement = new tHashUpdateEntry();

            hashElement.target = target;
            hashElement.list   = list;
            hashElement.entry  = listElement;
            m_pHashForUpdates.Add(target, hashElement);
        }
Example #3
0
        private void removeUpdateFromHash(tListEntry entry)
        {
            if (m_pHashForUpdates.ContainsKey(entry.target))
            {
                // list entry
                tHashUpdateEntry element = m_pHashForUpdates[entry.target];
                element.list.Remove(entry);
                element.entry = null;

                // hash entry
                element.target = null;
                SelectorProtocol target = null;
                foreach (KeyValuePair <SelectorProtocol, tHashUpdateEntry> kvp in m_pHashForUpdates)
                {
                    if (element == kvp.Value)
                    {
                        target = kvp.Key;
                        break;
                    }
                }
                m_pHashForUpdates.Remove(target);
            }
        }
Example #4
0
        /** 'tick' the scheduler.
         *   You should NEVER call this method, unless you know what you are doing.
         */
        public void tick(float dt)
        {
            m_bUpdateHashLocked = true;

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

            // updates with priority < 0
            // Jiri Formanek
            // http://www.cocos2d-x.org/boards/17/topics/10592
            for (int i = 0; i < m_pUpdatesNegList.Count; i++)
            {
                tListEntry entry = m_pUpdatesNegList[i];
                if ((!entry.paused) && (!entry.markedForDeletion))
                {
                    entry.target.update(dt);
                }
            }

            // updates with priority == 0
            // Jiri Formanek
            // http://www.cocos2d-x.org/boards/17/topics/10592
            for (int i = 0; i < m_pUpdates0List.Count; i++)
            {
                tListEntry entry = m_pUpdates0List[i];
                if ((!entry.paused) && (!entry.markedForDeletion))
                {
                    entry.target.update(dt);
                }
            }

            // updates with priority > 0
            // Jiri Formanek
            // http://www.cocos2d-x.org/boards/17/topics/10592
            for (int i = 0; i < m_pUpdatesPosList.Count; i++)
            {
                tListEntry entry = m_pUpdatesPosList[i];
                if ((!entry.paused) && (!entry.markedForDeletion))
                {
                    entry.target.update(dt);
                }
            }

            // Iterate all over the custom selectors
            SelectorProtocol[] keys = new SelectorProtocol[m_pHashForSelectors.Keys.Count];
            m_pHashForSelectors.Keys.CopyTo(keys, 0);
            for (int i = 0; i < keys.Length; i++)
            {
                if (!m_pHashForSelectors.ContainsKey(keys[i]))
                {
                    // Concurrent modification
                    continue;
                }
                tHashSelectorEntry elt = m_pHashForSelectors[keys[i]];
                m_pCurrentTarget         = elt;
                m_bCurrentTargetSalvaged = false;

                if (!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[(int)elt.timerIndex];
                        elt.currentTimerSalvaged = false;

                        elt.currentTimer.update(dt);

                        /* not needed
                         * if (elt.currentTimerSalvaged)
                         * {
                         *  // The currentTimer told the remove itself. To prevent the timer from
                         *  // accidentally deallocating itself before finishing its step, we retained
                         *  // it. Now that step is done, it's safe to release it.
                         *  elt->currentTimer->release();
                         * }
                         * */
                        elt.currentTimer = null;
                    }
                }

                // not needed
                // elt = (tHashSelectorEntry*)elt->hh.next;

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

            // delete all updates that are morked for deletion

            // updates with priority < 0
            for (int i = 0; i < m_pUpdatesNegList.Count; i++)
            {
                tListEntry entry = m_pUpdatesNegList[i];
                if (entry.markedForDeletion)
                {
                    //removeUpdateFromHash(entry);
                    m_listToDelete.Add(entry);
                }
            }

            // updates with priority == 0
            for (int i = 0; i < m_pUpdates0List.Count; i++)
            {
                tListEntry entry = m_pUpdates0List[i];
                if (entry.markedForDeletion)
                {
                    //removeUpdateFromHash(entry);
                    m_listToDelete.Add(entry);
                }
            }

            // updates with priority > 0
            for (int i = 0; i < m_pUpdatesPosList.Count; i++)
            {
                tListEntry entry = m_pUpdatesPosList[i];
                if (entry.markedForDeletion)
                {
                    //removeUpdateFromHash(entry);
                    m_listToDelete.Add(entry);
                }
            }

            // do the delete
            foreach (tListEntry entry in m_listToDelete)
            {
                removeUpdateFromHash(entry);
            }
            m_listToDelete.Clear();
        }