fix busted synchronization in non-file-backed txti buffer edits; fix some snapping issues in Output view

This commit is contained in:
Ryan Fleury
2024-01-29 13:57:24 -08:00
parent baca24c037
commit d1fde3c908
3 changed files with 47 additions and 32 deletions
+5 -5
View File
@@ -6997,7 +6997,7 @@ DF_VIEW_UI_FUNCTION_DEF(Output)
{
if(txti_buffer_is_ready && visible_line_num_range.max >= visible_line_num_range.min && ui_is_focus_active())
{
snap[Axis2_X] = snap[Axis2_Y] = df_do_txti_controls(txti_handle, ClampBot(visible_line_count, 10) - 10, &tv->cursor, &tv->mark, &tv->preferred_column);
snap[Axis2_X] = snap[Axis2_Y] = df_do_txti_controls(txti_handle, ClampBot(num_possible_visible_lines, 10) - 10, &tv->cursor, &tv->mark, &tv->preferred_column);
}
}
@@ -7140,10 +7140,10 @@ DF_VIEW_UI_FUNCTION_DEF(Output)
if(snap[Axis2_Y])
{
Rng1S64 cursor_visibility_range = r1s64(tv->cursor.line-4, tv->cursor.line+4);
cursor_visibility_range.min = Clamp(0, cursor_visibility_range.min, (S64)txti_buffer_info.total_line_count);
cursor_visibility_range.max = Clamp(0, cursor_visibility_range.max, (S64)txti_buffer_info.total_line_count);
S64 min_delta = Min(0, cursor_visibility_range.min-target_visible_line_num_range.min);
S64 max_delta = Max(0, cursor_visibility_range.max-target_visible_line_num_range.max);
cursor_visibility_range.min = ClampBot(0, cursor_visibility_range.min);
cursor_visibility_range.max = ClampBot(0, cursor_visibility_range.max);
S64 min_delta = Min(0, cursor_visibility_range.min-(target_visible_line_num_range.min));
S64 max_delta = Max(0, cursor_visibility_range.max-(target_visible_line_num_range.min+num_possible_visible_lines));
S64 new_idx = view->scroll_pos.y.idx+min_delta+max_delta;
new_idx = Clamp(0, new_idx, (S64)txti_buffer_info.total_line_count-1);
ui_scroll_pt_target_idx(&view->scroll_pos.y, new_idx);
+16 -7
View File
@@ -1,16 +1,25 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
#include <Windows.h>
int main(void)
{
int x = 0;
int y = 0;
int z = 0;
for(;;)
for(int i = 0; i < 1000; i += 1)
{
x += 1;
y += 1;
z += 1;
OutputDebugStringA("Hello, this is a long string which is being output in loop #1.\n");
}
for(int i = 0; i < 1000; i += 1)
{
OutputDebugStringA("Hello, this is a long string which is being output in loop #2.\n");
}
for(int i = 0; i < 1000; i += 1)
{
OutputDebugStringA("Hello, this is a long string which is being output in loop #3.\n");
}
for(int i = 0; i < 1000; i += 1)
{
OutputDebugStringA("Hello, this is a long string which is being output in loop #4.\n");
}
return 0;
}
+26 -20
View File
@@ -982,7 +982,7 @@ txti_mut_thread_entry_point(void *p)
String8 file_contents = {0};
TXTI_LangKind lang_kind = TXTI_LangKind_Null;
U64 timestamp = 0;
if(msg->kind == TXTI_MsgKind_Reload)
if(msg->kind == TXTI_MsgKind_Reload) ProfScope("reload file")
{
FileProperties pre_load_props = os_properties_from_file_path(msg->string);
OS_Handle file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_ShareRead|OS_AccessFlag_ShareWrite, msg->string);
@@ -1038,7 +1038,7 @@ txti_mut_thread_entry_point(void *p)
//- rjf: obtain initial buffer_apply_gen, reset byte processing counters
U64 initial_buffer_apply_gen = 0;
if(load_valid) OS_MutexScopeR(stripe->rw_mutex)
ProfScope("obtain initial buffer_apply_gen") OS_MutexScopeR(stripe->rw_mutex)
{
TXTI_Entity *entity = 0;
for(TXTI_Entity *e = slot->first; e != 0; e = e->next)
@@ -1061,17 +1061,19 @@ txti_mut_thread_entry_point(void *p)
}
//- rjf: apply edits
ProfScope("apply edits")
{
for(U64 buffer_apply_idx = 0;
buffer_apply_idx < TXTI_ENTITY_BUFFER_COUNT;
buffer_apply_idx += 1)
ProfScope("apply edit #%i", (int)buffer_apply_idx)
{
// rjf: last buffer we're going to edit? -> bump buffer_apply_gen,
// so that before we touch this last buffer, all readers of this
// entity will get the already-modified buffers.
if(buffer_apply_idx == TXTI_ENTITY_BUFFER_COUNT-1)
{
OS_MutexScopeW(stripe->rw_mutex)
ProfScope("exclusive lock -> buffer swap") OS_MutexScopeW(stripe->rw_mutex)
{
TXTI_Entity *entity = 0;
for(TXTI_Entity *e = slot->first; e != 0; e = e->next)
@@ -1109,7 +1111,7 @@ txti_mut_thread_entry_point(void *p)
// exclusive lock to bump the buffer_apply_gen (to change the
// actively viewable buffer).
//
OS_MutexScopeR(stripe->rw_mutex)
ProfScope("apply edit") OS_MutexScopeR(stripe->rw_mutex)
{
TXTI_Entity *entity = 0;
for(TXTI_Entity *e = slot->first; e != 0; e = e->next)
@@ -1164,6 +1166,7 @@ txti_mut_thread_entry_point(void *p)
}
// rjf: parse & store line range info
ProfScope("parse & store line range info")
{
// rjf: count # of lines
U64 line_count = 1;
@@ -1186,31 +1189,34 @@ txti_mut_thread_entry_point(void *p)
}
// rjf: allocate & store line ranges
buffer->lines_count = line_count;
buffer->lines_ranges = push_array_no_zero(buffer->analysis_arena, Rng1U64, buffer->lines_count);
U64 line_idx = 0;
U64 line_start_idx = 0;
for(U64 idx = 0; idx <= buffer->data.size; idx += 1)
ProfScope("allocate & store line ranges")
{
if(idx == buffer->data.size || buffer->data.str[idx] == '\n' || buffer->data.str[idx] == '\r')
buffer->lines_count = line_count;
buffer->lines_ranges = push_array_no_zero(buffer->analysis_arena, Rng1U64, buffer->lines_count);
U64 line_idx = 0;
U64 line_start_idx = 0;
for(U64 idx = 0; idx <= buffer->data.size; idx += 1)
{
Rng1U64 line_range = r1u64(line_start_idx, idx);
U64 line_size = dim_1u64(line_range);
buffer->lines_ranges[line_idx] = line_range;
buffer->lines_max_size = Max(buffer->lines_max_size, line_size);
line_idx += 1;
line_start_idx = idx+1;
if(idx < buffer->data.size && buffer->data.str[idx] == '\r')
if(idx == buffer->data.size || buffer->data.str[idx] == '\n' || buffer->data.str[idx] == '\r')
{
line_start_idx += 1;
idx += 1;
Rng1U64 line_range = r1u64(line_start_idx, idx);
U64 line_size = dim_1u64(line_range);
buffer->lines_ranges[line_idx] = line_range;
buffer->lines_max_size = Max(buffer->lines_max_size, line_size);
line_idx += 1;
line_start_idx = idx+1;
if(idx < buffer->data.size && buffer->data.str[idx] == '\r')
{
line_start_idx += 1;
idx += 1;
}
}
}
}
}
// rjf: lex file contents
if(lex_function != 0)
if(lex_function != 0) ProfScope("lex text")
{
buffer->tokens = lex_function(buffer->analysis_arena, buffer_apply_idx == 0 ? &entity->bytes_processed : 0, buffer->data);
}