GameInputDevice

Struct GameInputDevice 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn upload_haptic_effect<E: Effect>( &mut self, _effect: E, ) -> Result<UploadedEffect<'_, '_>, Error>

Uploads an haptic (force feedback) effect.

Source

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.
Source

pub fn stop_rumble(&mut self) -> Result<(), Error>

Stops early the simple rumble effect played with rumble().

Source

pub fn poll_iter<'a>(&'a mut self) -> PollIter<'dev, 'a>

Returns a polling iterator over this device’s event queue.

Source

pub fn wait_iter<'a, T: Into<Timeout>>( &'a mut self, timeout: T, ) -> WaitIter<'dev, 'a>

Returns a waiting iterator over this device’s event queue.

Trait Implementations§

Source§

impl<'dev> Debug for GameInputDevice<'dev>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'dev> Drop for GameInputDevice<'dev>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'dev> PartialEq for GameInputDevice<'dev>

Source§

fn eq(&self, other: &GameInputDevice<'dev>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'dev> Eq for GameInputDevice<'dev>

Source§

impl<'dev> StructuralPartialEq for GameInputDevice<'dev>

Auto Trait Implementations§

§

impl<'dev> Freeze for GameInputDevice<'dev>

§

impl<'dev> RefUnwindSafe for GameInputDevice<'dev>

§

impl<'dev> Send for GameInputDevice<'dev>

§

impl<'dev> Sync for GameInputDevice<'dev>

§

impl<'dev> Unpin for GameInputDevice<'dev>

§

impl<'dev> UnwindSafe for GameInputDevice<'dev>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.