void appendIn(utList <tListEntry> list, System.Object target, bool paused) { tListEntry listEntry = new tListEntry(); listEntry.target = target; listEntry.paused = paused; listEntry.markedForDeletion = false; MethodInfo method = target.GetType().GetMethod(updateSelector); listEntry.impMethod = (TICK_IMP)Delegate.CreateDelegate(typeof(TICK_IMP), target, method); utNode <tListEntry> listElement = new utNode <tListEntry> (); listElement.next = listElement.prev = null; listElement.obj = listEntry; list.DL_APPEND(listElement); tHashUpdateEntry hashElement = new tHashUpdateEntry(); hashElement.target = target; hashElement.list = list; hashElement.entry = listElement; hashForUpdates.HASH_ADD_INT(target.GetHashCode(), hashElement); }
public void DL_DELETE(utNode <T> del) { NSUtils.Assert((del).prev != null, "del.prev should not be null."); if ((del).prev == (del)) { (_head) = null; } else if ((del) == (_head)) { (del).next.prev = (del).prev; (_head) = (del).next; } else { (del).prev.next = (del).next; if ((del).next != null) { (del).next.prev = (del).prev; } else { (_head).prev = (del).prev; } } }
void priorityIn(utList <tListEntry> list, System.Object target, int priority, bool paused) { tListEntry listEntry = new tListEntry(); listEntry.target = target; listEntry.priority = priority; listEntry.paused = paused; MethodInfo method = target.GetType().GetMethod(updateSelector); listEntry.impMethod = (TICK_IMP)Delegate.CreateDelegate(typeof(TICK_IMP), target, method); listEntry.markedForDeletion = false; utNode <tListEntry> listElement = new utNode <tListEntry> (); listElement.next = listElement.prev = null; listElement.obj = listEntry; if (list.head == null) { list.DL_APPEND(listElement); } else { bool added = false; for (utNode <tListEntry> elem = list.head; elem != null; elem = elem.next) { if (priority < elem.obj.priority) { if (elem == list.head) { list.DL_PREPEND(listElement); } else { listElement.next = elem; listElement.prev = elem.prev; elem.prev.next = listElement; elem.prev = listElement; } added = true; break; } } if (!added) { list.DL_APPEND(listElement); } } tHashUpdateEntry hashElement = new tHashUpdateEntry(); hashElement.target = target; hashElement.list = list; hashElement.entry = listElement; hashForUpdates.HASH_ADD_INT(target.GetHashCode(), hashElement); }
public void DL_PREPEND(utNode <T> add) { (add).next = _head; if (_head != null) { (add).prev = (_head).prev; (_head).prev = (add); } else { (add).prev = (add); } (_head) = (add); }
/** Pause all selectors and blocks from all targets with a minimum priority. * You should only call this with kCCPriorityNonSystemMin or higher. * @since v2.0.0 */ public HashSet <System.Object> pauseAllTargetsWithMinPriority(int minPriority) { HashSet <System.Object> idsWithSelectors = new HashSet <System.Object>(); // Custom Selectors { var enumerator = hashForTimers.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <int, tHashTimerEntry> kv = enumerator.Current; tHashTimerEntry element = kv.Value; element.paused = true; idsWithSelectors.Add(element.target); } } // Updates selectors if (minPriority < 0) { for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (entry.obj.priority >= minPriority) { entry.obj.paused = true; idsWithSelectors.Add(entry.obj.target); } } } if (minPriority <= 0) { for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; entry.obj.paused = true; idsWithSelectors.Add(entry.obj.target); } } { for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (entry.obj.priority >= minPriority) { entry.obj.paused = true; idsWithSelectors.Add(entry.obj.target); } } } return(idsWithSelectors); }
void removeUpdatesFromHash(utNode <tListEntry> entry) { tHashUpdateEntry element = hashForUpdates.HASH_FIND_INT(entry.obj.target.GetHashCode()); if (element != null) { // list entry element.list.DL_DELETE(element.entry); element.entry = null; // hash entry System.Object target = element.target; hashForUpdates.HASH_DEL(target.GetHashCode()); } }
public void DL_APPEND(utNode <T> add) { if (_head != null) { add.prev = _head.prev; _head.prev.next = add; _head.prev = add; add.next = null; } else { _head = add; _head.prev = _head; _head.next = null; } }
public void addLaterDelegate(System.Object aDelegate, int priority, utList <tListEntry> list) { // XXX: Since, "remove" is "executed" after "add", it is not needed to check if the delegate was already added for removal. // In fact, if you remove it now, it could be a bug, since EventDispatcher doesn't support updated priority. // And the only way to update the priority is by deleting, re-adding the delegate with a new priority tListAddedEntry listEntry = new tListAddedEntry(); listEntry.aDelegate = aDelegate; listEntry.priority = priority; listEntry.listToBeAdded = list; utNode <tListAddedEntry> listElement = new utNode <tListAddedEntry> (); listElement.next = listElement.prev = null; listElement.obj = listEntry; _delegatesToBeAdded.DL_APPEND(listElement); }
public void removeLaterDelegate(System.Object aDelegate, utList <tListEntry> list) { // Only add it if it was not already added for deletion if (!removeDelegate <tListAddedEntry>(aDelegate, _delegatesToBeAdded)) { tListDeletedEntry listEntry = new tListDeletedEntry(); listEntry.aDelegate = aDelegate; listEntry.listToBeDeleted = list; utNode <tListDeletedEntry> listElement = new utNode <tListDeletedEntry> (); listElement.next = listElement.prev = null; listElement.obj = listEntry; _delegatesToBeRemoved.DL_APPEND(listElement); } }
public void addDelegate(System.Object aDelegate, int priority, utList <tListEntry> list) { tListEntry listEntry = new tListEntry(); listEntry.aDelegate = aDelegate; listEntry.priority = priority; utNode <tListEntry> listElement = new utNode <tListEntry> (); listElement.next = listElement.prev = null; listElement.obj = listEntry; bool added = false; for (utNode <tListEntry> elem = list.head; elem != null; elem = elem.next) { if (priority < elem.obj.priority) { if (elem == list.head) { list.DL_PREPEND(listElement); } else { listElement.next = elem; listElement.prev = elem.prev; elem.prev.next = listElement; elem.prev = listElement; } added = true; break; } } // Not added? priority has the higher value. Append it. if (!added) { list.DL_APPEND(listElement); } }
/** Unschedules all selectors and blocks from all targets with a minimum priority. * You should only call this with kCCPriorityNonSystemMin or higher. * @since v2.0.0 */ public void unscheduleAllWithMinPriority(int minPriority) { // Custom Selectors for (int i = hashForTimers.Count - 1; i >= 0; i--) { KeyValuePair <int, tHashTimerEntry> keyValue = hashForTimers.ElementAt(i); System.Object target = keyValue.Value.target; unscheduleAllForTarget(target); } // Updates selectors if (minPriority < 0) { for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (entry.obj.priority >= minPriority) { unscheduleUpdateForTarget(entry.obj.target); } } } if (minPriority <= 0) { for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; unscheduleUpdateForTarget(entry.obj.target); } } for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (entry.obj.priority >= minPriority) { unscheduleUpdateForTarget(entry.obj.target); } } }
//-------------update------------ /** 'update' the scheduler. * You should NEVER call this method, unless you know what you are doing. */ public void update(float dt) { if (_paused) { return; } updateHashLocked = true; if (!FloatUtils.EQ(_timeScale, 1.0f)) { dt *= _timeScale; } // Iterate all over the Updates selectors // updates with priority < 0 { for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (!entry.obj.paused && !entry.obj.markedForDeletion) { entry.obj.impMethod.Invoke(dt); } } } // updates with priority == 0 { for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (!entry.obj.paused && !entry.obj.markedForDeletion) { entry.obj.impMethod.Invoke(dt); } } } // updates with priority > 0 { for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (!entry.obj.paused && !entry.obj.markedForDeletion) { entry.obj.impMethod.Invoke(dt); } } } // Iterate all over the custom selectors (CCTimers) if (hashForTimers.Any()) { var enumerator = new Dictionary <int, tHashTimerEntry>(hashForTimers).GetEnumerator(); while (enumerator.MoveNext()) { var elt = enumerator.Current.Value; currentTarget = elt; currentTargetSalvaged = false; if (!currentTarget.paused) { 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; } } if (currentTargetSalvaged && currentTarget.timers.Count == 0) { removeHashElement(currentTarget); } } } for (utNode <tListEntry> tmp = updatesNeg.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (entry.obj.markedForDeletion) { removeUpdatesFromHash(entry); } } for (utNode <tListEntry> tmp = updates0.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (entry.obj.markedForDeletion) { removeUpdatesFromHash(entry); } } for (utNode <tListEntry> tmp = updatesPos.head; tmp != null; tmp = tmp.next) { utNode <tListEntry> entry = tmp; if (entry.obj.markedForDeletion) { removeUpdatesFromHash(entry); } } updateHashLocked = false; currentTarget = null; }