From 1c9329679f9487bdd434d81020bb67a95d30fc00 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 5 Apr 2024 17:04:12 +0200 Subject: [PATCH] Throttle tracking thread to reduce CPU usage --- client/scenes/stream_tracking.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index e0655da5..643eb5ed 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -120,8 +120,8 @@ void scenes::stream::tracking() {device_id::RIGHT_GRIP, application::right_grip()}}; XrSpace view_space = application::view(); - const 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 = 1'000'000; // Send tracking data every 1ms + const XrDuration dt = 100'000; // Wake up 0.1ms before measuring the position XrTime t0 = instance.now(); @@ -130,6 +130,8 @@ void scenes::stream::tracking() try { XrTime now = instance.now(); + // If tracking is slow, throttle so that we remain idle most of the time + tracking_period = std::clamp(5 * (now - t0), 1'000'000, 10'000'000); if (now < t0) std::this_thread::sleep_for(std::chrono::nanoseconds(t0 - now - dt));