From 1836ac3c6b2abd5dce487f1d7589cfe7466c0fd2 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Fri, 19 Sep 2025 12:02:54 +1200 Subject: Gate gamepad support behind a feature flag This is to make it possible to compile bedrock-pc without gamepad support, which is useful when the target platform doesn't have the libraries for udev (required by the gilrs dependency). This commit is a bit of a hack, it'd be nice to implement this better some day. --- src/emulators/graphical_emulator.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/emulators') 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, pub debug: DebugState, + #[cfg(feature = "gamepad")] pub gilrs: Option, 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) { 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); -- cgit v1.2.3-70-g09d2