public void LooperMultipleCallbacksWork() { long updates = 0; var resetEvent = new ManualResetEvent(false); var gameLoop = new Looper(); var timedCallback1 = new TimedCallback(30, () => { updates++; }); var timedCallback2 = new TimedCallback(60, () => { updates--; if (updates <= -30) { resetEvent.Set(); } }); gameLoop.AddCallback(timedCallback1); gameLoop.AddCallback(timedCallback2); gameLoop.Start(); Assert.True(resetEvent.WaitOne(TimeSpan.FromSeconds(1.01))); gameLoop.Dispose(); // Since timedCallback2 is executing twice as fast as timedCallback1 it will negate the value of updates Assert.Equal(updates, -30); }
private Action <int> CreateRateSetter(TimedCallback callback) { return((rate) => { callback.Fps = rate; }); }
private IEnumerator PlayTimedAnim(string animation, TimedCallback callback) { anim.Play(animation, -1, 0); yield return(new WaitForEndOfFrame()); float time = anim.GetCurrentAnimatorStateInfo(0).length; yield return(new WaitForSeconds(time)); callback(); }
public void TestScheduleTimeoutShouldRunAfterDelay() { var timer = new HashedWheelTimer(); var barrier = new CountdownEvent(1); Action cb = () => { Console.WriteLine("Test"); barrier.Signal();; }; TimedCallback timeout = timer.ScheduleTimeout(cb, TimeSpan.FromSeconds(4)); Assert.False(timeout.IsExpired, "TimedTask should not expire"); Assert.True(barrier.Wait(TimeSpan.FromSeconds(5)), "TimedTask should expire"); timer.Stop(); }
public virtual void OnDestruction() { _velocity = Vector2.zero; active = false; anim.enabled = true; TimedCallback destructionCallback = delegate() { destructionCoroutine = null; _spriteRenderer.enabled = false; }; destructionCoroutine = StartCoroutine( PlayTimedAnim(_owner.color == PlayerColor.RED ? "RedBulletExplosion" : "BlueBulletExplosion", destructionCallback)); }
protected BGlPanel() { InitializeComponent(); if (!DesignModeUtil.InDesignMode) { GlUtil.Init(); this.impl_.CreateGraphics(); this.impl_.MakeCurrent(); this.InitGl(); this.timedCallback = TimedCallback.WithFrequency(this.Invalidate, DEFAULT_FRAMERATE_); } }
public void TestScheduleTimeoutShouldNotRunBeforeDelay(double expiryTime, double waitTime) { var timer = new HashedWheelTimer(); var barrier = new CountdownEvent(1); bool flag = false; Action cb = () => { flag = true; barrier.Signal(); }; TimedCallback timeout = timer.ScheduleTimeout(cb, TimeSpan.FromMilliseconds(expiryTime)); Assert.False(barrier.Wait(TimeSpan.FromMilliseconds(waitTime))); Assert.False(timeout.IsExpired, "TimedTask should not be expired"); Assert.False(flag); timer.Stop(); }
public void AddTimedCallback(string key, TimedCallback timedCallback) { if (string.IsNullOrEmpty(key) || timedCallback.callback == null) { return; } for (int i = 0; i < timedCallbacks.Count; i++) { var cb = timedCallbacks[i]; if (cb.Key.Equals(key)) { return; } } timedCallbacks.Add(new KeyValuePair <string, TimedCallback>(key, timedCallback)); }
public void LooperSingleCallbackWorks() { long updates = 0; var resetEvent = new ManualResetEvent(false); var gameLoop = new Looper(); var timedCallback = new TimedCallback(30, () => { updates++; if (updates >= 30) { resetEvent.Set(); } }); gameLoop.AddCallback(timedCallback); gameLoop.Start(); Assert.True(resetEvent.WaitOne(TimeSpan.FromSeconds(1.01))); gameLoop.Dispose(); Assert.Equal(updates, 30); }
public virtual void Arrive() { OnArrive.Invoke(); destinations[count].gameObject.SetActive(false); count++; if (count < destinations.Length) { TCB = gameObject.AddComponent <TimedCallback>(); TCB.SetTimedCallback(SetKoFollow, delayAfterArrival); } if (count == destinations.Length && !loop) { TCB = gameObject.AddComponent <TimedCallback>(); TCB.SetTimedCallback(SetKoReturn, delayAfterArrival + 3.0f); } else if (count == destinations.Length && loop) { count = 0; TCB = gameObject.AddComponent <TimedCallback>(); TCB.SetTimedCallback(SetKoFollow, delayAfterArrival); } }
public virtual void Update() { float delta = ignoreTimeScale ? #if UNITY_5_5_OR_NEWER Time.unscaledDeltaTime #else UpdateRealDeltaTime() #endif : Time.deltaTime; float time = ignoreTimeScale ? #if UNITY_5_5_OR_NEWER Time.unscaledTime #else RealTime #endif : Time.time; if (!started) { started = true; startTime = time + delay; } if (time < startTime) { return; } float oldFactor = factor; factor += AmountPerDelta * delta; if (timedCallbacks.Count > 0) { for (int i = 0; i < timedCallbacks.Count; i++) { KeyValuePair <string, TimedCallback> pair = timedCallbacks[i]; TimedCallback timedCallback = pair.Value; if (timedCallback.callback != null && oldFactor < timedCallback.time && factor > timedCallback.time) { timedCallback.callback(this); } } } if (style == Style.Loop) { if (factor > 1f) { factor -= Mathf.Floor(factor); } else if (factor < 0f) { factor = 1f - factor; } } else if (style == Style.PingPong) { if (factor > 1f) { factor = 1f - (factor - Mathf.Floor(factor)); amountPerDelta = -AmountPerDelta; } else if (factor < 0f) { factor = -factor; factor -= Mathf.Floor(factor); amountPerDelta = -AmountPerDelta; } } if ((style == Style.Once) && ((factor > 1f) || (factor < 0f))) { factor = Mathf.Clamp01(factor); Sample(factor, true); enabled = false; if (OnFinished != null) { OnFinished(this); } invokeWhenFinished.Call(); } else { Sample(factor, false); } }