applyStateTransitions method

void applyStateTransitions()

Applies pending state transitions for every registered state machine.

Applies all queued state changes.

The standard driver calls this at the frame-start boundary, after the Schedules.frameStart schedule; headless callers invoke it themselves at the equivalent point.

Implementation

void applyStateTransitions() {
  if (!_finalized) {
    throw StateError('Call start() before applying state transitions.');
  }
  if (_stateMachines.isEmpty) return;
  var passes = 0;
  while (true) {
    var applied = false;
    for (final machine in _stateMachines) {
      if (machine.applyPending(_runStateSchedule, _despawnStateScoped)) {
        applied = true;
      }
    }
    if (!applied) return;
    passes++;
    if (passes >= maxStateTransitionPasses) {
      throw StateError(
        'State transitions did not settle after $maxStateTransitionPasses '
        'passes — an OnEnter/OnExit system is queueing transitions in a '
        'cycle.',
      );
    }
  }
}