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 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); }