diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/seq.c | 33 |
1 files changed, 26 insertions, 7 deletions
@@ -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; } } |