Move mouse event reader into system local variable

This commit is contained in:
Felix Ableitner 2021-01-02 22:34:05 +01:00
parent b38d86f54f
commit 105c93e012

View file

@ -17,18 +17,12 @@ pub struct PlayerPlugin;
impl Plugin for PlayerPlugin {
fn build(&self, app: &mut AppBuilder) {
app
.init_resource::<State>()
.add_system(player_movement_system.system())
.add_system(player_look_system.system())
.add_startup_system(init_player.system());
}
}
#[derive(Default)]
struct State {
mouse_motion_event_reader: EventReader<MouseMotion>,
}
#[derive(Default)]
struct PlayerMarker;
@ -133,12 +127,12 @@ fn movement_axis(input: &Res<Input<KeyCode>>, plus: KeyCode, minus: KeyCode) ->
fn player_look_system(
time: Res<Time>,
mut state: ResMut<State>,
mut mouse_event_reader: Local<EventReader<MouseMotion>>,
mouse_motion_events: Res<Events<MouseMotion>>,
mut query: Query<(&mut Transform, &mut CameraData)>,
) {
let mut delta: Vec2 = Vec2::zero();
for event in state.mouse_motion_event_reader.iter(&mouse_motion_events) {
for event in mouse_event_reader.iter(&mouse_motion_events) {
delta += event.delta;
}
if delta.is_nan() {