Use datatype monotonic_t instead of double to keep track of time

The time is stored in a signed 64 bit integer with nanosecond accuracy. This eliminates the possibility of floating-point inaccuracies.
`monotonic_t` can currently hold values large enough to work correctly for more than 200 years into the future.
Using a typedef instead of directly using `int64_t` everywhere will also allow easily changing the datatype in the future should the need arise for more precise or bigger time values.
This commit is contained in:
Luflosi
2019-08-02 11:49:02 -05:00
parent 4ec1a8d9c3
commit f3b9ff5f9f
33 changed files with 298 additions and 243 deletions

View File

@@ -7,6 +7,7 @@
#pragma once
#include "graphics.h"
#include "monotonic.h"
typedef enum ScrollTypes { SCROLL_LINE = -999999, SCROLL_PAGE, SCROLL_FULL } ScrollType;
@@ -86,13 +87,13 @@ typedef struct {
bool *tabstops, *main_tabstops, *alt_tabstops;
ScreenModes modes;
ColorProfile *color_profile;
double start_visual_bell_at;
monotonic_t start_visual_bell_at;
uint32_t parser_buf[PARSER_BUF_SZ];
unsigned int parser_state, parser_text_start, parser_buf_pos;
bool parser_has_pending_text;
uint8_t read_buf[READ_BUF_SZ], *write_buf;
double new_input_at;
monotonic_t new_input_at;
size_t read_buf_sz, write_buf_sz, write_buf_used;
pthread_mutex_t read_buf_lock, write_buf_lock;
@@ -101,7 +102,7 @@ typedef struct {
struct {
size_t capacity, used, stop_buf_pos;
uint8_t *buf;
double activated_at, wait_time;
monotonic_t activated_at, wait_time;
int state;
uint8_t stop_buf[32];
} pending_mode;
@@ -110,8 +111,8 @@ typedef struct {
} Screen;
void parse_worker(Screen *screen, PyObject *dump_callback, double now);
void parse_worker_dump(Screen *screen, PyObject *dump_callback, double now);
void parse_worker(Screen *screen, PyObject *dump_callback, monotonic_t now);
void parse_worker_dump(Screen *screen, PyObject *dump_callback, monotonic_t now);
void screen_align(Screen*);
void screen_restore_cursor(Screen *);
void screen_save_cursor(Screen *);