Trait bones_framework::input::InputCollector
source · pub trait InputCollector<'a, ControlMapping: HasSchema, ControlSource, Control>: Send + Sync {
// Required methods
fn apply_inputs(
&mut self,
mapping: &ControlMapping,
keyboard: &KeyboardInputs,
gamepad: &GamepadInputs,
);
fn advance_frame(&mut self);
fn update_just_pressed(&mut self);
fn get_control(
&self,
player_idx: usize,
control_source: ControlSource,
) -> &Control;
}
Expand description
Maps raw inputs to game controls and exposes controls for respective player and their control source.
InputCollector::apply_inputs
maps raw input to game controls and updates them.
InputCollector::update_just_pressed
computes any changes in pressed buttons that may be stored on control.
InputCollector::advance_frame
is used to mark that the input has been consumed, and update the prev frame inputs to current, to compute changes next frame.
Generic type param ControlMapping is HasSchema because it is expected to be a Resource retrievable on world.
Required Methods§
sourcefn apply_inputs(
&mut self,
mapping: &ControlMapping,
keyboard: &KeyboardInputs,
gamepad: &GamepadInputs,
)
fn apply_inputs( &mut self, mapping: &ControlMapping, keyboard: &KeyboardInputs, gamepad: &GamepadInputs, )
Update the internal state with new inputs. This must be called every render frame with the
input events. This updates which buttons are pressed, but does not compute what buttons were “just_pressed”.
use InputCollector::update_just_pressed
to do this.
sourcefn advance_frame(&mut self)
fn advance_frame(&mut self)
Indicate input for this frame has been consumed. An implementation of InputCollector
that is
used with a fixed simulation step may track what keys are currently pressed, and what keys were “just pressed”,
(changing from previous state).
This saves current inputs as previous frame’s inputs, allowing for determining what is “just pressed” next frame.
sourcefn update_just_pressed(&mut self)
fn update_just_pressed(&mut self)
Update which buttons have been “just pressed”, when input has changed from last frame and current input state.
This does not modify previous frame’s input, to do this use InputCollector::advance_frame
.
sourcefn get_control(
&self,
player_idx: usize,
control_source: ControlSource,
) -> &Control
fn get_control( &self, player_idx: usize, control_source: ControlSource, ) -> &Control
Get control for player based on provided ControlSource
.