// Add a new timer. protected static TimerInstance Begin(float duration, float delay = 0, string id = null) { TimerInstance timer = new TimerInstance(duration, delay, id); Instance.timers.Add(timer); return(timer); }
// ------------------------------------------ FADE IN ------------------------------------------ private void StartFadingIn() { fadingIn = true; timer = Timer.CreateTimer(fadeInTime, () => !this, false); timer.OnTick += OnFadingInTimerTick; timer.OnEnd += OnFadingInTimerEnd; }
internal static void Update() { float lastDeltaRealtime = Time.LastDelta; float lastDeltaGameTime = Time.MsPFMult * Time.TimeMult; for (int i = 0; i < _instances.Values.Count; i++) { TimerInstance timer = _instances.Values.ElementAt(i); timer.IsExpired = false; if (timer.IsRealTime) { timer.Elapsed += lastDeltaRealtime; } else { timer.Elapsed += lastDeltaGameTime; } if (timer.Elapsed >= timer.Interval) { timer.Elapsed -= timer.Interval; timer.IsExpired = true; if (timer.OnTimerElapsedHandler != null) { timer.OnTimerElapsedHandler(); } if (--timer.RepeatsLeft == 0) { timer.IsActive = false; } } } }
public void Create(string identifier, int delay, int repeations, Action function) { var t = new TimerInstance(identifier, delay, repeations, function); Timers.Add(t); t.Start(); }
public void Destroy(string identifier) { TimerInstance luatimer = Timers.Find(timer => timer.Identifier == identifier); luatimer.Stop(); Timers.Remove(luatimer); }
public TimerInstance NextFrame(Action callback) { TimerInstance timer = new TimerInstance(1, 0.0f, callback, null); alltimers.Add(timer); return(timer); }
public void Simple(int miliseconds, Action function) { var t = new TimerInstance("simple ..." + function.Method, miliseconds, 1, function); Timers.Add(t); t.Start(); }
public TimerInstance Once(float delay, Action callback, Plugin owner = null) { TimerInstance timer = new TimerInstance(1, delay, callback, owner); alltimers.Add(timer); return(timer); }
public TimerInstance Repeat(float delay, int reps, Action callback, Plugin owner = null) { TimerInstance timer = new TimerInstance(reps, delay, callback, owner); alltimers.Add(timer); return(timer); }
/// <summary> /// メニュー項目の有効無効を切り替える /// </summary> private void UpdateMenuItemEnabled() { int selCount = this.timerList.SelectedItems.Count; bool isItemSelected = selCount > 0; bool isMultiSelected = selCount > 1; bool isSingleSelected = selCount == 1; TimerInstance selinstance = null; if (isItemSelected) { selinstance = (TimerInstance)this.timerList.SelectedItems[0].Tag; } bool isTimerSelected = false; foreach (ListViewItem item in this.timerList.SelectedItems) { if (((TimerInstance)item.Tag).Type == TimerDef.cTypeTimer) { isTimerSelected = true; break; } } this.miDel.Enabled = isItemSelected; this.miEditInstance.Enabled = isSingleSelected; this.miStart.Enabled = isSingleSelected && selinstance.State != TimerState.Run; this.miStop.Enabled = isTimerSelected; }
public void SchoudleDelayedFunctionTrigger(float duration, Action _functionToBeCalledAfterDurationTimePassed) { float timerInstanceEndTime = Time.time + duration; TimerInstance newTimer = new TimerInstance(timerInstanceEndTime, _functionToBeCalledAfterDurationTimePassed); timersProcessing.Add(newTimer); }
/// <summary> /// 比較 /// </summary> /// <param name="x">アイテム1</param> /// <param name="y">アイテム2</param> /// <returns></returns> public int Compare(object x, object y) { ListViewItem itemX = (ListViewItem)x; ListViewItem itemY = (ListViewItem)y; TimerInstance instanceX = (TimerInstance)itemX.Tag; TimerInstance instanceY = (TimerInstance)itemY.Tag; if (instanceX.State != instanceY.State) { return(instanceY.State - instanceX.State); } if (instanceX.State == TimerState.Ready) { return(0); } if (instanceX.UpTime < instanceY.UpTime) { return(-1); } else if (instanceX.UpTime > instanceY.UpTime) { return(1); } else { return(0); } }
public void CreateTimer(float duration, Action <object> callback, object cookie) { TimerInstance timer = new TimerInstance { TimeLeft = duration, Callback = callback, Cookie = cookie }; timers.Add(timer); }
private void StopAutoClean() { if (autoCleanTimer != null) { //TimerService timerService = Facade.GetInstance().GetServicer<TimerService>(TimerService.NAME); //timerService.RemoveTimer(autoCleanTimer); autoCleanTimer = null; } }
/// <summary> /// リストダブルクリック /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void timerList_DoubleClick(object sender, EventArgs e) { ListViewItem item = this.GetFirstSelectdItem(); if (item != null) { TimerInstance instance = (TimerInstance)item.Tag; this.OperateEditInstance(); } }
/// <summary> /// 最初の選択行のタイマーインスタンスを返す /// </summary> /// <returns>選択行タイマーインスタンス、無い場合はnull</returns> private TimerInstance GetFirstSelectedInstance() { TimerInstance instance = null; ListViewItem item = this.GetFirstSelectdItem(); if (item != null) { instance = (TimerInstance)item.Tag; } return(instance); }
/// <summary> /// 自動開始となっているタイマーのインスタンスを生成し起動する /// </summary> private void InitCreateTimer() { foreach (TimerDef def in this.defs) { if (def.AutoStart) { TimerInstance instance = this.CreateTimerInstance(def); instance.Start(); this.timerList.Items.Add(this.CreateViewItem(instance)); } } }
public static void Cancel(object id) { TimerInstance[] toUpdate = new TimerInstance[Instance.timers.Count]; Instance.timers.CopyTo(toUpdate); foreach (TimerInstance timer in toUpdate) { if (timer.ID != null && timer.ID.Equals(id)) { Instance.timers.Remove(timer); } } }
// Cancel timers with the specified id. public static void Cancel(string id) { TimerInstance[] toUpdate = new TimerInstance[Instance.timers.Count]; Instance.timers.CopyTo(toUpdate); foreach (TimerInstance timer in toUpdate) { if (!string.IsNullOrEmpty(timer.ID) && timer.ID.Equals(id)) { Instance.timers.Remove(timer); } } }
/// <summary> /// Add a Timer to the managed list /// </summary> /// <param name="key">The key of the Timer</param> /// <param name="interval">The interval in milliseconds after which the Timer will fire</param> /// <param name="handler">The handler function that is called after the Timer fires</param> /// <param name="realTime">If true, the Timer will count time based on real time clock, instead of in-game one. Defaults to false</param> /// <param name="repeats">The maximum amount of times the Timer will fire before stopping. Defaults to 1</param> public static void AddTimer(object key, float interval, TimerElapsedEventDelegate handler, bool realTime = false, uint repeats = 1) { _instances[key] = new TimerInstance() { Interval = interval, Elapsed = 0, RepeatsLeft = repeats, IsRealTime = realTime, IsActive = true, IsExpired = false, OnTimerElapsedHandler = handler }; }
// Update this component between frames. void Update() { TimerInstance[] toUpdate = new TimerInstance[timers.Count]; timers.CopyTo(toUpdate); foreach (TimerInstance timer in toUpdate) { timer.Update(Time.deltaTime); if (timer.Completed) { timers.Remove(timer); } } }
private TimerInstance AddTimer(int repetitions, float delay, Action callback, Plugin owner = null) { var timer = new TimerInstance(repetitions, delay, callback, owner); if (Thread.CurrentThread == mainThread) { InsertTimer(timer); } else { Interface.Oxide.NextTick(() => InsertTimer(timer)); } return(timer); }
/// <summary> /// タイマー再起動操作 /// </summary> private void OperateStartTimer() { ListViewItem item = this.GetFirstSelectdItem(); if (item != null) { TimerInstance instance = (TimerInstance)item.Tag; if (instance.State == TimerState.Timeup || instance.State == TimerState.Pause) { instance.Start(); this.DoSoreList(); this.UpdateMenuItemEnabled(); } } }
public void GetExpired(double now, Queue <TimerInstance> queue) { TimerInstance instance = FirstInstance; while (instance != null) { if (instance.ExpiresAt > now) { break; } queue.Enqueue(instance); instance = instance.NextInstance; } }
private void InsertTimer(TimerInstance timer) { var index = timers.Count; for (var i = 0; i < timers.Count; i++) { if (timers[i].nextrep <= timer.nextrep) { continue; } index = i; break; } timers.Insert(index, timer); }
/// <summary> /// Called every server frame to process expired timers /// </summary> public void Update(float delta) { float now = Oxide.Now; TimeSlot[] time_slots = timeSlots; Queue <TimerInstance> expired_queue = expiredInstanceQueue; int checked_slots = 0; lock (Lock) { int current_slot = currentSlot; double next_slot_at = nextSlotAt; while (true) { time_slots[current_slot].GetExpired(next_slot_at > now ? now : next_slot_at, expired_queue); // Only move to the next slot once real time is out of the current slot so that the current slot is rechecked each frame if (now <= next_slot_at) { break; } checked_slots++; current_slot = current_slot < LastTimeSlot ? current_slot + 1 : 0; next_slot_at += TickDuration; } if (checked_slots > 0) { currentSlot = current_slot; nextSlotAt = next_slot_at; } int expired_count = expired_queue.Count; for (int i = 0; i < expired_count; i++) { TimerInstance instance = expired_queue.Dequeue(); if (!instance.Destroyed) { instance.Invoke(now); } } } }
/// <summary> /// 動作中タイマーのプロパティー編集 /// </summary> /// <param name="instance"></param> /// <returns></returns> private bool SubEditInstance(TimerInstance instance) { FrmTimerUpd dialog = new FrmTimerUpd(); dialog.Type = instance.Type; int countOrg = instance.SetCount; if (instance.Type == Cs.TimerType.Alarm) { countOrg = instance.SetCount; } else { if (instance.State == TimerState.Run) { countOrg = instance.ToSeconds; } else { countOrg = instance.SetCount; } } dialog.SetCount = countOrg; dialog.Title = instance.Title; dialog.Memo = instance.Memo; dialog.Soundfile = instance.Soundfile; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { bool autoStart = (dialog.Type != instance.Type || dialog.SetCount != countOrg); // 設定時刻などが変更されていたら自動的に起動する instance.Type = dialog.Type; instance.SetCount = dialog.SetCount; instance.Title = dialog.Title; instance.Memo = dialog.Memo; instance.Soundfile = dialog.Soundfile; if (instance.State == TimerState.Run || autoStart) { instance.Start(); } return(true); } return(false); }
/// <summary> /// 新規カウントダウンタイマー作成 /// </summary> private void OperateNewTimer() { FrmTimerSet dialog = new FrmTimerSet(); dialog.StartPosition = FormStartPosition.CenterParent; dialog.Defs = this.defs; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { TimerDef def = dialog.EditTimerDef; TimerInstance instance = this.CreateTimerInstance(def); instance.Start(); this.timerList.Items.Add(this.CreateViewItem(instance)); this.DoSoreList(); this.UpdateMenuItemEnabled(); } }
internal TimerInstance AddTimer(int repetitions, float delay, Action callback, Plugin owner = null) { lock (Lock) { TimerInstance timer; Queue <TimerInstance> pooled_instances = TimerInstance.Pool; if (pooled_instances.Count > 0) { timer = pooled_instances.Dequeue(); timer.Load(this, repetitions, delay, callback, owner); } else { timer = new TimerInstance(this, repetitions, delay, callback, owner); } InsertTimer(timer, timer.ExpiresAt < Oxide.Now); return(timer); } }
/// <summary> /// タイマ一次停止操作 /// </summary> /// <param name="clearList">停止操作対象リストビューアイテムのリスト NULL なら選択中のアイテムが対象</param> private void OperateStopTimer(IList clearList = null) { if (clearList == null) { clearList = this.timerList.SelectedItems; } foreach (ListViewItem item in this.timerList.SelectedItems) { TimerInstance instance = (TimerInstance)item.Tag; instance.Pause(); if (instance.State == TimerState.Pause) { item.SubItems[1].Text = "Pause"; } } this.DoSoreList(); this.UpdateMenuItemEnabled(); }
public bool Add(string name, Action callback, float time, bool looping, int loopForThisManyTimes = 0, Action afterCallback = null) { if (!sl_active.ContainsKey(name)){ //If the active timers doesn't contain a name that already exists create a new Timer instance. TimerInstance t = new TimerInstance(); t.A_FireQueue += callback; t.f_resetTime = time; t.f_curTime = time; t.b_looping = looping; t.i_triggerCount = 0; t.i_loopThisManyTimes = loopForThisManyTimes; t.A_AfterCallBackQueue += afterCallback; t.b_removeMe = false; if (sl_pending.ContainsKey(name)){ sl_pending.Remove(name); } sl_pending.Add(name, t); return true; } else return false; }
private void InsertTimer(TimerInstance timer) { var index = timers.Count; for (var i = 0; i < timers.Count; i++) { if (timers[i].nextrep <= timer.nextrep) continue; index = i; break; } timers.Insert(index, timer); }
private TimerInstance AddTimer(int repetitions, float delay, Action callback, Plugin owner = null) { var timer = new TimerInstance(repetitions, delay, callback, owner); if (Thread.CurrentThread == mainThread) InsertTimer(timer); else Interface.Oxide.NextTick(() => InsertTimer(timer)); return timer; }
private TimerInstance AddTimer(int repetitions, float delay, Action callback, Plugin owner = null) { var timer = new TimerInstance(repetitions, delay, callback, owner); InsertTimer(timer); return timer; }