Skip to content

Commit

Permalink
Add Max prediction setting
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Jan 17, 2025
1 parent 8354948 commit 22d3d65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 2 additions & 0 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct ConnectionContext {
pub view_params: RwLock<[ViewParams; 2]>,
pub uses_multimodal_protocol: RelaxedAtomic,
pub velocities_multiplier: RwLock<f32>,
pub max_prediction: RwLock<Duration>,
}

fn set_hud_message(event_queue: &Mutex<VecDeque<ClientCoreEvent>>, message: &str) {
Expand Down Expand Up @@ -205,6 +206,7 @@ fn connection_pipeline(
let negotiated_config = stream_config.negotiated_config;

*ctx.velocities_multiplier.write() = settings.extra.velocities_multiplier;
*ctx.max_prediction.write() = Duration::from_millis(settings.headset.max_prediction_ms);

*ctx.statistics_manager.lock() = Some(StatisticsManager::new(
settings.connection.statistics_history_size,
Expand Down
8 changes: 4 additions & 4 deletions alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ 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 @@ -236,10 +234,12 @@ impl ClientCoreContext {
) {
dbg_client_core!("send_tracking");

let max_prediction = *self.connection_context.max_prediction.read();

let target_timestamp = if let Some(stats) =
&*self.connection_context.statistics_manager.lock()
{
poll_timestamp + Duration::max(stats.average_total_pipeline_latency(), MAX_PREDICTION)
poll_timestamp + Duration::max(stats.average_total_pipeline_latency(), max_prediction)
} else {
poll_timestamp
};
Expand All @@ -266,7 +266,7 @@ impl ClientCoreContext {
motion.angular_velocity = Vec3::ZERO;
} else if let Some(stats) = &*self.connection_context.statistics_manager.lock() {
let tracker_timestamp = poll_timestamp
+ Duration::max(stats.tracker_prediction_offset(), MAX_PREDICTION);
+ Duration::max(stats.tracker_prediction_offset(), max_prediction);

*motion = motion.predict(poll_timestamp, tracker_timestamp);
}
Expand Down
8 changes: 8 additions & 0 deletions alvr/session/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,13 @@ Tilted: the world gets tilted when long pressing the oculus button. This is usef
#[schema(flag = "steamvr-restart")]
#[schema(strings(display_name = "VMC"))]
pub vmc: Switch<VMCConfig>,

#[schema(strings(
help = "Maximum prediction for head and controllers. Used to avoid too much jitter during loading."
))]
#[schema(flag = "real-time")]
#[schema(gui(slider(min = 0, max = 500, step = 10)), suffix = "ms")]
pub max_prediction_ms: u64,
}

#[derive(SettingsSchema, Serialize, Deserialize, Clone, Copy)]
Expand Down Expand Up @@ -1823,6 +1830,7 @@ pub fn session_settings_default() -> SettingsDefault {
rotation_recentering_mode: RotationRecenteringModeDefault {
variant: RotationRecenteringModeDefaultVariant::Yaw,
},
max_prediction_ms: 100,
},
connection: ConnectionConfigDefault {
stream_protocol: SocketProtocolDefault {
Expand Down

0 comments on commit 22d3d65

Please sign in to comment.