From 1caf006e33e3ce2541bbf25e0e290b09864df8e8 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 13 Mar 2026 14:40:57 -0500 Subject: [PATCH] vis blending wip --- src/pp/pp_vis/pp_vis_core.c | 136 ++++++++++++++++++++++++------------ 1 file changed, 92 insertions(+), 44 deletions(-) diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 90489bf5..48579b95 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -888,7 +888,8 @@ void V_TickForever(WaveLaneCtx *lane) ////////////////////////////// //- Compute movement & look - f32 max_look_radius = 5; + // f32 max_look_radius = 5; + f32 max_look_radius = 50; f32 min_look_radius = 0.025; frame->is_looking = !frame->is_editing && !frame->palette.is_showing && !frame->held_buttons[Button_Alt]; @@ -1619,7 +1620,10 @@ void V_TickForever(WaveLaneCtx *lane) bottom_tick = MinI64(bottom_tick, first_predict_tick); bottom_tick = MinI64(bottom_tick, last_predict_tick); bottom_tick = MinI64(bottom_tick, ack); + + // FIXME: Enable this // P_ClearFrames(sim_world, I64Min, bottom_tick - 1); + P_ClearFrames(sim_world, I64Min, bottom_tick - 100); } // P_ClearFrames(sim_world, I64Min, ack - SIM_TICKS_PER_SECOND); // P_ClearFrames(sim_world, I64Min, sim_world->last_frame->tick - 1); @@ -1653,9 +1657,12 @@ void V_TickForever(WaveLaneCtx *lane) } predict_world->seed = sim_world->seed; + // FIXME: Enable this // P_ClearFrames(predict_world, I64Min, MinI64(first_predict_tick - 1, prev_frame->blend_from_tick - 1)); // P_ClearFrames(predict_world, I64Min, MinI64(first_predict_tick - 2, prev_frame->blend_from_tick - 1)); // P_ClearFrames(predict_world, I64Min, MinI64(first_predict_tick - V_MaxInterpRatio, prev_frame->blend_from_tick - 1)); + P_ClearFrames(predict_world, I64Min, MinI64(first_predict_tick - V_MaxInterpRatio, prev_frame->blend_from_tick - 100)); + predict_frame = P_PushFrame(predict_world, P_FrameFromTick(sim_world, first_predict_tick), first_predict_tick); for (i64 predict_tick = first_predict_tick + 1; predict_tick <= last_predict_tick; ++predict_tick) @@ -1688,6 +1695,8 @@ void V_TickForever(WaveLaneCtx *lane) } P_tl.debug_draw_enabled = old_debug_draw; P_tl.debug_tint = old_debug_tint; + + V_PushTimelineMarker(predict_frame->time_ns, Color_Purple, 0); } predict_frame = predict_world->last_frame; @@ -1696,10 +1705,6 @@ void V_TickForever(WaveLaneCtx *lane) // TODO: Extract information that occurred between first & last prediction, like bullet hits etc? V_PushTimelineMarker(predict_frame->time_ns, Color_Purple, 1); - if (predict_to != prev_frame_predict_to) - { - V_PushTimelineMarker(predict_frame->time_ns, Color_Purple, 0); - } } @@ -1883,9 +1888,10 @@ void V_TickForever(WaveLaneCtx *lane) P_ClearFrames(frame->local_world, I64Min, I64Max); // i64 target_blend_dt_ns = frame->dt_ns + frame->dt_ns * dilation_factor; - i64 target_blend_dt_ns = frame->dt_ns; + // i64 target_blend_dt_ns = frame->dt_ns; + i64 blend_dt_ns = frame->dt_ns; - // i64 blend_dt_ns = target_blend_dt_ns; + // i64 blend_dt_ns = frame->dt_ns + frame->dt_ns * dilation_factor; // V.target_blend_time_ns += target_blend_dt_ns; V.blend_time_ns += blend_dt_ns; @@ -1894,25 +1900,39 @@ void V_TickForever(WaveLaneCtx *lane) // = * // E.g: At 1.5, the world will render 75ms back in time if the sim runs at 50tps f32 interp_ratio = TweakFloat("Interpolation ratio", 1.2, 0, V_MaxInterpRatio); + // if (ack != prev_frame_ack) // { // i64 delay_ns = SIM_TICK_INTERVAL_NS * interp_ratio; // V.target_blend_time_ns = ack_frame->time_ns - delay_ns; // } + // if (predict_to != prev_frame_predict_to) + // { + // i64 delay_ns = SIM_TICK_INTERVAL_NS * interp_ratio; + // V.target_blend_time_ns = predict_frame->time_ns - delay_ns; + // } + + { + P_Frame *target_blend_frame = P_FrameFromTick(predict_world, predict_world->last_frame->base_predict_to); + + i64 delay_ns = SIM_TICK_INTERVAL_NS * interp_ratio; + V.target_blend_time_ns = target_blend_frame->time_ns - delay_ns; + } + + if (ack != prev_frame_ack) { - i64 delay_ns = SIM_TICK_INTERVAL_NS * interp_ratio; - V.target_blend_time_ns = predict_frame->time_ns - delay_ns; - - V_PushTimelineMarker(ack_frame->time_ns, Color_Cyan, 0); + V_PushTimelineMarker(ack_frame->time_ns, Color_Green, 0); } // f64 blend_to_target_lerp_rate = 0.01 * frame->dt; f64 blend_to_target_lerp_rate = 1 * frame->dt; + // f64 blend_to_target_lerp_rate = 1 * frame->dt; + // f64 blend_to_target_lerp_rate = 0.0 * frame->dt; // f64 blend_to_target_lerp_rate = 0.0; // f64 blend_to_target_lerp_rate = 0.05; @@ -1922,6 +1942,8 @@ void V_TickForever(WaveLaneCtx *lane) { LogDebugF("Blend reset"); V.blend_time_ns = V.target_blend_time_ns; + + V_PushTimelineMarker(V.blend_time_ns, Color_Red, 0); } if (TweakBool("Interpolation enabled", 1)) @@ -1941,6 +1963,9 @@ void V_TickForever(WaveLaneCtx *lane) + V_PushTimelineMarker(V.blend_time_ns, Color_Red, 1); + V_PushTimelineMarker(V.target_blend_time_ns, Color_Yellow, 1); + @@ -1957,27 +1982,32 @@ void V_TickForever(WaveLaneCtx *lane) P_World *tmp_right_world = predict_worlds[tmp_right_predict_world_idx]; P_World *tmp_left_world = predict_worlds[tmp_left_predict_world_idx]; - // P_Frame *tmp_right = tmp_right_world->last_frame; - // P_Frame *tmp_left = tmp_left_world->last_frame; - - // P_Frame *tmp_right = P_FrameFromTick(tmp_right_world, tmp_right_world->last_frame->base_predict_to); - // P_Frame *tmp_left = P_FrameFromTick(tmp_left_world, tmp_left_world->last_frame->base_predict_to); - - P_Frame *tmp_right = P_FrameFromTick(tmp_right_world, tmp_right_world->last_frame->base_predict_from); - P_Frame *tmp_left = P_FrameFromTick(tmp_left_world, tmp_left_world->last_frame->base_predict_from); - - - + // P_Frame *tmp_right = P_FrameFromTick(tmp_right_world, tmp_right_world->last_frame->base_predict_from); + // P_Frame *tmp_left = P_FrameFromTick(tmp_left_world, tmp_left_world->last_frame->base_predict_from); // i64 right_time_ns = tmp_right->base_time_ns; // i64 left_time_ns = tmp_left->base_time_ns; + + + P_Frame *tmp_right = P_FrameFromTick(tmp_right_world, tmp_right_world->last_frame->base_predict_to); + P_Frame *tmp_left = P_FrameFromTick(tmp_left_world, tmp_left_world->last_frame->base_predict_to); + + // P_Frame *tmp_right = tmp_right_world->last_frame; + // P_Frame *tmp_left = tmp_left_world->last_frame; + i64 right_time_ns = tmp_right->time_ns; i64 left_time_ns = tmp_left->time_ns; + + V_PushTimelineMarker(left_time_ns, Color_Cyan, 1); + V_PushTimelineMarker(right_time_ns, Color_Orange, 1); + + + if (right_time_ns >= V.blend_time_ns && left_time_ns <= V.blend_time_ns) { right_predict_frame = tmp_right; @@ -2034,6 +2064,8 @@ void V_TickForever(WaveLaneCtx *lane) right_predict_frame = predict_world->last_frame; // left_predict_frame = right_predict_frame->prev; left_predict_frame = right_predict_frame; + + DEBUGBREAKABLE; } frame->blend_from_tick = left_predict_frame->tick; @@ -2057,12 +2089,8 @@ void V_TickForever(WaveLaneCtx *lane) // P_Frame *right_sim_frame = P_FrameFromTick(sim_world, right_predict_frame->src_tick); // P_Frame *left_sim_frame = right_sim_frame->prev; - f64 blend_t = (f64)(V.blend_time_ns - left_predict_frame->base_time_ns) / (f64)(right_predict_frame->base_time_ns - left_predict_frame->base_time_ns); - - - V_PushTimelineMarker(V.blend_time_ns, Color_Yellow, 1); - V_PushTimelineMarker(V.target_blend_time_ns, Color_Red, 1); - + // f64 blend_t = (f64)(V.blend_time_ns - left_predict_frame->base_time_ns) / (f64)(right_predict_frame->base_time_ns - left_predict_frame->base_time_ns); + f64 blend_t = (f64)(V.blend_time_ns - left_predict_frame->time_ns) / (f64)(right_predict_frame->time_ns - left_predict_frame->time_ns); @@ -4609,36 +4637,30 @@ void V_TickForever(WaveLaneCtx *lane) { // FIXME: Remove this - f64 timeline_span_seconds = TweakFloat("Timeline span", 1, 0.01, 5); - i64 timeline_span_ns = NsFromSeconds(timeline_span_seconds); + PERSIST i64 last_timeline_matchup_ns = 0; PERSIST i64 last_timeline_reset_ns = 0; PERSIST i64 timeline_start_ns = 0; PERSIST i64 current_marker_time_ns = 0; + f64 timeline_span_seconds = TweakFloat("Timeline span", 1, 0.01, 5); + i64 timeline_span_ns = NsFromSeconds(timeline_span_seconds); + // Current frame time marker if (!V.timeline.paused) { - current_marker_time_ns = frame->time_ns - last_timeline_reset_ns + timeline_start_ns; + current_marker_time_ns = frame->time_ns - last_timeline_matchup_ns + timeline_start_ns; + } + if (V.timeline.locked) + { + V_PushTimelineMarker(current_marker_time_ns, Color_White, 1); } - V_PushTimelineMarker(current_marker_time_ns, Color_White, 1); + b32 was_locked = V.timeline.locked; b32 locked = frame->held_buttons[Button_R]; b32 paused = frame->held_buttons[Button_E]; V.timeline.locked = locked; V.timeline.paused = paused; - i64 reset_span_ns = timeline_span_ns; - if (locked) - { - reset_span_ns *= 0.5; - } - - if (!paused && frame->time_ns - last_timeline_reset_ns > reset_span_ns) - { - last_timeline_reset_ns = frame->time_ns; - timeline_start_ns = ack_frame->time_ns; - ResetArena(V.timeline.persistent_markers_arena); - } if (V.timeline.show) { UI_Key timeline_key = UI_KeyF("Timeline box"); @@ -4746,6 +4768,32 @@ void V_TickForever(WaveLaneCtx *lane) UI_PopCP(UI_TopCP()); } + + i64 reset_span_ns = timeline_span_ns; + if (locked) + { + reset_span_ns = timeline_span_ns * 0.5; + } + + // reset_span_ns = NsFromSeconds(10); + + b32 should_reset = 0; + if (!paused) + { + b32 is_first_ack = prev_frame_ack == 0 && ack != 0; + should_reset = (frame->time_ns - last_timeline_reset_ns > reset_span_ns) || is_first_ack || (locked != was_locked); + } + if (!locked && should_reset) + { + last_timeline_matchup_ns = frame->time_ns; + timeline_start_ns = ack_frame->time_ns; + } + + if (should_reset) + { + last_timeline_reset_ns = frame->time_ns; + ResetArena(V.timeline.persistent_markers_arena); + } if (!paused) { ResetArena(V.timeline.transient_markers_arena);