Skip to content

Commit

Permalink
pipe through left-over OS events to subsequent frames; do not drop them
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfleury committed Jan 24, 2024
1 parent 04def87 commit fd0feef
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/df/gfx/df_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -10894,7 +10894,6 @@ df_gfx_init(OS_WindowRepaintFunctionType *window_repaint_entry_point, DF_StateDe
Arena *arena = arena_alloc();
df_gfx_state = push_array(arena, DF_GfxState, 1);
df_gfx_state->arena = arena;
df_gfx_state->frame_arena = arena_alloc();
df_gfx_state->num_frames_requested = 2;
df_gfx_state->hist = hist;
df_gfx_state->key_map_arena = arena_alloc();
Expand Down Expand Up @@ -10941,7 +10940,6 @@ internal void
df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds)
{
ProfBeginFunction();
arena_clear(df_gfx_state->frame_arena);
df_gfx_state->hover_line_set_this_frame = 0;

//- rjf: animate confirmation
Expand Down Expand Up @@ -11087,6 +11085,7 @@ df_gfx_begin_frame(Arena *arena, DF_CmdList *cmds)
arena_release(ws->hover_eval_arena);
arena_release(ws->arena);
SLLStackPush(df_gfx_state->free_window, ws);
ws->gen += 1;
}
}
}break;
Expand Down
1 change: 0 additions & 1 deletion src/df/gfx/df_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ struct DF_GfxState
{
// rjf: arenas
Arena *arena;
Arena *frame_arena;

// rjf: frame request state
U64 num_frames_requested;
Expand Down
32 changes: 32 additions & 0 deletions src/os/gfx/os_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,35 @@ os_text(OS_EventList *events, OS_Handle window, U32 character)
}
return result;
}

internal OS_EventList
os_event_list_copy(Arena *arena, OS_EventList *src)
{
OS_EventList dst = {0};
for(OS_Event *s = src->first; s != 0; s = s->next)
{
OS_Event *d = push_array(arena, OS_Event, 1);
MemoryCopyStruct(d, s);
d->strings = str8_list_copy(arena, &s->strings);
DLLPushBack(dst.first, dst.last, d);
dst.count += 1;
}
return dst;
}

internal void
os_event_list_concat_in_place(OS_EventList *dst, OS_EventList *to_push)
{
if(dst->last && to_push->first)
{
dst->last->next = to_push->first;
to_push->first->prev = dst->last;
dst->last = to_push->last;
dst->count += to_push->count;
}
else if(!dst->last && to_push->first)
{
MemoryCopyStruct(dst, to_push);
}
MemoryZeroStruct(to_push);
}
2 changes: 2 additions & 0 deletions src/os/gfx/os_gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ internal void os_eat_event(OS_EventList *events, OS_Event *event);
internal B32 os_key_press(OS_EventList *events, OS_Handle window, OS_EventFlags flags, OS_Key key);
internal B32 os_key_release(OS_EventList *events, OS_Handle window, OS_EventFlags flags, OS_Key key);
internal B32 os_text(OS_EventList *events, OS_Handle window, U32 character);
internal OS_EventList os_event_list_copy(Arena *arena, OS_EventList *src);
internal void os_event_list_concat_in_place(OS_EventList *dst, OS_EventList *to_push);

////////////////////////////////
//~ rjf: @os_hooks Main Initialization API (Implemented Per-OS)
Expand Down
1 change: 1 addition & 0 deletions src/os/gfx/win32/os_gfx_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ w32_push_event(OS_EventKind kind, W32_Window *window)
result->kind = kind;
result->window = os_window_from_w32_window(window);
result->flags = os_get_event_flags();
w32_event_list.count += 1;
return(result);
}

Expand Down
15 changes: 14 additions & 1 deletion src/raddbg/raddbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
OS_EventList events = {0};
if(os_handle_match(repaint_window_handle, os_handle_zero()))
{
events = os_get_events(scratch.arena, df_gfx_state->num_frames_requested == 0);
OS_EventList leftover_events_copy = os_event_list_copy(scratch.arena, &leftover_events);
OS_EventList new_events = os_get_events(scratch.arena, df_gfx_state->num_frames_requested == 0);
os_event_list_concat_in_place(&events, &leftover_events_copy);
os_event_list_concat_in_place(&events, &new_events);
}

//- rjf: enable txti change detection
Expand Down Expand Up @@ -296,6 +299,13 @@ update_and_render(OS_Handle repaint_window_handle, void *user_data)
}
}

//- rjf: gather leftover events for subsequent frame
if(events.count != 0)
{
arena_clear(leftover_events_arena);
leftover_events = os_event_list_copy(leftover_events_arena, &events);
}

//- rjf: determine frame time, record into history
U64 end_time_us = os_now_microseconds();
U64 frame_time_us = end_time_us-begin_time_us;
Expand Down Expand Up @@ -404,6 +414,9 @@ entry_point(int argc, char **argv)
IPCInfo *ipc_info = (IPCInfo *)ipc_shared_memory_base;
ipc_info->msg_size = 0;

//- rjf: set up leftover event arena
leftover_events_arena = arena_alloc();

//- rjf: initialize stuff we depend on
{
hs_init();
Expand Down
2 changes: 2 additions & 0 deletions src/raddbg/raddbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,8 @@ read_only global String8 ipc_shared_memory_name = str8_lit_comp("_raddbg_ipc_sha
read_only global String8 ipc_semaphore_name = str8_lit_comp("_raddbg_ipc_semaphore_");
global U64 frame_time_us_history[64] = {0};
global U64 frame_time_us_history_idx = 0;
global Arena *leftover_events_arena = 0;
global OS_EventList leftover_events = {0};

////////////////////////////////
//~ rjf: Frontend Entry Points
Expand Down

0 comments on commit fd0feef

Please sign in to comment.