#include #include namespace Game { void GameManager::run(std::stop_token stopToken) { using namespace std::chrono_literals; LOG("GameManager thread started"); while (!stopToken.stop_requested()) { const int updatesPerSecond = std::max(1, mTargetUpdatesPerSecond); const auto frameDuration = std::chrono::duration(1.0 / static_cast(updatesPerSecond)); const auto frameStart = std::chrono::steady_clock::now(); try { State::GameState::getInstance().withEntitiesLocked([](auto& entities) { for (auto& entity : entities) { entity->update(); } }); } catch (const std::exception& e) { ERROR("Exception in GameManager thread: " << e.what()); } const auto elapsed = std::chrono::steady_clock::now() - frameStart; const auto remaining = frameDuration - elapsed; if (remaining > 0s) { std::this_thread::sleep_for(remaining); } } } }