ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

Commit: 849ff4782b2fc8a30dd7c817dd3c9c03ba50b4ba
Parent: 16c32a812bd167d704d39740aec439f202bcc631
Author: Randy Palamar
Date:   Mon,  6 Jan 2025 13:23:25 -0700

debug: log when executable reloads and properly reload ui

Diffstat:
Mmain_generic.c | 2+-
Mos_unix.c | 2+-
Mstatic.c | 9++++++---
Mui.c | 18+++++++++++++++---
Mutil.h | 2+-
5 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/main_generic.c b/main_generic.c @@ -53,7 +53,7 @@ main(void) setup_beamformer(&ctx, temp_memory); while(!(ctx.flags & SHOULD_EXIT)) { - do_debug(&ctx.error_stream); + do_debug(&input, &ctx.error_stream); if (ctx.gl.vendor_id == GL_VENDOR_NVIDIA) check_and_load_cuda_lib(&ctx.cuda_lib, &ctx.error_stream); diff --git a/os_unix.c b/os_unix.c @@ -107,7 +107,7 @@ os_get_file_stats(char *fname) return (FileStats){ .filesize = st.st_size, - .timestamp = st.st_mtim.tv_sec + st.st_mtim.tv_nsec * 1e9, + .timestamp = (f64)st.st_mtim.tv_sec + (f64)st.st_mtim.tv_nsec * 1e-9, }; } diff --git a/static.c b/static.c @@ -20,15 +20,18 @@ static void *debug_lib; static beamformer_frame_step_fn *beamformer_frame_step; static void -do_debug(Stream *error_stream) +do_debug(BeamformerInput *input, Stream *error_stream) { - static f32 updated_time; + static f64 updated_time; FileStats test_stats = os_get_file_stats(OS_DEBUG_LIB_NAME); if (test_stats.filesize > 32 && test_stats.timestamp > updated_time) { os_unload_library(debug_lib); debug_lib = os_load_library(OS_DEBUG_LIB_NAME, OS_DEBUG_LIB_TEMP_NAME, error_stream); beamformer_frame_step = os_lookup_dynamic_symbol(debug_lib, "beamformer_frame_step", error_stream); - updated_time = test_stats.timestamp; + updated_time = test_stats.timestamp; + + input->executable_reloaded = 1; + os_write_err_msg(s8("Reloaded Main Executable\n")); } } diff --git a/ui.c b/ui.c @@ -769,11 +769,23 @@ ui_interact(BeamformerCtx *ctx, BeamformerInput *input) static void ui_init(BeamformerCtx *ctx, Arena store) { - /* NOTE: store the ui at the base of the passed in arena and use the rest for - * temporary allocations within the ui. If needed we can recall this function - * to completely clear the ui state */ + /* NOTE(rnp): store the ui at the base of the passed in arena and use the rest for + * temporary allocations within the ui. If needed we can recall this function to + * completely clear the ui state. The is that if we store pointers to static data + * such as embedded font data we will need to reset them when the executable reloads. + * We could also build some sort of ui structure here and store it then iterate over + * it to actually draw the ui. If we reload we may have changed it so we should + * rebuild it */ + + /* NOTE: unload old fonts from the GPU */ + if (ctx->ui) { + UnloadFont(ctx->ui->font); + UnloadFont(ctx->ui->small_font); + } + BeamformerUI *ui = ctx->ui = alloc(&store, typeof(*ctx->ui), 1); ui->arena_for_frame = store; + ui->frame_temporary_arena = begin_temp_arena(&ui->arena_for_frame); /* TODO: build these into the binary */ ui->font = LoadFontEx("assets/IBMPlexSans-Bold.ttf", 28, 0, 0); diff --git a/util.h b/util.h @@ -155,7 +155,7 @@ typedef struct { typedef struct { size filesize; - u64 timestamp; + f64 timestamp; } FileStats; #define ERROR_FILE_STATS (FileStats){.filesize = -1}