From e22475fb1df60c33dbb70f4dd74d82a916a6fd10 Mon Sep 17 00:00:00 2001 From: jacob Date: Thu, 2 Apr 2026 00:14:18 -0500 Subject: [PATCH] profiler snap --- src/pp/pp_vis/pp_vis_core.c | 58 +++++++++++++++++++++++++------------ src/pp/pp_vis/pp_vis_core.h | 1 + 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index f2c4df15..b2933ae5 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -5515,16 +5515,16 @@ void V_TickForever(WaveLaneCtx *lane) UI_SetDF(OmitFlags, UI_BoxFlag_CaptureMouse * !!(frame->is_looking)) if (profiler->is_showing) { + + + // FIXME: Remove this - - - - if (frame->tick == 1) - { - // profiler->ns_per_px = NsFromSeconds(0.0001); - profiler->target_ns_per_px = NsFromSeconds(0.01); - } + // if (frame->tick == 1) + // { + // // profiler->ns_per_px = NsFromSeconds(0.0001); + // profiler->target_ns_per_px = NsFromSeconds(0.01); + // } profiler->graph_dims = DimsFromRng2(UI_Rect(profiler_graph_box)); @@ -5584,19 +5584,23 @@ void V_TickForever(WaveLaneCtx *lane) profiler->cursor_ns = (cursor_px * profiler->ns_per_px) + profiler->view_ns; } + // Snap view + if (profiler->snap) + { + f64 snap_width_ns = NsFromSeconds(1.0 / 10.0); + profiler->target_view_ns = frame->time_ns - snap_width_ns; + profiler->target_ns_per_px = snap_width_ns / MaxF32(DimsFromRng2(UI_Rect(main_box)).x, 100); + } - - - - - - // FIXME: Remove this f32 prof_zoom_rate = 1.65; f64 prof_lerp_rate = SaturateF64(frame->dt * 25); - { f64 zooms = UI_Presses(main_box, Button_WheelDown) - UI_Presses(main_box, Button_WheelUp); + if (zooms != 0) + { + profiler->snap = 0; + } f64 zoom_factor = PowF64(prof_zoom_rate, zooms); profiler->target_ns_per_px *= zoom_factor; profiler->target_view_ns = profiler->cursor_ns - (profiler->cursor_ns - profiler->target_view_ns) * zoom_factor; @@ -5664,6 +5668,14 @@ void V_TickForever(WaveLaneCtx *lane) + if (is_main_hot) + { + profiler->cursor_ns = (cursor_px * profiler->ns_per_px) + profiler->view_ns; + } + + + + // TODO: Drag in px units for sharper resolution @@ -5678,10 +5690,12 @@ void V_TickForever(WaveLaneCtx *lane) b32 is_measuring = 0; if (UI_Downs(main_box, Button_M1)) { + profiler->snap = 0; profiler->ruler_start_ns = profiler->cursor_ns; } if (UI_Held(main_box, Button_M1)) { + profiler->snap = 0; is_measuring = 1; profiler->target_ruler_opacity = 1; } @@ -5694,6 +5708,7 @@ void V_TickForever(WaveLaneCtx *lane) // Drag view if (UI_Held(main_box, Button_M2) || UI_Held(main_box, Button_M3)) { + profiler->snap = 0; profiler->view_ns = profiler->drag_view_ns - ((cursor_px - profiler->drag_cursor_px) * profiler->ns_per_px); profiler->target_view_ns = profiler->view_ns; } @@ -5853,10 +5868,10 @@ void V_TickForever(WaveLaneCtx *lane) } } - b32 should_collapse_zone = (visual_zone_end_px - visual_zone_start_px) <= zone_collapse_threshold_px; - // Push vis zone + if (visual_zone_end_px <= (frame->time_ns / profiler->ns_per_px)) { + b32 should_collapse_zone = (visual_zone_end_px - visual_zone_start_px) <= zone_collapse_threshold_px; String zone_name = zone->name; u64 zone_id = zone->id; Vec4 zone_color = zone->color; @@ -6054,15 +6069,16 @@ void V_TickForever(WaveLaneCtx *lane) for (VisZone *zone = vis_track->first_zone; zone; zone = zone->next) { UI_Key zone_row_box = zone_row_boxes[zone->depth - 1]; + b32 can_hover = !profiler->snap; UI_Key zone_box = UI_KeyF("Zone %F", FmtUint(zone->id)); - b32 is_hovered = UI_HoveredAbsolute(zone_box) && UI_HotAbsolute(main_box); + b32 is_hovered = can_hover && UI_HoveredAbsolute(zone_box) && UI_HotAbsolute(main_box); if (is_hovered) { hovered_zone_box = zone_box; hovered_zone = zone; } - f32 zone_hovered = UI_Hovered(zone_box) * UI_Hot(main_box); + f32 zone_hovered = can_hover * UI_Hovered(zone_box) * UI_Hot(main_box); f64 zone_offset_px = zone->start_px - view_start_px; f64 zone_len_px = zone->end_px - zone->start_px; @@ -7278,6 +7294,10 @@ void V_TickForever(WaveLaneCtx *lane) case V_CmdKind_toggle_profiler: { frame->profiler.is_showing = !frame->profiler.is_showing; + if (frame->profiler.is_showing) + { + frame->profiler.snap = 1; + } } break; case V_CmdKind_toggle_timeline: diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index c4e20021..84cadaa8 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -299,6 +299,7 @@ Struct(V_Profiler) { Vec2 graph_dims; b32 is_showing; + b32 snap; f64 target_view_ns; f64 view_ns;