public void Clear() { if (_endOfLineCallback != null) { _endOfLineCallback.callback = null; } if (_timeoutInfos != null && _timeoutInfos.Count > 0) { if (_inUpdate) { if (_toAddOrRemove == null) { _toAddOrRemove = TempCollection.GetList <CallbackInfo>(); } var e = _timeoutInfos.GetEnumerator(); while (e.MoveNext()) { e.Current.callback = null; _toAddOrRemove.Add(e.Current); } } else { var e = _timeoutInfos.GetEnumerator(); while (e.MoveNext()) { _pool.Release(e.Current); } _timeoutInfos.Clear(); } } GameLoop.UpdatePump.Remove(this); }
public void Schedule(System.Action <ISPAnim> callback, float timeout, ITimeSupplier timeSupplier) { //if (!_state.IsPlaying) throw new System.InvalidOperationException("Can only schedule a callback on a playing animation."); if (callback == null) { throw new System.ArgumentNullException("callback"); } if (timeout == float.PositiveInfinity) { if (_endOfLineCallback == null) { _endOfLineCallback = new CallbackInfo() { timeout = float.PositiveInfinity } } ; _endOfLineCallback.callback += callback; } else { var info = _pool.GetInstance(); info.callback = callback; info.timeout = timeout; info.supplier = (timeSupplier != null) ? timeSupplier : SPTime.Normal; if (_inUpdate) { if (_toAddOrRemove == null) { _toAddOrRemove = TempCollection.GetList <CallbackInfo>(); } _toAddOrRemove.Add(info); } else { _timeoutInfos.Add(info); } } if (_waitRoutine == null || _waitRoutine.Finished) { this.InitWaitRoutine(); } if (!_waitRoutine.Active) { _waitRoutine.Start(_state.Controller); } }
public void Schedule(System.Action <ISPAnim> callback, float timeout, ITimeSupplier timeSupplier) { //if (!_state.IsPlaying) throw new System.InvalidOperationException("Can only schedule a callback on a playing animation."); if (callback == null) { throw new System.ArgumentNullException("callback"); } if (float.IsPositiveInfinity(timeout) || float.IsNaN(timeout)) { if (_endOfLineCallback == null) { _endOfLineCallback = new CallbackInfo() { timeout = float.NaN } } ; _endOfLineCallback.callback += callback; } else { var info = _pool.GetInstance(); info.callback = callback; info.current = 0f; info.timeout = timeout; info.supplier = (timeSupplier != null) ? timeSupplier : SPTime.Normal; if (_inUpdate) { if (_toAddOrRemove == null) { _toAddOrRemove = TempCollection.GetList <CallbackInfo>(); } _toAddOrRemove.Add(info); } else { _timeoutInfos.Add(info); } } GameLoop.UpdatePump.Add(this); }
void IUpdateable.Update() { _inUpdate = true; if (!_state.IsPlaying) { //close them all down this.CloseOutAllEventCallbacks(); } else { if (_timeoutInfos != null && _timeoutInfos.Count > 0) { var e = _timeoutInfos.GetEnumerator(); while (e.MoveNext()) { e.Current.timeout -= e.Current.supplier.Delta; if (e.Current.timeout <= 0f) { var a = e.Current.callback; e.Current.callback = null; if (_toAddOrRemove == null) { _toAddOrRemove = TempCollection.GetList <CallbackInfo>(); } _toAddOrRemove.Add(e.Current); try { a(_state); } catch (System.Exception ex) { Debug.LogException(ex); } } } } } _inUpdate = false; //check if any timeouts wanted to get registered while calling update if (_toAddOrRemove != null) { var e = _toAddOrRemove.GetEnumerator(); while (e.MoveNext()) { if (e.Current.callback == null) { //I set it null in the loop above to flag it as 'remove' rather than 'add' _timeoutInfos.Remove(e.Current); _pool.Release(e.Current); } else { _timeoutInfos.Add(e.Current); } } _toAddOrRemove.Dispose(); _toAddOrRemove = null; } //stop us if (!this.ContainsWaitHandles()) { GameLoop.UpdatePump.Remove(this); } }