From 54b1759afe1ca6e8fb75f7dd9efe158141b403ed Mon Sep 17 00:00:00 2001 From: jacob Date: Mon, 12 Jan 2026 09:21:22 -0600 Subject: [PATCH] rename 'last frame' -> 'prev frame' --- src/platform/platform.h | 2 +- src/platform/platform_win32/platform_win32.c | 14 +-- src/pp/pp.c | 7 +- src/pp/pp.h | 1 + src/pp/pp_vis/pp_vis_core.c | 90 ++++++++++---------- src/pp/pp_vis/pp_vis_core.h | 2 +- src/ui/ui_core.c | 18 ++-- src/ui/ui_core.h | 2 +- 8 files changed, 71 insertions(+), 65 deletions(-) diff --git a/src/platform/platform.h b/src/platform/platform.h index 101780ff..1fa5ca27 100644 --- a/src/platform/platform.h +++ b/src/platform/platform.h @@ -136,4 +136,4 @@ i64 PLT_GetCurrentTimerPeriodNs(void); //~ @hookdecl Sleep void PLT_SleepPrecise(i64 sleep_time_ns); -void PLT_SleepFrame(i64 last_frame_time_ns, i64 target_dt_ns); +void PLT_SleepFrame(i64 prev_frame_time_ns, i64 target_dt_ns); diff --git a/src/platform/platform_win32/platform_win32.c b/src/platform/platform_win32/platform_win32.c index 9c51ee00..1498b739 100644 --- a/src/platform/platform_win32/platform_win32.c +++ b/src/platform/platform_win32/platform_win32.c @@ -169,7 +169,7 @@ void PLT_W32_SyncTimerForever(WaveLaneCtx *lane) periods[i] = PLT_W32_DefaultTimerPeriodNs; } - i64 last_cycle_ns = 0; + i64 prev_cycle_ns = 0; // FIXME: shutdown for (;;) { @@ -185,8 +185,8 @@ void PLT_W32_SyncTimerForever(WaveLaneCtx *lane) WaitForSingleObject(timer, INFINITE); } i64 now_ns = TimeNs(); - i64 period_ns = last_cycle_ns == 0 ? PLT_W32_DefaultTimerPeriodNs : now_ns - last_cycle_ns; - last_cycle_ns = now_ns; + i64 period_ns = prev_cycle_ns == 0 ? PLT_W32_DefaultTimerPeriodNs : now_ns - prev_cycle_ns; + prev_cycle_ns = now_ns; // Compute mean period { @@ -935,13 +935,13 @@ void PLT_SleepPrecise(i64 sleep_time_ns) } } -void PLT_SleepFrame(i64 last_frame_time_ns, i64 target_dt_ns) +void PLT_SleepFrame(i64 prev_frame_time_ns, i64 target_dt_ns) { - if (last_frame_time_ns != 0 && target_dt_ns > 0) + if (prev_frame_time_ns != 0 && target_dt_ns > 0) { i64 now_ns = TimeNs(); - i64 last_frame_dt_ns = now_ns - last_frame_time_ns; - i64 sleep_time_ns = target_dt_ns - last_frame_dt_ns; + i64 prev_frame_dt_ns = now_ns - prev_frame_time_ns; + i64 sleep_time_ns = target_dt_ns - prev_frame_dt_ns; if (sleep_time_ns > 0) { PLT_SleepPrecise(sleep_time_ns); diff --git a/src/pp/pp.c b/src/pp/pp.c index 4f6025be..646f3d5b 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -1106,7 +1106,7 @@ Vec2 P_EdgePointFromShape(P_Shape shape, Vec2 dir) //////////////////////////////////////////////////////////// //~ Lookup helpers -P_Ent *P_EntFromKey(P_World *world, P_Key key) +P_Ent *P_EntFromKeyEx(P_World *world, P_Key key, i64 tick) { P_Ent *result = &P_NilEnt; if (!P_IsKeyNil(key) && world->ent_bins_count > 0) @@ -1124,6 +1124,11 @@ P_Ent *P_EntFromKey(P_World *world, P_Key key) return result; } +P_Ent *P_EntFromKey(P_World *world, P_Key key) +{ + return P_EntFromKeyEx(world, key, 0); +} + //////////////////////////////////////////////////////////// //~ Iteration helpers diff --git a/src/pp/pp.h b/src/pp/pp.h index 26e2d2ab..db48a4ec 100644 --- a/src/pp/pp.h +++ b/src/pp/pp.h @@ -431,6 +431,7 @@ Vec2 P_EdgePointFromShape(P_Shape shape, Vec2 dir); //////////////////////////////////////////////////////////// //~ Lookup helpers +P_Ent *P_EntFromKeyEx(P_World *world, P_Key key, i64 tick); P_Ent *P_EntFromKey(P_World *world, P_Key key); //////////////////////////////////////////////////////////// diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index a9dcd26c..ea398104 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -23,7 +23,7 @@ V_Frame *V_CurrentFrame(void) return &V.frames[V.current_frame_tick % countof(V.frames)]; } -V_Frame *V_LastFrame(void) +V_Frame *V_PrevFrame(void) { return &V.frames[(V.current_frame_tick - 1) % countof(V.frames)]; } @@ -496,7 +496,7 @@ void V_TickForever(WaveLaneCtx *lane) //- Begin frame V.current_frame_tick += 1; - V_Frame *last_frame = V_LastFrame(); + V_Frame *prev_frame = V_PrevFrame(); V_Frame *frame = V_CurrentFrame(); { @@ -517,22 +517,22 @@ void V_TickForever(WaveLaneCtx *lane) G_ResetArena(frame->cl, frame->gpu_arena); // Persist state - CopyBytes(frame->held_buttons, last_frame->held_buttons, sizeof(frame->held_buttons)); - frame->palette = last_frame->palette; - frame->is_editing = last_frame->is_editing; - frame->ui_debug = last_frame->ui_debug; - frame->show_console = last_frame->show_console; - frame->look = last_frame->look; - frame->edit_mode = last_frame->edit_mode; - frame->equipped_tile = last_frame->equipped_tile; - frame->edit_camera_pos = last_frame->edit_camera_pos; - frame->edit_camera_zoom = last_frame->edit_camera_zoom; + CopyBytes(frame->held_buttons, prev_frame->held_buttons, sizeof(frame->held_buttons)); + 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->edit_mode = prev_frame->edit_mode; + frame->equipped_tile = prev_frame->equipped_tile; + frame->edit_camera_pos = prev_frame->edit_camera_pos; + frame->edit_camera_zoom = prev_frame->edit_camera_zoom; frame->tick = V.current_frame_tick; frame->time_ns = TimeNs(); - frame->dt_ns = ClampI64(frame->time_ns - last_frame->time_ns, 1, NsFromSeconds(1.0 / 50)); + frame->dt_ns = ClampI64(frame->time_ns - prev_frame->time_ns, 1, NsFromSeconds(1.0 / 50)); frame->dt = SecondsFromNs(frame->dt_ns); - frame->rand = last_frame->rand; + frame->rand = prev_frame->rand; if (P_IsKeyNil(V.player_key)) { @@ -569,11 +569,11 @@ void V_TickForever(WaveLaneCtx *lane) if (swapout) { BB_WriteUBits(&bw, V.player_key.v, 64); - BB_WriteBit(&bw, last_frame->is_editing); - BB_WriteF32(&bw, last_frame->edit_camera_pos.x); - BB_WriteF32(&bw, last_frame->edit_camera_pos.y); - BB_WriteF32(&bw, last_frame->edit_camera_zoom); - BB_WriteString(&bw, last_frame->window_restore); + BB_WriteBit(&bw, prev_frame->is_editing); + BB_WriteF32(&bw, prev_frame->edit_camera_pos.x); + BB_WriteF32(&bw, prev_frame->edit_camera_pos.y); + BB_WriteF32(&bw, prev_frame->edit_camera_zoom); + BB_WriteString(&bw, prev_frame->window_restore); } else { @@ -815,27 +815,27 @@ void V_TickForever(WaveLaneCtx *lane) { b32 pan_button = Button_M3; frame->is_panning = frame->held_buttons[pan_button] != 0; - frame->edit_camera_zoom *= PowF32(zoom_rate, -last_frame->zooms); + frame->edit_camera_zoom *= PowF32(zoom_rate, -prev_frame->zooms); frame->edit_camera_zoom = ClampF32(frame->edit_camera_zoom, min_zoom, max_zoom); // Offset edit camera based on cursor if panning / zooming - b32 should_zoom = last_frame->zooms != 0 && (frame->edit_camera_zoom != last_frame->edit_camera_zoom); - if (last_frame->is_editing && (should_zoom || (frame->is_panning && last_frame->is_panning))) + b32 should_zoom = prev_frame->zooms != 0 && (frame->edit_camera_zoom != prev_frame->edit_camera_zoom); + if (prev_frame->is_editing && (should_zoom || (frame->is_panning && prev_frame->is_panning))) { - Xform last_frame_edit_to_ui_xf = Zi; + Xform prev_frame_edit_to_ui_xf = Zi; Xform edit_to_ui_xf = Zi; { - f32 last_edit_camera_scale = (f32)last_frame->draw_dims.x / (meters_per_draw_width * last_frame->edit_camera_zoom); + f32 prev_edit_camera_scale = (f32)prev_frame->draw_dims.x / (meters_per_draw_width * prev_frame->edit_camera_zoom); f32 edit_camera_scale = (f32)frame->draw_dims.x / (meters_per_draw_width * frame->edit_camera_zoom); - last_frame_edit_to_ui_xf = XformFromScale(VEC2(last_edit_camera_scale, last_edit_camera_scale)); - last_frame_edit_to_ui_xf = TranslateXform(last_frame_edit_to_ui_xf, NegVec2(last_frame->edit_camera_pos)); - last_frame_edit_to_ui_xf = WorldTranslateXform(last_frame_edit_to_ui_xf, MulVec2(Vec2FromVec(frame->draw_dims), 0.5)); + prev_frame_edit_to_ui_xf = XformFromScale(VEC2(prev_edit_camera_scale, prev_edit_camera_scale)); + prev_frame_edit_to_ui_xf = TranslateXform(prev_frame_edit_to_ui_xf, NegVec2(prev_frame->edit_camera_pos)); + prev_frame_edit_to_ui_xf = WorldTranslateXform(prev_frame_edit_to_ui_xf, MulVec2(Vec2FromVec(frame->draw_dims), 0.5)); edit_to_ui_xf = XformFromScale(VEC2(edit_camera_scale, edit_camera_scale)); edit_to_ui_xf = TranslateXform(edit_to_ui_xf, NegVec2(frame->edit_camera_pos)); edit_to_ui_xf = WorldTranslateXform(edit_to_ui_xf, MulVec2(Vec2FromVec(frame->draw_dims), 0.5)); } - Vec2 last_target_cursor = MulXformV2(InvertXform(last_frame_edit_to_ui_xf), last_frame->ui_cursor); + Vec2 prev_target_cursor = MulXformV2(InvertXform(prev_frame_edit_to_ui_xf), prev_frame->ui_cursor); Vec2 target_cursor = MulXformV2(InvertXform(edit_to_ui_xf), ui_frame->cursor_pos); - Vec2 diff = SubVec2(last_target_cursor, target_cursor); + Vec2 diff = SubVec2(prev_target_cursor, target_cursor); frame->edit_camera_pos = AddVec2(frame->edit_camera_pos, diff); } frame->edit_camera_pos.x = ClampF32(frame->edit_camera_pos.x, -world_pitch / 2, world_pitch / 2); @@ -859,19 +859,19 @@ void V_TickForever(WaveLaneCtx *lane) // Create world <-> ui xforms { - if (last_frame->tick == 0) + if (prev_frame->tick == 0) { frame->camera_lerp_rate = 1; } else if (frame->is_editing) { - b32 is_zooming = AbsF32(target_camera_zoom - last_frame->camera_zoom) > 0.001; + b32 is_zooming = AbsF32(target_camera_zoom - prev_frame->camera_zoom) > 0.001; if (frame->is_panning && !is_zooming) { // When panning & not zooming, we want camera interpolation to be // instant (no smoothing). However, the transition to non // interpolation must be smooth. - frame->camera_lerp_rate += last_frame->camera_lerp_rate + (5 * frame->dt); + frame->camera_lerp_rate += prev_frame->camera_lerp_rate + (5 * frame->dt); } else { @@ -883,8 +883,8 @@ void V_TickForever(WaveLaneCtx *lane) frame->camera_lerp_rate = 15.0 * frame->dt; } frame->camera_lerp_rate = ClampF32(frame->camera_lerp_rate, 0, 1); - frame->camera_pos = LerpVec2(last_frame->camera_pos, target_camera_pos, frame->camera_lerp_rate); - frame->camera_zoom = LerpF32(last_frame->camera_zoom, target_camera_zoom, frame->camera_lerp_rate); + frame->camera_pos = LerpVec2(prev_frame->camera_pos, target_camera_pos, frame->camera_lerp_rate); + frame->camera_zoom = LerpF32(prev_frame->camera_zoom, target_camera_zoom, frame->camera_lerp_rate); { f32 camera_scale = (f32)frame->draw_dims.x / (meters_per_draw_width * frame->camera_zoom); frame->xf.world_to_ui = XformFromScale(VEC2(camera_scale, camera_scale)); @@ -960,9 +960,9 @@ void V_TickForever(WaveLaneCtx *lane) // frame->equipped_tile = P_TileKind_Empty; } - if (frame->is_selecting && last_frame->is_selecting) + if (frame->is_selecting && prev_frame->is_selecting) { - frame->world_selection_start = last_frame->world_selection_start; + frame->world_selection_start = prev_frame->world_selection_start; } } @@ -982,18 +982,18 @@ void V_TickForever(WaveLaneCtx *lane) // TODO: Push vis cmd - if (frame->is_editing && last_frame->is_selecting && !frame->is_selecting) + if (frame->is_editing && prev_frame->is_selecting && !frame->is_selecting) { - if (last_frame->selection_mode == V_SelectionMode_Tile) + if (prev_frame->selection_mode == V_SelectionMode_Tile) { // TODO: Fix clamp when both start & end are outside of world Rng2I32 tile_range = Zi; - tile_range.p0 = Vec2I32FromVec(FloorVec2(MulXformV2(frame->xf.world_to_tile, last_frame->world_selection.p0))); - tile_range.p1 = Vec2I32FromVec(CeilVec2(MulXformV2(frame->xf.world_to_tile, last_frame->world_selection.p1))); + tile_range.p0 = Vec2I32FromVec(FloorVec2(MulXformV2(frame->xf.world_to_tile, prev_frame->world_selection.p0))); + tile_range.p1 = Vec2I32FromVec(CeilVec2(MulXformV2(frame->xf.world_to_tile, prev_frame->world_selection.p1))); P_Cmd *cmd = V_PushSimCmd(P_CmdKind_Delta); cmd->delta.kind = P_DeltaKind_Tile; - cmd->delta.tile_kind = last_frame->equipped_tile; + cmd->delta.tile_kind = prev_frame->equipped_tile; cmd->delta.tile_range = tile_range; } } @@ -2037,7 +2037,7 @@ void V_TickForever(WaveLaneCtx *lane) tweak_float = LerpF64(range_min, range_max, virtual_cursor_ratio); tweak_float = ClampF64(tweak_float, range_min, range_max); - if (frame->ui_cursor.x != last_frame->ui_cursor.x) + if (frame->ui_cursor.x != prev_frame->ui_cursor.x) { new_tweak_str = StringFromFloat(frame->arena, tweak_float, tweak_var.precision); } @@ -2449,7 +2449,7 @@ void V_TickForever(WaveLaneCtx *lane) case V_CmdKind_toggle_editor: { - if (!last_frame->is_editing) + if (!prev_frame->is_editing) { frame->is_editing = 1; frame->edit_camera_pos = frame->camera_pos; @@ -2572,7 +2572,7 @@ void V_TickForever(WaveLaneCtx *lane) if (frame->held_buttons[Button_S]) move.y += 1; } f32 fire_held = frame->held_buttons[Button_M1]; - f32 fire_presses = fire_held && !last_frame->held_buttons[Button_M1]; + f32 fire_presses = fire_held && !prev_frame->held_buttons[Button_M1]; Vec2 look = Zi; { Vec2 center = P_WorldShapeFromEnt(player).centroid; @@ -2728,7 +2728,7 @@ void V_TickForever(WaveLaneCtx *lane) // if (frame->held_buttons[Button_G]) // { // end = frame->world_cursor; - // if (!last_frame->held_buttons[Button_G]) + // if (!prev_frame->held_buttons[Button_G]) // { // start = end; // } diff --git a/src/pp/pp_vis/pp_vis_core.h b/src/pp/pp_vis/pp_vis_core.h index f745678c..49bfe394 100644 --- a/src/pp/pp_vis/pp_vis_core.h +++ b/src/pp/pp_vis/pp_vis_core.h @@ -313,7 +313,7 @@ void V_Shutdown(void); //~ Misc helpers V_Frame *V_CurrentFrame(void); -V_Frame *V_LastFrame(void); +V_Frame *V_PrevFrame(void); V_Cmd *V_PushVisCmd(String name); P_Cmd *V_PushSimCmd(P_CmdKind kind); String V_StringFromHotkey(Arena *arena, V_Hotkey hotkey); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index cb89aeaf..e8c10872 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -584,7 +584,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) //- Begin frame UI.current_frame_tick += 1; - UI_Frame *last_frame = UI_LastFrame(); + UI_Frame *prev_frame = UI_PrevFrame(); UI_Frame *frame = UI_CurrentFrame(); { @@ -604,7 +604,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) { i64 now_ns = TimeNs(); - i64 dt_ns = now_ns - last_frame->time_ns; + i64 dt_ns = now_ns - prev_frame->time_ns; frame->time_ns = now_ns; frame->dt_ns = dt_ns; frame->dt = SecondsFromNs(frame->dt_ns); @@ -622,16 +622,16 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) ////////////////////////////// //- Process controller events - frame->cursor_pos = last_frame->cursor_pos; - frame->drag_cursor_pos = last_frame->drag_cursor_pos; + frame->cursor_pos = prev_frame->cursor_pos; + frame->drag_cursor_pos = prev_frame->drag_cursor_pos; - if (last_frame->boxes_pre != 0) + if (prev_frame->boxes_pre != 0) { ControllerEventsArray controller_events = frame->window_frame.controller_events; // Locate boxes UI_Box *top_hovered_box = 0; - UI_Box *active_box = UI_BoxFromKey(last_frame->active_box); + UI_Box *active_box = UI_BoxFromKey(prev_frame->active_box); // Update cursor pos for (u64 cev_index = 0; cev_index < controller_events.count; ++cev_index) @@ -646,7 +646,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) // Init box reports for (u64 pre_index = UI.boxes_count; pre_index-- > 0;) { - UI_Box *box = last_frame->boxes_pre[pre_index]; + UI_Box *box = prev_frame->boxes_pre[pre_index]; UI_BoxReport *report = &box->reports.draw; b32 is_cursor_in_box = 0; { @@ -794,7 +794,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags) f32 upper_target = TweakFloat("UI upper blend target", 1.05, 1, 10); for (u64 pre_index = 0; pre_index < UI.boxes_count; ++pre_index) { - UI_Box *box = last_frame->boxes_pre[pre_index]; + UI_Box *box = prev_frame->boxes_pre[pre_index]; UI_BoxReport *report = &box->reports.draw; report->is_hot = box == hot_box; @@ -861,7 +861,7 @@ UI_Frame *UI_CurrentFrame(void) return &UI.frames[UI.current_frame_tick % countof(UI.frames)]; }; -UI_Frame *UI_LastFrame(void) +UI_Frame *UI_PrevFrame(void) { return &UI.frames[(UI.current_frame_tick - 1) % countof(UI.frames)]; }; diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index ef84b809..f0388c6b 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -527,7 +527,7 @@ UI_Frame *UI_BeginFrame(UI_FrameFlag frame_flags); //~ Frame helpers UI_Frame *UI_CurrentFrame(void); -UI_Frame *UI_LastFrame(void); +UI_Frame *UI_PrevFrame(void); Arena *UI_FrameArena(void); Vec2 UI_CursorPos(void);