Struct dmc::game_input_device::GameInputDevice
[−]
[src]
pub struct GameInputDevice<'dev> { pub mappings: Vec<Mapping>, // some fields omitted }
A Gamepad, joystick, steering wheel, or whatever device that's reported as a game input device by the backend.
See this module's root documentation for learning how to get and properly use one.
You should drop it when it receives the Disconnected
event.
Fields
mappings: Vec<Mapping>
The vector of mappings applied to this device.
A device has a vector of Mapping
objects, each acting
as a "conversion pass" for events, applied from first to last.
You are free to mutate this vector freely.
Note that this vector can be initially empty, in which case no
memory is allocated.
This is provided because a non-negligible number of devices/drivers
are quirky and require mappings to "fix" their behaviour
(this is the reason why SDL2 provides
SDL_GameControllerAddMapping()
,
and also implicitly adds mappings based on its own little
database (SDL_GameControllerDB
)).
Incidentally, this might be useful to you if you want to allow your users to remap buttons and axes for your game.
Methods
impl<'dev> GameInputDevice<'dev>
[src]
fn is_connected() -> bool
Queries whether the device is still connected or not.
If it's not, you may drop this object.
You're not required to do this before every query
to the device. The queries themselves return a
Disconnected
error when appropriate.
The returned value is not cached: every call to this function involves a roundtrip to the backend.
fn query_state(&self) -> Result<State, Error>
Query the device's current state (buttons and axes values).
This queries the whole state every time, for these reasons:
- This is how some backends implement it;
- Providing one method for every possible button or axis would clutter this API.
The returned state is not cached: every call to this function involves a roundtrip to the backend.
fn query_battery(&self) -> BatteryState
Query the device's current battery state, if relevant.
Some backends or drivers don't support this, in which case
the fields are simply set to Unknown
.
fn info(&self) -> &Info<'dev>
Get an immutable reference to the device's Info
data.
This method is cheap because the data is retrieved and stored once
at device initialization time (hence the get
prefix).
Mutation is not allowed because it doesn't make sense for most
of Info
's members. Some backends partially implement this,
but I don't see a proper use case for this yet, and it could be
abstracted by your application.
fn upload_haptic_effect<E: Effect>(
&mut self,
_effect: E
) -> Result<UploadedEffect, Error>
&mut self,
_effect: E
) -> Result<UploadedEffect, Error>
Uploads an haptic (force feedback) effect.
fn rumble(&mut self, _rumble: &RumbleEffect) -> Result<(), Error>
Quickly plays a rumble effect.
This shortcut is provided because the RumbleEffect
is the
most commonly implemented and used one. Also, on some backends (eg.
Microsoft's XInput), it is implemented most efficiently this way.
There's no way to query the current vibration values - you have to cache them yourself if you so wish.
fn stop_rumble(&mut self) -> Result<(), Error>
Stops early the simple rumble effect played with rumble()
.
fn poll_iter<'a>(&'a mut self) -> PollIter<'dev, 'a>
Returns a polling iterator over this device's event queue.
fn wait_iter<'a, T: Into<Timeout>>(
&'a mut self,
timeout: T
) -> WaitIter<'dev, 'a>
&'a mut self,
timeout: T
) -> WaitIter<'dev, 'a>
Returns a waiting iterator over this device's event queue.
Trait Implementations
impl<'dev> Debug for GameInputDevice<'dev>
[src]
impl<'dev> Eq for GameInputDevice<'dev>
[src]
impl<'dev> PartialEq for GameInputDevice<'dev>
[src]
fn eq(&self, __arg_0: &GameInputDevice<'dev>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &GameInputDevice<'dev>) -> bool
This method tests for !=
.