updateComponents method Null safety

bool updateComponents()

Walk the dependency tree and update components in order. Returns true if any component updated.

Implementation

bool updateComponents() {
  bool didUpdate = false;

  if ((_dirt & ComponentDirt.drawOrder) != 0) {
    sortDrawOrder();
    _dirt &= ~ComponentDirt.drawOrder;
    didUpdate = true;
  }
  if ((_dirt & ComponentDirt.components) != 0) {
    const int maxSteps = 100;
    int step = 0;
    int count = _dependencyOrder.length;
    while ((_dirt & ComponentDirt.components) != 0 && step < maxSteps) {
      _dirt &= ~ComponentDirt.components;
      // Track dirt depth here so that if something else marks
      // dirty, we restart.
      for (int i = 0; i < count; i++) {
        Component component = _dependencyOrder[i];
        _dirtDepth = i;
        int d = component.dirt;
        if (d == 0) {
          continue;
        }
        component.dirt = 0;
        component.update(d);
        if (_dirtDepth < i) {
          break;
        }
      }
      step++;
    }
    return true;
  }
  return didUpdate;
}