summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-08-29 13:38:21 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-08-29 13:41:35 -0700
commit64e4cd08b56866ab64da4ab0be158155747243ec (patch)
tree43a9678bf8e205d47364535a4c8305923ad9f611
parent25ae095b243cd2fc221200944c0fbcf9cc9429b4 (diff)
main: prevent ticks from going backwards
Outside of overflow (which I'm ignoring for now) ticks shouldn't go backwards. With the introduction of adding the frame-buffer delays, which vary, there's the potential for the delay to go from large to short in quick succession, to such a degree that the next render's now+delay is in the past relative to the previous now+delay. For now this simple fix is to just track the last_ticks and always use the maximum of the last_ticks and now+delay, ensuring it never goes backwards. This was making alphazed exit prematurely at spurious times by sending the rocket_row into oblivion because (ticks - last_ticks) was negative w/unsigned arithmetic. This will all get more work, and maybe ticks should be allowed to go backwards actually, but some things are assuming that's not the case as-is. Regardless, it's not desirable for ticks to go backwards because of the frame-buffer delay. In that case just chill on the ticks advancement for a frame. This will need revisiting for sure, as I don't think re-rendering the exact same tick as the last frame is likely to be what's wanted either. Probably some little advancement should still be performed...
-rw-r--r--src/main.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index b555bbf..45e8c3b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -324,6 +324,7 @@ static int print_help(void)
static void * rototiller_thread(void *_rt)
{
rototiller_t *rt = _rt;
+ unsigned last_ticks = til_ticks_now();
while (til_stream_active(rt->stream)) {
unsigned ticks, delay = 0;
@@ -335,9 +336,10 @@ static void * rototiller_thread(void *_rt)
}
til_stream_start_frame(rt->stream);
- ticks = til_ticks_now();
- til_module_render(rt->module_context, rt->stream, ticks + delay, &rt->fragment);
+ ticks = MAX(til_ticks_now() + delay, last_ticks);
+ til_module_render(rt->module_context, rt->stream, ticks, &rt->fragment);
til_fb_fragment_submit(rt->fragment);
+ last_ticks = ticks;
if (rt->args.print_module_contexts || rt->args.print_pipes) {
/* render threads are idle at this point */
© All Rights Reserved