Skip to content

HistoryCache

Ilia Petrov-Komotskii edited this page Sep 30, 2026 · 4 revisions

Fixed-length ring buffer of recent values. Overlapping Append, Clear, and GetAverage calls on one cache are serialized.

using Mane.DotNet;

FloatHistoryCache fps = new(60);
fps.Append(Time.deltaTime);
float meanDt = fps.GetAverage();
fps.Clear();

API

Member Behavior
Append(value) Write; overwrite the oldest entry once full.
Clear() Reset count/index and zero the buffer.
GetAverage() Mean of stored values. Empty → type zero.

HistoryCache<T> is abstract. Concrete types:

  • IntHistoryCache — mean rounded to the nearest int; a midpoint rounds away from zero (1 and 2 average to 2, -1 and -2 average to -2)
  • FloatHistoryCache
  • DoubleHistoryCache

ManeTools-Unity adds Vector2HistoryCache and Vector3HistoryCache (see HistoryCache).

Constructor length must be greater than 0. Before the buffer fills, only the prefix of written values is valid; after it fills, the average uses every slot (order does not matter for a mean).

Clone this wiki locally