namespace Godosa.Core.Runs;
/// Runs frames as fast as possible: frame(n) for n = 1, 2, … until it returns false,
/// is reached, or (Capped = true).
public static class HeadlessLoop
{
public const long DefaultCap = 100_000;
public static (long Frames, bool Capped) Run(Func frame, long? frames, long cap = DefaultCap)
{
for (long n = 1; ; n++)
{
if (n > cap)
return (cap, true);
var more = frame(n);
if (!more || n == frames)
return (n, false);
}
}
}