Display: small FPS counting fix

This is way more readable and more semantically correct. Essentially, instead of truncating the current and last timestamps to seconds and checking if we were "in" a different second, actually check the duration between the current frame and our last lap point .
This commit is contained in:
Charles Dang 2024-11-05 01:58:14 -05:00
parent 9a77b72aac
commit 37adb200e6
2 changed files with 6 additions and 11 deletions

View file

@ -1510,22 +1510,17 @@ void display::set_diagnostic(const std::string& msg)
void display::update_fps_count()
{
using std::chrono::duration_cast;
using std::chrono::steady_clock;
auto now = steady_clock::now();
auto now = std::chrono::steady_clock::now();
if(last_frame_finished_) {
frametimes_.push_back(duration_cast<std::chrono::milliseconds>(now - *last_frame_finished_));
frametimes_.push_back(std::chrono::duration_cast<std::chrono::milliseconds>(now - *last_frame_finished_));
}
last_frame_finished_ = now;
++fps_counter_;
const auto current_second = duration_cast<std::chrono::seconds>(now.time_since_epoch());
if(current_second != fps_start_) {
fps_start_ = current_second;
fps_actual_ = fps_counter_;
fps_counter_ = 0;
if(now - fps_start_ >= 1s) {
fps_start_ = now;
fps_actual_ = std::exchange(fps_counter_, 0);
}
}

View file

@ -760,7 +760,7 @@ protected:
boost::circular_buffer<std::chrono::milliseconds> frametimes_;
int current_frame_sample_ = 0;
unsigned int fps_counter_;
std::chrono::seconds fps_start_;
std::chrono::steady_clock::time_point fps_start_;
unsigned int fps_actual_;
utils::optional<std::chrono::steady_clock::time_point> last_frame_finished_ = {};