update method

void update(
  1. Duration dt
)

Advances the world by dt. The first call also runs every startup system. Drains the per-tick event buffer after all systems have run. No-op if the world has been disposed.

System lists are snapshotted before iteration so a running system can safely add or remove systems; the change takes effect on the next tick.

Re-entrant updates (a system calling world.update recursively) share the outer tick's event buffer; only the outermost return drains it, so events sent before a re-entrant update remain visible to subsequent outer-tick systems.

Implementation

void update(Duration dt) {
  if (_disposed) return;
  _updateDepth++;
  try {
    if (!_ranStartup) {
      _ranStartup = true;
      for (final system in List.of(_startupSystems)) {
        system.update(this, Duration.zero);
      }
    }
    _elapsed += dt;
    for (final system in List.of(_systems)) {
      system.update(this, dt);
    }
  } finally {
    _updateDepth--;
    if (_updateDepth == 0) {
      _eventBuffer.clear();
    }
  }
}