From f36fc4bd7127517e6e5cd330a27c32bcd689b652 Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 19 Sep 2022 14:46:43 -0400 Subject: [PATCH 1/8] Derived Copy trait for bevy_input events. --- crates/bevy_input/src/gamepad.rs | 10 +++++----- crates/bevy_input/src/keyboard.rs | 2 +- crates/bevy_input/src/mouse.rs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/bevy_input/src/gamepad.rs b/crates/bevy_input/src/gamepad.rs index 1a2734df0cc60..7756fc47af89b 100644 --- a/crates/bevy_input/src/gamepad.rs +++ b/crates/bevy_input/src/gamepad.rs @@ -68,7 +68,7 @@ impl Gamepads { } /// The data contained in a [`GamepadEvent`] or [`GamepadEventRaw`]. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum GamepadEventType { /// A [`Gamepad`] has been connected. @@ -101,7 +101,7 @@ pub enum GamepadEventType { /// [`Axis`], and [`Axis`] resources won't be updated correctly. /// /// An example for gamepad input mocking can be seen in the documentation of the [`GamepadEventRaw`]. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct GamepadEvent { /// The gamepad this event corresponds to. @@ -204,7 +204,7 @@ impl GamepadEvent { /// # /// # bevy_ecs::system::assert_is_system(change_resource_on_gamepad_button_press); /// ``` -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct GamepadEventRaw { /// The gamepad this event corresponds to. @@ -703,7 +703,7 @@ pub fn gamepad_event_system( for event in raw_events.iter() { match event.event_type { GamepadEventType::Connected => { - events.send(GamepadEvent::new(event.gamepad, event.event_type.clone())); + events.send(GamepadEvent::new(event.gamepad, event.event_type)); for button_type in &ALL_BUTTON_TYPES { let gamepad_button = GamepadButton::new(event.gamepad, *button_type); button_input.reset(gamepad_button); @@ -714,7 +714,7 @@ pub fn gamepad_event_system( } } GamepadEventType::Disconnected => { - events.send(GamepadEvent::new(event.gamepad, event.event_type.clone())); + events.send(GamepadEvent::new(event.gamepad, event.event_type)); for button_type in &ALL_BUTTON_TYPES { let gamepad_button = GamepadButton::new(event.gamepad, *button_type); button_input.reset(gamepad_button); diff --git a/crates/bevy_input/src/keyboard.rs b/crates/bevy_input/src/keyboard.rs index de0bdbbe3316a..9239f6b6b0f99 100644 --- a/crates/bevy_input/src/keyboard.rs +++ b/crates/bevy_input/src/keyboard.rs @@ -11,7 +11,7 @@ use bevy_reflect::{FromReflect, Reflect}; /// /// The event is consumed inside of the [`keyboard_input_system`](crate::keyboard::keyboard_input_system) /// to update the [`Input`](crate::Input) resource. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct KeyboardInput { /// The scan code of the key. pub scan_code: u32, diff --git a/crates/bevy_input/src/mouse.rs b/crates/bevy_input/src/mouse.rs index b06a5c2ae355a..8e989c438c52b 100644 --- a/crates/bevy_input/src/mouse.rs +++ b/crates/bevy_input/src/mouse.rs @@ -10,7 +10,7 @@ use bevy_math::Vec2; /// /// The event is read inside of the [`mouse_button_input_system`](crate::mouse::mouse_button_input_system) /// to update the [`Input`](crate::Input) resource. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct MouseButtonInput { /// The mouse button assigned to the event. pub button: MouseButton, @@ -50,7 +50,7 @@ pub enum MouseButton { /// However, the event data does not make it possible to distinguish which device it is referring to. /// /// [`DeviceEvent::MouseMotion`]: https://docs.rs/winit/latest/winit/event/enum.DeviceEvent.html#variant.MouseMotion -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct MouseMotion { /// The change in the position of the pointing device since the last event was sent. pub delta: Vec2, @@ -79,7 +79,7 @@ pub enum MouseScrollUnit { /// A mouse wheel event. /// /// This event is the translated version of the `WindowEvent::MouseWheel` from the `winit` crate. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] pub struct MouseWheel { /// The mouse scroll unit. pub unit: MouseScrollUnit, From e684d797e4b5bd929738cd87d6289adb4716d308 Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 19 Sep 2022 15:34:07 -0400 Subject: [PATCH 2/8] Added serde::Serialize/Deserialize under "serialize" feature for bevy_window. --- crates/bevy_window/Cargo.toml | 1 + crates/bevy_window/src/event.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/crates/bevy_window/Cargo.toml b/crates/bevy_window/Cargo.toml index c974af23651ac..01d8f77bce21c 100644 --- a/crates/bevy_window/Cargo.toml +++ b/crates/bevy_window/Cargo.toml @@ -20,6 +20,7 @@ bevy_input = { path = "../bevy_input", version = "0.9.0-dev" } raw-window-handle = "0.4.2" # other +serde = { version = "1.0", features = ["derive"] } [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = "0.3" diff --git a/crates/bevy_window/src/event.rs b/crates/bevy_window/src/event.rs index 0ac0d01c2d37d..f8e1b3e75c566 100644 --- a/crates/bevy_window/src/event.rs +++ b/crates/bevy_window/src/event.rs @@ -5,6 +5,7 @@ use bevy_math::{IVec2, Vec2}; /// A window event that is sent whenever a window's logical size has changed. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowResized { pub id: WindowId, /// The new logical width of the window. @@ -15,6 +16,7 @@ pub struct WindowResized { /// An event that indicates that a new window should be created. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CreateWindow { pub id: WindowId, pub descriptor: WindowDescriptor, @@ -23,6 +25,7 @@ pub struct CreateWindow { /// An event that indicates the window should redraw, even if its control flow is set to `Wait` and /// there have been no window events. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct RequestRedraw; /// An event that is sent whenever a new window is created. @@ -30,6 +33,7 @@ pub struct RequestRedraw; /// To create a new window, send a [`CreateWindow`] event - this /// event will be sent in the handler for that event. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowCreated { pub id: WindowId, } @@ -46,6 +50,7 @@ pub struct WindowCreated { /// [`Window`]: crate::Window /// [closing]: crate::Window::close #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowCloseRequested { pub id: WindowId, } @@ -55,6 +60,7 @@ pub struct WindowCloseRequested { /// /// [`Window::close`]: crate::Window::close #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowClosed { pub id: WindowId, } @@ -68,6 +74,7 @@ pub struct WindowClosed { /// [`WindowEvent::CursorMoved`]: https://docs.rs/winit/latest/winit/event/enum.WindowEvent.html#variant.CursorMoved /// [`MouseMotion`]: bevy_input::mouse::MouseMotion #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CursorMoved { /// The identifier of the window the cursor has moved on. pub id: WindowId, @@ -77,17 +84,20 @@ pub struct CursorMoved { } /// An event that is sent whenever the user's cursor enters a window. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CursorEntered { pub id: WindowId, } /// An event that is sent whenever the user's cursor leaves a window. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CursorLeft { pub id: WindowId, } /// An event that is sent whenever a window receives a character from the OS or underlying system. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct ReceivedCharacter { pub id: WindowId, pub char: char, @@ -102,12 +112,14 @@ pub struct WindowFocused { /// An event that indicates a window's scale factor has changed. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowScaleFactorChanged { pub id: WindowId, pub scale_factor: f64, } /// An event that indicates a window's OS-reported scale factor has changed. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowBackendScaleFactorChanged { pub id: WindowId, pub scale_factor: f64, @@ -115,6 +127,7 @@ pub struct WindowBackendScaleFactorChanged { /// Events related to files being dragged and dropped on a window. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum FileDragAndDrop { DroppedFile { id: WindowId, path_buf: PathBuf }, @@ -125,6 +138,7 @@ pub enum FileDragAndDrop { /// An event that is sent when a window is repositioned in physical pixels. #[derive(Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowMoved { pub id: WindowId, pub position: IVec2, From be401d6b3f2ae5db895f8019ac6a9ad1fac7c953 Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 19 Sep 2022 15:36:04 -0400 Subject: [PATCH 3/8] Add serde::Serialize/Deserialize traits via "serialize" feature for events in bevy_input. Added PartialEq trait to bevy_input events without it. --- crates/bevy_input/src/keyboard.rs | 3 ++- crates/bevy_input/src/mouse.rs | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/bevy_input/src/keyboard.rs b/crates/bevy_input/src/keyboard.rs index 9239f6b6b0f99..0b6914cec440b 100644 --- a/crates/bevy_input/src/keyboard.rs +++ b/crates/bevy_input/src/keyboard.rs @@ -11,7 +11,8 @@ use bevy_reflect::{FromReflect, Reflect}; /// /// The event is consumed inside of the [`keyboard_input_system`](crate::keyboard::keyboard_input_system) /// to update the [`Input`](crate::Input) resource. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct KeyboardInput { /// The scan code of the key. pub scan_code: u32, diff --git a/crates/bevy_input/src/mouse.rs b/crates/bevy_input/src/mouse.rs index 8e989c438c52b..f77e89e097f47 100644 --- a/crates/bevy_input/src/mouse.rs +++ b/crates/bevy_input/src/mouse.rs @@ -10,7 +10,8 @@ use bevy_math::Vec2; /// /// The event is read inside of the [`mouse_button_input_system`](crate::mouse::mouse_button_input_system) /// to update the [`Input`](crate::Input) resource. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct MouseButtonInput { /// The mouse button assigned to the event. pub button: MouseButton, @@ -50,7 +51,8 @@ pub enum MouseButton { /// However, the event data does not make it possible to distinguish which device it is referring to. /// /// [`DeviceEvent::MouseMotion`]: https://docs.rs/winit/latest/winit/event/enum.DeviceEvent.html#variant.MouseMotion -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct MouseMotion { /// The change in the position of the pointing device since the last event was sent. pub delta: Vec2, @@ -63,6 +65,7 @@ pub struct MouseMotion { /// The value of the event can either be interpreted as the amount of lines or the amount of pixels /// to scroll. #[derive(Debug, Clone, Copy, Eq, PartialEq)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum MouseScrollUnit { /// The line scroll unit. /// @@ -79,7 +82,8 @@ pub enum MouseScrollUnit { /// A mouse wheel event. /// /// This event is the translated version of the `WindowEvent::MouseWheel` from the `winit` crate. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct MouseWheel { /// The mouse scroll unit. pub unit: MouseScrollUnit, From 644dca01c974c68ac277aa1098af1d8aeede6db3 Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 19 Sep 2022 16:31:24 -0400 Subject: [PATCH 4/8] Added the serialize feature into bevy_window's Cargo.toml, and made serde an optional dependency. Added conditional #derives for necessary types in bevy_window. --- crates/bevy_window/Cargo.toml | 6 +++++- crates/bevy_window/src/cursor.rs | 1 + crates/bevy_window/src/window.rs | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/bevy_window/Cargo.toml b/crates/bevy_window/Cargo.toml index 01d8f77bce21c..f1402447072de 100644 --- a/crates/bevy_window/Cargo.toml +++ b/crates/bevy_window/Cargo.toml @@ -8,6 +8,10 @@ repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" keywords = ["bevy"] +[features] +default = [] +serialize = ["serde"] + [dependencies] # bevy bevy_app = { path = "../bevy_app", version = "0.9.0-dev" } @@ -20,7 +24,7 @@ bevy_input = { path = "../bevy_input", version = "0.9.0-dev" } raw-window-handle = "0.4.2" # other -serde = { version = "1.0", features = ["derive"] } +serde = { version = "1.0", features = ["derive"], optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] web-sys = "0.3" diff --git a/crates/bevy_window/src/cursor.rs b/crates/bevy_window/src/cursor.rs index 56de60cdf01ad..de1fa563ba96b 100644 --- a/crates/bevy_window/src/cursor.rs +++ b/crates/bevy_window/src/cursor.rs @@ -4,6 +4,7 @@ /// This `enum` is simply a copy of a similar `enum` found in [`winit`](https://docs.rs/winit/latest/winit/window/enum.CursorIcon.html). /// `winit`, in turn, mostly copied cursor types available in the browser. #[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum CursorIcon { /// The platform-dependent default cursor. Default, diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index 11e8bad32cc9f..54e95221b4082 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -7,6 +7,7 @@ use raw_window_handle::RawWindowHandle; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Reflect, FromReflect)] #[reflect_value(PartialEq, Hash)] /// A unique ID for a [`Window`]. +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowId(Uuid); /// Presentation mode for a window. @@ -24,6 +25,7 @@ pub struct WindowId(Uuid); /// or updated on a [`Window`](Window::set_present_mode). #[repr(C)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] #[doc(alias = "vsync")] pub enum PresentMode { /// Chooses FifoRelaxed -> Fifo based on availability. @@ -96,6 +98,7 @@ impl Default for WindowId { /// maximized it may have a size outside of these limits. The functionality /// required to disable maximizing is not yet exposed by winit. #[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowResizeConstraints { pub min_width: f32, pub min_height: f32, @@ -215,6 +218,7 @@ pub struct Window { /// Bevy apps don't interact with this `enum` directly. Instead, they should use the methods on [`Window`]. /// This `enum` is meant for authors of windowing plugins. See the documentation on [`crate::WindowPlugin`] for more information. #[derive(Debug)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum WindowCommand { /// Set the window's [`WindowMode`]. SetWindowMode { @@ -288,6 +292,7 @@ pub enum WindowCommand { /// Defines the way a window is displayed. #[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum WindowMode { /// Creates a window that uses the given size. Windowed, @@ -746,6 +751,7 @@ impl Window { /// Defines where window should be placed at on creation. #[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum WindowPosition { /// The position will be set by the window manager. Automatic, @@ -763,6 +769,7 @@ pub enum WindowPosition { /// Defines which monitor to use. #[derive(Debug, Clone, Copy)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum MonitorSelection { /// Uses current monitor of the window. /// @@ -783,6 +790,7 @@ pub enum MonitorSelection { /// /// [`examples/window/window_settings.rs`]: https://github.com/bevyengine/bevy/blob/latest/examples/window/window_settings.rs #[derive(Resource, Debug, Clone)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowDescriptor { /// The requested logical width of the window's client area. /// From 617ee6c1b5e1b3b997626ee56ad54d930af2088f Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 19 Sep 2022 18:19:15 -0400 Subject: [PATCH 5/8] Added "bevy_window/serialize" to serialize=[ ... ] set. --- crates/bevy_internal/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index d4be55fc72878..f38c60c203f9a 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -45,7 +45,7 @@ wav = ["bevy_audio/wav"] # Enable watching file system for asset hot reload filesystem_watcher = ["bevy_asset/filesystem_watcher"] -serialize = ["bevy_input/serialize"] +serialize = ["bevy_input/serialize", "bevy_window/serialize"] # Display server protocol support (X11 is enabled by default) wayland = ["bevy_winit/wayland"] From 815cccdc7f588379fbbfcc37d7fa01b1928fc31e Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 19 Sep 2022 21:19:51 -0400 Subject: [PATCH 6/8] Added PartialEq trait to bevy_window events, WindowDescriptor and its structure fields. --- crates/bevy_window/src/event.rs | 30 +++++++++++++++--------------- crates/bevy_window/src/window.rs | 8 ++++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/crates/bevy_window/src/event.rs b/crates/bevy_window/src/event.rs index f8e1b3e75c566..a7ab68daec82e 100644 --- a/crates/bevy_window/src/event.rs +++ b/crates/bevy_window/src/event.rs @@ -4,7 +4,7 @@ use super::{WindowDescriptor, WindowId}; use bevy_math::{IVec2, Vec2}; /// A window event that is sent whenever a window's logical size has changed. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowResized { pub id: WindowId, @@ -15,7 +15,7 @@ pub struct WindowResized { } /// An event that indicates that a new window should be created. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CreateWindow { pub id: WindowId, @@ -24,7 +24,7 @@ pub struct CreateWindow { /// An event that indicates the window should redraw, even if its control flow is set to `Wait` and /// there have been no window events. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct RequestRedraw; @@ -32,7 +32,7 @@ pub struct RequestRedraw; /// /// To create a new window, send a [`CreateWindow`] event - this /// event will be sent in the handler for that event. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowCreated { pub id: WindowId, @@ -49,7 +49,7 @@ pub struct WindowCreated { /// [`WindowPlugin`]: crate::WindowPlugin /// [`Window`]: crate::Window /// [closing]: crate::Window::close -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowCloseRequested { pub id: WindowId, @@ -59,7 +59,7 @@ pub struct WindowCloseRequested { /// handler for [`Window::close`]. /// /// [`Window::close`]: crate::Window::close -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowClosed { pub id: WindowId, @@ -73,7 +73,7 @@ pub struct WindowClosed { /// /// [`WindowEvent::CursorMoved`]: https://docs.rs/winit/latest/winit/event/enum.WindowEvent.html#variant.CursorMoved /// [`MouseMotion`]: bevy_input::mouse::MouseMotion -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CursorMoved { /// The identifier of the window the cursor has moved on. @@ -83,20 +83,20 @@ pub struct CursorMoved { pub position: Vec2, } /// An event that is sent whenever the user's cursor enters a window. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CursorEntered { pub id: WindowId, } /// An event that is sent whenever the user's cursor leaves a window. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CursorLeft { pub id: WindowId, } /// An event that is sent whenever a window receives a character from the OS or underlying system. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct ReceivedCharacter { pub id: WindowId, @@ -104,21 +104,21 @@ pub struct ReceivedCharacter { } /// An event that indicates a window has received or lost focus. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] pub struct WindowFocused { pub id: WindowId, pub focused: bool, } /// An event that indicates a window's scale factor has changed. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowScaleFactorChanged { pub id: WindowId, pub scale_factor: f64, } /// An event that indicates a window's OS-reported scale factor has changed. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowBackendScaleFactorChanged { pub id: WindowId, @@ -126,7 +126,7 @@ pub struct WindowBackendScaleFactorChanged { } /// Events related to files being dragged and dropped on a window. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum FileDragAndDrop { DroppedFile { id: WindowId, path_buf: PathBuf }, @@ -137,7 +137,7 @@ pub enum FileDragAndDrop { } /// An event that is sent when a window is repositioned in physical pixels. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowMoved { pub id: WindowId, diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index 54e95221b4082..016cc3b02e111 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -97,7 +97,7 @@ impl Default for WindowId { /// Please note that if the window is resizable, then when the window is /// maximized it may have a size outside of these limits. The functionality /// required to disable maximizing is not yet exposed by winit. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowResizeConstraints { pub min_width: f32, @@ -750,7 +750,7 @@ impl Window { } /// Defines where window should be placed at on creation. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum WindowPosition { /// The position will be set by the window manager. @@ -768,7 +768,7 @@ pub enum WindowPosition { } /// Defines which monitor to use. -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum MonitorSelection { /// Uses current monitor of the window. @@ -789,7 +789,7 @@ pub enum MonitorSelection { /// See [`examples/window/window_settings.rs`] for usage. /// /// [`examples/window/window_settings.rs`]: https://github.com/bevyengine/bevy/blob/latest/examples/window/window_settings.rs -#[derive(Resource, Debug, Clone)] +#[derive(Resource, Debug, Clone, PartialEq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowDescriptor { /// The requested logical width of the window's client area. From 1994230a5a93c3b682fa177e3f4ed07fb05cae51 Mon Sep 17 00:00:00 2001 From: targrub Date: Mon, 19 Sep 2022 21:29:50 -0400 Subject: [PATCH 7/8] Added Eq trait where possible to bevy_windows events, WindowDescriptor and its structs. --- crates/bevy_window/src/event.rs | 20 ++++++++++---------- crates/bevy_window/src/window.rs | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/bevy_window/src/event.rs b/crates/bevy_window/src/event.rs index a7ab68daec82e..a432e559c28cf 100644 --- a/crates/bevy_window/src/event.rs +++ b/crates/bevy_window/src/event.rs @@ -24,7 +24,7 @@ pub struct CreateWindow { /// An event that indicates the window should redraw, even if its control flow is set to `Wait` and /// there have been no window events. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct RequestRedraw; @@ -32,7 +32,7 @@ pub struct RequestRedraw; /// /// To create a new window, send a [`CreateWindow`] event - this /// event will be sent in the handler for that event. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowCreated { pub id: WindowId, @@ -49,7 +49,7 @@ pub struct WindowCreated { /// [`WindowPlugin`]: crate::WindowPlugin /// [`Window`]: crate::Window /// [closing]: crate::Window::close -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowCloseRequested { pub id: WindowId, @@ -59,7 +59,7 @@ pub struct WindowCloseRequested { /// handler for [`Window::close`]. /// /// [`Window::close`]: crate::Window::close -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowClosed { pub id: WindowId, @@ -83,20 +83,20 @@ pub struct CursorMoved { pub position: Vec2, } /// An event that is sent whenever the user's cursor enters a window. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CursorEntered { pub id: WindowId, } /// An event that is sent whenever the user's cursor leaves a window. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct CursorLeft { pub id: WindowId, } /// An event that is sent whenever a window receives a character from the OS or underlying system. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct ReceivedCharacter { pub id: WindowId, @@ -104,7 +104,7 @@ pub struct ReceivedCharacter { } /// An event that indicates a window has received or lost focus. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct WindowFocused { pub id: WindowId, pub focused: bool, @@ -126,7 +126,7 @@ pub struct WindowBackendScaleFactorChanged { } /// Events related to files being dragged and dropped on a window. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum FileDragAndDrop { DroppedFile { id: WindowId, path_buf: PathBuf }, @@ -137,7 +137,7 @@ pub enum FileDragAndDrop { } /// An event that is sent when a window is repositioned in physical pixels. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub struct WindowMoved { pub id: WindowId, diff --git a/crates/bevy_window/src/window.rs b/crates/bevy_window/src/window.rs index 016cc3b02e111..127eb4ca5a2ca 100644 --- a/crates/bevy_window/src/window.rs +++ b/crates/bevy_window/src/window.rs @@ -768,7 +768,7 @@ pub enum WindowPosition { } /// Defines which monitor to use. -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] pub enum MonitorSelection { /// Uses current monitor of the window. From 807fbcfa2b40966487eb403a0d3e88dd250efc1e Mon Sep 17 00:00:00 2001 From: targrub Date: Tue, 20 Sep 2022 08:56:18 -0400 Subject: [PATCH 8/8] Test serialization of Bevy's Duration, not std::time::Duration. --- crates/bevy_reflect/src/impls/std.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 462791d32bc95..0c021ba8c4c35 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -9,7 +9,8 @@ use crate::{ use crate::utility::{GenericTypeInfoCell, NonGenericTypeInfoCell}; use bevy_reflect_derive::{impl_from_reflect_value, impl_reflect_value}; -use bevy_utils::{Duration, HashMap, HashSet, Instant}; +use bevy_utils::{Duration, Instant}; +use bevy_utils::{HashMap, HashSet}; use std::{ any::Any, borrow::Cow, @@ -889,18 +890,19 @@ mod tests { Enum, FromReflect, Reflect, ReflectSerialize, TypeInfo, TypeRegistry, Typed, VariantInfo, VariantType, }; - use bevy_utils::{HashMap, Instant}; + use bevy_utils::HashMap; + use bevy_utils::{Duration, Instant}; use std::f32::consts::{PI, TAU}; #[test] fn can_serialize_duration() { let mut type_registry = TypeRegistry::default(); - type_registry.register::(); + type_registry.register::(); let reflect_serialize = type_registry - .get_type_data::(std::any::TypeId::of::()) + .get_type_data::(std::any::TypeId::of::()) .unwrap(); - let _serializable = reflect_serialize.get_serializable(&std::time::Duration::ZERO); + let _serializable = reflect_serialize.get_serializable(&Duration::ZERO); } #[test]