// Methods. public void Add(float timeDelta, out bool complete) { timeDelta = Floats.SetPositive(timeDelta); accumulated += timeDelta; complete = (accumulated >= limit); if (complete) { accumulated = Floats.LimitPositive(accumulated - limit, limit); } }
// Constructors. public TimeAccumulator(float limit, float accumulated = 0) { this.limit = Floats.SetPositive(limit); this.accumulated = Floats.LimitPositive(accumulated, this.limit); }