diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index 32d592bd..7142f6da 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -30,6 +30,9 @@ using tid = to_headset::tracking_control::id; +static const XrDuration min_tracking_period = 2'000'000; +static const XrDuration max_tracking_period = 5'000'000; + static from_headset::tracking::pose locate_space(device_id device, XrSpace space, XrSpace reference, XrTime time) { XrSpaceVelocity velocity{ @@ -183,8 +186,7 @@ void scenes::stream::tracking() XrSpace view_space = application::space(xr::spaces::view); XrSpace world_space = application::space(xr::spaces::world); - XrDuration tracking_period = 1'000'000; // Send tracking data every 1ms - const XrDuration dt = 100'000; // Wake up 0.1ms before measuring the position + XrDuration tracking_period = min_tracking_period; XrTime t0 = instance.now(); XrTime last_hand_sample = t0; @@ -204,7 +206,7 @@ void scenes::stream::tracking() XrTime now = instance.now(); if (now < t0) - std::this_thread::sleep_for(std::chrono::nanoseconds(t0 - now - dt)); + std::this_thread::sleep_for(std::chrono::nanoseconds(t0 - now)); // If thread can't keep up, skip timestamps t0 = std::max(t0, now); @@ -291,7 +293,7 @@ void scenes::stream::tracking() XrDuration busy_time = t.count(); // Target: polling between 1 and 5ms, with 20% busy time - tracking_period = std::clamp(std::lerp(tracking_period, busy_time * 5, 0.2), 1'000'000, 5'000'000); + tracking_period = std::clamp(std::lerp(tracking_period, busy_time * 5, 0.2), min_tracking_period, max_tracking_period); if (samples and busy_time / samples > 2'000'000) {