public void Tick(int currentTick) { tickInProgress = true; numCalls = 0; if (nextCycleStart <= currentTick) { currentIndex = 0; listProgress = 0; nextCycleStart = currentTick + tickInterval; } listProgress += tickList.Count / (float)tickInterval; var maxIndex = Mathf.Min(tickList.Count, Mathf.CeilToInt(listProgress)); for (; currentIndex < maxIndex; currentIndex++) { var entry = tickList[currentIndex]; if (entry.owner.Spawned) { try { entry.callback(); numCalls++; } catch (Exception e) { HugsLibController.Logger.Error("DistributedTickScheduler caught an exception while calling {0} registered by {1}: {2}", HugsLibUtility.DescribeDelegate(entry.callback), entry.owner, e); } } else { scheduler.UnregisterAtEndOfTick(entry.owner); } } tickInProgress = false; }
private void DoCallback(Action callback) { try { callback(); } catch (Exception e) { HugsLibUtility.BlameCallbackException("CallbackScheduler", callback, e); } }
/// <summary> /// Reads assembly version information for a mod assembly. /// </summary> /// <param name="assembly">The assembly to read</param> /// <param name="contentPack">The content pack the assembly was loaded from</param> /// <returns>See <see cref="ReadAssembly"/></returns> public static AssemblyVersionInfo ReadModAssembly(Assembly assembly, ModContentPack contentPack) { if (assembly == null) { throw new ArgumentNullException("assembly"); } var fileHandle = HugsLibUtility.TryGetModAssemblyFileInfo(assembly.GetName().Name, contentPack); var fullFilePath = fileHandle != null ? fileHandle.FullName : null; return(ReadAssembly(assembly, fullFilePath)); }
private bool DoCallback(SchedulerEntry entry) { if (entry.owner == null || entry.owner.Spawned) { try { entry.callback(); return(true); } catch (Exception e) { HugsLibController.Logger.Error("TickDelayScheduler caught an exception while calling {0} registered by {1}: {2}", HugsLibUtility.DescribeDelegate(entry.callback), entry.owner == null ? "[null]" : entry.owner.ToString(), e); } } return(false); }
internal void OnMapLoaded(Map map) { var numCalls = nextMapLoaded.Count; while (numCalls-- > 0) { var callback = nextMapLoaded.Dequeue(); try { callback(map); } catch (Exception e) { HugsLibUtility.BlameCallbackException("DoLaterScheduler", callback, e); } } }
private void InvokeCallbacks(Queue <Action> queue) { // allows for re-scheduling callbacks while they are being invoked var numCalls = queue.Count; while (numCalls-- > 0) { var callback = queue.Dequeue(); try { callback(); } catch (Exception e) { HugsLibUtility.BlameCallbackException("DoLaterScheduler", callback, e); } } }
public void Tick(int currentTick) { if (nextCycleStart <= currentTick) { currentIndex = 0; nextCycleStart = currentTick + tickInterval; } var numCallbacksThisTick = Math.Ceiling(tickList.Count / (float)tickInterval); while (numCallbacksThisTick > 0) { if (currentIndex >= tickList.Count) { break; } try { tickList[currentIndex](); } catch (Exception e) { HugsLibUtility.BlameCallbackException("DistributedTickScheduler", tickList[currentIndex], e); } currentIndex++; numCallbacksThisTick--; } }