begin prediction work

This commit is contained in:
jacob 2026-01-13 16:29:21 -06:00
parent 1ccaf37d3f
commit 891efffc27
3 changed files with 31 additions and 28 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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)
{