summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml5
-rw-r--r--src/devices/input_device.rs1
-rw-r--r--src/emulators/graphical_emulator.rs24
-rw-r--r--src/types/controller.rs6
4 files changed, 23 insertions, 13 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 72ffb28..30941df 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,12 +16,15 @@ switchboard = { git = "git://benbridle.com/switchboard", tag = "v2.1.0" }
vagabond = { git = "git://benbridle.com/vagabond", tag = "v1.1.1" }
chrono = { version = "0.4.38" }
-gilrs = "0.11.0"
+gilrs = { version = "0.11.0", optional = true }
dirs-next = "1.0.2"
[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = "0.58.0", features = ["Win32_Storage_FileSystem"] }
+[features]
+default = ["gamepad"]
+gamepad = ["dep:gilrs"]
[profile.release]
lto=true
diff --git a/src/devices/input_device.rs b/src/devices/input_device.rs
index d4e0cb0..3ebeb4c 100644
--- a/src/devices/input_device.rs
+++ b/src/devices/input_device.rs
@@ -132,6 +132,7 @@ impl InputDevice {
}
}
+ #[cfg(feature = "gamepad")]
pub fn on_gamepad_event(&mut self, event: gilrs::Event) {
if let Some(g) = self.gamepad_1.register(event.id) {
self.wake |= g.process_event(&event); return; }
diff --git a/src/emulators/graphical_emulator.rs b/src/emulators/graphical_emulator.rs
index 3d7ea4a..503a8f4 100644
--- a/src/emulators/graphical_emulator.rs
+++ b/src/emulators/graphical_emulator.rs
@@ -1,11 +1,9 @@
use crate::*;
-use gilrs::Gilrs;
-
-
pub struct GraphicalEmulator {
pub br: BedrockEmulator<GraphicalDeviceBus>,
pub debug: DebugState,
+ #[cfg(feature = "gamepad")]
pub gilrs: Option<Gilrs>,
pub fullscreen: bool,
@@ -19,18 +17,18 @@ pub struct GraphicalEmulator {
impl GraphicalEmulator {
pub fn new(config: EmulatorConfig, debug: bool) -> Self {
- let gilrs = match Gilrs::new() {
- Ok(gilrs) => Some(gilrs),
- Err(err) => {
- info!("Could not start gamepad listener: {}", err);
- None
- }
- };
-
Self {
br: BedrockEmulator::new(GraphicalDeviceBus::new(&config)),
debug: DebugState::new(debug, config.symbols_path.as_ref()),
- gilrs,
+
+ #[cfg(feature = "gamepad")]
+ gilrs: match Gilrs::new() {
+ Ok(gilrs) => Some(gilrs),
+ Err(err) => {
+ info!("Could not start gamepad listener: {}", err);
+ None
+ }
+ },
fullscreen: config.fullscreen,
scale: config.zoom.into(),
@@ -205,6 +203,8 @@ impl WindowProgram for GraphicalEmulator {
fn process(&mut self, requests: &mut EventWriter<Request>) {
self.br.dev.stream.flush();
+
+ #[cfg(feature = "gamepad")]
if let Some(gilrs) = &mut self.gilrs {
while let Some(event) = gilrs.next_event() {
self.br.dev.input.on_gamepad_event(event);
diff --git a/src/types/controller.rs b/src/types/controller.rs
index 76b77e3..42d3f8c 100644
--- a/src/types/controller.rs
+++ b/src/types/controller.rs
@@ -1,11 +1,15 @@
use crate::*;
+#[cfg(feature = "gamepad")]
pub use gilrs::{Gilrs, GamepadId};
pub struct OwnedGamepad {
tag: usize,
+ #[cfg(feature = "gamepad")]
id: Option<GamepadId>,
+ #[cfg(not(feature = "gamepad"))]
+ id: Option<()>,
gamepad: Gamepad,
}
@@ -15,6 +19,7 @@ impl OwnedGamepad {
}
/// Returns Some if the ID owns this gamepad.
+ #[cfg(feature = "gamepad")]
pub fn register(&mut self, new_id: GamepadId) -> Option<&mut Gamepad> {
if let Some(id) = self.id {
match id == new_id {
@@ -102,6 +107,7 @@ impl Gamepad {
}
// Returns true if the state changed.
+ #[cfg(feature = "gamepad")]
pub fn process_event(&mut self, event: &gilrs::Event) -> bool {
macro_rules! schmitt {
($name_neg:ident, $name_pos:ident, $v:expr) => {{