stepcompress: Store step times using 64bit integers

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-11-01 19:38:37 -04:00
parent 77d486f8d2
commit ff6fef927a
1 changed files with 14 additions and 18 deletions

View File

@ -27,9 +27,9 @@
struct stepcompress { struct stepcompress {
// Buffer management // Buffer management
uint32_t *queue, *queue_end, *queue_pos, *queue_next; uint64_t *queue, *queue_end, *queue_pos, *queue_next;
// Internal tracking // Internal tracking
uint32_t relclock, max_error; uint32_t max_error;
// Error checking // Error checking
uint32_t errors; uint32_t errors;
// Message generation // Message generation
@ -47,12 +47,10 @@ struct stepcompress {
static void static void
clean_queue(struct stepcompress *sc) clean_queue(struct stepcompress *sc)
{ {
uint32_t *src = sc->queue_pos, *dest = sc->queue; int in_use = sc->queue_next - sc->queue_pos;
while (src < sc->queue_next) memmove(sc->queue, sc->queue_pos, in_use * sizeof(*sc->queue));
*dest++ = *src++ - sc->relclock;
sc->queue_pos = sc->queue; sc->queue_pos = sc->queue;
sc->queue_next = dest; sc->queue_next = sc->queue + in_use;
sc->relclock = 0;
} }
// Expand the internal queue of step times // Expand the internal queue of step times
@ -110,10 +108,10 @@ struct points {
// Given a requested step time, return the minimum and maximum // Given a requested step time, return the minimum and maximum
// acceptable times // acceptable times
static struct points static struct points
minmax_point(struct stepcompress *sc, uint32_t *pos) minmax_point(struct stepcompress *sc, uint64_t *pos)
{ {
uint32_t prevpoint = pos > sc->queue_pos ? *(pos-1) - sc->relclock : 0; uint32_t prevpoint = pos > sc->queue_pos ? *(pos-1) - sc->last_step_clock : 0;
uint32_t point = *pos - sc->relclock; uint32_t point = *pos - sc->last_step_clock;
uint32_t max_error = (point - prevpoint) / 2; uint32_t max_error = (point - prevpoint) / 2;
if (max_error > sc->max_error) if (max_error > sc->max_error)
max_error = sc->max_error; max_error = sc->max_error;
@ -136,7 +134,7 @@ struct step_move {
static struct step_move static struct step_move
compress_bisect_add(struct stepcompress *sc) compress_bisect_add(struct stepcompress *sc)
{ {
uint32_t *last = sc->queue_next; uint64_t *last = sc->queue_next;
if (last > sc->queue_pos + 65535) if (last > sc->queue_pos + 65535)
last = sc->queue_pos + 65535; last = sc->queue_pos + 65535;
struct points point = minmax_point(sc, sc->queue_pos); struct points point = minmax_point(sc, sc->queue_pos);
@ -278,7 +276,7 @@ void
stepcompress_push(struct stepcompress *sc, double step_clock) stepcompress_push(struct stepcompress *sc, double step_clock)
{ {
check_expand(sc, 1); check_expand(sc, 1);
step_clock += 0.5 + sc->relclock - sc->last_step_clock; step_clock += 0.5;
*sc->queue_next++ = step_clock; *sc->queue_next++ = step_clock;
} }
@ -301,8 +299,8 @@ stepcompress_push_factor(struct stepcompress *sc
check_expand(sc, count); check_expand(sc, count);
// Calculate each step time // Calculate each step time
uint32_t *qn = sc->queue_next, *end = &qn[count]; uint64_t *qn = sc->queue_next, *end = &qn[count];
clock_offset += 0.5 + sc->relclock - sc->last_step_clock; clock_offset += 0.5;
double pos = step_offset; double pos = step_offset;
while (qn < end) { while (qn < end) {
*qn++ = clock_offset + pos*factor; *qn++ = clock_offset + pos*factor;
@ -331,8 +329,8 @@ stepcompress_push_sqrt(struct stepcompress *sc, double steps, double step_offset
check_expand(sc, count); check_expand(sc, count);
// Calculate each step time // Calculate each step time
uint32_t *qn = sc->queue_next, *end = &qn[count]; uint64_t *qn = sc->queue_next, *end = &qn[count];
clock_offset += 0.5 + sc->relclock - sc->last_step_clock; clock_offset += 0.5;
double pos = step_offset + sqrt_offset/factor; double pos = step_offset + sqrt_offset/factor;
if (factor >= 0.0) if (factor >= 0.0)
while (qn < end) { while (qn < end) {
@ -370,11 +368,9 @@ stepcompress_flush(struct stepcompress *sc, uint64_t move_clock)
sc->last_step_clock += ticks; sc->last_step_clock += ticks;
if (sc->queue_pos + move.count >= sc->queue_next) { if (sc->queue_pos + move.count >= sc->queue_next) {
sc->queue_pos = sc->queue_next = sc->queue; sc->queue_pos = sc->queue_next = sc->queue;
sc->relclock = 0;
break; break;
} }
sc->queue_pos += move.count; sc->queue_pos += move.count;
sc->relclock += ticks;
} }
} }