prediction testing

This commit is contained in:
jacob 2026-01-18 21:12:00 -06:00
parent 4fad7cf6de
commit 6a0fef0b1d
4 changed files with 80 additions and 41 deletions

View File

@ -1167,7 +1167,7 @@ void P_DebugDrawShape(P_Shape shape, Vec4 srgb)
} }
void P_DebugDrawFrame(P_Frame *frame, Vec4 tint) void P_DebugDrawFrame(P_Frame *frame)
{ {
if (P_tl.debug_draw_enabled) if (P_tl.debug_draw_enabled)
{ {
@ -1186,7 +1186,7 @@ void P_DebugDrawFrame(P_Frame *frame, Vec4 tint)
{ {
// Vec4 color = Color_Cyan; // Vec4 color = Color_Cyan;
// Vec4 color = VEC4(0.2, 0.4, 0.2, 1); // Vec4 color = VEC4(0.2, 0.4, 0.2, 1);
Vec4 color = MulVec4Vec4(VEC4(1, 1, 1, 1), tint); Vec4 color = MulVec4Vec4(VEC4(1, 1, 1, 1), P_tl.debug_tint);
P_DebugDrawShape(world_shape, color); P_DebugDrawShape(world_shape, color);
} }
@ -2110,6 +2110,11 @@ void P_StepFrame(P_Frame *frame)
} }
} }
//////////////////////////////
//- Debug draw
P_DebugDrawFrame(frame);
////////////////////////////// //////////////////////////////
//- End frame //- End frame

View File

@ -388,6 +388,7 @@ Struct(P_ThreadLocalCtx)
//- Per-thread debug info //- Per-thread debug info
Arena *debug_arena; Arena *debug_arena;
b32 debug_draw_enabled; b32 debug_draw_enabled;
Vec4 debug_tint;
P_DebugDrawNode *first_debug_draw_node; P_DebugDrawNode *first_debug_draw_node;
P_DebugDrawNode *last_debug_draw_node; P_DebugDrawNode *last_debug_draw_node;
i64 debug_draw_nodes_count; i64 debug_draw_nodes_count;
@ -484,7 +485,7 @@ void P_DebugDrawPoint(Vec2 p, Vec4 srgb);
void P_DebugDrawLine(Vec2 p0, Vec2 p1, Vec4 srgb); void P_DebugDrawLine(Vec2 p0, Vec2 p1, Vec4 srgb);
void P_DebugDrawRect(Rng2 rect, Vec4 srgb); void P_DebugDrawRect(Rng2 rect, Vec4 srgb);
void P_DebugDrawShape(P_Shape shape, Vec4 srgb); void P_DebugDrawShape(P_Shape shape, Vec4 srgb);
void P_DebugDrawFrame(P_Frame *frame, Vec4 tint); void P_DebugDrawFrame(P_Frame *frame);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
//~ Msg //~ Msg

View File

@ -57,6 +57,7 @@ void S_TickForever(WaveLaneCtx *lane)
Arena *perm = PermArena(); Arena *perm = PermArena();
Arena *frame_arena = AcquireArena(Gibi(64)); Arena *frame_arena = AcquireArena(Gibi(64));
P_tl.debug_arena = AcquireArena(Gibi(64)); P_tl.debug_arena = AcquireArena(Gibi(64));
P_tl.debug_tint = VEC4(0.2, 0.4, 0.2, 0.75);
P_tl.out_msgs_arena = AcquireArena(Gibi(64)); P_tl.out_msgs_arena = AcquireArena(Gibi(64));
P_World *world = P_AcquireWorld(); P_World *world = P_AcquireWorld();
@ -346,6 +347,7 @@ void S_TickForever(WaveLaneCtx *lane)
P_Control *control = &client->controls[control_tick % client->max_controls]; P_Control *control = &client->controls[control_tick % client->max_controls];
{ {
*control = *raw_control; *control = *raw_control;
control->move = ClampVec2Len(control->move, 1);
} }
//- Propagate control //- Propagate control
@ -748,7 +750,6 @@ void S_TickForever(WaveLaneCtx *lane)
{ {
P_StepFrame(world_frame); P_StepFrame(world_frame);
P_DebugDrawFrame(world_frame, VEC4(0.2, 0.4, 0.2, 0.75));
} }
////////////////////////////// //////////////////////////////

View File

@ -337,6 +337,7 @@ void V_TickForever(WaveLaneCtx *lane)
Arena *perm = PermArena(); Arena *perm = PermArena();
G_ArenaHandle gpu_perm = G_PermArena(); G_ArenaHandle gpu_perm = G_PermArena();
P_tl.debug_arena = AcquireArena(Gibi(64)); P_tl.debug_arena = AcquireArena(Gibi(64));
P_tl.debug_tint = VEC4(0, 0, 1, 0.75);
P_tl.out_msgs_arena = AcquireArena(Gibi(64)); P_tl.out_msgs_arena = AcquireArena(Gibi(64));
const i32 world_pitch = P_WorldPitch; const i32 world_pitch = P_WorldPitch;
@ -2978,6 +2979,7 @@ void V_TickForever(WaveLaneCtx *lane)
if (frame->held_buttons[Button_W]) move.y -= 1; if (frame->held_buttons[Button_W]) move.y -= 1;
if (frame->held_buttons[Button_S]) move.y += 1; if (frame->held_buttons[Button_S]) move.y += 1;
} }
move = ClampVec2Len(move, 1);
f32 fire_held = frame->held_buttons[Button_M1]; f32 fire_held = frame->held_buttons[Button_M1];
f32 fire_presses = fire_held && !prev_frame->held_buttons[Button_M1]; f32 fire_presses = fire_held && !prev_frame->held_buttons[Button_M1];
Vec2 look = Zi; Vec2 look = Zi;
@ -2992,6 +2994,13 @@ void V_TickForever(WaveLaneCtx *lane)
f32 edit_move_speed = 20.0 * MaxF32(frame->edit_camera_zoom, min_zoom); f32 edit_move_speed = 20.0 * MaxF32(frame->edit_camera_zoom, min_zoom);
frame->edit_camera_pos = AddVec2(frame->edit_camera_pos, MulVec2(move, edit_move_speed * frame->dt)); frame->edit_camera_pos = AddVec2(frame->edit_camera_pos, MulVec2(move, edit_move_speed * frame->dt));
} }
// FIXME: Remove this
frame->move = prev_frame->move;
frame->look = prev_frame->look;
frame->fire_held = prev_frame->fire_held;
frame->fire_presses = prev_frame->fire_presses;
} }
else else
{ {
@ -3168,46 +3177,38 @@ void V_TickForever(WaveLaneCtx *lane)
} }
} }
// if (frame->predict_to != prev_frame->predict_to)
// {
// {
// P_UserSnapshot snapshot = Zi;
// snapshot->user = V.;
// snapshot->src_tick = 0;
// // FIXME: Generate snapshots for all new frames, not just last
// snapshot->tick = frame->predict_to;
// snapshot->move = frame->move;
// snapshot->look = frame->look;
// snapshot->fire_held = frame->fire_held;
// snapshot->fire_presses = frame->fire_presses;
// }
// }
//////////////////////////////
//- Submit sim commands
// {
// LockTicketMutex(&P.sim_input_back_tm);
// {
// P_InputState *v2s = &P.sim_input_states[P.sim_input_back_idx];
// for (P_MsgNode *src_cmd_node = V.sim_cmds.first; src_cmd_node; src_cmd_node = src_cmd_node->next)
// {
// P_MsgNode *dst_cmd_node = PushStruct(v2s->arena, P_MsgNode);
// dst_cmd_node->cmd = src_cmd_node->cmd;
// dst_cmd_node->cmd.tick = frame->predict_to;
// DllQueuePush(v2s->cmds.first, v2s->cmds.last, dst_cmd_node);
// ++v2s->cmds.count;
// }
// }
// UnlockTicketMutex(&P.sim_input_back_tm);
// }
////////////////////////////// //////////////////////////////
//- Predict //- Predict
// TODO: Only predict when new sim snapshot is received // TODO: Only predict when new sim snapshot is received
// P_Frame *predict_frame = &P_NilFrame;
// {
// if (predict_world->tiles_hash != sim_world->tiles_hash)
// {
// predict_world->tiles_hash = sim_world->tiles_hash;
// CopyStructs(predict_world->tiles, sim_world->tiles, P_TilesCount);
// }
// predict_world->seed = sim_world->seed;
// P_ClearFrames(predict_world, I64Min, I64Max);
// predict_frame = P_PushFrame(predict_world, sim_world->last_frame, sim_world->last_frame->tick);
// P_DebugDrawFrame(predict_frame);
// predict_frame = predict_world->last_frame;
// }
// Predict // Predict
P_Frame *predict_frame = &P_NilFrame; P_Frame *predict_frame = &P_NilFrame;
{ {
@ -3218,9 +3219,39 @@ void V_TickForever(WaveLaneCtx *lane)
} }
predict_world->seed = sim_world->seed; predict_world->seed = sim_world->seed;
P_ClearFrames(predict_world, I64Min, I64Max);
predict_frame = P_PushFrame(predict_world, sim_world->last_frame, sim_world->last_frame->tick);
P_DebugDrawFrame(predict_frame, VEC4(0, 0, 1, 0.75)); // P_ClearFrames(predict_world, I64Min, I64Max);
// predict_frame = P_PushFrame(predict_world, sim_world->last_frame, sim_world->last_frame->tick);
// FIXME: Not like this
i64 max_predict_ticks = SIM_TICKS_PER_SECOND;
i64 last_predict_tick = frame->predict_to;
i64 first_predict_tick = sim_world->last_frame->tick;
first_predict_tick = MaxI64(first_predict_tick, last_predict_tick - max_predict_ticks);
P_ClearFrames(predict_world, I64Min, first_predict_tick - 1);
predict_frame = P_PushFrame(predict_world, sim_world->last_frame, first_predict_tick);
for (i64 predict_tick = first_predict_tick + 1; predict_tick <= last_predict_tick; ++predict_tick)
{
predict_frame = P_PushFrame(predict_world, predict_world->last_frame, predict_tick);
P_Ent *predict_player = P_EntFromKey(predict_frame, local_player->key);
if (!P_IsEntNil(predict_player))
{
P_Control *predict_control = &local_controls[predict_tick % max_local_controls];
if (predict_control->tick == predict_tick)
{
predict_player->control = *predict_control;
}
}
P_StepFrame(predict_frame);
}
@ -3249,6 +3280,7 @@ void V_TickForever(WaveLaneCtx *lane)
// } // }
predict_frame = predict_world->last_frame; predict_frame = predict_world->last_frame;
P_DebugDrawFrame(predict_frame);
// TODO: Extract information that occurred between first & last prediction, like bullet hits etc? // TODO: Extract information that occurred between first & last prediction, like bullet hits etc?
} }