private void RemoveHashElement(HashSelectorEntry element) { m_pHashForSelectors.Remove(element.Target); element.Timers.Clear(); element.Target = null; }
/** 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(SEL_SCHEDULE selector, SelectorProtocol target, float interval, bool paused, uint repeat, float delay) { Debug.Assert(selector != null); Debug.Assert(target != null); HashSelectorEntry element; if (!m_pHashForSelectors.TryGetValue(target, out element)) { element = new HashSelectorEntry { 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 = 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)); }
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) { node.Value.Target.Update(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) { node.Value.Target.Update(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) { node.Value.Target.Update(dt); } } // Iterate over all the custom selectors var count = m_pHashForSelectors.Keys.Count; if (s_pTmpSelectorArray.Length < count) { s_pTmpSelectorArray = new SelectorProtocol[s_pTmpSelectorArray.Length * 2]; } m_pHashForSelectors.Keys.CopyTo(s_pTmpSelectorArray, 0); for (int i = 0; i < count; i++) { HashSelectorEntry elt = m_pHashForSelectors[s_pTmpSelectorArray[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[elt.TimerIndex]; elt.CurrentTimerSalvaged = false; elt.CurrentTimer.Update(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; } }
/** 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(SEL_SCHEDULE selector, SelectorProtocol target, float interval, bool paused, uint repeat, float delay) { Debug.Assert(selector != null); Debug.Assert(target != null); HashSelectorEntry element; if (!m_pHashForSelectors.TryGetValue(target, out element)) { element = new HashSelectorEntry { 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 = 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)); }
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) { node.Value.Target.Update(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) { node.Value.Target.Update(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) { node.Value.Target.Update(dt); } } // Iterate over all the custom selectors var count = m_pHashForSelectors.Keys.Count; if (s_pTmpSelectorArray.Length < count) { s_pTmpSelectorArray = new SelectorProtocol[s_pTmpSelectorArray.Length * 2]; } m_pHashForSelectors.Keys.CopyTo(s_pTmpSelectorArray, 0); for (int i = 0; i < count; i++) { SelectorProtocol key = s_pTmpSelectorArray[i]; if (!m_pHashForSelectors.ContainsKey(key)) { continue; } HashSelectorEntry elt = m_pHashForSelectors[key]; 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[elt.TimerIndex]; elt.CurrentTimerSalvaged = false; elt.CurrentTimer.Update(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; } }