From c3ded7b8081cc5c4bb392d69c074d3dd0d25d5e2 Mon Sep 17 00:00:00 2001 From: silverweed Date: Thu, 18 Jul 2024 17:43:44 +0200 Subject: [PATCH] add ReadOnly but allow selecting bytes --- src/render.cpp | 38 +++++++++++++++++--- src/render.h | 4 +++ src/rntuple.h | 12 +++++++ third_party/imgui_club/imgui_memory_editor.h | 6 ++-- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/render.cpp b/src/render.cpp index 5c7d7f0..afa3cde 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -120,7 +120,7 @@ internal MemoryEditor make_memory_editor(App_State &app) { MemoryEditor mem_edit; - // mem_edit.ReadOnly = true; + mem_edit.ReadOnly = true; mem_edit.Cols = 32; mem_edit.OptShowDataPreview = true; mem_edit.BgColorFn = mem_edit_bg_color_fn; @@ -176,6 +176,18 @@ void viewer_jump_to_page(App_State &app, u64 page_idx) viewer_jump_to(app.viewer, page->range.start); } +internal +void viewer_jump_to_page_list(App_State &app, u64 page_list_idx) +{ + assert(app.rndata.n_cluster_groups > 0); + page_list_idx = (page_list_idx + app.rndata.n_cluster_groups) % app.rndata.n_cluster_groups; + + Cluster_Group_Info &cg_info = app.rndata.cluster_groups[page_list_idx]; + + app.viewer.latest_page_list_gone_to = page_list_idx; + viewer_jump_to(app.viewer, cg_info.rng_page_list.start); +} + internal void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms) { @@ -216,6 +228,8 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms) // Draw main content { + const u64 step_u64 = 1; + ImGui::BeginTable("Hex View", 2, ImGuiTableFlags_Resizable); ImGui::TableNextColumn(); @@ -236,14 +250,20 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms) ImGui::ColorEdit3("_TFile Object", app.viewer.col_tfile_obj, flags); ImGui::SameLine(); if (ImGui::Button("TFile Object")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_obj.start); + ImGui::SameLine(); + ImGui::Text("%s", to_pretty_size(scratch.arena, app.tfile_data.rng_root_file_obj.len).c()); ImGui::ColorEdit3("_TFile Info", app.viewer.col_tfile_info, flags); ImGui::SameLine(); if (ImGui::Button("TFile Info")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_info.start); + ImGui::SameLine(); + ImGui::Text("%s", to_pretty_size(scratch.arena, app.tfile_data.rng_root_file_info.len).c()); ImGui::ColorEdit3("_TFile FreeList", app.viewer.col_tfile_free, flags); ImGui::SameLine(); if (ImGui::Button("TFile FreeList")) viewer_jump_to(app.viewer, app.tfile_data.rng_root_file_free.start); + ImGui::SameLine(); + ImGui::Text("%s", to_pretty_size(scratch.arena, app.tfile_data.rng_root_file_free.len).c()); ImGui::ColorEdit3("_RNTuple Anchor", app.viewer.col_anchor, flags); ImGui::SameLine(); @@ -276,10 +296,10 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms) if (ImGui::Button("Page")) viewer_jump_to_page(app, app.viewer.latest_page_gone_to); ImGui::SameLine(); { - // TODO: support u64 - i32 page_to_go_to = static_cast(app.viewer.latest_page_gone_to); + const u64 step_fast_u64 = app.rndata.n_pages / 100; + u64 page_to_go_to = app.viewer.latest_page_gone_to; ImGui::PushItemWidth(100.f); - if (ImGui::InputInt("##page_viewed", &page_to_go_to)) + if (ImGui::InputScalar("##page_viewed", ImGuiDataType_U64, &page_to_go_to, &step_u64, &step_fast_u64, "%u")) viewer_jump_to_page(app, page_to_go_to); ImGui::PopItemWidth(); } @@ -292,7 +312,15 @@ void update_and_render(Arena *arena, App_State &app, f32 delta_time_ms) ImGui::ColorEdit3("_Page List", app.viewer.col_page_list, flags); ImGui::SameLine(); - if (ImGui::Button("Page List")) {} // TODO jump to next page list + if (ImGui::Button("Page List")) viewer_jump_to_page_list(app, app.viewer.latest_page_list_gone_to); + ImGui::SameLine(); + { + u64 page_list_to_go_to = app.viewer.latest_page_list_gone_to; + ImGui::PushItemWidth(80.f); + if (ImGui::InputScalar("##page_list_viewed", ImGuiDataType_U64, &page_list_to_go_to, &step_u64, nullptr, "%u")) + viewer_jump_to_page_list(app, page_list_to_go_to); + ImGui::PopItemWidth(); + } ImGui::SameLine(); ImGui::Text("%s", to_pretty_size(scratch.arena, app.rndata.tot_page_list_size).c()); diff --git a/src/render.h b/src/render.h index 3777019..eb33c6e 100644 --- a/src/render.h +++ b/src/render.h @@ -15,7 +15,11 @@ struct Viewer { f32 col_page_list[3]; u64 base_display_addr; + u64 latest_page_gone_to; + u64 latest_key_gone_to; + u64 latest_checksum_gone_to; + u64 latest_page_list_gone_to; }; struct Edit_Bg_Color_Data { diff --git a/src/rntuple.h b/src/rntuple.h index 9037817..5becf8d 100644 --- a/src/rntuple.h +++ b/src/rntuple.h @@ -16,6 +16,12 @@ struct Page_Info_Node { } }; +// Used to store location information about stuff like checksums, page lists, etc +struct Range_Seq { + Range_Seq *next; + Byte_Range range; +}; + static const Page_Info_Node invalid_pinfo {}; struct Page_Info_Group { @@ -65,6 +71,12 @@ struct RNTuple_Data { u64 n_elems; u64 tot_page_size; + Range_Seq *checksums; + u64 n_checksums; + + Range_Seq *page_lists; + u64 n_page_lists; + Cluster_Group_Info *cluster_groups; u64 n_cluster_groups; u64 tot_page_list_size; diff --git a/third_party/imgui_club/imgui_memory_editor.h b/third_party/imgui_club/imgui_memory_editor.h index 3fd1dcf..63eb01f 100644 --- a/third_party/imgui_club/imgui_memory_editor.h +++ b/third_party/imgui_club/imgui_memory_editor.h @@ -245,7 +245,7 @@ struct MemoryEditor bool data_next = false; - if (ReadOnly || DataEditingAddr >= mem_size) + if (/*ReadOnly ||*/ DataEditingAddr >= mem_size) DataEditingAddr = (size_t)-1; if (DataPreviewAddr >= mem_size) DataPreviewAddr = (size_t)-1; @@ -320,6 +320,7 @@ struct MemoryEditor draw_list->AddRectFilled(pos, ImVec2(pos.x + highlight_width, pos.y + s.LineHeight), BgColorFn(mem_data, addr, BgColorFnUserData)); } + #if 0 if (DataEditingAddr == addr) { // Display text input on current byte @@ -380,6 +381,7 @@ struct MemoryEditor ImGui::PopID(); } else + #endif { // NB: The trailing space is not visible but ensure there's no gap that the mouse cannot click on. ImU8 b = ReadFn ? ReadFn(mem_data, addr) : mem_data[addr]; @@ -402,7 +404,7 @@ struct MemoryEditor else ImGui::Text(format_byte_space, b); } - if (!ReadOnly && ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) + if (/*!ReadOnly &&*/ ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) { DataEditingTakeFocus = true; data_editing_addr_next = addr;