From 6cb20921e04d134438723feb7b938f74efed8bc8 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 7 Mar 2022 17:37:02 -0500 Subject: Fix sequencing, again --- src/seq.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/seq.c b/src/seq.c index af49281..ea51bb0 100644 --- a/src/seq.c +++ b/src/seq.c @@ -16,6 +16,7 @@ xas_seq *xas_seq_new(xas_spatial_scene *scene, size_t buffer_size) { seq->scene = scene; seq->first = NULL; + seq->last = NULL; seq->buffer_size = buffer_size; return seq; @@ -39,10 +40,12 @@ void xas_seq_destroy(xas_seq *seq) { } static void add_event(xas_seq *seq, xas_seq_event *ev) { - xas_seq_event *current = seq->first; + xas_seq_event *current = seq->first, + *prev = NULL; if (seq->first == NULL) { seq->first = ev; + seq->last = ev; return; } @@ -50,20 +53,36 @@ static void add_event(xas_seq *seq, xas_seq_event *ev) { while (current) { xas_seq_event *next = current->next; - if (next == NULL) { + if (timercmp(&ev->timestamp, &seq->last->timestamp, >=)) { + seq->last->next = ev; + seq->last = ev; + + return; + } else if (timercmp(&ev->timestamp, ¤t->timestamp, >)) { + ev->next = current->next; current->next = ev; return; - } + } else if (prev && timercmp(&ev->timestamp, &prev->timestamp, >) + && timercmp(&ev->timestamp, ¤t->timestamp, <=)) { + prev->next = ev; + ev->next = current; - if (timercmp(&ev->timestamp, ¤t->timestamp, >=) - && timercmp(&ev->timestamp, &next->timestamp, <)) { - current->next = ev; - ev->next = next; + return; + } else if (prev && timercmp(&ev->timestamp, &prev->timestamp, <=) + && timercmp(&ev->timestamp, &seq->first->timestamp, >)) { + ev->next = seq->first->next; + seq->first->next = ev; + + return; + } else if (timercmp(&ev->timestamp, &seq->first->timestamp, <=)) { + ev->next = seq->first; + seq->first = ev; return; } + prev = current; current = next; } } -- cgit v1.2.3