/// <summary> /// Registers a delegate to be called every tickInterval ticks. /// </summary> /// <param name="callback">The delegate that will be called</param> /// <param name="tickInterval">The interval between the calls (for example 30 to have the delegate be called 2 times a second)</param> /// <param name="owner">The Thing the delegate is attached to. The callback will be automatically unregistered if the owner is found to be despawned at call time.</param> public void RegisterTickability(Action callback, int tickInterval, Thing owner) { if (lastProcessedTick < 0) { throw new Exception("Adding callback to not initialized DistributedTickScheduler"); } if (owner == null || owner.Destroyed) { throw new Exception("A non-null, not destroyed owner Thing is required to register for tickability"); } if (tickInterval < 1) { throw new Exception("Invalid tick interval: " + tickInterval); } if (entries.ContainsKey(owner)) { HugsLibController.Logger.Warning("DistributedTickScheduler tickability already registered for: " + owner); } else { var entry = new TickableEntry(callback, tickInterval, owner); GetTicker(tickInterval).Register(entry); entries.Add(owner, entry); } }
public void Unregister(TickableEntry entry) { AssertNotTicking(); tickList.Remove(entry); }
public void Register(TickableEntry entry) { AssertNotTicking(); tickList.Add(entry); }