using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace WCell.Core.Timers { public struct TimerEntry { private float _totalTime; public float InitialDelay, Interval; Action Callback; public TimerEntry(float delay, float interval, Action callback) { _totalTime = 0.0f; InitialDelay = delay; Interval = interval; Callback = callback; } public void Start() { _totalTime = 0.0f; } public void Stop() { _totalTime = -1.0f; } public void Update(float updateDelta) { // means this timer is not running. if (_totalTime == -1.0f) return; if (InitialDelay > 0.0f) { InitialDelay -= updateDelta; } else { if (_totalTime == 0.0f) { // initial fire. Callback(_totalTime); } else { _totalTime += updateDelta; if (_totalTime >= Interval) { // time to fire off? i tink so! Callback(_totalTime); _totalTime = 0.0f; } } } } } }