pub struct GameInputDevice<'dev> {
pub mappings: Vec<Mapping>,
/* private fields */
}Expand description
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.
Implementations§
Source§impl<'dev> GameInputDevice<'dev>
impl<'dev> GameInputDevice<'dev>
Sourcepub fn is_connected() -> bool
pub 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.
Sourcepub fn query_state(&self) -> Result<State, Error>
pub 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.
Sourcepub fn query_battery(&self) -> BatteryState
pub 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.
Sourcepub fn info(&self) -> &Info<'dev>
pub 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.
Sourcepub fn upload_haptic_effect<E: Effect>(
&mut self,
_effect: E,
) -> Result<UploadedEffect<'_, '_>, Error>
pub fn upload_haptic_effect<E: Effect>( &mut self, _effect: E, ) -> Result<UploadedEffect<'_, '_>, Error>
Uploads an haptic (force feedback) effect.
Sourcepub fn rumble(&mut self, _rumble: &RumbleEffect) -> Result<(), Error>
pub 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.
Sourcepub fn stop_rumble(&mut self) -> Result<(), Error>
pub fn stop_rumble(&mut self) -> Result<(), Error>
Stops early the simple rumble effect played with rumble().