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 <kevin@koconnor.net>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user