public void Update(float deltaTime, EUpdatePriority startPriority, EUpdatePriority endPriority) { int startIndex = (int)startPriority; int endIndex = (int)endPriority; for (int i = startIndex; i <= endIndex; ++i) { List <CUpdateScope> updates = m_priorityUpdateBuckets[i]; for (int j = updates.Count - 1; j >= 0; --j) { CUpdateScope update = updates[j]; if (update.IsConnected()) { update.Callback(deltaTime); } else { // If the update was disconnected remove it from the list ContainerUtilities.RemoveSwapAt(updates, j); } } List <CUpdateScope> singleUpdates = m_oneTimeUpdateBucket[i]; for (int j = 0; j < singleUpdates.Count; j++) { CUpdateScope update = singleUpdates[j]; if (update.IsConnected()) { update.Callback(deltaTime); } update.Disconnect(); } singleUpdates.Clear(); } }
/// <summary> /// Register a new UpdateCallback that is called one time /// </summary> /// <param name="callback"></param> /// <param name="priority"></param> /// <returns></returns> public CUpdateScope ConnectOneTimeUpdate(UpdateCallback callback, EUpdatePriority priority) { CUpdateScope outScope = new CUpdateScope(callback); m_oneTimeUpdateBucket[(int)priority].Add(outScope); return(outScope); }
/// <summary> /// Register a new UpdateCallback that is called every frame until disconnected /// </summary> /// <param name="callback"></param> /// <param name="priority"></param> /// <returns></returns> public CUpdateScope Connect(UpdateCallback callback, EUpdatePriority priority) { CUpdateScope outScope = new CUpdateScope(callback); // Add the scope to the priority bucket m_priorityUpdateBuckets[(int)priority].Add(outScope); return(outScope); }