diff --git a/include/edyn/networking/settings/client_network_settings.hpp b/include/edyn/networking/settings/client_network_settings.hpp index 5c2a1126..484c5d5a 100644 --- a/include/edyn/networking/settings/client_network_settings.hpp +++ b/include/edyn/networking/settings/client_network_settings.hpp @@ -29,6 +29,13 @@ struct client_network_settings { * will be applied at the start of an extrapolation. */ double action_time_threshold {0.06}; + + // All actions older than this amount are deleted in every update. + // The entire action history is included in every registry snapshot, thus + // it is desirable to keep this low to minimize packet size. Though, a + // longer action history decreases the chances of actions being lost. It + // is sensible to increase it in case packet loss is high. + double action_history_max_age {1.0}; }; } diff --git a/src/edyn/networking/sys/client_side.cpp b/src/edyn/networking/sys/client_side.cpp index 7d2aac88..a3082e89 100644 --- a/src/edyn/networking/sys/client_side.cpp +++ b/src/edyn/networking/sys/client_side.cpp @@ -301,14 +301,16 @@ static void client_update_clock_sync(entt::registry ®istry, double time) { } static void trim_and_insert_actions(entt::registry ®istry, double time) { + auto &ctx = registry.ctx(); + auto &settings = registry.ctx(); + auto &client_settings = std::get(settings.network_settings); + // Erase old actions. - double action_history_max_length = 2; registry.view().each([&](action_history &history) { - history.erase_until(time - action_history_max_length); + history.erase_until(time - client_settings.action_history_max_age); }); // Insert current action lists into action history. - auto &ctx = registry.ctx(); ctx.snapshot_exporter->append_current_actions(registry, time); }