-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ndk-glue: impossible to poll events in a non-blocking fashion #111
Comments
@nwessing When used with If you are not using |
Related side-note: @dvc94ch You added the event loop logic to Instead Shall I clean that up and send some PRs? Important is to get |
I see, I was using the glue module directly, I am experimenting with using the Oculus Mobile SDK in Rust, and it doesn't make too much sense to use winit since I need to hook into a lot of android specific functionality directly anyways. I will use the winit/android implementation as guide then for how to use the ndk-glue crate. Thanks for pointing me in the right direction! |
@MarijnS95 ups, it is always 0 because it was set to |
@dvc94ch it's actually set to 1 for the input queue which is why it works. Have a commit written up, will submit that in a bit ;) @nwessing using the links provided in the comment and the winit source should help you on your way, but don't hesitate to ask more questions: ndk-glue is largely undocumented and it'd be great to get some usage feedback! |
For reference, this is taken care of in rust-windowing/winit#1826. |
Chiming in to say that I'm also mucking about with the Oculus Mobile SDK in a similar manner to @nwessing, and some documentation on an easy, non-blocking way to get these events would be marvelous. 😄 |
@kanerogers Does my comment above and the docstrings introduced in #112 provide that? Let us know if anything is missing, then I guess someone has to work that into a minimal looper example. |
@kanerogers I have this working pretty well at this point. I've defined the following function: pub const LOOPER_ID_MAIN: u32 = 0;
pub const LOOPER_ID_INPUT: u32 = 1;
pub fn poll_all_ms(block: bool) -> Option<ndk_glue::Event> {
let looper = ThreadLooper::for_thread().unwrap();
let result = if block {
let result = looper.poll_all();
result
} else {
looper.poll_all_timeout(std::time::Duration::from_millis(0u64))
};
match result {
Ok(Poll::Event { ident, .. }) => {
let ident = ident as u32;
if ident == LOOPER_ID_MAIN {
ndk_glue::poll_events()
} else if ident == LOOPER_ID_INPUT {
if let Some(input_queue) = ndk_glue::input_queue().as_ref() {
while let Some(event) = input_queue.get_event() {
if let Some(event) = input_queue.pre_dispatch(event) {
input_queue.finish_event(event, false);
}
}
}
None
} else {
unreachable!("Unrecognized looper identifer");
}
}
_ => None,
}
} And it is called in my game loop like this: while !app.destroy_requested { // Main game loop
loop { // event pump loop
let block = !app.destroy_requested && app.ovr.is_none();
if let Some(event) = poll_all_ms(block) {
trace!("event: {:?}", event);
app.handle_lifecycle_event(&event);
app.update_vr_mode();
} else {
break;
}
}
// update and render
}
|
@MarijnS95 your documentation definitely helped! Thanks so much! You are a fantastic maintainer of a fantastic project. ❤️ @nwessing Thanks so much for this! 😄 It looks like we are doing the exact same thing (porting VrCubeWorld_NativeActivity to rust) at the same time - lovely to know I'm not alone. |
@kanerogers Neat! I'm hoping to get some remaining PRs reviewed/merged before merging #112 and bumping the minor version this weekend 😁. Will try to stuff in a minimal looper example similar to the code pasted above 🎉! |
Just chiming in to say this is working perfectly for me! :)
…On Wed, 27 Jan 2021 at 7:23 pm, Marijn Suijten ***@***.***> wrote:
@kanerogers <https://github.com/kanerogers> Neat! I'm hoping to get some
remaining PRs reviewed/merged before merging #112
<#112> and bumping
the minor version this weekend 😁. Will try to stuff in a minimal looper
example similar to the code pasted above 🎉!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#111 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAPNXZ6ZUIOTD4ABJMJE3F3S37EOZANCNFSM4WBG46IA>
.
|
Originally proposed [here], this adds a simple looper example demonstrating how to use Android's `Looper` through the NDK bindings in similar fashion to `winit`. It uses `ndk_glue`'s event pipe, Android's `InputQueue` and a custom Unix pipe to transfer events to the Looper (thread). [here]: rust-mobile#111 (comment)
Originally proposed [here], this adds a simple looper example demonstrating how to use Android's `Looper` through the NDK bindings in similar fashion to `winit`. It uses `ndk_glue`'s event pipe, Android's `InputQueue` and a custom Unix pipe to transfer events to the Looper (thread). [here]: rust-mobile#111 (comment)
* ndk-example: Demonstrate Looper usage without winit Originally proposed [here], this adds a simple looper example demonstrating how to use Android's `Looper` through the NDK bindings in similar fashion to `winit`. It uses `ndk_glue`'s event pipe, Android's `InputQueue` and a custom Unix pipe to transfer events to the Looper (thread). [here]: #111 (comment)
* ndk-example: Demonstrate Looper usage without winit Originally proposed [here], this adds a simple looper example demonstrating how to use Android's `Looper` through the NDK bindings in similar fashion to `winit`. It uses `ndk_glue`'s event pipe, Android's `InputQueue` and a custom Unix pipe to transfer events to the Looper (thread). [here]: rust-mobile/ndk#111 (comment)
* ndk-example: Demonstrate Looper usage without winit Originally proposed [here], this adds a simple looper example demonstrating how to use Android's `Looper` through the NDK bindings in similar fashion to `winit`. It uses `ndk_glue`'s event pipe, Android's `InputQueue` and a custom Unix pipe to transfer events to the Looper (thread). [here]: rust-mobile/ndk#111 (comment)
it's impossible to poll events in ndk-glue without blocking the thread. In the NDK samples I have seen ALooper is used to poll events with a timeout value that can be configured to block or not. Where the ndk-glue module will read the file descriptor directly with a blocking call. This makes it impossible to program games, or any application that wants to keep running without having to block for events/input.
The text was updated successfully, but these errors were encountered: