public void ContinueTimer(TimerBase timer) { if (!this.IsTimerRunning(timer)) { this.RunningTimers.Add(timer); } }
public void HandleGameUpdate() { if (this.frameCounter >= TimerManager.FrameUpdateFreq) { this.frameCounter = 0; for (int i = 0; i < this.RunningTimers.Count; i++) { TimerBase abstractTimer = this.RunningTimers[i]; abstractTimer.Update(TimerManager.FrameUpdateFreq); if (abstractTimer.IsExpired()) { if (this.InvokeTimerCallback(abstractTimer)) { abstractTimer.Reset(); } else { this.RunningTimers.RemoveAt(i--); } } } } this.frameCounter++; }
public void StartTimer(TimerBase timer) { if (!this.IsTimerRunning(timer)) { this.RunningTimers.Add(timer); timer.Reset(); } }
private bool InvokeTimerCallback(TimerBase timer) { try { return(timer.Callback(timer)); } catch (Exception ex) { this.PluginTrace.WriteLineError("A Timer's callback has thrown an exception. Excpetion details: " + ex); return(false); } }
private void AddTimer(TimerBase timer) { lock (this.alterTimersLock) { List <TimerBase> newTimers = new List <TimerBase>(this.runningTimers.Count); newTimers.AddRange(this.runningTimers); newTimers.Add(timer); Interlocked.Exchange(ref this.runningTimers, newTimers); } }
public void RemoveTimer(TimerBase timer, bool andInvokeCallback = false) { try { if (andInvokeCallback) { this.InvokeTimerCallback(timer); } } finally { this.RunningTimers.Remove(timer); } }
public void StartOrResetTimer(TimerBase timer) { if (this.IsTimerRunning(timer)) { timer.Reset(); } else { this.AddTimer(timer); } }
public void RemoveTimer(TimerBase timer, bool andInvokeCallback = false) { lock (this.alterTimersLock) { List <TimerBase> newTimers = new List <TimerBase>(this.runningTimers.Count); newTimers.AddRange(this.runningTimers); newTimers.Remove(timer); Interlocked.Exchange(ref this.runningTimers, newTimers); } if (andInvokeCallback) { this.InvokeTimerCallback(timer); } }
private bool RefillChestTimer_Callback(TimerBase timer) { RefillChestMetadata refillChest = (RefillChestMetadata)timer.Data; lock (this.WorldMetadata.Protections) { ProtectionEntry protection = this.WorldMetadata.Protections.Values.SingleOrDefault(p => p.RefillChestData == refillChest); if (protection == null) return false; DPoint chestLocation = protection.TileLocation; this.TryRefillChest(chestLocation, refillChest); // Returning true would mean the Timer would repeat. return false; } }
public bool IsTimerRunning(TimerBase timer) { return(this.RunningTimers.Contains(timer)); }
private bool RefillChestTimer_Callback(TimerBase timer) { RefillChestMetadata refillChest = (RefillChestMetadata)timer.Data; lock (this.WorldMetadata.Protections) { ProtectionEntry protection = this.WorldMetadata.Protections.Values.SingleOrDefault(p => p.RefillChestData == refillChest); if (protection == null) return false; DPoint chestLocation = protection.TileLocation; try { this.TryRefillChest(chestLocation, refillChest); } catch (InvalidOperationException) { this.PluginTrace.WriteLineWarning($"Chest at position {chestLocation} doesn't seem to exist anymore. Can't refill it."); return false; } // Returning true would mean the Timer would repeat. return false; } }