// 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); }
/** Schedules the 'update' selector for a given target with a given priority. * The 'update' selector will be called every frame. * The lower the priority, the earlier it is called. * @since v0.99.3 */ public void scheduleUpdateForTarget(SelectorProtocol targt, int nPriority, bool bPaused) { tHashUpdateEntry hashElement = null; if (m_pHashForUpdates.ContainsKey(targt)) { // TODO: check if priority has changed! hashElement = m_pHashForUpdates[targt]; hashElement.entry.markedForDeletion = false; } // most of the updates are going to be 0, that's way there // is an special list for updates with priority 0 if (nPriority == 0) { appendIn(m_pUpdates0List, targt, bPaused); } else if (nPriority < 0) { priorityIn(m_pUpdatesNegList, targt, nPriority, bPaused); } else { priorityIn(m_pUpdatesPosList, targt, nPriority, bPaused); } }
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); }
/** Unschedules the update selector for a given target * @since v0.99.3 */ public void unscheduleUpdateForTarget(SelectorProtocol target) { if (target == null) { return; } if (m_pHashForUpdates.ContainsKey(target)) { tHashUpdateEntry element = m_pHashForUpdates[target]; if (m_bUpdateHashLocked) { element.entry.markedForDeletion = true; } else { removeUpdateFromHash(element.entry); } } }
/** Resumes the target. * The 'target' will be unpaused, so all schedule selectors/update will be 'ticked' again. * If the target is not present, nothing happens. * @since v0.99.3 */ public void resumeTarget(SelectorProtocol target) { if (target == null) { return; } // custom selectors if (m_pHashForSelectors.ContainsKey(target)) { m_pHashForSelectors[target].paused = false; } // Update selector if (m_pHashForUpdates.ContainsKey(target)) { tHashUpdateEntry element = m_pHashForUpdates[target]; Debug.Assert(element != null); element.entry.paused = false; } }
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); } }
/** Pauses the target. * All scheduled selectors/update for a given target won't be 'ticked' until the target is resumed. * If the target is not present, nothing happens. * @since v0.99.3 */ public void pauseTarget(SelectorProtocol target) { if (target == null) { return; } // custom selectors if (m_pHashForSelectors.ContainsKey(target)) { m_pHashForSelectors[target].paused = true; } // Update selector if (m_pHashForUpdates.ContainsKey(target)) { tHashUpdateEntry element = m_pHashForUpdates[target]; if (element != null) { element.entry.paused = true; } } }