/** Unschedules all selectors for a given target. * This also includes the "update" selector. * @since v0.99.3 */ public void unscheduleAllSelectors() { tHashSelectorEntry[] hashSelectorToDelete = new tHashSelectorEntry[m_pHashForSelectors.Values.Count]; m_pHashForSelectors.Values.CopyTo(hashSelectorToDelete, 0); for (int i = 0; i < hashSelectorToDelete.Length; i++) { unscheduleAllSelectorsForTarget(hashSelectorToDelete[i].target); } // Updates selectors tListEntry[] listEntryToDelete = m_pUpdates0List.ToArray(); for (int i = 0; i < listEntryToDelete.Length; i++) { unscheduleAllSelectorsForTarget(listEntryToDelete[i].target); } listEntryToDelete = m_pUpdatesNegList.ToArray(); for (int i = 0; i < listEntryToDelete.Length; i++) { unscheduleAllSelectorsForTarget(listEntryToDelete[i].target); } listEntryToDelete = m_pUpdatesPosList.ToArray(); for (int i = 0; i < listEntryToDelete.Length; i++) { unscheduleAllSelectorsForTarget(listEntryToDelete[i].target); } }
/** Unschedules all selectors for a given target. * This also includes the "update" selector. * @since v0.99.3 */ public void unscheduleAllSelectorsForTarget(SelectorProtocol target) { // explicit NULL handling if (target == null) { return; } // custom selectors if (m_pHashForSelectors.ContainsKey(target)) { tHashSelectorEntry element = m_pHashForSelectors[target]; 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); }
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; } } } }
/** 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); }
/** 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; } } } }
private void removeHashElement(tHashSelectorEntry element) { element.timers.Clear(); element.target = null; SelectorProtocol key = null; foreach (KeyValuePair <SelectorProtocol, tHashSelectorEntry> pair in this.m_pHashForSelectors) { if (element == pair.Value) { key = pair.Key; break; } } this.m_pHashForSelectors.Remove(key); }
private void removeHashElement(tHashSelectorEntry element) { element.timers.Clear(); element.target = null; SelectorProtocol target = null; foreach (KeyValuePair <SelectorProtocol, tHashSelectorEntry> kvp in m_pHashForSelectors) { if (element == kvp.Value) { target = kvp.Key; break; } } m_pHashForSelectors.Remove(target); }
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); }
public void unscheduleAllSelectors() { tHashSelectorEntry[] array = new tHashSelectorEntry[this.m_pHashForSelectors.Values.Count]; this.m_pHashForSelectors.Values.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { this.unscheduleAllSelectorsForTarget(array[i].target); } tListEntry[] entryArray2 = this.m_pUpdates0List.ToArray(); for (int j = 0; j < entryArray2.Length; j++) { this.unscheduleAllSelectorsForTarget(entryArray2[j].target); } entryArray2 = this.m_pUpdatesNegList.ToArray(); for (int k = 0; k < entryArray2.Length; k++) { this.unscheduleAllSelectorsForTarget(entryArray2[k].target); } entryArray2 = this.m_pUpdatesPosList.ToArray(); for (int m = 0; m < entryArray2.Length; m++) { this.unscheduleAllSelectorsForTarget(entryArray2[m].target); } }
public void unscheduleAllSelectorsForTarget(SelectorProtocol target) { if (target != null) { if (this.m_pHashForSelectors.ContainsKey(target)) { tHashSelectorEntry element = this.m_pHashForSelectors[target]; if (element.timers.Contains(element.currentTimer)) { element.currentTimerSalvaged = true; } element.timers.Clear(); if (this.m_pCurrentTarget == element) { this.m_bCurrentTargetSalvaged = true; } else { this.removeHashElement(element); } } this.unscheduleUpdateForTarget(target); } }
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 removeHashElement(tHashSelectorEntry element) { element.timers.Clear(); element.target = null; SelectorProtocol target = null; foreach (KeyValuePair<SelectorProtocol, tHashSelectorEntry> kvp in m_pHashForSelectors) { if (element == kvp.Value) { target = kvp.Key; break; } } m_pHashForSelectors.Remove(target); }
/** Unschedules all selectors for a given target. This also includes the "update" selector. @since v0.99.3 */ public void unscheduleAllSelectors() { tHashSelectorEntry[] hashSelectorToDelete = new tHashSelectorEntry[m_pHashForSelectors.Values.Count]; m_pHashForSelectors.Values.CopyTo(hashSelectorToDelete, 0); for (int i = 0; i < hashSelectorToDelete.Length; i++) { unscheduleAllSelectorsForTarget(hashSelectorToDelete[i].target); } // Updates selectors tListEntry[] listEntryToDelete = m_pUpdates0List.ToArray(); for (int i = 0; i < listEntryToDelete.Length; i++) { unscheduleAllSelectorsForTarget(listEntryToDelete[i].target); } listEntryToDelete = m_pUpdatesNegList.ToArray(); for (int i = 0; i < listEntryToDelete.Length; i++) { unscheduleAllSelectorsForTarget(listEntryToDelete[i].target); } listEntryToDelete = m_pUpdatesPosList.ToArray(); for (int i = 0; i < listEntryToDelete.Length; i++) { unscheduleAllSelectorsForTarget(listEntryToDelete[i].target); } }
/** '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(); }
/** 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); }
/** '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 foreach (tListEntry entry in m_pUpdatesNegList) { if ((!entry.paused) && (!entry.markedForDeletion)) { entry.target.update(dt); } } // updates with priority == 0 foreach (tListEntry entry in m_pUpdates0List) { if ((!entry.paused) && (!entry.markedForDeletion)) { entry.target.update(dt); } } // updates with priority > 0 foreach (tListEntry entry in m_pUpdatesPosList) { if ((!entry.paused) && (!entry.markedForDeletion)) { entry.target.update(dt); } } // Interate 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++) { 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(); }
/** 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); }