stepcompress: Rename 'struct history_move' to 'struct history_steps'

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-07-19 14:40:50 -04:00
parent 07f0ecb4d0
commit fbfa31a3c3
1 changed files with 25 additions and 25 deletions

View File

@ -56,7 +56,7 @@ struct step_move {
#define HISTORY_EXPIRE (30.0) #define HISTORY_EXPIRE (30.0)
struct history_move { struct history_steps {
struct list_node node; struct list_node node;
uint64_t first_clock, last_clock; uint64_t first_clock, last_clock;
int64_t start_position; int64_t start_position;
@ -274,12 +274,12 @@ static void
free_history(struct stepcompress *sc, uint64_t end_clock) free_history(struct stepcompress *sc, uint64_t end_clock)
{ {
while (!list_empty(&sc->history_list)) { while (!list_empty(&sc->history_list)) {
struct history_move *hm = list_last_entry( struct history_steps *hs = list_last_entry(
&sc->history_list, struct history_move, node); &sc->history_list, struct history_steps, node);
if (hm->last_clock > end_clock) if (hs->last_clock > end_clock)
break; break;
list_del(&hm->node); list_del(&hs->node);
free(hm); free(hs);
} }
} }
@ -351,14 +351,14 @@ add_move(struct stepcompress *sc, uint64_t first_clock, struct step_move *move)
sc->last_step_clock = last_clock; sc->last_step_clock = last_clock;
// Create and store move in history tracking // Create and store move in history tracking
struct history_move *hm = malloc(sizeof(*hm)); struct history_steps *hs = malloc(sizeof(*hs));
hm->first_clock = first_clock; hs->first_clock = first_clock;
hm->last_clock = last_clock; hs->last_clock = last_clock;
hm->start_position = sc->last_position; hs->start_position = sc->last_position;
hm->step_count = sc->sdir ? move->count : -move->count; hs->step_count = sc->sdir ? move->count : -move->count;
sc->last_position += hm->step_count; sc->last_position += hs->step_count;
memcpy(&hm->sm, move, sizeof(hm->sm)); memcpy(&hs->sm, move, sizeof(hs->sm));
list_add_head(&hm->node, &sc->history_list); list_add_head(&hs->node, &sc->history_list);
} }
// Convert previously scheduled steps into commands for the mcu // Convert previously scheduled steps into commands for the mcu
@ -567,16 +567,16 @@ int64_t __visible
stepcompress_find_past_position(struct stepcompress *sc, uint64_t clock) stepcompress_find_past_position(struct stepcompress *sc, uint64_t clock)
{ {
int64_t last_position = sc->last_position; int64_t last_position = sc->last_position;
struct history_move *hm; struct history_steps *hs;
list_for_each_entry(hm, &sc->history_list, node) { list_for_each_entry(hs, &sc->history_list, node) {
if (clock < hm->first_clock) { if (clock < hs->first_clock) {
last_position = hm->start_position; last_position = hs->start_position;
continue; continue;
} }
if (clock >= hm->last_clock) if (clock >= hs->last_clock)
return hm->start_position + hm->step_count; return hs->start_position + hs->step_count;
int32_t interval = hm->sm.interval, add = hm->sm.add; int32_t interval = hs->sm.interval, add = hs->sm.add;
int32_t ticks = (int32_t)(clock - hm->first_clock) + interval, offset; int32_t ticks = (int32_t)(clock - hs->first_clock) + interval, offset;
if (!add) { if (!add) {
offset = ticks / interval; offset = ticks / interval;
} else { } else {
@ -584,9 +584,9 @@ stepcompress_find_past_position(struct stepcompress *sc, uint64_t clock)
double a = .5 * add, b = interval - .5 * add, c = -ticks; double a = .5 * add, b = interval - .5 * add, c = -ticks;
offset = (sqrt(b*b - 4*a*c) - b) / (2. * a); offset = (sqrt(b*b - 4*a*c) - b) / (2. * a);
} }
if (hm->step_count < 0) if (hs->step_count < 0)
return hm->start_position - offset; return hs->start_position - offset;
return hm->start_position + offset; return hs->start_position + offset;
} }
return last_position; return last_position;
} }