From 0a03ea05f1047740d3d9d91ff0f12b922fda3a7f Mon Sep 17 00:00:00 2001 From: PS Date: Sat, 10 Feb 2024 14:25:22 -0800 Subject: [PATCH] Adding dirty file reloading --- code/custom/4coder_default_hooks.cpp | 33 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/code/custom/4coder_default_hooks.cpp b/code/custom/4coder_default_hooks.cpp index ddda7ab8..627ff66f 100644 --- a/code/custom/4coder_default_hooks.cpp +++ b/code/custom/4coder_default_hooks.cpp @@ -80,7 +80,6 @@ CUSTOM_DOC("Input consumption loop for default view behavior") Managed_Scope scope = view_get_managed_scope(app, view); for (;;){ - // NOTE(allen): Get input User_Input input = get_next_input(app, EventPropertyGroup_Any, 0); if (input.abort){ break; @@ -149,30 +148,42 @@ code_index_update_tick(Application_Links *app){ buffer_modified_set_clear(); } +f32 time_since_last_dirty_buffers_check = 0; +function void +reload_clean_buffers_on_filesystem_change(Application_Links *app, Frame_Info frame_info) +{ + time_since_last_dirty_buffers_check += frame_info.literal_dt; + if (time_since_last_dirty_buffers_check > 1) + { + time_since_last_dirty_buffers_check = 0; + for (Buffer_ID buffer = get_buffer_next(app, 0, Access_Always); + buffer != 0; + buffer = get_buffer_next(app, buffer, Access_Always)) { + Dirty_State dirty = buffer_get_dirty_state(app, buffer); + if (dirty == DirtyState_UnloadedChanges) { + buffer_reopen(app, buffer, 0); + } + } + } +} + function void default_tick(Application_Links *app, Frame_Info frame_info){ - //////////////////////////////// - // NOTE(allen): Update code index - code_index_update_tick(app); - //////////////////////////////// - // NOTE(allen): Update fade ranges - if (tick_all_fade_ranges(app, frame_info.animation_dt)){ animate_in_n_milliseconds(app, 0); } - //////////////////////////////// - // NOTE(allen): Clear layouts if virtual whitespace setting changed. - - { + { // Clear layouts if virtual whitespace setting changed b32 enable_virtual_whitespace = def_get_config_b32(vars_save_string_lit("enable_virtual_whitespace")); if (enable_virtual_whitespace != def_enable_virtual_whitespace){ def_enable_virtual_whitespace = enable_virtual_whitespace; clear_all_layouts(app); } } + + reload_clean_buffers_on_filesystem_change(app, frame_info); } function Rect_f32