summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-31 10:33:21 -0500
committerpommicket <pommicket@gmail.com>2022-12-31 10:33:21 -0500
commit2b3b1bd0ed03739e3357516490e265261c5f815f (patch)
tree2be37644621ab86838bb6fdb20954660ce617064
parentf1751dbb895996728f293c6f895691693c9e8a86 (diff)
use double instead of struct timespec
-rw-r--r--buffer.c8
-rw-r--r--ide-autocomplete.c4
-rw-r--r--ide-definitions.c2
-rw-r--r--ide-usages.c2
-rw-r--r--main.c2
-rw-r--r--menu.c2
-rw-r--r--ted.h12
7 files changed, 16 insertions, 16 deletions
diff --git a/buffer.c b/buffer.c
index 9b25538..4c9a3b1 100644
--- a/buffer.c
+++ b/buffer.c
@@ -701,7 +701,7 @@ static bool buffer_edit_split(TextBuffer *buffer) {
if (buffer->chaining_edits) return false;
double curr_time = time_get_seconds();
double undo_time_cutoff = buffer_settings(buffer)->undo_save_time; // only keep around edits for this long (in seconds).
- return last_edit->time <= timespec_to_seconds(buffer->last_write_time) // last edit happened before buffer write (we need to split this so that undo_history_write_pos works)
+ return last_edit->time <= buffer->last_write_time // last edit happened before buffer write (we need to split this so that undo_history_write_pos works)
|| curr_time - last_edit->time > undo_time_cutoff;
}
@@ -2307,7 +2307,7 @@ Status buffer_load_file(TextBuffer *buffer, char const *filename) {
buffer->frame_latest_line_modified = nlines - 1;
buffer->lines_capacity = lines_capacity;
buffer->filename = filename_copy;
- buffer->last_write_time = time_last_modified(buffer->filename);
+ buffer->last_write_time = timespec_to_seconds(time_last_modified(buffer->filename));
if (!(fs_path_permission(filename) & FS_PERMISSION_WRITE)) {
// can't write to this file; make the buffer view only.
buffer->view_only = true;
@@ -2358,7 +2358,7 @@ void buffer_reload(TextBuffer *buffer) {
bool buffer_externally_changed(TextBuffer *buffer) {
if (!buffer->filename || buffer_is_untitled(buffer))
return false;
- return !timespec_eq(buffer->last_write_time, time_last_modified(buffer->filename));
+ return buffer->last_write_time != timespec_to_seconds(time_last_modified(buffer->filename));
}
void buffer_new_file(TextBuffer *buffer, char const *filename) {
@@ -2418,7 +2418,7 @@ bool buffer_save(TextBuffer *buffer) {
if (!buffer_haserr(buffer))
buffer_seterr(buffer, "Couldn't close file %s.", buffer->filename);
}
- buffer->last_write_time = time_last_modified(buffer->filename);
+ buffer->last_write_time = timespec_to_seconds(time_last_modified(buffer->filename));
bool success = !buffer_haserr(buffer);
if (success) {
buffer->undo_history_write_pos = arr_len(buffer->undo_history);
diff --git a/ide-autocomplete.c b/ide-autocomplete.c
index a30a33f..47b238f 100644
--- a/ide-autocomplete.c
+++ b/ide-autocomplete.c
@@ -352,8 +352,8 @@ static void autocomplete_frame(Ted *ted) {
size_t ncompletions = arr_len(ac->suggested);
if (ac->waiting_for_lsp && ncompletions == 0) {
- struct timespec now = ted->frame_time;
- if (timespec_sub(now, ac->lsp_request_time) < 0.2) {
+ double now = ted->frame_time;
+ if (now - ac->lsp_request_time < 0.2) {
// don't show "Loading..." unless we've actually been loading for a bit of time
return;
}
diff --git a/ide-definitions.c b/ide-definitions.c
index 6c48e26..46dc1f4 100644
--- a/ide-definitions.c
+++ b/ide-definitions.c
@@ -68,7 +68,7 @@ void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition p
void definitions_frame(Ted *ted) {
Definitions *defs = &ted->definitions;
- if (defs->last_request_id && timespec_sub(ted->frame_time, defs->last_request_time) > 0.2) {
+ if (defs->last_request_id && ted->frame_time - defs->last_request_time > 0.2) {
ted->cursor = ted->cursor_wait;
}
}
diff --git a/ide-usages.c b/ide-usages.c
index 21999be..dccb3d0 100644
--- a/ide-usages.c
+++ b/ide-usages.c
@@ -63,6 +63,6 @@ void usages_process_lsp_response(Ted *ted, LSPResponse *response) {
void usages_frame(Ted *ted) {
Usages *usages = &ted->usages;
- if (usages->last_request_id && timespec_sub(ted->frame_time, usages->last_request_time) > 0.2)
+ if (usages->last_request_id && ted->frame_time - usages->last_request_time > 0.2)
ted->cursor = ted->cursor_wait; // this request is takin a while
}
diff --git a/main.c b/main.c
index d091c64..3f8cc1c 100644
--- a/main.c
+++ b/main.c
@@ -651,7 +651,7 @@ int main(int argc, char **argv) {
while (!ted->quit) {
double frame_start = time_get_seconds();
- ted->frame_time = time_get();
+ ted->frame_time = frame_start;
SDL_Event event;
Uint8 const *keyboard_state = SDL_GetKeyboardState(NULL);
diff --git a/menu.c b/menu.c
index 4c62768..99a9a5b 100644
--- a/menu.c
+++ b/menu.c
@@ -196,7 +196,7 @@ static void menu_update(Ted *ted) {
case POPUP_NO:
menu_close(ted);
if (buffer)
- buffer->last_write_time = time_last_modified(buffer->filename);
+ buffer->last_write_time = timespec_to_seconds(time_last_modified(buffer->filename));
break;
case POPUP_CANCEL: assert(0); break;
}
diff --git a/ted.h b/ted.h
index c8e62a6..9201a89 100644
--- a/ted.h
+++ b/ted.h
@@ -225,7 +225,7 @@ typedef struct {
char *filename; // NULL if this buffer doesn't correspond to a file (e.g. line buffers)
struct Ted *ted; // we keep a back-pointer to the ted instance so we don't have to pass it in to every buffer function
double scroll_x, scroll_y; // number of characters scrolled in the x/y direction
- struct timespec last_write_time; // last write time to filename.
+ double last_write_time; // last write time to filename.
i16 manual_language; // 1 + the language the buffer has been manually set to, or 0 if it hasn't been manually set to anything
BufferPos cursor_pos;
BufferPos selection_pos; // if selection is true, the text between selection_pos and cursor_pos is selected.
@@ -375,7 +375,7 @@ typedef struct {
// when we sent the request to the LSP for completions
// (this is used to figure out when we should display "Loading...")
- struct timespec lsp_request_time;
+ double lsp_request_time;
Autocompletion *completions; // dynamic array of all completions
u32 *suggested; // dynamic array of completions to be suggested (indices into completions)
@@ -389,7 +389,7 @@ typedef struct {
typedef struct {
LSPID last_request_lsp;
LSPRequestID last_request_id;
- struct timespec last_request_time;
+ double last_request_time;
} Usages;
typedef struct {
@@ -439,7 +439,7 @@ typedef struct {
// if we got a response for the last request, or no requests have been made,
// last_request_id is set to 0.
LSPRequestID last_request_id;
- struct timespec last_request_time;
+ double last_request_time;
char *last_request_query; // last query string which we sent a request for
Selector selector; // for "go to definition of..." menu
@@ -455,8 +455,8 @@ typedef struct {
typedef struct Ted {
LSP *lsps[TED_LSP_MAX + 1];
- // current time, as of the start of this frame
- struct timespec frame_time;
+ // current time (see time_get_seconds), as of the start of this frame
+ double frame_time;
SDL_Window *window;
Font *font_bold;