move logging to panel

This commit is contained in:
jacob 2026-04-03 13:09:53 -05:00
parent d7ecdfb950
commit 1a7794e81b
4 changed files with 1127 additions and 1226 deletions

View File

@ -570,6 +570,14 @@ String V_StringFromTextboxSelection(Arena *arena, V_TextboxState *tb)
return StringFromString32(arena, (String32) { .len = max - min, .text = tb->text32 + min });
}
////////////////////////////////////////////////////////////
//~ Panel
b32 V_ShouldIgnorePanel(V_Panel *panel)
{
return panel->flags & V_PanelFlag_Ignore;
}
////////////////////////////////////////////////////////////
//~ Timeline helpers
@ -930,7 +938,6 @@ void V_TickForever(WaveLaneCtx *lane)
frame->palette = prev_frame->palette;
frame->is_editing = prev_frame->is_editing;
frame->ui_debug = prev_frame->ui_debug;
frame->show_console = prev_frame->show_console;
frame->look = prev_frame->look;
frame->fire_presses = prev_frame->fire_presses;
frame->roll_presses = prev_frame->roll_presses;
@ -3746,6 +3753,8 @@ void V_TickForever(WaveLaneCtx *lane)
V_Panel *parent_panel = parent_panel_bfs->panel;
for (V_Panel *panel = parent_panel->first; panel; panel = panel->next)
{
if (!V_ShouldIgnorePanel(panel))
{
BfsPanel *panel_bfs = PushStruct(frame->arena, BfsPanel);
panel_bfs->panel = panel;
@ -3757,15 +3766,29 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Build console panel
if (panel->flags & V_PanelFlag_Console)
ProfZoneDF("Build console panel")
{
Vec4 level_colors[LogLevel_COUNT][2] = Zi;
SetBytes(level_colors, 0xFF, sizeof(level_colors));
level_colors[LogLevel_Trace][0] = Rgb(0.1, 0.4, 0.4);
level_colors[LogLevel_Trace][1] = Rgb(0.2, 0.5, 0.5);
level_colors[LogLevel_Debug][0] = Rgb(0.4, 0.1, 0.4);
level_colors[LogLevel_Debug][1] = Rgb(0.5, 0.2, 0.5);
level_colors[LogLevel_Info][0] = Rgb(0.2, 0.2, 0.2);
level_colors[LogLevel_Info][1] = Rgb(0.25, 0.25, 0.25);
level_colors[LogLevel_Success][0] = Rgb(0.1, 0.3, 0.1);
level_colors[LogLevel_Success][1] = Rgb(0.2, 0.4, 0.2);
level_colors[LogLevel_Warning][0] = Rgb(0.4, 0.4, 0.1);
level_colors[LogLevel_Warning][1] = Rgb(0.5, 0.5, 0.2);
level_colors[LogLevel_Error][0] = Rgb(0.4, 0.1, 0.1);
level_colors[LogLevel_Error][1] = Rgb(0.5, 0.2, 0.2);
//- Gather visible logs
Struct(VisLog)
{
VisLog *next;
VisLog *prev;
LogEvent log_ev;
};
u64 display_logs_count = 0;
@ -3774,29 +3797,20 @@ void V_TickForever(WaveLaneCtx *lane)
i32 max_log_level = LogLevel_Trace;
u32 max_display_logs = 30;
i64 max_time_ns = NsFromSeconds(1000);
f32 max_display_logs = MaxF32(10, DimsFromRng2(UI_Rect(panel->contents_box)).y / (UI_Top(FontSize)));
LogEventsArray log_events = GetLogEvents();
{
b32 done = 0;
for (u64 log_event_idx = log_events.count; log_event_idx-- > 0 && display_logs_count < max_display_logs && !done;)
for (u64 log_event_idx = log_events.count; log_event_idx-- > 0 && display_logs_count < max_display_logs;)
{
LogEvent ev = log_events.events[log_event_idx];
if (ev.time_ns > (frame->time_ns - max_time_ns))
{
if (ev.level <= max_log_level)
{
VisLog *vis_log = PushStruct(frame->arena, VisLog);
vis_log->log_ev = ev;
SllQueuePush(first_vis_log, last_vis_log, vis_log);
DllQueuePush(first_vis_log, last_vis_log, vis_log);
++display_logs_count;
}
}
else
{
done = 1;
}
}
}
//- Build log entries UI
@ -3813,23 +3827,32 @@ void V_TickForever(WaveLaneCtx *lane)
UI_SetNext(Height, UI_Shrink(0, 1));
UI_PushDF(Parent, UI_BuildColumn())
{
for (VisLog *vis_log = first_vis_log; vis_log; vis_log = vis_log->next)
for (VisLog *vis_log = last_vis_log; vis_log; vis_log = vis_log->prev)
{
LogEvent ev = vis_log->log_ev;
String log_msg = ev.msg;
String display_text = StringF(frame->arena, "%F", FmtString(log_msg));
Vec4 color = level_colors[ev.level][ev.level_id % 2];
color.a *= 0.55;
UI_SetNext(BackgroundColor, color);
UI_SetNext(Height, UI_Shrink(0, 1));
UI_PushDF(Parent, UI_BuildRow())
{
// UI_BuildLabelF("%F", FmtString(text));
UI_SetNext(Height, UI_Shrink(0, 1));
UI_SetNext(Text, display_text);
// UI_SetNext(ChildAlignment, UI_Region_BottomLeft);
UI_SetNext(ChildAlignment, UI_Region_TopLeft);
// UI_SetNext(ChildAlignment, UI_Region_TopLeft);
UI_SetNext(Flags, UI_BoxFlag_DrawText);
UI_BuildBox();
}
}
}
}
}
@ -3859,7 +3882,7 @@ void V_TickForever(WaveLaneCtx *lane)
//////////////////////////////
//- Build profiler panel
if (!TweakBool("Hide profiler", 0))
if (!TweakBool("Hide profiler", 1))
if (panel->flags & V_PanelFlag_Profiler)
ProfZoneDF("Build profiler panel")
{
@ -4242,8 +4265,8 @@ void V_TickForever(WaveLaneCtx *lane)
{
visual_zone_start_px = MaxF64(visual_zone_start_px, left_vis->end_px);
}
visual_zone_start_px = RoundF32(visual_zone_start_px);
visual_zone_end_px = RoundF32(visual_zone_end_px);
visual_zone_start_px = RoundF64(visual_zone_start_px);
visual_zone_end_px = RoundF64(visual_zone_end_px);
}
// Push vis zone
@ -4318,7 +4341,8 @@ void V_TickForever(WaveLaneCtx *lane)
Vec4 profiler_color = theme.col.window_bg;
f32 profiler_opacity = TweakFloat("Profiler opacity", 1, 0, 1);
Vec4 timeline_cursor_color = theme.col.window_bd;
// Vec4 timeline_cursor_color = theme.col.window_bd;
Vec4 timeline_cursor_color = VEC4(0.5, 0.5, 0.5, 1);
timeline_cursor_color.a = UI_Hot(main_box) * 0.75;
UI_Size timeline_cursor_width = UI_Fnt(0.15, 1);
@ -4692,7 +4716,8 @@ void V_TickForever(WaveLaneCtx *lane)
{
// UI_SetNext(BorderSize, 1);
// UI_SetNext(BorderColor, Color_White);
UI_SetNext(BackgroundColor, timeline_cursor_color);
// UI_SetNext(BackgroundColor, timeline_cursor_color);
UI_SetNext(BackgroundColor, ruler_color);
UI_SetNext(Width, timeline_cursor_width);
UI_SetNext(FloatingPos, ruler_cursor_pos);
UI_SetNext(Anchor, UI_Region_Top);
@ -4862,6 +4887,7 @@ void V_TickForever(WaveLaneCtx *lane)
}
}
}
}
@ -4948,7 +4974,7 @@ void V_TickForever(WaveLaneCtx *lane)
panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v));
panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v));
panel->flags |= V_PanelFlag_Console;
panel->pct = 0.5;
panel->pct = 0.75;
}
//- Vis screen panel
@ -4974,7 +5000,7 @@ void V_TickForever(WaveLaneCtx *lane)
DllQueuePush(parent->first, parent->last, panel);
panel->box = UI_KeyF("test raah profiler panel");
panel->contents_box = UI_KeyF("panel contents box %F", FmtUint(panel->box.v));
panel->resizer_box = UI_KeyF("panel r esizer box %F", FmtUint(panel->box.v)); if (!TweakBool("Hide profiler", 0))
panel->resizer_box = UI_KeyF("panel resizer box %F", FmtUint(panel->box.v));
panel->flags |= V_PanelFlag_Profiler;
panel->pct = 0.5;
}
@ -5045,20 +5071,28 @@ void V_TickForever(WaveLaneCtx *lane)
f32 pct_accum = 0;
f32 children_count = 0;
for (V_Panel *panel = parent_panel->first; panel; panel = panel->next)
{
if (!V_ShouldIgnorePanel(panel))
{
children_count += 1;
pct_accum += panel->pct;
}
}
f32 violation = 1.0 - pct_accum;
for (V_Panel *panel = parent_panel->first; panel; panel = panel->next)
{
if (!V_ShouldIgnorePanel(panel))
{
panel->pct += violation / children_count;
panel->pct = MaxF32(panel->pct, minimum_panel_pct);
}
}
}
//- Build panel boxes
for (V_Panel *panel = parent_panel->first; panel; panel = panel->next)
{
if (!V_ShouldIgnorePanel(panel))
{
PanelBfs *bfs_panel = PushStruct(frame->arena, PanelBfs);
bfs_panel->panel = panel;
@ -5144,7 +5178,7 @@ void V_TickForever(WaveLaneCtx *lane)
}
//- Left null-resizer box
// if (!panel->prev)
// if (!panel->prev && !V_ShouldIgnorePanel(panel->prev))
// {
// UI_SetNext(AxisSize, resizer_size, .axis = parent_axis);
// UI_SetNext(BackgroundColor, resizer_color);
@ -5171,7 +5205,7 @@ void V_TickForever(WaveLaneCtx *lane)
//- Resizer box
b32 can_resize = panel->next != 0;
b32 can_resize = panel->next != 0 && !V_ShouldIgnorePanel(panel->next);
if (can_resize)
{
UI_SetNext(AxisSize, resizer_size, .axis = parent_axis);
@ -5219,6 +5253,7 @@ void V_TickForever(WaveLaneCtx *lane)
}
}
}
}
@ -7050,7 +7085,10 @@ void V_TickForever(WaveLaneCtx *lane)
UI_Push(Width, UI_Grow(1, 0));
UI_Push(Height, header_height);
UI_SetNext(Flags, UI_BoxFlag_DrawText | (UI_BoxFlag_CaptureMouse * !!palette->is_showing));
UI_PushCp(UI_BuildBoxEx(titlebar_key));
UI_PushDF(FontSize, UI_Top(FontSize) * theme.h5)
UI_PushDF(TextColor, theme.col.hint)
UI_PushDF(ChildAlignment, UI_Region_Center)
UI_PushDF(Parent, UI_BuildBoxEx(titlebar_key))
{
UI_Push(Width, UI_Grow(1, 0));
UI_Push(BorderColor, 0);
@ -7058,11 +7096,11 @@ void V_TickForever(WaveLaneCtx *lane)
// Left title box
UI_BuildRow();
UI_SetNext(Width, UI_Shrink(0, 1));
UI_BuildIcon(theme.icon_font, UI_Icon_Wrench);
// Title box
// UI_SetNext(FontSize, UI_Top(FontSize) * theme.h3);
UI_SetNext(FontSize, UI_Top(FontSize) * theme.h5);
UI_SetNext(TextColor, theme.col.hint);
UI_SetNext(ChildAlignment, UI_Region_Center);
UI_SetNext(Width, UI_Shrink(0, 1));
UI_SetNext(Text, Lit(" Developer Palette"));
UI_SetNext(Flags, UI_BoxFlag_DrawText);
@ -7071,7 +7109,6 @@ void V_TickForever(WaveLaneCtx *lane)
// Right title box
UI_BuildRow();
}
UI_PopCp(UI_TopCp());
}
UI_PopCp(UI_TopCp());
@ -8159,7 +8196,8 @@ void V_TickForever(WaveLaneCtx *lane)
G_Stats gpu_stats = G_QueryStats();
if (frame->show_console)
// if (frame->show_console)
if (0)
{
UI_Key dbg_box = UI_KeyF("Debug box");
Vec2 dbg_dims = DimsFromRng2(UI_Rect(dbg_box));
@ -8698,149 +8736,6 @@ void V_TickForever(WaveLaneCtx *lane)
}
}
//////////////////////////////
//- Build console UI
// TODO: Remove this whole thing
if (frame->show_console)
{
b32 minimized = 0;
// i32 console_level = minimized ? LogLevel_Success : LogLevel_Debug;
i32 console_level = LogLevel_Trace;
Vec4 colors[LogLevel_COUNT][2] = Zi;
SetBytes(colors, 0xFF, sizeof(colors));
// Trace colors
colors[LogLevel_Trace][0] = Rgb(0.1, 0.4, 0.4);
colors[LogLevel_Trace][1] = Rgb(0.2, 0.5, 0.5);
// Debug colors
colors[LogLevel_Debug][0] = Rgb(0.4, 0.1, 0.4);
colors[LogLevel_Debug][1] = Rgb(0.5, 0.2, 0.5);
// Info colors
colors[LogLevel_Info][0] = Rgb(0.2, 0.2, 0.2);
colors[LogLevel_Info][1] = Rgb(0.25, 0.25, 0.25);
// Success colors
colors[LogLevel_Success][0] = Rgb(0.1, 0.3, 0.1);
colors[LogLevel_Success][1] = Rgb(0.2, 0.4, 0.2);
// Warning colors
colors[LogLevel_Warning][0] = Rgb(0.4, 0.4, 0.1);
colors[LogLevel_Warning][1] = Rgb(0.5, 0.5, 0.2);
// Error colors
colors[LogLevel_Error][0] = Rgb(0.4, 0.1, 0.1);
colors[LogLevel_Error][1] = Rgb(0.5, 0.2, 0.2);
i64 max_time_ns = I64Max;
i64 fade_time_ns = max_time_ns;
if (minimized)
{
max_time_ns = NsFromSeconds(10);
fade_time_ns = max_time_ns;
}
f32 fade_curve = 0.5;
{
UI_Push(FloatingPos, VEC2(0, 0));
UI_SetNext(Flags, UI_BoxFlag_Floating);
UI_SetNext(BorderSize, 0);
if (minimized)
{
UI_SetNext(BackgroundColor, 0);
UI_SetNext(Width, UI_Fnt(50, 0));
UI_SetNext(Height, UI_Shrink(0, 1));
}
else
{
UI_SetNext(BackgroundColor, Rgba(0, 0, 0, 1));
UI_SetNext(Width, UI_Grow(1, 0));
UI_SetNext(Height, UI_Shrink(0, 1));
}
UI_Key console_box = UI_BuildColumnEx(UI_KeyF("Console box"));
UI_PushCp(console_box);
{
// Gather display logs
u64 max = 20;
u64 display_count = 0;
LogEvent *display_logs = PushStructs(frame->arena, LogEvent, max);
{
b32 done = 0;
if (minimized)
{
max = 5;
}
LogEventsArray log_events = GetLogEvents();
for (u64 i = log_events.count; i-- > 0 && display_count < max && !done;)
{
LogEvent ev = log_events.events[i];
if (ev.time_ns > (frame->time_ns - max_time_ns))
{
if (ev.level <= console_level)
{
display_logs[display_count] = ev;
++display_count;
}
}
else
{
done = 1;
}
}
}
// Display logs in reverse
for (u64 i = display_count; i-- > 0;)
{
LogEvent log = display_logs[i];
f32 opacity = 0.75;
f32 lin = 1.0 - ClampF64((f64)(frame->time_ns - log.time_ns) / (f64)fade_time_ns, 0, 1);
opacity *= PowF32(lin, fade_curve);
String text = log.msg;
if (!minimized)
{
DateTime datetime = log.datetime;
text = StringF(
frame->arena,
"[%F:%F:%F.%F] %F",
FmtUint(datetime.hour, .z = 2),
FmtUint(datetime.minute, .z = 2),
FmtUint(datetime.second, .z = 2),
FmtUint(datetime.milliseconds, .z = 3),
FmtString(text)
);
}
UI_PushCp(UI_NilKey);
{
Vec4 tint = VEC4(1, 1, 1, opacity);
UI_Push(Tint, tint);
{
Vec4 color = colors[log.level][log.level_id % 2];
UI_Push(BackgroundColor, color);
UI_Push(Width, UI_Grow(1, 0));
UI_Push(Height, UI_Fnt(1.5, 1));
UI_Push(Rounding, UI_Rpx(0));
UI_Push(BorderSize, 0);
UI_Push(ChildAlignment, UI_Region_Left);
UI_PushCp(UI_BuildRow());
{
// UI_SetNext(Height, UI_Px(100, 0));
UI_BuildSpacer(UI_Px(10, 0), Axis_X);
UI_Push(BackgroundColor, 0);
UI_Push(BorderSize, 0);
UI_Push(Text, text);
UI_Push(Width, UI_Grow(1, 0));
UI_Push(Height, UI_Shrink(0, 1));
UI_Push(Flags, UI_BoxFlag_DrawText);
UI_BuildBox();
}
UI_PopCp(UI_TopCp());
}
}
UI_PopCp(UI_TopCp());
}
}
UI_PopCp(UI_TopCp());
}
}
//////////////////////////////
//- Process vis commands
@ -8910,7 +8805,7 @@ void V_TickForever(WaveLaneCtx *lane)
case V_CmdKind_toggle_console:
{
frame->show_console = !frame->show_console;
// frame->show_console = !frame->show_console;
} break;
case V_CmdKind_toggle_profiler:

View File

@ -315,9 +315,10 @@ Struct(V_Profiler)
Enum(V_PanelFlag)
{
V_PanelFlag_None = 0,
V_PanelFlag_Spawn = (1 << 0),
V_PanelFlag_Profiler = (1 << 1),
V_PanelFlag_Console = (1 << 2),
V_PanelFlag_Ignore = (1 << 0),
V_PanelFlag_Spawn = (1 << 1),
V_PanelFlag_Profiler = (1 << 2),
V_PanelFlag_Console = (1 << 3),
};
Struct(V_Panel)
@ -523,6 +524,11 @@ V_TextboxDeltaFlag V_ApplyTextboxDeltas(V_TextboxState *tb, V_TextboxDeltaList d
String V_StringFromTextbox(Arena *arena, V_TextboxState *tb);
String V_StringFromTextboxSelection(Arena *arena, V_TextboxState *tb);
////////////////////////////////////////////////////////////
//~ Panel
b32 V_ShouldIgnorePanel(V_Panel *panel);
////////////////////////////////////////////////////////////
//~ Timeline helpers

View File

@ -1012,7 +1012,8 @@ ComputeShader(V_CompositeCS)
Vec4 grid_color = 0;
if (is_in_world)
{
b32 draw_grid = frame.show_console;
// b32 draw_grid = frame.show_console;
b32 draw_grid = 0;
// Grid outline
if (draw_grid)

View File

@ -316,7 +316,6 @@ Struct(V_SharedFrame)
b32 is_editing;
b32 ui_debug;
b32 show_console;
b32 is_selecting;
b32 is_panning;
b32 has_mouse_focus;