InputProcessor

Struct InputProcessor 

Source
pub struct InputProcessor { /* private fields */ }
Expand description

Parse input events, particularly key-down/up pairs, into character control and such.

This is designed to be a leaf of the dependency graph: it does not own or send messages to any other elements of the application. Instead, the following steps must occur in the given order.

  1. The platform-specific code should call InputProcessor::key_down and such to to provide input information.
  2. The game loop should call InputProcessor::apply_input to apply the effects of input on the relevant Character. (This is currently only possible via Session.)
  3. The game loop should call InputProcessor::step to apply the effects of time on the input processor. (This is currently only possible via Session.)

TODO: Refactor APIs till this can be explained more cleanly without reference to private items.

Implementations§

Source§

impl InputProcessor

Source

pub fn new() -> Self

Constructs a new InputProcessor.

Consider using Session instead of directly calling this.

Source

pub fn key_down(&mut self, key: Key) -> bool

Handles incoming key-down events. Returns whether the key was unbound.

Source

pub fn key_up(&mut self, key: Key)

Handles incoming key-up events.

Source

pub fn key_momentary(&mut self, key: Key) -> bool

Handles incoming key events in the case where key-up events are not available, such that an assumption about equivalent press duration must be made.

Source

pub fn key_focus(&mut self, has_focus: bool)

Handles the keyboard focus being gained or lost. If the platform does not have a concept of focus, you need not call this method, but may call it with true.

InputProcessor will assume that if focus is lost, key-up events may be lost and so currently held keys should stop taking effect.

Source

pub fn wants_pointer_lock(&self) -> bool

True when the UI is in a state which should have mouse pointer lock/capture/disable. This is not the same as actually having it since the window may lack focus, the application may lack permission, etc.; use InputProcessor::has_pointer_lock to report that state.

Source

pub fn has_pointer_lock(&mut self, value: bool)

Use this method to report whether mouse mouse pointer lock/capture/disable is known to be successfully enabled, after InputProcessor::wants_pointer_lock requests it or it is disabled for any reason.

Source

pub fn mouselook_delta(&mut self, delta: Vector2D<FreeCoordinate, NominalPixel>)

Provide relative movement information for mouselook.

This value is an accumulated displacement, not an angular velocity, so it is not suitable for joystick-type input.

Note that absolute cursor positions must be provided separately.

Source

pub fn mouse_ndc_position(&mut self, position: Option<NdcPoint2>)

Provide position of mouse pointer or other input device in normalized device coordinates (range -1 to 1 upward and rightward). None denotes the cursor being outside the viewport, and out-of-range coordinates will be treated the same.

Pixel coordinates may be converted to NDC using Viewport::normalize_nominal_point or by using InputProcessor::mouse_pixel_position.

If this is never called, the default value is (0, 0) which corresponds to the center of the screen.

Source

pub fn mouse_pixel_position( &mut self, viewport: Viewport, position: Option<Point2D<f64, NominalPixel>>, derive_movement: bool, )

Provide position of mouse pointer or other input device in pixel coordinates framed by the given Viewport’s nominal_size. None denotes the cursor being outside the viewport, and out-of-range coordinates will be treated the same.

This is equivalent to converting the coordinates and calling InputProcessor::mouse_ndc_position.

If this is never called, the default mouse_ndc_position value is (0, 0), which corresponds to the center of the screen.

TODO: this should take float input, probably

Source

pub fn movement(&self) -> FreeVector

Returns the character movement direction that input is currently requesting.

This is always a vector of length at most 1.

Source

pub fn mouselook_mode(&self) -> DynSource<bool>

Returns a source which reports whether the mouselook mode (mouse movement is interpreted as view rotation) is currently active.

This value may be toggled by in-game UI.

Source

pub fn set_mouselook_mode(&mut self, active: bool)

Activates or deactivates mouselook mode, identically to user input doing so.

Source

pub fn cursor_ndc_position(&self) -> Option<NdcPoint2>

Returns the position which should be used for click/cursor raycasting. This is not necessarily equal to the tracked mouse position.

Returns None if the mouse position is out of bounds, the window has lost focus, or similar conditions under which no cursor should be shown.

Trait Implementations§

Source§

impl Debug for InputProcessor

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> ConditionalSend for T
where T: Send,