main.c: proper fix for render frame drops

This commit is contained in:
veclav talica 2024-07-31 18:24:21 +03:00
parent 35b7c23d27
commit 71292a1995

View File

@ -144,8 +144,11 @@ static void main_loop(void) {
} }
/* finally, let's get to work */ /* finally, let's get to work */
int frames = 0;
while (ctx.frame_accumulator >= ctx.desired_frametime * ctx.update_multiplicity) { while (ctx.frame_accumulator >= ctx.desired_frametime * ctx.update_multiplicity) {
frames += 1;
for (size_t i = 0; i < ctx.update_multiplicity; ++i) { for (size_t i = 0; i < ctx.update_multiplicity; ++i) {
/* TODO: disable rendering pushes on not-last ? */
render_queue_clear(); render_queue_clear();
poll_events(); poll_events();
@ -163,9 +166,11 @@ static void main_loop(void) {
ctx.frame_accumulator -= ctx.desired_frametime; ctx.frame_accumulator -= ctx.desired_frametime;
ctx.tick_count = (ctx.tick_count % ULLONG_MAX) + 1; ctx.tick_count = (ctx.tick_count % ULLONG_MAX) + 1;
}
}
if (frames != 0)
render(); render();
}
}
} }