Simplified predicted data logic.

This commit is contained in:
Caball009
2026-07-07 19:08:59 +02:00
parent f1ec94f50b
commit b1e467d511
3 changed files with 60 additions and 158 deletions
+9 -42
View File
@@ -47,7 +47,7 @@ namespace // demo class
void shutdown_watcher();
void process_network_data(auto old_connstate, auto new_connstate, std::span<const std::uint8_t> network_data);
void process_predicted_data();
void process_predicted_data(auto old_connstate, auto new_connstate);
private:
[[nodiscard]] bool is_auto_recording() const;
@@ -419,38 +419,18 @@ namespace // demo class
}
}
void demo_recording_t::process_predicted_data()
void demo_recording_t::process_predicted_data(auto old_connstate, auto new_connstate)
{
if (old_connstate < game::CA_ACTIVE || new_connstate < game::CA_ACTIVE)
{
return;
}
process_helo_pilot_turret_fire();
if (is_recording())
{
// only one predicted data packet is needed per (1000 / sv_fps) msec
// the best way to limit the amount of predicted data is to attempt to predict the next playerState_t::commandTime
// because during demo playback the playerState_t::commandTime determines which predicted data is used
const auto& cl = *game::mp::cl;
const auto cmd_number = static_cast<std::size_t>(cl.cmdNumber);
const auto pred_svr_time_delta = cl.cmds[cmd_number % std::size(cl.cmds)].serverTime
- cl.cmds[(cmd_number - 1) % std::size(cl.cmds)].serverTime;
const auto pred_svr_time = cl.cgamePredictedDataServerTime;
const auto svr_time_delta = std::clamp(cl.snap.serverTime - cl.oldSnapServerTime, 50, 100);
const auto cur_cmd_time = cl.snap.ps.commandTime;
const auto next_cmd_time = cur_cmd_time + svr_time_delta;
const auto threshold = (3 * pred_svr_time_delta) / 2;
if (pred_svr_time + threshold >= next_cmd_time && next_cmd_time + threshold >= pred_svr_time)
{
times_.predicted_data_time = cl.serverTime;
write_predicted_data(user_file_);
}
else if (cl.serverTime >= times_.predicted_data_time + svr_time_delta - 5)
{
times_.predicted_data_time = cl.serverTime;
write_predicted_data(user_file_);
}
write_predicted_data(user_file_);
}
if (is_auto_recording())
@@ -494,21 +474,11 @@ namespace // hooks
return;
}
demo.process_predicted_data(old_connstate, new_connstate);
demo.process_network_data(old_connstate, new_connstate,
std::span<const std::uint8_t>(reinterpret_cast<const std::uint8_t*>(msg.data), msg.cursize));
}
void capture_predicted_data(game::msg_t& msg, std::int32_t value, std::uint32_t bits)
{
if (!demo_playback::playing())
{
demo.process_predicted_data();
}
// call MSG_WriteBits that this hook replaces
game::MSG_WriteBits(&msg, value, bits);
}
void request_non_delta_data(game::msg_t& msg, std::int32_t value, std::uint32_t bits)
{
if (!demo_playback::playing() && demo.non_delta_data_requested())
@@ -715,9 +685,6 @@ namespace demo_recording
// capture incoming packets
CL_ParseServerMessage_hook.create(game::CL_ParseServerMessage, capture_data);
// capture client predicted data (in CL_WritePacket)
utils::hook::call(0x1402C21B9, capture_predicted_data);
// request the server for no delta data (in CL_WritePacket)
utils::hook::call(0x1402C2026, request_non_delta_data);