Skip to content

Commit

Permalink
Make max action age a client settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
xissburg committed Apr 23, 2022
1 parent 4ca4f4c commit 5259fc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/edyn/networking/settings/client_network_settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
};

}
Expand Down
8 changes: 5 additions & 3 deletions src/edyn/networking/sys/client_side.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,16 @@ static void client_update_clock_sync(entt::registry &registry, double time) {
}

static void trim_and_insert_actions(entt::registry &registry, double time) {
auto &ctx = registry.ctx<client_network_context>();
auto &settings = registry.ctx<edyn::settings>();
auto &client_settings = std::get<client_network_settings>(settings.network_settings);

// Erase old actions.
double action_history_max_length = 2;
registry.view<action_history>().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<client_network_context>();
ctx.snapshot_exporter->append_current_actions(registry, time);
}

Expand Down

0 comments on commit 5259fc1

Please sign in to comment.