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 priorityIn(List <tListEntry> list, SelectorProtocol target, int nPriority, bool bPaused)
        {
            tListEntry item = new tListEntry
            {
                target            = target,
                priority          = nPriority,
                paused            = bPaused,
                markedForDeletion = false
            };
            int index = 0;

            foreach (tListEntry entry2 in list)
            {
                if (nPriority < entry2.priority)
                {
                    break;
                }
                index++;
            }
            list.Insert(index, item);
            tHashUpdateEntry entry3 = new tHashUpdateEntry
            {
                target = target,
                list   = list,
                entry  = item
            };

            this.m_pHashForUpdates.Add(target, entry3);
        }
Example #3
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 #4
0
        private void appendIn(List <tListEntry> list, SelectorProtocol target, bool bPaused)
        {
            tListEntry item = new tListEntry
            {
                target            = target,
                paused            = bPaused,
                markedForDeletion = false
            };

            list.Add(item);
            tHashUpdateEntry entry2 = new tHashUpdateEntry
            {
                target = target,
                list   = list,
                entry  = item
            };

            this.m_pHashForUpdates.Add(target, entry2);
        }
Example #5
0
 private void removeUpdateFromHash(tListEntry entry)
 {
     if (this.m_pHashForUpdates.ContainsKey(entry.target))
     {
         tHashUpdateEntry entry2 = this.m_pHashForUpdates[entry.target];
         entry2.list.Remove(entry);
         entry2.entry  = null;
         entry2.target = null;
         SelectorProtocol key = null;
         foreach (KeyValuePair <SelectorProtocol, tHashUpdateEntry> pair in this.m_pHashForUpdates)
         {
             if (entry2 == pair.Value)
             {
                 key = pair.Key;
                 break;
             }
         }
         this.m_pHashForUpdates.Remove(key);
     }
 }
Example #6
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 #7
0
 public void tick(float dt)
 {
     this.m_bUpdateHashLocked = true;
     if (this.m_fTimeScale != 1f)
     {
         dt *= this.m_fTimeScale;
     }
     for (int i = 0; i < this.m_pUpdatesNegList.Count; i++)
     {
         tListEntry entry = this.m_pUpdatesNegList[i];
         if (!entry.paused && !entry.markedForDeletion)
         {
             entry.target.update(dt);
         }
     }
     for (int j = 0; j < this.m_pUpdates0List.Count; j++)
     {
         tListEntry entry2 = this.m_pUpdates0List[j];
         if (!entry2.paused && !entry2.markedForDeletion)
         {
             entry2.target.update(dt);
         }
     }
     for (int k = 0; k < this.m_pUpdatesPosList.Count; k++)
     {
         tListEntry entry3 = this.m_pUpdatesPosList[k];
         if (!entry3.paused && !entry3.markedForDeletion)
         {
             entry3.target.update(dt);
         }
     }
     SelectorProtocol[] array = new SelectorProtocol[this.m_pHashForSelectors.Keys.Count];
     this.m_pHashForSelectors.Keys.CopyTo(array, 0);
     for (int m = 0; m < array.Length; m++)
     {
         if (this.m_pHashForSelectors.ContainsKey(array[m]))
         {
             tHashSelectorEntry entry4 = this.m_pHashForSelectors[array[m]];
             this.m_pCurrentTarget         = entry4;
             this.m_bCurrentTargetSalvaged = false;
             if (!this.m_pCurrentTarget.paused)
             {
                 entry4.timerIndex = 0;
                 while (entry4.timerIndex < entry4.timers.Count)
                 {
                     entry4.currentTimer         = entry4.timers[(int)entry4.timerIndex];
                     entry4.currentTimerSalvaged = false;
                     entry4.currentTimer.update(dt);
                     entry4.currentTimer = null;
                     entry4.timerIndex++;
                 }
             }
             if (this.m_bCurrentTargetSalvaged && (this.m_pCurrentTarget.timers.Count == 0))
             {
                 this.removeHashElement(this.m_pCurrentTarget);
             }
         }
     }
     for (int n = 0; n < this.m_pUpdatesNegList.Count; n++)
     {
         tListEntry item = this.m_pUpdatesNegList[n];
         if (item.markedForDeletion)
         {
             this.m_listToDelete.Add(item);
         }
     }
     for (int num6 = 0; num6 < this.m_pUpdates0List.Count; num6++)
     {
         tListEntry entry6 = this.m_pUpdates0List[num6];
         if (entry6.markedForDeletion)
         {
             this.m_listToDelete.Add(entry6);
         }
     }
     for (int num7 = 0; num7 < this.m_pUpdatesPosList.Count; num7++)
     {
         tListEntry entry7 = this.m_pUpdatesPosList[num7];
         if (entry7.markedForDeletion)
         {
             this.m_listToDelete.Add(entry7);
         }
     }
     foreach (tListEntry entry8 in this.m_listToDelete)
     {
         this.removeUpdateFromHash(entry8);
     }
     this.m_listToDelete.Clear();
 }
        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);
            }
        }
        // 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);
        }
        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 #11
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();
        }