advance method

int advance(
  1. Duration realDelta
)

Advances the clock by realDelta (clamped to [0, maxDeltaPerTick], then multiplied by scale). A no-op while paused.

With no fixed step configured, elapsed just advances by the scaled delta and this always returns 0. With a fixed step, this instead accumulates the scaled delta and only advances elapsed in whole Duration multiples of it — leftover time carries into the next call — returning how many whole steps were taken this call (0 if not enough accumulated yet).

Implementation

int advance(Duration realDelta) {
  if (paused) return 0;
  final clamped = realDelta < Duration.zero
      ? Duration.zero
      : (realDelta > maxDeltaPerTick ? maxDeltaPerTick : realDelta);
  final scaledMicros = (clamped.inMicroseconds * _scale).round();
  final scaledDelta = Duration(microseconds: scaledMicros);

  final fixedStep = _fixedStep;
  if (fixedStep == null) {
    _elapsed += scaledDelta;
    return 0;
  }
  _accumulator += scaledDelta;
  var steps = 0;
  while (_accumulator >= fixedStep) {
    _accumulator -= fixedStep;
    _elapsed += fixedStep;
    steps++;
  }
  return steps;
}