Skip to content

[WIP] Joystick: platform independent interface - #462

Closed
emberian wants to merge 1 commit into
rust-windowing:masterfrom
emberian:joystick
Closed

emberian wants to merge 1 commit into
rust-windowing:masterfrom
emberian:joystick

Conversation

@emberian

Copy link
Copy Markdown

This is essentially the same API that SDL2 and GLFW support. It does not
have the limitation of a max number of joysticks. It's possible that we may
want to support a max number of joysticks, because that can avoid an
allocation, but there's not really a significant amount of allocation that
can happen due to this!

I've trawled docs for all the major platforms and this API should be fine.
SDL2 emulates both a poll and event-based interface, by either polling
joystick state during the event loop, or updating a local copy of joystick
state and returning that for the poll.

The way this API will work, is that users are encouraged to call
scan_joysticks on startup, when a joystick is detached (noticed by poll
returning None), and when their game logic wants it ("Player 2 press
start!"), but not every frame because it can be slow. The Joystick will
internally contain an Rc to any state it needs. poll should be
non-blocking and return whatever state it had at the last poll if it would
block (though I am not sure if there are many devices where that would be
an issue).

On some platforms, rather than polling for joystick state, you get events.
AFAICT the only platform that does not support events is Windows with
XInput.

I'm not sure I like tying this to the Window, as on no platform are
joystick events tied directly to a window. Instead, all applications
observe the same state. Plus, scanning for joysticks can be off-main-thread
for most platforms!

There's a fair amount of room for alternative design. This seems easiest
and most conservative.

@emberian
emberian force-pushed the joystick branch 2 times, most recently from 6f14adc to f3e2741 Compare May 22, 2015 04:56
@emberian

Copy link
Copy Markdown
Author

Action item from IRC: make it separate from Window, they have no dependency.

Comment thread Cargo.toml Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be fixed before merging.

@emberian

Copy link
Copy Markdown
Author

Action item from IRC: expose both event and poll-based interfaces. Emulate them on platforms where they are different (only XInput comes to mind).

@tomaka

tomaka commented May 22, 2015

Copy link
Copy Markdown
Contributor

All joystick-related stuff could be moved from src/window.rs to src/joystick.rs

@emberian

Copy link
Copy Markdown
Author

Will need to add "ball" support as well, forgot about that. http://www.usb.org/developers/hidpage/Hut1_12v2.pdf has a comprehensive list of all the various kinds of input devices (only some of which Glutin cares about).

This is essentially the same API that SDL2 and GLFW support. It does not have
the limitation of a max number of joysticks. It's possible that we may want to
support a max number of joysticks, because that can avoid an allocation, but
there's not really a significant amount of allocation that can happen due to
this!

I've trawled docs for all the major platforms and this API should be fine.
SDL2 emulates both a poll and event-based interface, by either polling
joystick state during the event loop, or updating a local copy of joystick
state and returning that for the poll.
@emberian emberian changed the title Joystick: platform independent interface [WIP] Joystick: platform independent interface May 25, 2015
@emberian

Copy link
Copy Markdown
Author

@tomaka I will ping you when it's ready for another review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants