From 7f1289bbb03019a7487376f14889dc37075e2940 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Mon, 19 Aug 2024 01:52:59 +0900 Subject: [PATCH] move battery check out of prediction loop --- client/scenes/stream_tracking.cpp | 60 +++++++++++++++---------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/client/scenes/stream_tracking.cpp b/client/scenes/stream_tracking.cpp index a100026f..4e054192 100644 --- a/client/scenes/stream_tracking.cpp +++ b/client/scenes/stream_tracking.cpp @@ -246,36 +246,6 @@ 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); - -#ifdef __ANDROID__ - if (next_battery_check < now) - { - timer t2(instance); - from_headset::battery battery{}; - auto intent = ctx.call>(register_receiver, receiver_jobj, filter_jobj); - if (intent) - { - auto level_jint = intent.call(get_int_extra, level_jstr, default_jint); - auto scale_jint = intent.call(get_int_extra, scale_jstr, default_jint); - - if (level_jint && level_jint.value >= 0 && scale_jint && scale_jint.value >= 0) - { - battery.present = true; - battery.charge = (float)(level_jint.value) / (float)(scale_jint.value); - } - - auto plugged_jint = intent.call(get_int_extra, plugged_jstr, default_jint); - battery.charging = plugged_jint && plugged_jint.value > 0; - } - - network_session->send_stream(battery); - - next_battery_check = now + battery_check_interval; - XrDuration battery_dur = t2.count(); - - spdlog::info("Battery check took: {}", battery_dur); - } -#endif } catch (const std::system_error & e) { @@ -285,6 +255,36 @@ void scenes::stream::tracking() } } +#ifdef __ANDROID__ + if (next_battery_check < now) + { + timer t2(instance); + from_headset::battery battery{}; + auto intent = ctx.call>(register_receiver, receiver_jobj, filter_jobj); + if (intent) + { + auto level_jint = intent.call(get_int_extra, level_jstr, default_jint); + auto scale_jint = intent.call(get_int_extra, scale_jstr, default_jint); + + if (level_jint && level_jint.value >= 0 && scale_jint && scale_jint.value >= 0) + { + battery.present = true; + battery.charge = (float)(level_jint.value) / (float)(scale_jint.value); + } + + auto plugged_jint = intent.call(get_int_extra, plugged_jstr, default_jint); + battery.charging = plugged_jint && plugged_jint.value > 0; + } + + network_session->send_stream(battery); + + next_battery_check = now + battery_check_interval; + XrDuration battery_dur = t2.count(); + + spdlog::info("Battery check took: {}", battery_dur); + } +#endif + t0 += tracking_period; } catch (std::exception & e)