startFPSMonitor method

void startFPSMonitor()
inherited

Implementation

void startFPSMonitor() {
  // Initialize the stopwatch for FPS calculation and start it
  _stopwatch = Stopwatch();
  _stopwatch?.start();

  // Initialize the FPS ticker with a callback that increments the frame counter
  // and calculates the FPS every second
  _fpsTicker = Ticker((Duration elapsed) {
    // Increment the frame counter
    _frameCount++;

    // If one second has passed, calculate and print the FPS
    if (_stopwatch!.elapsedMilliseconds >= 1000) {
      int fps = (_frameCount / (_stopwatch!.elapsedMilliseconds / 1000)).ceil();
      if (fps < 40) {
        TencentCloudChat.instance.logInstance.console(
          logs: 'FPS: $fps',
          componentName: runtimeType.toString(),
          logLevel: TencentCloudChatLogLevel.error,
        );
      }

      // Reset the frame counter and stopwatch for the next FPS calculation
      _frameCount = 0;
      _stopwatch!.reset();
      _stopwatch!.start();
    }
  });

  // Start the FPS ticker
  _fpsTicker!.start();
}