From c078ba9c9f63f623665b69bce99f7c633c201a1a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 18 Jan 2020 22:22:39 +0100 Subject: Fix GLITCH_BACK --- glitchyclock.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/glitchyclock.c b/glitchyclock.c index 8b3ca90..2a960fc 100644 --- a/glitchyclock.c +++ b/glitchyclock.c @@ -193,19 +193,23 @@ static gboolean draw_sig(GtkWidget *widget, cairo_t *cr, struct glitchyclock *gc } if ( cues[gc->cue].type == GLITCH_BACK ) { - glitch = 1; - duty = 0.5 + seconds_elapsed / 4; - if ( duty > 1.0 ) { - duty = 1.0; - if ( !gc->flag ) { - gc->base_minutes += cues[gc->cue].parameter; - gc->base_hours += gc->base_minutes / 60; - gc->base_minutes = gc->base_minutes % 60; - gc->base_hours = gc->base_hours % 24; + if ( !gc->flag ) { + duty = 0.5 + seconds_elapsed / 4; + glitch = 1; + if ( duty > 1.0 ) { + duty = 1.0; + gc->real_time_last_reset += cues[gc->cue].parameter * 60; + + /* The real_time_elapsed will now probably be + * negative (unless the clock glitched back by + * less than real_time_elapsed). To avoid + * negative numbers appearing, go back a whole + * day. Yes, I'm a dirty cheat. */ + gc->real_time_last_reset -= 24*60*60; gc->flag = 1; - } else { - glitch = 0; } + } else { + glitch = 0; } } -- cgit v1.2.3