| 579 | } |
| 580 | |
| 581 | void EngineWorker::slowdownTPS() |
| 582 | { |
| 583 | if (_slowDownTimepoint) { |
| 584 | auto timestepDuration = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - *_slowDownTimepoint); |
| 585 | if (_slowDownOvershot) { |
| 586 | timestepDuration += *_slowDownOvershot; |
| 587 | } |
| 588 | auto tpsRestriction = _tpsRestriction.load(); |
| 589 | if (_isSimulationRunning.load() && tpsRestriction > 0) { |
| 590 | auto desiredDuration = std::chrono::microseconds(1000000 / tpsRestriction); |
| 591 | if (desiredDuration > timestepDuration) { |
| 592 | waitAndAllowAccess(desiredDuration - timestepDuration); |
| 593 | } else { |
| 594 | } |
| 595 | _slowDownOvershot = std::min(std::max(timestepDuration - desiredDuration, std::chrono::microseconds(0)), desiredDuration); |
| 596 | } |
| 597 | } |
| 598 | _slowDownTimepoint = std::chrono::steady_clock::now(); |
| 599 | } |
| 600 | |
| 601 | void EngineWorker::registerImageResource() |
| 602 | { |