From 4dbe795ac2b9af24c3c45d4d25ac0eedf86f3d12 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 1 Nov 2019 18:32:06 -0400 Subject: trapq: Implement sentinel nodes on the trapq list Use sentinels to make list traversal code simpler. Also add in null moves so that there are no time gaps in the list. Signed-off-by: Kevin O'Connor --- klippy/chelper/itersolve.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'klippy/chelper/itersolve.c') diff --git a/klippy/chelper/itersolve.c b/klippy/chelper/itersolve.c index 5eafd2a7..84fd5f71 100644 --- a/klippy/chelper/itersolve.c +++ b/klippy/chelper/itersolve.c @@ -144,14 +144,12 @@ itersolve_generate_steps(struct stepper_kinematics *sk, double flush_time) { double last_flush_time = sk->last_flush_time; sk->last_flush_time = flush_time; - if (!sk->tq || list_empty(&sk->tq->moves)) + if (!sk->tq) return 0; + trapq_check_sentinels(sk->tq); struct move *m = list_first_entry(&sk->tq->moves, struct move, node); - while (last_flush_time >= m->print_time + m->move_t) { - if (list_is_last(&m->node, &sk->tq->moves)) - return 0; + while (last_flush_time >= m->print_time + m->move_t) m = list_next_entry(m, node); - } for (;;) { double start = m->print_time, end = start + m->move_t; if (start < last_flush_time) @@ -166,7 +164,7 @@ itersolve_generate_steps(struct stepper_kinematics *sk, double flush_time) return ret; } last_flush_time = end; - if (list_is_last(&m->node, &sk->tq->moves)) + if (flush_time <= m->print_time + m->move_t) return 0; m = list_next_entry(m, node); } @@ -176,22 +174,19 @@ itersolve_generate_steps(struct stepper_kinematics *sk, double flush_time) double __visible itersolve_check_active(struct stepper_kinematics *sk, double flush_time) { - if (!sk->tq || list_empty(&sk->tq->moves)) + if (!sk->tq) return 0.; + trapq_check_sentinels(sk->tq); struct move *m = list_first_entry(&sk->tq->moves, struct move, node); - while (sk->last_flush_time >= m->print_time + m->move_t) { - if (list_is_last(&m->node, &sk->tq->moves)) - return 0.; + while (sk->last_flush_time >= m->print_time + m->move_t) m = list_next_entry(m, node); - } - while (m->print_time < flush_time) { + for (;;) { if (check_active(sk, m)) return m->print_time; - if (list_is_last(&m->node, &sk->tq->moves)) + if (flush_time <= m->print_time + m->move_t) return 0.; m = list_next_entry(m, node); } - return 0.; } void __visible -- cgit v1.2.3-70-g09d2