From 5b09aeeac16a69efe01b31238053fab440644168 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Tue, 27 Jan 2026 16:02:38 -0600 Subject: [PATCH 01/15] refactor: remove ControlMapping & ControlSource requirements The InputCollector's job is entirely local. It does not need to access any network updated resources. It's job is to get the local player's current inputs however neccessary. This means both the ControlMapping and the ControlSource can be handled with local resources or Self stored fields/values if neccessary. --- framework_crates/bones_framework/src/input.rs | 19 ++----------- .../bones_framework/src/networking.rs | 28 ++++--------------- .../bones_framework/src/networking/input.rs | 18 ++++-------- 3 files changed, 15 insertions(+), 50 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index 2891298155..6c8b78a799 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -42,9 +42,7 @@ pub mod prelude { /// [`InputCollector::advance_frame`] is used to mark that the input has been consumed, and update the prev frame inputs to current, to compute changes next frame. /// /// Generic type param ControlMapping is HasSchema because it is expected to be a Resource retrievable on world. -pub trait InputCollector<'a, ControlMapping: HasSchema, ControlSource, Control>: - Send + Sync -{ +pub trait InputCollector<'a, Control>: Send + Sync { /// Update the internal state with new inputs. This must be called every render frame with the /// input events. This updates which buttons are pressed, but does not compute what buttons were "just_pressed". /// use [`InputCollector::update_just_pressed`] to do this. @@ -63,26 +61,15 @@ pub trait InputCollector<'a, ControlMapping: HasSchema, ControlSource, Control>: fn update_just_pressed(&mut self); /// Get control for player based on provided `ControlSource`. - fn get_control(&self, player_idx: usize, control_source: ControlSource) -> &Control; + fn get_control(&self) -> &Control; } /// Trait that tracks player control state. Provides associated types for other input trait implementations. pub trait PlayerControls<'a, Control> { /// InputCollector used to update controls. - type InputCollector: InputCollector<'a, Self::ControlMapping, Self::ControlSource, Control>; - - /// Control mapping from raw input, expected to be able to be retrieved as `Resource` from world. - type ControlMapping: HasSchema; - - /// Type used to map source of input to control. - type ControlSource; - + type InputCollector: InputCollector<'a, Control>; /// Update control state from input collector. fn update_controls(&mut self, collector: &mut Self::InputCollector); - - /// Get `ControlSource` for player (only present for local player). - fn get_control_source(&self, local_player_idx: usize) -> Option; - /// Get control for player. fn get_control(&self, player_idx: usize) -> &Control; diff --git a/framework_crates/bones_framework/src/networking.rs b/framework_crates/bones_framework/src/networking.rs index 4e71fc3c2c..3b8438fbed 100644 --- a/framework_crates/bones_framework/src/networking.rs +++ b/framework_crates/bones_framework/src/networking.rs @@ -20,8 +20,6 @@ use { ggrs::{NetworkStats, PlayerHandle}, }; -use crate::input::PlayerControls as PlayerControlsTrait; - pub use iroh; pub mod input; @@ -658,26 +656,12 @@ where let mut skip_frames: u32 = 0; - { - let player_inputs = world.resource::(); - - // Collect inputs and update controls - self.input_collector.apply_inputs(world); - self.input_collector.update_just_pressed(); - - // save local players dense input for use with ggrs - match player_inputs.get_control_source(self.local_player_idx as usize) { - Some(control_source) => { - let control = self - .input_collector - .get_control(self.local_player_idx as usize, control_source); - - self.last_player_input = control.get_dense_input(); - }, - None => warn!("GgrsSessionRunner local_player_idx {} has no control source, no local input provided.", - self.local_player_idx) - }; - } + // Collect inputs and update controls + self.input_collector.apply_inputs(world); + self.input_collector.update_just_pressed(); + + // save local players dense input for use with ggrs + self.last_player_input = self.input_collector.get_control().get_dense_input(); #[cfg(feature = "net-debug")] // Current frame before we start network update loop diff --git a/framework_crates/bones_framework/src/networking/input.rs b/framework_crates/bones_framework/src/networking/input.rs index a4a737733f..2222e0fb9c 100644 --- a/framework_crates/bones_framework/src/networking/input.rs +++ b/framework_crates/bones_framework/src/networking/input.rs @@ -22,12 +22,7 @@ pub trait NetworkInputConfig<'a> { type PlayerControls: PlayerControls<'a, Self::Control> + HasSchema; // InputCollector type params must match that of PlayerControls, so using associated types. - type InputCollector: InputCollector< - 'a, - >::ControlMapping, - >::ControlSource, - Self::Control, - > + Default; + type InputCollector: InputCollector<'a, Self::Control> + Default; } /// Required for use of [`PlayerControls`] in networking. @@ -96,14 +91,14 @@ pub trait NetworkPlayerControl: Send + Sync + Default { /// This trait is automatically implemented for [`InputCollector`]'s such that `Control` /// implements [`NetworkPlayerControl`] (i.e. implements dense input) pub trait NetworkInputCollector<'a, Dense, ControlMapping, ControlSource, Control>: - InputCollector<'a, ControlMapping, ControlSource, Control> + InputCollector<'a, Control> where Dense: DenseInput, ControlMapping: HasSchema, Control: NetworkPlayerControl, { /// Get dense control - fn get_dense_control(&self, player_idx: usize, control_soure: ControlSource) -> Dense; + fn get_dense_control(&self) -> Dense; } /// Provide automatic [`NetworkInputCollector`] for [`InputCollector`] when type parameters @@ -114,10 +109,9 @@ where Dense: DenseInput, Control: NetworkPlayerControl, ControlMapping: HasSchema, - T: InputCollector<'a, ControlMapping, ControlSource, Control>, + T: InputCollector<'a, Control>, { - fn get_dense_control(&self, player_idx: usize, control_source: ControlSource) -> Dense { - self.get_control(player_idx, control_source) - .get_dense_input() + fn get_dense_control(&self) -> Dense { + self.get_control().get_dense_input() } } From 6a10afc4aa07cb92ca1bcbc0ea37c5ae4b1ed205 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Tue, 27 Jan 2026 16:03:06 -0600 Subject: [PATCH 02/15] refactor: remove update_controls from InputCollector This is implemented in jumpy but unused and unneccessary. If anything like this is implemented it should probably be done through a blanket implementation. --- framework_crates/bones_framework/src/input.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index 6c8b78a799..ea94da8a69 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -68,8 +68,7 @@ pub trait InputCollector<'a, Control>: Send + Sync { pub trait PlayerControls<'a, Control> { /// InputCollector used to update controls. type InputCollector: InputCollector<'a, Control>; - /// Update control state from input collector. - fn update_controls(&mut self, collector: &mut Self::InputCollector); + /// Get control for player. fn get_control(&self, player_idx: usize) -> &Control; From 7c2ce0018f78e7b31007d692907e4b97c87e7053 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Tue, 27 Jan 2026 16:03:41 -0600 Subject: [PATCH 03/15] refactor: move wasm32 safe traits out of networking::input module This moves several traits out of networking::input to be used for offline or wasm32 if needed. --- framework_crates/bones_framework/src/input.rs | 74 ++++++++++++++++++- .../bones_framework/src/networking.rs | 6 +- .../bones_framework/src/networking/input.rs | 73 +----------------- 3 files changed, 76 insertions(+), 77 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index ea94da8a69..b9ad42fb4d 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -30,7 +30,10 @@ impl ButtonState { /// Module prelude. pub mod prelude { pub use super::{gamepad::*, keyboard::*, mouse::*, window::*, ButtonState}; - pub use crate::input::{InputCollector, PlayerControls}; + pub use crate::input::{ + DenseInput, InputCollector, NetworkInputCollector, NetworkInputConfig, + NetworkPlayerControl, PlayerControls, + }; } /// Maps raw inputs to game controls and exposes controls for respective player and their control source. @@ -75,3 +78,72 @@ pub trait PlayerControls<'a, Control> { /// Get mutable control for player. fn get_control_mut(&mut self, player_idx: usize) -> &mut Control; } + +use std::fmt::Debug; + +/// Dense input for network replication. +pub trait DenseInput: + bytemuck::Pod + bytemuck::Zeroable + Copy + Clone + PartialEq + Eq + Send + Sync +{ +} + +/// Automatic implementation for `DenseInput`. +impl DenseInput for T where + T: bytemuck::Pod + bytemuck::Zeroable + Copy + Clone + PartialEq + Eq + Send + Sync +{ +} + +/// Define input types used by game for use in networking. +/// +/// As long as types `PlayerControls` and `InputCollector` implement traits [`PlayerControls`] and [`InputCollector`], +/// trait bounds [`NetworkPlayerControl`] and [`NetworkInputCollector`] are automatically implemented. +#[allow(missing_docs)] +pub trait NetworkInputConfig<'a> { + type Dense: DenseInput + Debug + Default; + type Control: NetworkPlayerControl; + + // Must be HasSchema because expected to be retrieved from `World` as `Resource`. + type PlayerControls: PlayerControls<'a, Self::Control> + HasSchema; + + // InputCollector type params must match that of PlayerControls, so using associated types. + type InputCollector: InputCollector<'a, Self::Control> + Default; +} + +/// Trait allowing for creating and applying [`DenseInput`] from control. +pub trait NetworkPlayerControl: Send + Sync + Default { + /// Get [`DenseInput`] for control. + fn get_dense_input(&self) -> Dense; + + /// Update control from [`DenseInput`]. + fn update_from_dense(&mut self, new_control: &Dense); +} + +/// Extension of [`InputCollector`] exposing dense control for networking. +/// +/// This trait is automatically implemented for [`InputCollector`]'s such that `Control` +/// implements [`NetworkPlayerControl`] (i.e. implements dense input) +pub trait NetworkInputCollector<'a, Dense, ControlMapping, ControlSource, Control>: + InputCollector<'a, Control> +where + Dense: DenseInput, + ControlMapping: HasSchema, + Control: NetworkPlayerControl, +{ + /// Get dense control + fn get_dense_control(&self) -> Dense; +} + +/// Provide automatic [`NetworkInputCollector`] for [`InputCollector`] when type parameters +/// meet required bounds for networking. +impl<'a, T, Dense, ControlMapping, ControlSource, Control> + NetworkInputCollector<'a, Dense, ControlMapping, ControlSource, Control> for T +where + Dense: DenseInput, + Control: NetworkPlayerControl, + ControlMapping: HasSchema, + T: InputCollector<'a, Control>, +{ + fn get_dense_control(&self) -> Dense { + self.get_control().get_dense_input() + } +} diff --git a/framework_crates/bones_framework/src/networking.rs b/framework_crates/bones_framework/src/networking.rs index 3b8438fbed..419a48024d 100644 --- a/framework_crates/bones_framework/src/networking.rs +++ b/framework_crates/bones_framework/src/networking.rs @@ -1,9 +1,7 @@ #![doc = include_str!("./networking.md")] -use self::{ - input::{DenseInput, NetworkInputConfig, NetworkPlayerControl, NetworkPlayerControls}, - socket::Socket, -}; +use self::{input::NetworkPlayerControls, socket::Socket}; +use crate::input::{DenseInput, NetworkInputConfig, NetworkPlayerControl}; use crate::networking::online::OnlineMatchmakerResponse; pub use crate::networking::random::RngGenerator; use crate::prelude::*; diff --git a/framework_crates/bones_framework/src/networking/input.rs b/framework_crates/bones_framework/src/networking/input.rs index 2222e0fb9c..5feebb1b17 100644 --- a/framework_crates/bones_framework/src/networking/input.rs +++ b/framework_crates/bones_framework/src/networking/input.rs @@ -1,30 +1,10 @@ //! Input traits required by networking. These traits are networking specific, either only used in networking, //! or extending other traits from [`crate::input`] for networking. -use std::fmt::Debug; - -use bones_schema::HasSchema; - -use crate::input::{InputCollector, PlayerControls}; +use crate::input::{DenseInput, NetworkPlayerControl, PlayerControls}; use super::NetworkInputStatus; -/// Define input types used by game for use in networking. -/// -/// As long as types `PlayerControls` and `InputCollector` implement traits [`PlayerControls`] and [`InputCollector`], -/// trait bounds [`NetworkPlayerControl`] and [`NetworkInputCollector`] are automatically implemented. -#[allow(missing_docs)] -pub trait NetworkInputConfig<'a> { - type Dense: DenseInput + Debug + Default; - type Control: NetworkPlayerControl; - - // Must be HasSchema because expected to be retrieved from `World` as `Resource`. - type PlayerControls: PlayerControls<'a, Self::Control> + HasSchema; - - // InputCollector type params must match that of PlayerControls, so using associated types. - type InputCollector: InputCollector<'a, Self::Control> + Default; -} - /// Required for use of [`PlayerControls`] in networking. pub trait NetworkPlayerControls<'a, Dense: DenseInput, Control>: PlayerControls<'a, Control> @@ -64,54 +44,3 @@ where self.get_control(player_idx).get_dense_input() } } - -/// Dense input for network replication. -pub trait DenseInput: - bytemuck::Pod + bytemuck::Zeroable + Copy + Clone + PartialEq + Eq + Send + Sync -{ -} - -/// Automatic implementation for `DenseInput`. -impl DenseInput for T where - T: bytemuck::Pod + bytemuck::Zeroable + Copy + Clone + PartialEq + Eq + Send + Sync -{ -} - -/// Trait allowing for creating and applying [`DenseInput`] from control. -pub trait NetworkPlayerControl: Send + Sync + Default { - /// Get [`DenseInput`] for control. - fn get_dense_input(&self) -> Dense; - - /// Update control from [`DenseInput`]. - fn update_from_dense(&mut self, new_control: &Dense); -} - -/// Extension of [`InputCollector`] exposing dense control for networking. -/// -/// This trait is automatically implemented for [`InputCollector`]'s such that `Control` -/// implements [`NetworkPlayerControl`] (i.e. implements dense input) -pub trait NetworkInputCollector<'a, Dense, ControlMapping, ControlSource, Control>: - InputCollector<'a, Control> -where - Dense: DenseInput, - ControlMapping: HasSchema, - Control: NetworkPlayerControl, -{ - /// Get dense control - fn get_dense_control(&self) -> Dense; -} - -/// Provide automatic [`NetworkInputCollector`] for [`InputCollector`] when type parameters -/// meet required bounds for networking. -impl<'a, T, Dense, ControlMapping, ControlSource, Control> - NetworkInputCollector<'a, Dense, ControlMapping, ControlSource, Control> for T -where - Dense: DenseInput, - Control: NetworkPlayerControl, - ControlMapping: HasSchema, - T: InputCollector<'a, Control>, -{ - fn get_dense_control(&self) -> Dense { - self.get_control().get_dense_input() - } -} From 18ceea8f06aa134d40792f8fd2a365103ddaa115 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Tue, 27 Jan 2026 16:06:36 -0600 Subject: [PATCH 04/15] refactor: prefix wasm32 safe traits with Dense instead of Network These traits are no longer network specific so the new names are more appropriate. --- framework_crates/bones_framework/src/input.rs | 18 +++++++++--------- .../bones_framework/src/networking.rs | 8 ++++---- .../bones_framework/src/networking/input.rs | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index b9ad42fb4d..811fcaafab 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -31,8 +31,8 @@ impl ButtonState { pub mod prelude { pub use super::{gamepad::*, keyboard::*, mouse::*, window::*, ButtonState}; pub use crate::input::{ - DenseInput, InputCollector, NetworkInputCollector, NetworkInputConfig, - NetworkPlayerControl, PlayerControls, + DenseInput, DenseInputCollector, DenseInputConfig, DensePlayerControl, InputCollector, + PlayerControls, }; } @@ -98,9 +98,9 @@ impl DenseInput for T where /// As long as types `PlayerControls` and `InputCollector` implement traits [`PlayerControls`] and [`InputCollector`], /// trait bounds [`NetworkPlayerControl`] and [`NetworkInputCollector`] are automatically implemented. #[allow(missing_docs)] -pub trait NetworkInputConfig<'a> { +pub trait DenseInputConfig<'a> { type Dense: DenseInput + Debug + Default; - type Control: NetworkPlayerControl; + type Control: DensePlayerControl; // Must be HasSchema because expected to be retrieved from `World` as `Resource`. type PlayerControls: PlayerControls<'a, Self::Control> + HasSchema; @@ -110,7 +110,7 @@ pub trait NetworkInputConfig<'a> { } /// Trait allowing for creating and applying [`DenseInput`] from control. -pub trait NetworkPlayerControl: Send + Sync + Default { +pub trait DensePlayerControl: Send + Sync + Default { /// Get [`DenseInput`] for control. fn get_dense_input(&self) -> Dense; @@ -122,12 +122,12 @@ pub trait NetworkPlayerControl: Send + Sync + Default { /// /// This trait is automatically implemented for [`InputCollector`]'s such that `Control` /// implements [`NetworkPlayerControl`] (i.e. implements dense input) -pub trait NetworkInputCollector<'a, Dense, ControlMapping, ControlSource, Control>: +pub trait DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control>: InputCollector<'a, Control> where Dense: DenseInput, ControlMapping: HasSchema, - Control: NetworkPlayerControl, + Control: DensePlayerControl, { /// Get dense control fn get_dense_control(&self) -> Dense; @@ -136,10 +136,10 @@ where /// Provide automatic [`NetworkInputCollector`] for [`InputCollector`] when type parameters /// meet required bounds for networking. impl<'a, T, Dense, ControlMapping, ControlSource, Control> - NetworkInputCollector<'a, Dense, ControlMapping, ControlSource, Control> for T + DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control> for T where Dense: DenseInput, - Control: NetworkPlayerControl, + Control: DensePlayerControl, ControlMapping: HasSchema, T: InputCollector<'a, Control>, { diff --git a/framework_crates/bones_framework/src/networking.rs b/framework_crates/bones_framework/src/networking.rs index 419a48024d..0b5257a609 100644 --- a/framework_crates/bones_framework/src/networking.rs +++ b/framework_crates/bones_framework/src/networking.rs @@ -1,7 +1,7 @@ #![doc = include_str!("./networking.md")] use self::{input::NetworkPlayerControls, socket::Socket}; -use crate::input::{DenseInput, NetworkInputConfig, NetworkPlayerControl}; +use crate::input::{DenseInput, DenseInputConfig, DensePlayerControl}; use crate::networking::online::OnlineMatchmakerResponse; pub use crate::networking::random::RngGenerator; use crate::prelude::*; @@ -445,7 +445,7 @@ pub struct DisconnectedPlayers { /// [`SessionRunner`] implementation that uses [`ggrs`] for network play. /// /// This is where the whole `ggrs` integration is implemented. -pub struct GgrsSessionRunner<'a, InputTypes: NetworkInputConfig<'a>> { +pub struct GgrsSessionRunner<'a, InputTypes: DenseInputConfig<'a>> { /// The last player input we detected. pub last_player_input: InputTypes::Dense, @@ -536,7 +536,7 @@ impl GgrsSessionRunnerInfo { impl<'a, InputTypes> GgrsSessionRunner<'a, InputTypes> where - InputTypes: NetworkInputConfig<'a>, + InputTypes: DenseInputConfig<'a>, { /// Creates a new session runner from a `OnlineMatchmakerResponse::GameStarting` /// Any input values set as `None` will be set to default. @@ -643,7 +643,7 @@ where impl SessionRunner for GgrsSessionRunner<'static, InputTypes> where - InputTypes: NetworkInputConfig<'static> + 'static, + InputTypes: DenseInputConfig<'static> + 'static, { fn step(&mut self, frame_start: Instant, world: &mut World, stages: &mut SystemStages) { let step: f64 = 1.0 / self.network_fps; diff --git a/framework_crates/bones_framework/src/networking/input.rs b/framework_crates/bones_framework/src/networking/input.rs index 5feebb1b17..e3810f4c13 100644 --- a/framework_crates/bones_framework/src/networking/input.rs +++ b/framework_crates/bones_framework/src/networking/input.rs @@ -1,7 +1,7 @@ //! Input traits required by networking. These traits are networking specific, either only used in networking, //! or extending other traits from [`crate::input`] for networking. -use crate::input::{DenseInput, NetworkPlayerControl, PlayerControls}; +use crate::input::{DenseInput, DensePlayerControl, PlayerControls}; use super::NetworkInputStatus; @@ -26,7 +26,7 @@ pub trait NetworkPlayerControls<'a, Dense: DenseInput, Control>: impl<'a, T, Dense, Control> NetworkPlayerControls<'a, Dense, Control> for T where Dense: DenseInput, - Control: NetworkPlayerControl, + Control: DensePlayerControl, T: PlayerControls<'a, Control>, { // type NetworkControl = PlayerControl; From f90202b28543d16ec0155af8493c99f4dd7ec913 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Tue, 27 Jan 2026 16:06:58 -0600 Subject: [PATCH 05/15] fix: input trait documentation --- framework_crates/bones_framework/src/input.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index 811fcaafab..b3495ec824 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -96,7 +96,7 @@ impl DenseInput for T where /// Define input types used by game for use in networking. /// /// As long as types `PlayerControls` and `InputCollector` implement traits [`PlayerControls`] and [`InputCollector`], -/// trait bounds [`NetworkPlayerControl`] and [`NetworkInputCollector`] are automatically implemented. +/// trait bounds [`DensePlayerControl`] and [`DenseInputCollector`] are automatically implemented. #[allow(missing_docs)] pub trait DenseInputConfig<'a> { type Dense: DenseInput + Debug + Default; @@ -121,7 +121,7 @@ pub trait DensePlayerControl: Send + Sync + Default { /// Extension of [`InputCollector`] exposing dense control for networking. /// /// This trait is automatically implemented for [`InputCollector`]'s such that `Control` -/// implements [`NetworkPlayerControl`] (i.e. implements dense input) +/// implements [`DensePlayerControl`] (i.e. implements dense input) pub trait DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control>: InputCollector<'a, Control> where @@ -133,7 +133,7 @@ where fn get_dense_control(&self) -> Dense; } -/// Provide automatic [`NetworkInputCollector`] for [`InputCollector`] when type parameters +/// Provide automatic [`DenseInputCollector`] for [`InputCollector`] when type parameters /// meet required bounds for networking. impl<'a, T, Dense, ControlMapping, ControlSource, Control> DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control> for T From e5795674f315f2c0e45a4270a65feadba6e58485 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Tue, 27 Jan 2026 17:54:57 -0600 Subject: [PATCH 06/15] refactor: move proto out of network module --- framework_crates/bones_framework/src/input.rs | 3 ++- .../bones_framework/src/{networking => input}/proto.rs | 0 framework_crates/bones_framework/src/networking.rs | 3 +-- 3 files changed, 3 insertions(+), 3 deletions(-) rename framework_crates/bones_framework/src/{networking => input}/proto.rs (100%) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index b3495ec824..3722ae08e1 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -7,6 +7,7 @@ pub mod gamepad; pub mod gilrs; pub mod keyboard; pub mod mouse; +pub mod proto; pub mod window; /// The state of a button, ether pressed or released. @@ -29,7 +30,7 @@ impl ButtonState { /// Module prelude. pub mod prelude { - pub use super::{gamepad::*, keyboard::*, mouse::*, window::*, ButtonState}; + pub use super::{gamepad::*, keyboard::*, mouse::*, proto, window::*, ButtonState}; pub use crate::input::{ DenseInput, DenseInputCollector, DenseInputConfig, DensePlayerControl, InputCollector, PlayerControls, diff --git a/framework_crates/bones_framework/src/networking/proto.rs b/framework_crates/bones_framework/src/input/proto.rs similarity index 100% rename from framework_crates/bones_framework/src/networking/proto.rs rename to framework_crates/bones_framework/src/input/proto.rs diff --git a/framework_crates/bones_framework/src/networking.rs b/framework_crates/bones_framework/src/networking.rs index 0b5257a609..c27d261a21 100644 --- a/framework_crates/bones_framework/src/networking.rs +++ b/framework_crates/bones_framework/src/networking.rs @@ -25,7 +25,6 @@ pub mod lan; pub mod online; pub mod online_lobby; pub mod online_matchmaking; -pub mod proto; pub mod random; pub mod socket; @@ -60,7 +59,7 @@ impl From for NetworkInputStatus { /// Module prelude. pub mod prelude { pub use super::{ - input, lan, online, proto, random, DisconnectedPlayers, RngGenerator, SyncingInfo, RUNTIME, + input, lan, online, random, DisconnectedPlayers, RngGenerator, SyncingInfo, RUNTIME, }; #[cfg(feature = "net-debug")] From dd778b983403242cf99a13fb9266f648811ba646 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 09:15:56 -0600 Subject: [PATCH 07/15] fix: proto move by allowing numquant on wasm32 --- framework_crates/bones_framework/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework_crates/bones_framework/Cargo.toml b/framework_crates/bones_framework/Cargo.toml index 7c266dd720..0cba3411c4 100644 --- a/framework_crates/bones_framework/Cargo.toml +++ b/framework_crates/bones_framework/Cargo.toml @@ -103,6 +103,7 @@ once_cell = "1.17" thiserror = "1.0" gilrs = "0.11.0" send_wrapper = "0.6.0" +numquant = "0.2" # Tracing @@ -147,7 +148,6 @@ ggrs = { git = "https://github.com/MaxCWhitehead/ggrs.git", rev = "96499377407ce bones_matchmaker_proto = { version = "0.4.0", path = "../../other_crates/bones_matchmaker_proto" } bytes = "1.4" mdns-sd = { version = "0.10", default-features = false } -numquant = "0.2" ping-rs = "0.1" postcard = { version = "1.0", features = ["alloc"] } rcgen = "0.12" From d113c679b98afaaeee3015a62299dfc5fdf31f42 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 09:57:46 -0600 Subject: [PATCH 08/15] rename: DensePlayerControl to DenseControl --- framework_crates/bones_framework/src/input.rs | 10 +++++----- framework_crates/bones_framework/src/networking.rs | 2 +- .../bones_framework/src/networking/input.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index 3722ae08e1..057c4112f5 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -32,7 +32,7 @@ impl ButtonState { pub mod prelude { pub use super::{gamepad::*, keyboard::*, mouse::*, proto, window::*, ButtonState}; pub use crate::input::{ - DenseInput, DenseInputCollector, DenseInputConfig, DensePlayerControl, InputCollector, + DenseControl, DenseInput, DenseInputCollector, DenseInputConfig, InputCollector, PlayerControls, }; } @@ -101,7 +101,7 @@ impl DenseInput for T where #[allow(missing_docs)] pub trait DenseInputConfig<'a> { type Dense: DenseInput + Debug + Default; - type Control: DensePlayerControl; + type Control: DenseControl; // Must be HasSchema because expected to be retrieved from `World` as `Resource`. type PlayerControls: PlayerControls<'a, Self::Control> + HasSchema; @@ -111,7 +111,7 @@ pub trait DenseInputConfig<'a> { } /// Trait allowing for creating and applying [`DenseInput`] from control. -pub trait DensePlayerControl: Send + Sync + Default { +pub trait DenseControl: Send + Sync + Default { /// Get [`DenseInput`] for control. fn get_dense_input(&self) -> Dense; @@ -128,7 +128,7 @@ pub trait DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control> where Dense: DenseInput, ControlMapping: HasSchema, - Control: DensePlayerControl, + Control: DenseControl, { /// Get dense control fn get_dense_control(&self) -> Dense; @@ -140,7 +140,7 @@ impl<'a, T, Dense, ControlMapping, ControlSource, Control> DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control> for T where Dense: DenseInput, - Control: DensePlayerControl, + Control: DenseControl, ControlMapping: HasSchema, T: InputCollector<'a, Control>, { diff --git a/framework_crates/bones_framework/src/networking.rs b/framework_crates/bones_framework/src/networking.rs index c27d261a21..6d6c0a3def 100644 --- a/framework_crates/bones_framework/src/networking.rs +++ b/framework_crates/bones_framework/src/networking.rs @@ -1,7 +1,7 @@ #![doc = include_str!("./networking.md")] use self::{input::NetworkPlayerControls, socket::Socket}; -use crate::input::{DenseInput, DenseInputConfig, DensePlayerControl}; +use crate::input::{DenseControl, DenseInput, DenseInputConfig}; use crate::networking::online::OnlineMatchmakerResponse; pub use crate::networking::random::RngGenerator; use crate::prelude::*; diff --git a/framework_crates/bones_framework/src/networking/input.rs b/framework_crates/bones_framework/src/networking/input.rs index e3810f4c13..ab49c75ea4 100644 --- a/framework_crates/bones_framework/src/networking/input.rs +++ b/framework_crates/bones_framework/src/networking/input.rs @@ -1,7 +1,7 @@ //! Input traits required by networking. These traits are networking specific, either only used in networking, //! or extending other traits from [`crate::input`] for networking. -use crate::input::{DenseInput, DensePlayerControl, PlayerControls}; +use crate::input::{DenseControl, DenseInput, PlayerControls}; use super::NetworkInputStatus; @@ -26,7 +26,7 @@ pub trait NetworkPlayerControls<'a, Dense: DenseInput, Control>: impl<'a, T, Dense, Control> NetworkPlayerControls<'a, Dense, Control> for T where Dense: DenseInput, - Control: DensePlayerControl, + Control: DenseControl, T: PlayerControls<'a, Control>, { // type NetworkControl = PlayerControl; From 106c142d114fccf71d8a5c491707e6f97e45b915 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 10:01:43 -0600 Subject: [PATCH 09/15] rename: PlayerControls to Controls --- framework_crates/bones_framework/src/input.rs | 7 +++---- framework_crates/bones_framework/src/networking.rs | 2 +- framework_crates/bones_framework/src/networking/input.rs | 8 +++----- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index 057c4112f5..b848b85656 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -32,8 +32,7 @@ impl ButtonState { pub mod prelude { pub use super::{gamepad::*, keyboard::*, mouse::*, proto, window::*, ButtonState}; pub use crate::input::{ - DenseControl, DenseInput, DenseInputCollector, DenseInputConfig, InputCollector, - PlayerControls, + Controls, DenseControl, DenseInput, DenseInputCollector, DenseInputConfig, InputCollector, }; } @@ -69,7 +68,7 @@ pub trait InputCollector<'a, Control>: Send + Sync { } /// Trait that tracks player control state. Provides associated types for other input trait implementations. -pub trait PlayerControls<'a, Control> { +pub trait Controls<'a, Control> { /// InputCollector used to update controls. type InputCollector: InputCollector<'a, Control>; @@ -104,7 +103,7 @@ pub trait DenseInputConfig<'a> { type Control: DenseControl; // Must be HasSchema because expected to be retrieved from `World` as `Resource`. - type PlayerControls: PlayerControls<'a, Self::Control> + HasSchema; + type Controls: Controls<'a, Self::Control> + HasSchema; // InputCollector type params must match that of PlayerControls, so using associated types. type InputCollector: InputCollector<'a, Self::Control> + Default; diff --git a/framework_crates/bones_framework/src/networking.rs b/framework_crates/bones_framework/src/networking.rs index 6d6c0a3def..a5f7f883f3 100644 --- a/framework_crates/bones_framework/src/networking.rs +++ b/framework_crates/bones_framework/src/networking.rs @@ -843,7 +843,7 @@ where // update game controls from ggrs inputs let mut player_inputs = - world.resource_mut::(); + world.resource_mut::(); for (player_idx, (input, status)) in network_inputs.into_iter().enumerate() { diff --git a/framework_crates/bones_framework/src/networking/input.rs b/framework_crates/bones_framework/src/networking/input.rs index ab49c75ea4..1a38dde572 100644 --- a/framework_crates/bones_framework/src/networking/input.rs +++ b/framework_crates/bones_framework/src/networking/input.rs @@ -1,14 +1,12 @@ //! Input traits required by networking. These traits are networking specific, either only used in networking, //! or extending other traits from [`crate::input`] for networking. -use crate::input::{DenseControl, DenseInput, PlayerControls}; +use crate::input::{Controls, DenseControl, DenseInput}; use super::NetworkInputStatus; /// Required for use of [`PlayerControls`] in networking. -pub trait NetworkPlayerControls<'a, Dense: DenseInput, Control>: - PlayerControls<'a, Control> -{ +pub trait NetworkPlayerControls<'a, Dense: DenseInput, Control>: Controls<'a, Control> { /// Update control of player from dense input. /// /// [`NetworkInputStatus`] communicates if input is confirmed, predicted, or from disconnected player. @@ -27,7 +25,7 @@ impl<'a, T, Dense, Control> NetworkPlayerControls<'a, Dense, Control> for T where Dense: DenseInput, Control: DenseControl, - T: PlayerControls<'a, Control>, + T: Controls<'a, Control>, { // type NetworkControl = PlayerControl; fn network_update( From 5cc784d9c76b0636916baf6739868bbf82a91917 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 10:03:46 -0600 Subject: [PATCH 10/15] fix: documentation per renaming --- framework_crates/bones_framework/src/input.rs | 8 ++++---- framework_crates/bones_framework/src/networking/input.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index b848b85656..5ea083f498 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -95,8 +95,8 @@ impl DenseInput for T where /// Define input types used by game for use in networking. /// -/// As long as types `PlayerControls` and `InputCollector` implement traits [`PlayerControls`] and [`InputCollector`], -/// trait bounds [`DensePlayerControl`] and [`DenseInputCollector`] are automatically implemented. +/// As long as types `Controls` and `InputCollector` implement traits [`Controls`] and [`InputCollector`], +/// trait bounds [`DenseControl`] and [`DenseInputCollector`] are automatically implemented. #[allow(missing_docs)] pub trait DenseInputConfig<'a> { type Dense: DenseInput + Debug + Default; @@ -105,7 +105,7 @@ pub trait DenseInputConfig<'a> { // Must be HasSchema because expected to be retrieved from `World` as `Resource`. type Controls: Controls<'a, Self::Control> + HasSchema; - // InputCollector type params must match that of PlayerControls, so using associated types. + // InputCollector type params must match that of Controls, so using associated types. type InputCollector: InputCollector<'a, Self::Control> + Default; } @@ -121,7 +121,7 @@ pub trait DenseControl: Send + Sync + Default { /// Extension of [`InputCollector`] exposing dense control for networking. /// /// This trait is automatically implemented for [`InputCollector`]'s such that `Control` -/// implements [`DensePlayerControl`] (i.e. implements dense input) +/// implements [`DenseControl`] (i.e. implements dense input) pub trait DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control>: InputCollector<'a, Control> where diff --git a/framework_crates/bones_framework/src/networking/input.rs b/framework_crates/bones_framework/src/networking/input.rs index 1a38dde572..1a4caa454f 100644 --- a/framework_crates/bones_framework/src/networking/input.rs +++ b/framework_crates/bones_framework/src/networking/input.rs @@ -5,7 +5,7 @@ use crate::input::{Controls, DenseControl, DenseInput}; use super::NetworkInputStatus; -/// Required for use of [`PlayerControls`] in networking. +/// Required for use of [`Controls`] in networking. pub trait NetworkPlayerControls<'a, Dense: DenseInput, Control>: Controls<'a, Control> { /// Update control of player from dense input. /// @@ -27,7 +27,7 @@ where Control: DenseControl, T: Controls<'a, Control>, { - // type NetworkControl = PlayerControl; + // type NetworkControl = Control; fn network_update( &mut self, player_idx: usize, From 2953d99683aab4cfc0f0de7c508c1ce2d111866f Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 10:05:59 -0600 Subject: [PATCH 11/15] rename: NetworkPlayerControls to NetworkControls --- framework_crates/bones_framework/src/networking.rs | 2 +- framework_crates/bones_framework/src/networking/input.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/framework_crates/bones_framework/src/networking.rs b/framework_crates/bones_framework/src/networking.rs index a5f7f883f3..b7953687b1 100644 --- a/framework_crates/bones_framework/src/networking.rs +++ b/framework_crates/bones_framework/src/networking.rs @@ -1,6 +1,6 @@ #![doc = include_str!("./networking.md")] -use self::{input::NetworkPlayerControls, socket::Socket}; +use self::{input::NetworkControls, socket::Socket}; use crate::input::{DenseControl, DenseInput, DenseInputConfig}; use crate::networking::online::OnlineMatchmakerResponse; pub use crate::networking::random::RngGenerator; diff --git a/framework_crates/bones_framework/src/networking/input.rs b/framework_crates/bones_framework/src/networking/input.rs index 1a4caa454f..52ff4eb826 100644 --- a/framework_crates/bones_framework/src/networking/input.rs +++ b/framework_crates/bones_framework/src/networking/input.rs @@ -6,7 +6,7 @@ use crate::input::{Controls, DenseControl, DenseInput}; use super::NetworkInputStatus; /// Required for use of [`Controls`] in networking. -pub trait NetworkPlayerControls<'a, Dense: DenseInput, Control>: Controls<'a, Control> { +pub trait NetworkControls<'a, Dense: DenseInput, Control>: Controls<'a, Control> { /// Update control of player from dense input. /// /// [`NetworkInputStatus`] communicates if input is confirmed, predicted, or from disconnected player. @@ -21,7 +21,7 @@ pub trait NetworkPlayerControls<'a, Dense: DenseInput, Control>: Controls<'a, Co fn get_dense_control(&self, player_idx: usize) -> Dense; } -impl<'a, T, Dense, Control> NetworkPlayerControls<'a, Dense, Control> for T +impl<'a, T, Dense, Control> NetworkControls<'a, Dense, Control> for T where Dense: DenseInput, Control: DenseControl, From e5c7a03e37e9c3045574e0d215a64168a3a488f5 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 10:12:20 -0600 Subject: [PATCH 12/15] fix: remove unused generics --- framework_crates/bones_framework/src/input.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index 5ea083f498..11af85fbf9 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -122,11 +122,9 @@ pub trait DenseControl: Send + Sync + Default { /// /// This trait is automatically implemented for [`InputCollector`]'s such that `Control` /// implements [`DenseControl`] (i.e. implements dense input) -pub trait DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control>: - InputCollector<'a, Control> +pub trait DenseInputCollector<'a, Dense, Control>: InputCollector<'a, Control> where Dense: DenseInput, - ControlMapping: HasSchema, Control: DenseControl, { /// Get dense control @@ -135,12 +133,10 @@ where /// Provide automatic [`DenseInputCollector`] for [`InputCollector`] when type parameters /// meet required bounds for networking. -impl<'a, T, Dense, ControlMapping, ControlSource, Control> - DenseInputCollector<'a, Dense, ControlMapping, ControlSource, Control> for T +impl<'a, T, Dense, Control> DenseInputCollector<'a, Dense, Control> for T where Dense: DenseInput, Control: DenseControl, - ControlMapping: HasSchema, T: InputCollector<'a, Control>, { fn get_dense_control(&self) -> Dense { From ce073fad031fd6336a9faf789b079d514e71c7c5 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 10:13:42 -0600 Subject: [PATCH 13/15] fix: remove old doc comments --- framework_crates/bones_framework/src/input.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index 11af85fbf9..a90eb67586 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -43,8 +43,6 @@ pub mod prelude { /// [`InputCollector::update_just_pressed`] computes any changes in pressed buttons that may be stored on control. /// /// [`InputCollector::advance_frame`] is used to mark that the input has been consumed, and update the prev frame inputs to current, to compute changes next frame. -/// -/// Generic type param ControlMapping is HasSchema because it is expected to be a Resource retrievable on world. pub trait InputCollector<'a, Control>: Send + Sync { /// Update the internal state with new inputs. This must be called every render frame with the /// input events. This updates which buttons are pressed, but does not compute what buttons were "just_pressed". @@ -63,7 +61,7 @@ pub trait InputCollector<'a, Control>: Send + Sync { /// This does not modify previous frame's input, to do this use [`InputCollector::advance_frame`]. fn update_just_pressed(&mut self); - /// Get control for player based on provided `ControlSource`. + /// Get control for player. fn get_control(&self) -> &Control; } From 075ead4c9eea286cce311adb6a92efc3e7a193e9 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 10:15:35 -0600 Subject: [PATCH 14/15] fix: remove unused trait type --- framework_crates/bones_framework/src/input.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/framework_crates/bones_framework/src/input.rs b/framework_crates/bones_framework/src/input.rs index a90eb67586..d87a74837f 100644 --- a/framework_crates/bones_framework/src/input.rs +++ b/framework_crates/bones_framework/src/input.rs @@ -67,9 +67,6 @@ pub trait InputCollector<'a, Control>: Send + Sync { /// Trait that tracks player control state. Provides associated types for other input trait implementations. pub trait Controls<'a, Control> { - /// InputCollector used to update controls. - type InputCollector: InputCollector<'a, Control>; - /// Get control for player. fn get_control(&self, player_idx: usize) -> &Control; From d1efaa785b436afe4061ce05831cc75343d32ed1 Mon Sep 17 00:00:00 2001 From: Tekhnae Raav Date: Wed, 28 Jan 2026 15:39:48 -0600 Subject: [PATCH 15/15] fix: broken doc link --- framework_crates/bones_framework/src/input/proto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework_crates/bones_framework/src/input/proto.rs b/framework_crates/bones_framework/src/input/proto.rs index 126b052c6a..842ad72cb2 100644 --- a/framework_crates/bones_framework/src/input/proto.rs +++ b/framework_crates/bones_framework/src/input/proto.rs @@ -6,7 +6,7 @@ use numquant::{IntRange, Quantized}; use crate::prelude::*; /// A newtype around [`Vec2`] that implements [`From`] and [`Into`] as a way to compress -/// user stick input for use in [`self::input::DenseInput`]. +/// user stick input for use in [`crate::input::DenseInput`]. #[derive(Debug, Deref, DerefMut, Default)] pub struct DenseMoveDirection(pub Vec2);