mirror of
https://github.com/bevyengine/bevy
synced 2024-11-25 22:20:20 +00:00
11b41206eb
This updates the `pipelined-rendering` branch to use the latest `bevy_ecs` from `main`. This accomplishes a couple of goals: 1. prepares for upcoming `custom-shaders` branch changes, which were what drove many of the recent bevy_ecs changes on `main` 2. prepares for the soon-to-happen merge of `pipelined-rendering` into `main`. By including bevy_ecs changes now, we make that merge simpler / easier to review. I split this up into 3 commits: 1. **add upstream bevy_ecs**: please don't bother reviewing this content. it has already received thorough review on `main` and is a literal copy/paste of the relevant folders (the old folders were deleted so the directories are literally exactly the same as `main`). 2. **support manual buffer application in stages**: this is used to enable the Extract step. we've already reviewed this once on the `pipelined-rendering` branch, but its worth looking at one more time in the new context of (1). 3. **support manual archetype updates in QueryState**: same situation as (2).
67 lines
2 KiB
Rust
67 lines
2 KiB
Rust
use bevy::{
|
|
input::gamepad::{Gamepad, GamepadButton, GamepadEvent, GamepadEventType},
|
|
prelude::*,
|
|
utils::HashSet,
|
|
};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.init_resource::<GamepadLobby>()
|
|
.add_system_to_stage(CoreStage::PreUpdate, connection_system)
|
|
.add_system(gamepad_system)
|
|
.run();
|
|
}
|
|
|
|
#[derive(Default)]
|
|
struct GamepadLobby {
|
|
gamepads: HashSet<Gamepad>,
|
|
}
|
|
|
|
fn connection_system(
|
|
mut lobby: ResMut<GamepadLobby>,
|
|
mut gamepad_event: EventReader<GamepadEvent>,
|
|
) {
|
|
for event in gamepad_event.iter() {
|
|
match &event {
|
|
GamepadEvent(gamepad, GamepadEventType::Connected) => {
|
|
lobby.gamepads.insert(*gamepad);
|
|
info!("{:?} Connected", gamepad);
|
|
}
|
|
GamepadEvent(gamepad, GamepadEventType::Disconnected) => {
|
|
lobby.gamepads.remove(gamepad);
|
|
info!("{:?} Disconnected", gamepad);
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn gamepad_system(
|
|
lobby: Res<GamepadLobby>,
|
|
button_inputs: Res<Input<GamepadButton>>,
|
|
button_axes: Res<Axis<GamepadButton>>,
|
|
axes: Res<Axis<GamepadAxis>>,
|
|
) {
|
|
for gamepad in lobby.gamepads.iter().cloned() {
|
|
if button_inputs.just_pressed(GamepadButton(gamepad, GamepadButtonType::South)) {
|
|
info!("{:?} just pressed South", gamepad);
|
|
} else if button_inputs.just_released(GamepadButton(gamepad, GamepadButtonType::South)) {
|
|
info!("{:?} just released South", gamepad);
|
|
}
|
|
|
|
let right_trigger = button_axes
|
|
.get(GamepadButton(gamepad, GamepadButtonType::RightTrigger2))
|
|
.unwrap();
|
|
if right_trigger.abs() > 0.01 {
|
|
info!("{:?} RightTrigger2 value is {}", gamepad, right_trigger);
|
|
}
|
|
|
|
let left_stick_x = axes
|
|
.get(GamepadAxis(gamepad, GamepadAxisType::LeftStickX))
|
|
.unwrap();
|
|
if left_stick_x.abs() > 0.01 {
|
|
info!("{:?} LeftStickX value is {}", gamepad, left_stick_x);
|
|
}
|
|
}
|
|
}
|