| 555 | } |
| 556 | |
| 557 | void EngineWorker::measureTPS() |
| 558 | { |
| 559 | if (_isSimulationRunning.load()) { |
| 560 | auto timepoint = std::chrono::steady_clock::now(); |
| 561 | if (!_measureTimepoint) { |
| 562 | _measureTimepoint = timepoint; |
| 563 | } else { |
| 564 | int duration = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(timepoint - *_measureTimepoint).count()); |
| 565 | if (duration > 199) { |
| 566 | _measureTimepoint = timepoint; |
| 567 | if (duration < 350) { |
| 568 | _tps.store(toFloat(_timestepsSinceMeasurement) * 5 * 200 / duration); |
| 569 | } else { |
| 570 | _tps.store(1000.0f / duration); |
| 571 | } |
| 572 | _timestepsSinceMeasurement = 0; |
| 573 | } |
| 574 | } |
| 575 | ++_timestepsSinceMeasurement; |
| 576 | } else { |
| 577 | _tps.store(0); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | void EngineWorker::slowdownTPS() |
| 582 | { |