From d1f26af03e62c272c2b66b92546286763e2f69ed Mon Sep 17 00:00:00 2001 From: Ron Bessems Date: Tue, 1 Oct 2024 16:00:36 -0700 Subject: [PATCH] Fix deprecated use of ALooper_PollAll Issue: #133 Fix double spawn with multiple controllers Issue #137 --- Chapter1/main.cpp | 2 +- Chapter2/main.cpp | 2 +- Chapter3/main.cpp | 2 +- Chapter4/main.cpp | 8 +++++--- Chapter5/main.cpp | 2 +- Chapter6_1_Multiview/Chapter6/main.cpp | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Chapter1/main.cpp b/Chapter1/main.cpp index 6d59920..faed373 100644 --- a/Chapter1/main.cpp +++ b/Chapter1/main.cpp @@ -100,7 +100,7 @@ class OpenXRTutorial { int events = 0; // The timeout depends on whether the application is active. const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0; - if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) { + if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) { if (source != nullptr) { source->process(androidApp, source); } diff --git a/Chapter2/main.cpp b/Chapter2/main.cpp index 5afd67e..9937dc7 100644 --- a/Chapter2/main.cpp +++ b/Chapter2/main.cpp @@ -401,7 +401,7 @@ class OpenXRTutorial { int events = 0; // The timeout depends on whether the application is active. const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0; - if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) { + if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) { if (source != nullptr) { source->process(androidApp, source); } diff --git a/Chapter3/main.cpp b/Chapter3/main.cpp index df7a67e..85617f3 100644 --- a/Chapter3/main.cpp +++ b/Chapter3/main.cpp @@ -961,7 +961,7 @@ class OpenXRTutorial { int events = 0; // The timeout depends on whether the application is active. const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0; - if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) { + if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) { if (source != nullptr) { source->process(androidApp, source); } diff --git a/Chapter4/main.cpp b/Chapter4/main.cpp index 2705467..7943a5c 100644 --- a/Chapter4/main.cpp +++ b/Chapter4/main.cpp @@ -351,6 +351,7 @@ class OpenXRTutorial { // Each Action here has two paths, one for each SubAction path. any_ok |= SuggestBindings("/interaction_profiles/khr/simple_controller", {{m_changeColorAction, CreateXrPath("/user/hand/left/input/select/click")}, {m_grabCubeAction, CreateXrPath("/user/hand/right/input/select/click")}, + {m_spawnCubeAction, CreateXrPath("/user/hand/right/input/menu/click")}, {m_palmPoseAction, CreateXrPath("/user/hand/left/input/grip/pose")}, {m_palmPoseAction, CreateXrPath("/user/hand/right/input/grip/pose")}, {m_buzzAction, CreateXrPath("/user/hand/left/output/haptic")}, @@ -893,8 +894,9 @@ class OpenXRTutorial { thisBlock.color = color; } } else { - // not near a block? We can spawn one. - if (m_spawnCubeState.isActive == XR_TRUE && m_spawnCubeState.currentState == XR_FALSE && m_spawnCubeState.changedSinceLastSync == XR_TRUE) { + // right hand not near a block? + // i = 1 means sub action path /user/hand/right + if (i == 1 && m_spawnCubeState.isActive == XR_TRUE && m_spawnCubeState.currentState == XR_FALSE && m_spawnCubeState.changedSinceLastSync == XR_TRUE) { XrQuaternionf q = {0.0f, 0.0f, 0.0f, 1.0f}; XrVector3f color = {pseudorandom_distribution(pseudo_random_generator), pseudorandom_distribution(pseudo_random_generator), pseudorandom_distribution(pseudo_random_generator)}; m_blocks.push_back({{q, FixPosition(m_handPose[i].position)}, {0.095f, 0.095f, 0.095f}, color}); @@ -1329,7 +1331,7 @@ class OpenXRTutorial { int events = 0; // The timeout depends on whether the application is active. const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0; - if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) { + if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) { if (source != nullptr) { source->process(androidApp, source); } diff --git a/Chapter5/main.cpp b/Chapter5/main.cpp index 0213f10..96f4f9c 100644 --- a/Chapter5/main.cpp +++ b/Chapter5/main.cpp @@ -1420,7 +1420,7 @@ class OpenXRTutorial { int events = 0; // The timeout depends on whether the application is active. const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0; - if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) { + if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) { if (source != nullptr) { source->process(androidApp, source); } diff --git a/Chapter6_1_Multiview/Chapter6/main.cpp b/Chapter6_1_Multiview/Chapter6/main.cpp index 650af0e..a4cf601 100644 --- a/Chapter6_1_Multiview/Chapter6/main.cpp +++ b/Chapter6_1_Multiview/Chapter6/main.cpp @@ -1323,7 +1323,7 @@ class OpenXRTutorial { int events = 0; // The timeout depends on whether the application is active. const int timeoutMilliseconds = (!androidAppState.resumed && !m_sessionRunning && androidApp->destroyRequested == 0) ? -1 : 0; - if (ALooper_pollAll(timeoutMilliseconds, nullptr, &events, (void **)&source) >= 0) { + if (ALooper_pollOnce(timeoutMilliseconds, nullptr, &events, (void**)&source) >= 0) { if (source != nullptr) { source->process(androidApp, source); }