Fix inconsistencies with the FPS scheduler (#241)

The current Fps manager will sometime skip the intended delay and start
the next frame immediately, I'm not 100% sure why it happens, but I
rewrote most of it to stay consistent and improved the overall precision
by compensating for OS wake delay after sleep and finishing with a busy
wait
I also changed the behavior of mlx_set_fps_goal to allow zero/negative
values and treat them as uncapped (like most graphics libraries)
This commit is contained in:
Daemo
2026-08-08 15:45:56 +02:00
committed by GitHub
parent c9df651a14
commit 63fe3088bf
4 changed files with 43 additions and 34 deletions
+6 -7
View File
@@ -45,10 +45,9 @@ extern "C"
void mlx_set_fps_goal(mlx_context mlx, int fps)
{
MLX_CHECK_APPLICATION_POINTER(mlx);
if(fps < 0)
mlx::Error("You cannot set a negative FPS cap (nice try)");
else
mlx->app->SetFPSCap(static_cast<std::uint32_t>(fps));
if(fps <= 0)
fps = -1;
mlx->app->SetFPSCap(static_cast<std::uint32_t>(fps));
}
void mlx_destroy_context(mlx_context mlx)
@@ -313,14 +312,14 @@ extern "C"
mlx::Error("Font loader: filepath is NULL");
return;
}
std::filesystem::path file(filepath);
if (std::strcmp(filepath, "default") != 0 && !std::filesystem::exists(file))
{
mlx::Error("TTF loader: unable to find file '%'", filepath);
return;
}
if(std::strcmp(filepath, "default") != 0)
{
if(file.extension() != ".ttf" && file.extension() != ".tte")
@@ -350,7 +349,7 @@ extern "C"
mlx::Error("Font loader: filepath is NULL");
return;
}
std::filesystem::path file(filepath);
if (std::strcmp(filepath, "default") != 0 && !std::filesystem::exists(file))
{