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
impl RuntimeInput
pub fn key_held(&self, key: KeyCode) -> bool
pub fn key_just_pressed(&self, key: KeyCode) -> bool
pub fn key_just_released(&self, key: KeyCode) -> bool
Sourcepub fn keys_pressed(&self) -> impl Iterator<Item = KeyCode> + '_
pub fn keys_pressed(&self) -> impl Iterator<Item = KeyCode> + '_
Keys pressed since the last Self::clear_frame_edges, for a
“press any key” prompt.
Sourcepub fn keys_released(&self) -> impl Iterator<Item = KeyCode> + '_
pub fn keys_released(&self) -> impl Iterator<Item = KeyCode> + '_
Keys released since the last Self::clear_frame_edges.
pub fn mouse_held(&self, button: MouseButton) -> bool
pub fn mouse_just_pressed(&self, button: MouseButton) -> bool
pub fn mouse_just_released(&self, button: MouseButton) -> bool
pub fn cursor_position(&self) -> Option<[f32; 2]>
Sourcepub fn mouse_motion(&self) -> [f32; 2]
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.
Sourcepub fn scroll(&self) -> [f32; 2]
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.
Sourcepub fn cursor_captured(&self) -> bool
pub fn cursor_captured(&self) -> bool
True when gameplay asked the window to hide and lock the cursor.
Sourcepub fn set_cursor_captured(&mut self, captured: bool)
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.
Sourcepub fn cursor_capture_asked(&self) -> bool
pub fn cursor_capture_asked(&self) -> bool
True when Self::set_cursor_captured asked for a grab this frame.
Sourcepub fn viewport_size(&self) -> [f32; 2]
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.
Sourcepub fn record_key(&mut self, key: KeyCode, pressed: bool)
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.
Records one mouse button WindowEvent.
Sourcepub fn release_all(&mut self)
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.
Sourcepub fn focused(&self) -> bool
pub fn focused(&self) -> bool
Whether the game window has keyboard focus. True until a
Self::record_focus says otherwise.
Sourcepub fn record_focus(&mut self, focused: bool)
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.
Sourcepub fn record_cursor_position(&mut self, position: [f32; 2])
pub fn record_cursor_position(&mut self, position: [f32; 2])
Records the latest cursor position from a CursorMoved event.
Sourcepub fn record_mouse_motion(&mut self, delta: [f32; 2])
pub fn record_mouse_motion(&mut self, delta: [f32; 2])
Adds one raw DeviceEvent::MouseMotion delta.
Sourcepub fn record_scroll(&mut self, lines: [f32; 2])
pub fn record_scroll(&mut self, lines: [f32; 2])
Adds one MouseWheel event, in lines.
Sourcepub fn record_viewport_size(&mut self, size: [f32; 2])
pub fn record_viewport_size(&mut self, size: [f32; 2])
Records the current window/render-viewport size in pixels.
pub fn pad_held(&self, button: PadButton) -> bool
pub fn pad_just_pressed(&self, button: PadButton) -> bool
pub fn pad_just_released(&self, button: PadButton) -> bool
Sourcepub fn pads_pressed(&self) -> impl Iterator<Item = PadButton> + '_
pub fn pads_pressed(&self) -> impl Iterator<Item = PadButton> + '_
Pad buttons pressed since the last Self::clear_frame_edges.
Sourcepub fn stick(&self, stick: Stick) -> [f32; 2]
pub fn stick(&self, stick: Stick) -> [f32; 2]
Stick tilt, each axis -1..1; [0, 1] is pushed fully up.
Records one gamepad button press or release.
Sourcepub fn record_stick(&mut self, stick: Stick, tilt: [f32; 2])
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.
Sourcepub fn record_press_tick(&mut self, binding: InputBinding, tick: f64)
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.
Sourcepub fn press_tick(&self, binding: InputBinding) -> Option<f64>
pub fn press_tick(&self, binding: InputBinding) -> Option<f64>
When binding was pressed this frame, if the runner recorded it.
Sourcepub fn take_presses_after(&mut self, end: f64) -> Self
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.
Sourcepub fn merge_frame_edges(&mut self, earlier: &Self)
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.
pub fn clear_frame_edges(&mut self)
Trait Implementations§
Source§impl Clone for RuntimeInput
impl Clone for RuntimeInput
Source§impl Component for RuntimeInput
impl Component for RuntimeInput
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read moreSource§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
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 moreSource§impl Debug for RuntimeInput
impl Debug for RuntimeInput
Source§impl Default for RuntimeInput
impl Default for RuntimeInput
Source§impl<'de> Deserialize<'de> for RuntimeInput
impl<'de> Deserialize<'de> for RuntimeInput
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for RuntimeInput
impl PartialEq for RuntimeInput
impl Resource for RuntimeInput
Source§impl Serialize for RuntimeInput
impl Serialize for RuntimeInput
impl StructuralPartialEq for RuntimeInput
Auto Trait Implementations§
impl Freeze for RuntimeInput
impl RefUnwindSafe for RuntimeInput
impl Send for RuntimeInput
impl Sync for RuntimeInput
impl Unpin for RuntimeInput
impl UnsafeUnpin for RuntimeInput
impl UnwindSafe for RuntimeInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§fn get_component_ids(
components: &Components,
) -> impl Iterator<Item = Option<ComponentId>>
fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConditionalSend for Twhere
T: Send,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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 Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
Source§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Source§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
Source§impl<T> FromTemplate for T
impl<T> FromTemplate for T
Source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
Source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self using default().
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
Source§fn into_result(self) -> Result<T, RunSystemError>
fn into_result(self) -> Result<T, RunSystemError>
impl<T> Scalar for T
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> Template for T
impl<T> Template for T
Source§fn build_template(
&self,
_context: &mut TemplateContext<'_, '_>,
) -> Result<<T as Template>::Output, BevyError>
fn build_template( &self, _context: &mut TemplateContext<'_, '_>, ) -> Result<<T as Template>::Output, BevyError>
entity context to produce a Template::Output.Source§fn clone_template(&self) -> T
fn clone_template(&self) -> T
Clone.