# Khaotic Engine Reborn: enginecustom/src/inc/system/fps_limiter.h Source File

Loading...
Searching...
No Matches
fps_limiter.h
#pragma once
#include <chrono>
class fps_limiter {
public:
explicit fps_limiter(const float target_fps = 60.0f)
: min_delta_(1.0f / target_fps), last_time_(std::chrono::high_resolution_clock::now()) {}
// Retourne true si la fonction peut etre executee
bool should_run() {
const auto now = std::chrono::high_resolution_clock::now();
if (const float elapsed = std::chrono::duration<float>(now - last_time_).count(); elapsed >= min_delta_) {
last_time_ = now;
return true;
}
return false;
}
private:
float min_delta_;
std::chrono::high_resolution_clock::time_point last_time_;
};
fps_limiter
Definition fps_limiter.h:4