Repository navigation
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();| 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 nearestint; a midpoint rounds away from zero (1and2average to2,-1and-2average to-2) FloatHistoryCacheDoubleHistoryCache
ManeTools-Unity adds
Vector2HistoryCacheandVector3HistoryCache(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).
openupm add com.manefunction.tools-dotnet