From 891efffc270392461edaa767ce7b32f63651d5de Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 13 Jan 2026 16:29:21 -0600 Subject: [PATCH] begin prediction work --- src/pp/pp.c | 1 + src/pp/pp.h | 2 +- src/pp/pp_vis/pp_vis_core.c | 56 +++++++++++++++++++------------------ 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/pp/pp.c b/src/pp/pp.c index 12a0041d..6f848a31 100644 --- a/src/pp/pp.c +++ b/src/pp/pp.c @@ -1488,6 +1488,7 @@ void P_StepFrame(P_Frame *frame, P_CmdList cmds) // TODO: Not like this + frame->constraints_count = MinI64(prev_frame->constraints_count, frame->max_constraints); CopyStructs(frame->constraints, prev_frame->constraints, frame->constraints_count); diff --git a/src/pp/pp.h b/src/pp/pp.h index 2d801da7..701e42eb 100644 --- a/src/pp/pp.h +++ b/src/pp/pp.h @@ -546,4 +546,4 @@ P_Frame *P_PushFrame(P_World *world, P_Frame *src_frame, i64 tick); //////////////////////////////////////////////////////////// //~ Step -void P_StepFrame(P_Frame *frame, P_CmdList cmds); +void P_StepFrame(P_Frame *frame, P_CmdList queued_cmds); diff --git a/src/pp/pp_vis/pp_vis_core.c b/src/pp/pp_vis/pp_vis_core.c index 4cde3a08..1eafdc2b 100644 --- a/src/pp/pp_vis/pp_vis_core.c +++ b/src/pp/pp_vis/pp_vis_core.c @@ -2633,8 +2633,8 @@ void V_TickForever(WaveLaneCtx *lane) //- Submit sim commands // FIXME: Real ping - // f64 ping = 0.250; - f64 ping = 0; + f64 ping = 0.250; + // f64 ping = 0; i64 ping_ns = NsFromSeconds(ping); frame->predict_to = sim_world->last_frame->tick + MaxF64(CeilF64(ping * SIM_TICKS_PER_SECOND), 1.0); @@ -2675,7 +2675,7 @@ void V_TickForever(WaveLaneCtx *lane) // TODO: Only predict when new sim snapshot is received // Predict - P_Frame *predict_frame = 0; + P_Frame *predict_frame = &P_NilFrame; { if (predict_world->tiles_hash != sim_world->tiles_hash) { @@ -2683,34 +2683,36 @@ void V_TickForever(WaveLaneCtx *lane) CopyStructs(predict_world->tiles, sim_world->tiles, P_TilesCount); } - // i64 step_count = predict_to - sim_world->last_frame->tick; - - // // TODO: Preserve constraints? - // P_ClearFrames(predict_world, I64Min, I64Max); - // P_Frame *base_predict_frame = P_PushFrame(predict_world, sim_world->last_frame, sim_world->last_frame->tick); - // P_Frame *prev_predict_frame = base_predict_frame; - // for (i64 step_idx = 0; step_idx < step_count; ++step_idx) - // { - // // P_CmdList step_cmds = V_StepCmdsFromTick(prev_predict_frame->tick + 1); - - // P_CmdList step_cmds = Zi; - // for (P_CmdNode *src = V.sim_cmds.first; src; src = src->next) - // { - // P_CmdNode *n = PushStructNoZero(frame->arena, P_CmdNode); - // *n = *src; - // DllQueuePush(step_cmds.first, step_cmds.last, n); - // ++step_cmds.count; - // } + // predict_frame = P_PushFrame(predict_world, sim_world->last_frame, sim_world->last_frame->tick); - // P_Frame *stepped = P_StepWorld(predict_world, prev_predict_frame, step_cmds); - // prev_predict_frame = stepped; - // } + // We want to keep previously predicted ticks to preserve constraints + P_ClearFrames(predict_world, I64Min, sim_world->last_frame->tick - 2); - P_ClearFrames(predict_world, I64Min, I64Max); - predict_frame = P_PushFrame(predict_world, sim_world->last_frame, sim_world->last_frame->tick); + i64 step_count = frame->predict_to - sim_world->last_frame->tick; + P_Frame *base_predict_frame = P_PushFrame(predict_world, sim_world->last_frame, sim_world->last_frame->tick); + for (i64 step_idx = 0; step_idx < step_count; ++step_idx) + { + P_Frame *step_frame = P_PushFrame(predict_world, predict_world->last_frame, predict_world->last_frame->tick + 1); + + // FIXME: Cmds + P_CmdList step_cmds = Zi; + for (P_CmdNode *src_cmd_node = V.sim_cmds.first; src_cmd_node; src_cmd_node = src_cmd_node->next) + { + if (src_cmd_node->cmd.predicted && src_cmd_node->cmd.tick == step_frame->tick) + { + P_CmdNode *dst_cmd_node = PushStruct(frame->arena, P_CmdNode); + DllQueuePush(step_cmds.first, step_cmds.last, dst_cmd_node); + ++step_cmds.count; + } + } + + P_StepFrame(step_frame, step_cmds); + } + + predict_frame = predict_world->last_frame; } @@ -2725,7 +2727,7 @@ void V_TickForever(WaveLaneCtx *lane) b32 should_clear_particles = 0; // TODO: Remove this - P_Frame *blend_frame = 0; + P_Frame *blend_frame = &P_NilFrame; { if (blend_world->tiles_hash != predict_world->tiles_hash) {