Skip to main content

RuntimeInput

Struct RuntimeInput 

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

Held keys, mouse buttons, and cursor position for the current frame.

just_pressed/just_released sets are edge-triggered: they hold exactly the keys or buttons that changed state since the last call to RuntimeInput::clear_frame_edges. Runtime integrations call that method once per rendered frame after gameplay systems have had a chance to read them.

It serializes whole, so replays can record what each frame’s systems saw.

Implementations§

Source§

impl RuntimeInput

Source

pub fn key_held(&self, key: KeyCode) -> bool

Source

pub fn key_just_pressed(&self, key: KeyCode) -> bool

Source

pub fn key_just_released(&self, key: KeyCode) -> bool

Source

pub fn keys_pressed(&self) -> impl Iterator<Item = KeyCode> + '_

Keys pressed since the last Self::clear_frame_edges, for a “press any key” prompt.

Source

pub fn keys_released(&self) -> impl Iterator<Item = KeyCode> + '_

Keys released since the last Self::clear_frame_edges.

Source

pub fn mouse_held(&self, button: MouseButton) -> bool

Source

pub fn mouse_just_pressed(&self, button: MouseButton) -> bool

Source

pub fn mouse_just_released(&self, button: MouseButton) -> bool

Source

pub fn cursor_position(&self) -> Option<[f32; 2]>

Source

pub fn mouse_motion(&self) -> [f32; 2]

Raw mouse movement since the last Self::clear_frame_edges. It keeps counting while the cursor is captured and cannot move.

Source

pub fn scroll(&self) -> [f32; 2]

Mouse wheel turned since the last Self::clear_frame_edges, in lines: positive y turns the wheel away from the player, which shows content above.

Source

pub fn cursor_captured(&self) -> bool

True when gameplay asked the window to hide and lock the cursor.

Source

pub fn set_cursor_captured(&mut self, captured: bool)

Asks the window to hide and lock the cursor, for mouse look. The window runner applies the request after the frame’s systems ran. A grab asked for on the frame Esc went down outlasts the player controller’s Esc release, so a game that used that Esc keeps it.

Source

pub fn cursor_capture_asked(&self) -> bool

True when Self::set_cursor_captured asked for a grab this frame.

Source

pub fn viewport_size(&self) -> [f32; 2]

Current window/render-viewport size in pixels, used to convert cursor positions into normalized device coordinates for gameplay picking.

Source

pub fn record_key(&mut self, key: KeyCode, pressed: bool)

Records one keyboard WindowEvent. Ignores OS auto-repeat: repeated presses do not re-fire just_pressed.

Source

pub fn record_mouse_button(&mut self, button: MouseButton, pressed: bool)

Records one mouse button WindowEvent.

Source

pub fn release_all(&mut self)

Releases every held key and button, reporting each as just released. Call it when the window loses focus, because the matching release events then go to another window.

Source

pub fn focused(&self) -> bool

Whether the game window has keyboard focus. True until a Self::record_focus says otherwise.

Source

pub fn record_focus(&mut self, focused: bool)

Records a WindowEvent::Focused. Losing focus also releases every held key and button, as Self::release_all does, and frees the cursor until the next grab.

Source

pub fn record_cursor_position(&mut self, position: [f32; 2])

Records the latest cursor position from a CursorMoved event.

Source

pub fn record_mouse_motion(&mut self, delta: [f32; 2])

Adds one raw DeviceEvent::MouseMotion delta.

Source

pub fn record_scroll(&mut self, lines: [f32; 2])

Adds one MouseWheel event, in lines.

Source

pub fn record_viewport_size(&mut self, size: [f32; 2])

Records the current window/render-viewport size in pixels.

Source

pub fn pad_held(&self, button: PadButton) -> bool

Source

pub fn pad_just_pressed(&self, button: PadButton) -> bool

Source

pub fn pad_just_released(&self, button: PadButton) -> bool

Source

pub fn pads_pressed(&self) -> impl Iterator<Item = PadButton> + '_

Pad buttons pressed since the last Self::clear_frame_edges.

Source

pub fn stick(&self, stick: Stick) -> [f32; 2]

Stick tilt, each axis -1..1; [0, 1] is pushed fully up.

Source

pub fn record_pad_button(&mut self, button: PadButton, pressed: bool)

Records one gamepad button press or release.

Source

pub fn record_stick(&mut self, stick: Stick, tilt: [f32; 2])

Records a stick’s tilt and presses or releases its four direction buttons: pressed past 0.5, released below 0.3, so a stick resting near the threshold does not flicker.

Source

pub fn record_press_tick(&mut self, binding: InputBinding, tick: f64)

Records when a press happened, in fractional fixed ticks. The windowed runner calls it as key and mouse events arrive; the first press of a binding in a frame wins.

Source

pub fn press_tick(&self, binding: InputBinding) -> Option<f64>

When binding was pressed this frame, if the runner recorded it.

Source

pub fn take_presses_after(&mut self, end: f64) -> Self

Moves the presses recorded at or after end, in fractional fixed ticks, out of this input and returns them as an input holding only those presses, so a frame that runs several ticks gives each press to the tick it happened in. Untimed presses and releases stay.

Source

pub fn merge_frame_edges(&mut self, earlier: &Self)

Clears this frame’s edge sets. Runtime integrations call this once per rendered frame after gameplay systems have read them, so the next frame starts empty. Adds the edge sets, press times, mouse motion and scroll of earlier, an earlier frame, to this one, so presses from frames that ran no fixed tick reach the next tick.

Source

pub fn clear_frame_edges(&mut self)

Trait Implementations§

Source§

impl Clone for RuntimeInput

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Component for RuntimeInput
where Self: Send + Sync + 'static,

Source§

const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet

A constant indicating the storage type used for this component.
Source§

type Mutability = Mutable

A marker type to assist Bevy with determining if this component is mutable, or immutable. Mutable components will have Component<Mutability = Mutable>, while immutable components will instead have Component<Mutability = Immutable>. Read more
Source§

fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )

Registers required components. Read more
Source§

fn clone_behavior() -> ComponentCloneBehavior

Called when registering this component, allowing to override clone function (or disable cloning altogether) for this component. Read more
Source§

fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>

Returns ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read more
Source§

fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_add ComponentHook for this Component if one is defined.
Source§

fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_insert ComponentHook for this Component if one is defined.
Source§

fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_discard ComponentHook for this Component if one is defined.
Source§

fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_remove ComponentHook for this Component if one is defined.
Source§

fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>

Gets the on_despawn ComponentHook for this Component if one is defined.
Source§

fn map_entities<E>(_this: &mut Self, _mapper: &mut E)
where E: EntityMapper,

Maps the entities on this component using the given EntityMapper. This is used to remap entities in contexts like scenes and entity cloning. When deriving Component, this is populated by annotating fields containing entities with #[entities] Read more
Source§

impl Debug for RuntimeInput

Source§

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

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

impl Default for RuntimeInput

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RuntimeInput

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for RuntimeInput

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Resource for RuntimeInput
where Self: Send + Sync + 'static,

Source§

impl Serialize for RuntimeInput

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RuntimeInput

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> 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<C> Bundle for C
where C: Component,

Source§

fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>

Source§

fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>

Return a iterator over this Bundle’s component ids. This will be None if the component has not been registered.
Source§

impl<C> BundleFromComponents for C
where C: Component,

Source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>, C: Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<C> DynamicBundle for C
where C: Component,

Source§

type Effect = ()

An operation on the entity that happens after inserting this bundle.
Source§

unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect

Moves the components out of the bundle. Read more
Source§

unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )

Applies the after-effects of spawning this bundle. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromTemplate for T
where T: Clone + Default + Unpin,

Source§

type Template = T

The Template for this type.
Source§

impl<T> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> Template for T
where T: Clone + Default + Unpin,

Source§

type Output = T

The type of value produced by this Template.
Source§

fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>

Uses this template and the given entity context to produce a Template::Output.
Source§

fn clone_template(&self) -> T

Clones this template. See Clone.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> TypeData for T
where T: 'static + Send + Sync + Clone,

Source§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more