Skip to content

Commit

Permalink
fix(client_core): 🐛 Cap prediction to avoid head and controllers flyi…
Browse files Browse the repository at this point in the history
…ng off
  • Loading branch information
zmerp committed Jan 16, 2025
1 parent 64828ae commit 8354948
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ use storage::Config;
pub use alvr_system_info::Platform;
pub use logging_backend::init_logging;

pub const MAX_PREDICTION: Duration = Duration::from_millis(100);

pub enum ClientCoreEvent {
UpdateHudMessage(String),
StreamingStarted(Box<StreamConfig>),
Expand Down Expand Up @@ -234,12 +236,13 @@ impl ClientCoreContext {
) {
dbg_client_core!("send_tracking");

let target_timestamp =
if let Some(stats) = &*self.connection_context.statistics_manager.lock() {
poll_timestamp + stats.average_total_pipeline_latency()
} else {
poll_timestamp
};
let target_timestamp = if let Some(stats) =
&*self.connection_context.statistics_manager.lock()
{
poll_timestamp + Duration::max(stats.average_total_pipeline_latency(), MAX_PREDICTION)
} else {
poll_timestamp
};

for (id, motion) in &mut device_motions {
let velocity_multiplier = *self.connection_context.velocities_multiplier.read();
Expand All @@ -262,7 +265,8 @@ impl ClientCoreContext {
motion.linear_velocity = Vec3::ZERO;
motion.angular_velocity = Vec3::ZERO;
} else if let Some(stats) = &*self.connection_context.statistics_manager.lock() {
let tracker_timestamp = poll_timestamp + stats.tracker_prediction_offset();
let tracker_timestamp = poll_timestamp
+ Duration::max(stats.tracker_prediction_offset(), MAX_PREDICTION);

*motion = motion.predict(poll_timestamp, tracker_timestamp);
}
Expand Down

0 comments on commit 8354948

Please sign in to comment.