From 47f7ae1e6917074b926bed6714a7110f15a376b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Rom=C3=A1n=20N=C3=BA=C3=B1ez?= Date: Fri, 2 Oct 2026 11:19:01 +0000 Subject: [PATCH] Disable GameCube adapter on Windows (#80) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - add a feature flag for the GameCube adapter driver - keep the driver enabled by default on supported platforms - exclude the adapter dependency and polling systems on Windows Reviewed-on: https://git.eirexe.moe/EIREXE/shinespark/pulls/80 Co-authored-by: Álex Román Núñez --- Cargo.toml | 7 ++++-- src/input/gamecube/bridge.rs | 12 ++------- src/input/gamecube/mod.rs | 48 ++++++++++++++++++++++++------------ 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 537e519..78e1f28 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,9 +7,10 @@ authors = [""] [workspace] [features] -default = ["development", "debug_features"] +default = ["development", "debug_features", "gamecube-adapter"] development = ["bevy/dynamic_linking", "bevy/file_watcher", "bevy/embedded_watcher"] debug_features = ["bevy/free_camera"] +gamecube-adapter = ["dep:gc-adapter-neo"] [dependencies] bevy = { version = "0.19", features = ["asset_processor", "basis-universal", "compressed_image_saver", "bevy_settings"] } @@ -34,7 +35,6 @@ strum = "0.28.0" strum_macros = "0.28.0" bevy_asset_loader = "0.27.0" ron_asset_manager = "0.9.0" -gc-adapter-neo = { version = "1.1.1", features = ["libusb"] } rhai = "1.26.0" enum_cycling = "0.2.1" enum_cycling_derive = "0.2.1" @@ -49,3 +49,6 @@ inherits = "release" lto = "thin" codegen-units = 1 strip = "symbols" + +[target.'cfg(not(target_os = "windows"))'.dependencies] +gc-adapter-neo = { version = "1.1.1", features = ["libusb"], optional = true } diff --git a/src/input/gamecube/bridge.rs b/src/input/gamecube/bridge.rs index 97e9030..bb8d7a9 100644 --- a/src/input/gamecube/bridge.rs +++ b/src/input/gamecube/bridge.rs @@ -7,7 +7,8 @@ use bevy::input::gamepad::{ }; use bevy::prelude::*; -use super::poll::{GcAdapterSnapshot, GcPortState}; +use super::GcPorts; +use super::poll::GcAdapterSnapshot; /// GameCube adapters report 4 ports. pub const GC_PORT_COUNT: usize = 4; @@ -23,15 +24,6 @@ const GC_ADAPTER_PID: u16 = 0x0337; #[derive(Component, Debug, Clone, Copy)] pub struct GcPort(pub u8); -/// Tracks which entity (if any) represents each of the 4 adapter ports, -/// and the last snapshot seen, so both systems below can diff instead of -/// re-deriving state every frame. -#[derive(Resource, Default)] -pub struct GcPorts { - pub entities: [Option; GC_PORT_COUNT], - last: [GcPortState; GC_PORT_COUNT], -} - fn passthrough_gamepad_settings() -> GamepadSettings { let mut settings = GamepadSettings::default(); for axis in GamepadAxis::all() { diff --git a/src/input/gamecube/mod.rs b/src/input/gamecube/mod.rs index 35ac83c..8eceb87 100644 --- a/src/input/gamecube/mod.rs +++ b/src/input/gamecube/mod.rs @@ -1,10 +1,23 @@ +#[cfg(all(feature = "gamecube-adapter", not(target_os = "windows")))] pub mod bridge; +#[cfg(all(feature = "gamecube-adapter", not(target_os = "windows")))] pub mod poll; -pub use bridge::{GC_PORT_COUNT, GcPort, GcPorts}; +#[cfg(all(feature = "gamecube-adapter", not(target_os = "windows")))] +pub use bridge::{GC_PORT_COUNT, GcPort}; +#[cfg(all(feature = "gamecube-adapter", not(target_os = "windows")))] pub use poll::{GcAdapterSnapshot, GcPortState}; +#[derive(Resource, Default)] +pub struct GcPorts { + pub entities: [Option; 4], + #[cfg(all(feature = "gamecube-adapter", not(target_os = "windows")))] + pub(super) last: [poll::GcPortState; 4], +} + +#[cfg(all(feature = "gamecube-adapter", not(target_os = "windows")))] use bevy::input::InputSystems; +#[cfg(all(feature = "gamecube-adapter", not(target_os = "windows")))] use bevy::input::gamepad::{gamepad_connection_system, gamepad_event_processing_system}; use bevy::prelude::*; @@ -15,21 +28,24 @@ impl Plugin for GamecubeAdapterPlugin { fn build(&self, app: &mut App) { app.init_resource::(); - let Ok(snapshot) = poll::spawn_poll_thread() else { - // No adapter connected; leave GcPorts empty and skip wiring the - // polling systems. - return; - }; + #[cfg(all(feature = "gamecube-adapter", not(target_os = "windows")))] + { + let Ok(snapshot) = poll::spawn_poll_thread() else { + // No adapter connected; leave GcPorts empty and skip wiring the + // polling systems. + return; + }; - app.insert_resource(snapshot).add_systems( - PreUpdate, - ( - bridge::gc_connection_system.before(gamepad_connection_system), - bridge::gc_event_system - .after(gamepad_connection_system) - .before(gamepad_event_processing_system), - ) - .in_set(InputSystems), - ); + app.insert_resource(snapshot).add_systems( + PreUpdate, + ( + bridge::gc_connection_system.before(gamepad_connection_system), + bridge::gc_event_system + .after(gamepad_connection_system) + .before(gamepad_event_processing_system), + ) + .in_set(InputSystems), + ); + } } }