strip out update/render/repaint window cruft; promote layer per-tick APIs to base layer

This commit is contained in:
Ryan Fleury
2024-09-01 09:00:58 -07:00
parent 98840c73d8
commit 6ead03ac17
10 changed files with 63 additions and 72 deletions
+20
View File
@@ -102,3 +102,23 @@ supplement_thread_base_entry_point(void (*entry_point)(void *params), void *para
entry_point(params);
tctx_release();
}
internal B32
update(void)
{
ProfTick(0);
#if defined(TEXT_CACHE_H)
txt_user_clock_tick();
#endif
#if defined(DASM_CACHE_H)
dasm_user_clock_tick();
#endif
#if defined(GEO_CACHE_H)
geo_user_clock_tick();
#endif
#if defined(TEXTURE_CACHE_H)
tex_user_clock_tick();
#endif
B32 result = frame();
return result;
}
+1
View File
@@ -6,5 +6,6 @@
internal void main_thread_base_entry_point(void (*entry_point)(CmdLine *cmdline), char **arguments, U64 arguments_count);
internal void supplement_thread_base_entry_point(void (*entry_point)(void *params), void *params);
internal B32 update(void);
#endif // BASE_ENTRY_POINT_H
+6 -7
View File
@@ -1075,7 +1075,6 @@ df_window_open(Vec2F32 size, OS_Handle preferred_monitor, D_CfgSrc cfg_src)
scratch_end(scratch);
}
}
os_window_equip_repaint(window->os, df_state->repaint_hook, window);
DLLPushBack(df_state->first_window, df_state->last_window, window);
return window;
}
@@ -7834,7 +7833,7 @@ df_msg_(DF_MsgKind kind, D_Regs *regs)
#endif
internal void
df_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, D_StateDeltaHistory *hist)
df_init(D_StateDeltaHistory *hist)
{
ProfBeginFunction();
Arena *arena = arena_alloc();
@@ -7853,7 +7852,6 @@ df_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, D_StateDeltaHi
df_state->entity_ctx_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_entity_ctx_menu_"));
df_state->tab_ctx_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_tab_ctx_menu_"));
df_state->string_search_arena = arena_alloc();
df_state->repaint_hook = window_repaint_entry_point;
df_state->cfg_main_font_path_arena = arena_alloc();
df_state->cfg_code_font_path_arena = arena_alloc();
df_state->rich_hover_info_next_arena = arena_alloc();
@@ -7959,10 +7957,11 @@ df_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, D_StateDeltaHi
}
internal void
df_frame(OS_Handle repaint_window_handle)
df_frame(void)
{
Temp scratch = scratch_begin(0, 0);
DI_Scope *di_scope = di_scope_open();
local_persist S32 depth = 0;
//////////////////////////////
//- rjf: mark user-facing thread tick
@@ -7977,7 +7976,7 @@ df_frame(OS_Handle repaint_window_handle)
//- rjf: get events from the OS
//
OS_EventList events = {0};
if(os_handle_match(repaint_window_handle, os_handle_zero()))
if(depth == 0) DeferLoop(depth += 1, depth -= 1)
{
events = os_get_events(scratch.arena, df_state->num_frames_requested == 0);
}
@@ -12319,7 +12318,7 @@ df_frame(OS_Handle repaint_window_handle)
//////////////////////////////
//- rjf: show windows after first frame
//
if(os_handle_match(repaint_window_handle, os_handle_zero()))
if(depth == 0)
{
D_HandleList windows_to_show = {0};
for(DF_Window *w = df_state->first_window; w != 0; w = w->next)
@@ -12332,7 +12331,7 @@ df_frame(OS_Handle repaint_window_handle)
for(D_HandleNode *n = windows_to_show.first; n != 0; n = n->next)
{
DF_Window *window = df_window_from_handle(n->handle);
os_window_first_paint(window->os);
DeferLoop(depth += 1, depth -= 1) os_window_first_paint(window->os);
}
}
+2 -3
View File
@@ -660,7 +660,6 @@ struct DF_State
D_CmdParamSlotViewSpecRuleList cmd_param_slot_view_spec_table[D_CmdParamSlot_COUNT];
// rjf: windows
OS_WindowRepaintFunctionType *repaint_hook;
DF_Window *first_window;
DF_Window *last_window;
DF_Window *free_window;
@@ -967,7 +966,7 @@ __VA_ARGS__\
////////////////////////////////
//~ rjf: Main Layer Top-Level Calls
internal void df_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, D_StateDeltaHistory *hist);
internal void df_frame(OS_Handle repaint_window_handle);
internal void df_init(D_StateDeltaHistory *hist);
internal void df_frame(void);
#endif // DBG_FRONTEND_CORE_H
-6
View File
@@ -142,12 +142,6 @@ os_window_first_paint(OS_Handle handle)
XMapWindow(os_lnx_gfx_state->display, w->window);
}
internal void
os_window_equip_repaint(OS_Handle handle, OS_WindowRepaintFunctionType *repaint, void *user_data)
{
if(os_handle_match(handle, os_handle_zero())) {return;}
}
internal void
os_window_focus(OS_Handle handle)
{
+5 -3
View File
@@ -24,8 +24,6 @@ enum
OS_WindowFlag_CustomBorder = (1<<0),
};
typedef void OS_WindowRepaintFunctionType(OS_Handle window, void *user_data);
////////////////////////////////
//~ rjf: Cursor Types
@@ -103,6 +101,11 @@ struct OS_EventList
OS_Event *last;
};
////////////////////////////////
//~ rjf: Application-Defined Frame Hook Forward Declaration
internal B32 frame(void);
////////////////////////////////
//~ rjf: Event Functions (Helpers, Implemented Once)
@@ -139,7 +142,6 @@ internal String8 os_get_clipboard_text(Arena *arena);
internal OS_Handle os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title);
internal void os_window_close(OS_Handle window);
internal void os_window_first_paint(OS_Handle window);
internal void os_window_equip_repaint(OS_Handle window, OS_WindowRepaintFunctionType *repaint, void *user_data);
internal void os_window_focus(OS_Handle window);
internal B32 os_window_is_focused(OS_Handle window);
internal B32 os_window_is_fullscreen(OS_Handle window);
-5
View File
@@ -50,11 +50,6 @@ os_window_first_paint(OS_Handle window)
{
}
internal void
os_window_equip_repaint(OS_Handle window, OS_WindowRepaintFunctionType *repaint, void *user_data)
{
}
internal void
os_window_focus(OS_Handle window)
{
+5 -23
View File
@@ -356,18 +356,11 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_SIZE:
case WM_PAINT:
{
if(window->repaint != 0)
{
PAINTSTRUCT ps = {0};
BeginPaint(hwnd, &ps);
window->repaint(os_w32_handle_from_window(window), window->repaint_user_data);
EndPaint(hwnd, &ps);
}
else
{
result = DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
{
PAINTSTRUCT ps = {0};
BeginPaint(hwnd, &ps);
update();
EndPaint(hwnd, &ps);
}break;
case WM_CLOSE:
@@ -1089,14 +1082,6 @@ os_window_first_paint(OS_Handle window_handle)
}
}
internal void
os_window_equip_repaint(OS_Handle handle, OS_WindowRepaintFunctionType *repaint, void *user_data)
{
OS_W32_Window *window = os_w32_window_from_handle(handle);
window->repaint = repaint;
window->repaint_user_data = user_data;
}
internal void
os_window_focus(OS_Handle handle)
{
@@ -1125,8 +1110,6 @@ internal void
os_window_set_fullscreen(OS_Handle handle, B32 fullscreen)
{
OS_W32_Window *window = os_w32_window_from_handle(handle);
OS_WindowRepaintFunctionType *repaint = window->repaint;
window->repaint = 0;
DWORD window_style = GetWindowLong(window->hwnd, GWL_STYLE);
B32 is_fullscreen_already = os_window_is_fullscreen(handle);
if(fullscreen)
@@ -1155,7 +1138,6 @@ os_window_set_fullscreen(OS_Handle handle, B32 fullscreen)
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
}
window->repaint = repaint;
}
internal B32
-2
View File
@@ -39,8 +39,6 @@ struct OS_W32_Window
OS_W32_Window *prev;
HWND hwnd;
WINDOWPLACEMENT last_window_placement;
OS_WindowRepaintFunctionType *repaint;
void *repaint_user_data;
F32 dpi;
B32 first_paint_done;
B32 maximized;
+24 -23
View File
@@ -656,13 +656,22 @@ ipc_signaler_thread__entry_point(void *p)
}
}
////////////////////////////////
//~ rjf: Ctrl -> Main Thread Wakeup Hook
internal CTRL_WAKEUP_FUNCTION_DEF(wakeup_hook_ctrl)
{
os_send_wakeup_event();
}
////////////////////////////////
//~ rjf: Per-Frame Entry Point
internal void
update_and_render(OS_Handle repaint_window_handle, void *user_data)
internal B32
frame(void)
{
ProfBeginFunction();
B32 should_quit = 0;
Temp scratch = scratch_begin(0, 0);
//- rjf: begin logging
@@ -679,7 +688,7 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
log_scope_begin();
//- rjf: do frontend frame
df_frame(repaint_window_handle);
df_frame();
//- rjf: end logging
{
@@ -691,16 +700,15 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
}
}
//- rjf: quit if no windows are left
if(df_state->first_window == 0)
{
should_quit = 1;
}
scratch_end(scratch);
ProfEnd();
}
////////////////////////////////
//~ rjf: Ctrl -> Main Thread Wakeup Hook
internal CTRL_WAKEUP_FUNCTION_DEF(wakeup_hook_ctrl)
{
os_send_wakeup_event();
return should_quit;
}
////////////////////////////////
@@ -798,7 +806,7 @@ entry_point(CmdLine *cmd_line)
fnt_init();
D_StateDeltaHistory *hist = d_state_delta_history_alloc();
d_init(cmd_line, hist);
df_init(update_and_render, d_state_delta_history());
df_init(d_state_delta_history());
}
//- rjf: setup initial target from command line args
@@ -874,7 +882,7 @@ entry_point(CmdLine *cmd_line)
//- rjf: main application loop
{
for(;;)
for(B32 quit = 0; !quit;)
{
//- rjf: consume IPC messages, dispatch UI commands
{
@@ -939,9 +947,8 @@ entry_point(CmdLine *cmd_line)
scratch_end(scratch);
}
//- rjf: update & render frame
OS_Handle repaint_window = {0};
update_and_render(repaint_window, 0);
//- rjf: update
quit = update();
//- rjf: auto run
if(auto_run)
@@ -963,12 +970,6 @@ entry_point(CmdLine *cmd_line)
jit_attach = 0;
d_cmd(D_CmdKind_Attach, .id = jit_pid);
}
//- rjf: quit if no windows are left
if(df_state->first_window == 0)
{
break;
}
}
}
@@ -1037,7 +1038,7 @@ entry_point(CmdLine *cmd_line)
scratch_end(scratch);
}break;
//- rjf: built-in pdb/dwarf -> raddbg converter mode
//- rjf: built-in pdb/dwarf -> rdi converter mode
case ExecMode_Converter:
{
Temp scratch = scratch_begin(0, 0);