From b40bc9cefd1867add69167acf93aa1b8fabad2ee Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Wed, 27 Aug 2025 23:42:08 +0300 Subject: [PATCH] migrate to latest winit + glutin --- editor/src/lib.rs | 16 +++++---- fyrox-graphics-gl/Cargo.toml | 8 ++--- fyrox-graphics-gl/src/server.rs | 22 ++++++------ fyrox-impl/Cargo.toml | 4 +-- fyrox-impl/src/engine/executor.rs | 26 +++++++------- fyrox-impl/src/engine/mod.rs | 59 ++++++++----------------------- project-manager/src/main.rs | 14 ++++---- 7 files changed, 63 insertions(+), 86 deletions(-) diff --git a/editor/src/lib.rs b/editor/src/lib.rs index 38fdc5beb..9c6b16b3e 100644 --- a/editor/src/lib.rs +++ b/editor/src/lib.rs @@ -18,6 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#![allow(deprecated)] // TODO #![allow(irrefutable_let_patterns)] #![allow(clippy::too_many_arguments)] #![allow(clippy::large_enum_variant)] @@ -85,7 +86,7 @@ use crate::{ SerializationContext, }, event::{Event, WindowEvent}, - event_loop::{EventLoop, EventLoopWindowTarget}, + event_loop::EventLoop, fxhash::{FxHashMap, FxHashSet}, graph::{BaseSceneGraph, SceneGraph}, gui::{ @@ -174,6 +175,7 @@ use crate::{ utils::doc::DocWindow, world::{graph::EditorSceneWrapper, menu::SceneNodeContextMenu, WorldViewer}, }; +use fyrox::event_loop::ActiveEventLoop; use fyrox_build_tools::{build::BuildWindow, CommandDescriptor}; pub use message::Message; use plugins::inspector::InspectorPlugin; @@ -2901,10 +2903,10 @@ impl Editor { ||!self.loading_scenes.lock().is_empty() } - fn on_resumed(&mut self, evt: &EventLoopWindowTarget<()>) { + fn on_resumed(&mut self, event_loop: &ActiveEventLoop) { let engine = &mut self.engine; - engine.initialize_graphics_context(evt).unwrap(); + engine.initialize_graphics_context(event_loop).unwrap(); let graphics_context = engine.graphics_context.as_initialized_mut(); @@ -3118,7 +3120,7 @@ fn set_ui_scaling(ui: &UserInterface, scale: f32) { )); } -fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) { +fn update(editor: &mut Editor, event_loop: &ActiveEventLoop) { let elapsed = editor.game_loop_data.clock.elapsed().as_secs_f32(); editor.game_loop_data.clock = Instant::now(); editor.game_loop_data.lag += elapsed; @@ -3161,7 +3163,7 @@ fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) { editor.engine.pre_update( FIXED_TIMESTEP, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(event_loop), &mut editor.game_loop_data.lag, switches, ); @@ -3220,7 +3222,7 @@ fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) { FIXED_TIMESTEP, &Default::default(), &mut editor.game_loop_data.lag, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(event_loop), ); if need_reload_plugins { @@ -3234,7 +3236,7 @@ fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) { editor.engine.handle_plugins_hot_reloading( FIXED_TIMESTEP, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(event_loop), &mut editor.game_loop_data.lag, on_plugin_reloaded, ); diff --git a/fyrox-graphics-gl/Cargo.toml b/fyrox-graphics-gl/Cargo.toml index 3ab1624b0..5d86fb39d 100644 --- a/fyrox-graphics-gl/Cargo.toml +++ b/fyrox-graphics-gl/Cargo.toml @@ -13,7 +13,7 @@ repository = "https://github.com/FyroxEngine/Fyrox" rust-version = "1.86" [dependencies] -winit = { version = "0.29.2", features = ["serde"] } +winit = { version = "0.30", features = ["serde"] } fyrox-graphics = { version = "1.0.0-rc.1", path = "../fyrox-graphics" } fyrox-core = { version = "1.0.0-rc.1", path = "../fyrox-core" } fxhash = "0.2.1" @@ -22,9 +22,9 @@ glow = "0.16" serde = { version = "1.0.215", features = ["derive"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -glutin = "0.31" -glutin-winit = "0.4.2" -raw-window-handle = "0.5.0" +glutin = "0.32" +glutin-winit = "0.5" +raw-window-handle = "0.6" [target.'cfg(target_arch = "wasm32")'.dependencies] serde-wasm-bindgen = "0.6.3" \ No newline at end of file diff --git a/fyrox-graphics-gl/src/server.rs b/fyrox-graphics-gl/src/server.rs index 54f819b57..909c24541 100644 --- a/fyrox-graphics-gl/src/server.rs +++ b/fyrox-graphics-gl/src/server.rs @@ -18,6 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#![allow(deprecated)] // TODO + use crate::{ buffer::GlBuffer, framebuffer::GlFrameBuffer, @@ -65,10 +67,8 @@ use std::cell::{Cell, RefCell}; use std::rc::{Rc, Weak}; #[cfg(not(target_arch = "wasm32"))] use std::{ffi::CString, num::NonZeroU32}; -use winit::{ - event_loop::EventLoopWindowTarget, - window::{Window, WindowBuilder}, -}; +use winit::event_loop::ActiveEventLoop; +use winit::window::{Window, WindowAttributes}; impl ToGlConstant for PolygonFace { fn into_gl(self) -> u32 { @@ -490,8 +490,8 @@ impl GlGraphicsServer { pub fn new( #[allow(unused_variables)] vsync: bool, #[allow(unused_variables)] msaa_sample_count: Option, - window_target: &EventLoopWindowTarget<()>, - window_builder: WindowBuilder, + window_target: &ActiveEventLoop, + mut window_attributes: WindowAttributes, named_objects: bool, ) -> Result<(Window, SharedGraphicsServer), FrameworkError> { #[cfg(not(target_arch = "wasm32"))] @@ -506,14 +506,14 @@ impl GlGraphicsServer { } let (opt_window, gl_config) = DisplayBuilder::new() - .with_window_builder(Some(window_builder)) + .with_window_attributes(Some(window_attributes)) .build(window_target, template, |mut configs| { configs.next().unwrap() })?; let window = opt_window.unwrap(); - let raw_window_handle = window.raw_window_handle(); + let raw_window_handle = window.raw_window_handle().unwrap(); let gl_display = gl_config.display(); @@ -536,7 +536,7 @@ impl GlGraphicsServer { .build(Some(raw_window_handle)); unsafe { - let attrs = window.build_surface_attributes(Default::default()); + let attrs = window.build_surface_attributes(Default::default()).unwrap(); let gl_surface = gl_config .display() @@ -588,8 +588,8 @@ impl GlGraphicsServer { platform::web::WindowExtWebSys, }; - let inner_size = window_builder.window_attributes().inner_size; - let window = window_builder.build(window_target).unwrap(); + let inner_size = window_attributes.inner_size; + let window = window_target.create_window(window_attributes).unwrap(); let web_window = fyrox_core::web_sys::window().unwrap(); let scale_factor = web_window.device_pixel_ratio(); diff --git a/fyrox-impl/Cargo.toml b/fyrox-impl/Cargo.toml index 68be88bd5..5b083d8f9 100644 --- a/fyrox-impl/Cargo.toml +++ b/fyrox-impl/Cargo.toml @@ -41,7 +41,7 @@ fxhash = "0.2.1" strum = "0.27" strum_macros = "0.27" clap = { version = "4", features = ["derive"] } -winit = { version = "0.29.2", features = ["serde"] } +winit = { version = "0.30", features = ["serde"] } half = { version = "2.2.1", features = ["bytemuck"] } base64 = "0.22.1" uvgen = "0.3.0" @@ -83,4 +83,4 @@ enable_profiler = ["fyrox-core/enable_profiler"] mesh_analysis = [] [target.'cfg(target_os = "android")'.dependencies] -winit = { version = "0.29.2", features = ["android-native-activity"] } +winit = { version = "0.30", features = ["android-native-activity"] } diff --git a/fyrox-impl/src/engine/executor.rs b/fyrox-impl/src/engine/executor.rs index 80c521a96..99cced66f 100644 --- a/fyrox-impl/src/engine/executor.rs +++ b/fyrox-impl/src/engine/executor.rs @@ -33,7 +33,7 @@ use crate::{ Engine, EngineInitParams, GraphicsContext, GraphicsContextParams, SerializationContext, }, event::{Event, WindowEvent}, - event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget}, + event_loop::{ControlFlow, EventLoop}, plugin::Plugin, utils::translate_event, window::WindowAttributes, @@ -48,6 +48,7 @@ use std::{ ops::{Deref, DerefMut}, sync::Arc, }; +use winit::event_loop::ActiveEventLoop; #[derive(Parser, Debug, Default)] #[clap(author, version, about, long_about = None)] @@ -316,16 +317,16 @@ fn run_normal( engine.enable_plugins( override_scene, true, - ApplicationLoopController::WindowTarget(&event_loop), + ApplicationLoopController::EventLoop(&event_loop), ); - run_executor(event_loop, move |event, window_target| { - window_target.set_control_flow(ControlFlow::Wait); + run_executor(event_loop, move |event, active_event_loop| { + active_event_loop.set_control_flow(ControlFlow::Wait); engine.handle_os_event_by_plugins( &event, fixed_time_step, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(active_event_loop), &mut lag, ); @@ -337,12 +338,12 @@ fn run_normal( match event { Event::Resumed => { engine - .initialize_graphics_context(window_target) + .initialize_graphics_context(active_event_loop) .expect("Unable to initialize graphics context!"); engine.handle_graphics_context_created_by_plugins( fixed_time_step, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(active_event_loop), &mut lag, ); } @@ -353,14 +354,14 @@ fn run_normal( engine.handle_graphics_context_destroyed_by_plugins( fixed_time_step, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(active_event_loop), &mut lag, ); } Event::AboutToWait => { game_loop_iteration( &mut engine, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(active_event_loop), &mut previous, &mut lag, fixed_time_step, @@ -372,7 +373,7 @@ fn run_normal( } Event::WindowEvent { event, .. } => { match event { - WindowEvent::CloseRequested => window_target.exit(), + WindowEvent::CloseRequested => active_event_loop.exit(), WindowEvent::Resized(size) => { if let Err(e) = engine.set_frame_size(size.into()) { Log::writeln( @@ -384,7 +385,7 @@ fn run_normal( WindowEvent::RedrawRequested => { engine.handle_before_rendering_by_plugins( fixed_time_step, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(active_event_loop), &mut lag, ); @@ -472,9 +473,10 @@ fn game_loop_iteration( } } +#[allow(deprecated)] // TODO fn run_executor(event_loop: EventLoop<()>, callback: F) where - F: FnMut(Event<()>, &EventLoopWindowTarget<()>) + 'static, + F: FnMut(Event<()>, &ActiveEventLoop) + 'static, { #[cfg(target_arch = "wasm32")] { diff --git a/fyrox-impl/src/engine/mod.rs b/fyrox-impl/src/engine/mod.rs index 155e5a0b7..2682e5300 100644 --- a/fyrox-impl/src/engine/mod.rs +++ b/fyrox-impl/src/engine/mod.rs @@ -100,11 +100,12 @@ use crate::{ Script, ScriptContext, ScriptDeinitContext, ScriptMessage, ScriptMessageContext, ScriptMessageKind, ScriptMessageSender, UniversalScriptContext, }, - window::{Window, WindowBuilder}, + window::Window, }; use fxhash::{FxHashMap, FxHashSet}; use fyrox_animation::AnimationTracksData; use fyrox_core::visitor::error::VisitError; +use fyrox_core::warn; use fyrox_graphics::server::SharedGraphicsServer; use fyrox_graphics_gl::server::GlGraphicsServer; use fyrox_sound::{ @@ -127,9 +128,9 @@ use std::{ time::Duration, }; use uuid::Uuid; +use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::{ dpi::{Position, Size}, - event_loop::EventLoopWindowTarget, window::Icon, window::WindowAttributes, }; @@ -1080,8 +1081,8 @@ pub type GraphicsServerConstructorResult = Result<(Window, SharedGraphicsServer) /// as the server. pub type GraphicsServerConstructorCallback = dyn Fn( &GraphicsContextParams, - &EventLoopWindowTarget<()>, - WindowBuilder, + &ActiveEventLoop, + WindowAttributes, bool, ) -> GraphicsServerConstructorResult; @@ -1374,7 +1375,9 @@ pub enum ApplicationLoopController<'a> { running: &'a Cell, }, /// Normal application loop controller with full window, graphics, sound support. - WindowTarget(&'a EventLoopWindowTarget<()>), + ActiveEventLoop(&'a ActiveEventLoop), + /// Normal application loop controller without a window. + EventLoop(&'a EventLoop<()>), } impl ApplicationLoopController<'_> { @@ -1382,7 +1385,10 @@ impl ApplicationLoopController<'_> { pub fn exit(&self) { match self { ApplicationLoopController::Headless { running } => running.set(false), - ApplicationLoopController::WindowTarget(window_target) => window_target.exit(), + ApplicationLoopController::ActiveEventLoop(event_loop) => event_loop.exit(), + ApplicationLoopController::EventLoop(_) => { + warn!("Can't exit the loop until it is activated!") + } } } } @@ -1488,48 +1494,13 @@ impl Engine { /// graphics context at all (for example - if you're making game server). pub fn initialize_graphics_context( &mut self, - window_target: &EventLoopWindowTarget<()>, + event_loop: &ActiveEventLoop, ) -> Result<(), EngineError> { if let GraphicsContext::Uninitialized(params) = &self.graphics_context { - let mut window_builder = WindowBuilder::new(); - if let Some(inner_size) = params.window_attributes.inner_size { - window_builder = window_builder.with_inner_size(inner_size); - } - if let Some(min_inner_size) = params.window_attributes.min_inner_size { - window_builder = window_builder.with_min_inner_size(min_inner_size); - } - if let Some(max_inner_size) = params.window_attributes.max_inner_size { - window_builder = window_builder.with_min_inner_size(max_inner_size); - } - if let Some(position) = params.window_attributes.position { - window_builder = window_builder.with_position(position); - } - if let Some(resize_increments) = params.window_attributes.resize_increments { - window_builder = window_builder.with_resize_increments(resize_increments); - } - unsafe { - window_builder = window_builder - .with_parent_window(params.window_attributes.parent_window().cloned()); - } - window_builder = window_builder - .with_resizable(params.window_attributes.resizable) - .with_enabled_buttons(params.window_attributes.enabled_buttons) - .with_title(params.window_attributes.title.clone()) - .with_fullscreen(params.window_attributes.fullscreen().cloned()) - .with_maximized(params.window_attributes.maximized) - .with_visible(params.window_attributes.visible) - .with_transparent(params.window_attributes.transparent) - .with_decorations(params.window_attributes.decorations) - .with_window_icon(params.window_attributes.window_icon.clone()) - .with_theme(params.window_attributes.preferred_theme) - .with_content_protected(params.window_attributes.content_protected) - .with_window_level(params.window_attributes.window_level) - .with_active(params.window_attributes.active); - let (window, server) = params.graphics_server_constructor.0( params, - window_target, - window_builder, + event_loop, + params.window_attributes.clone(), params.named_objects, )?; let frame_size = (window.inner_size().width, window.inner_size().height); diff --git a/project-manager/src/main.rs b/project-manager/src/main.rs index 933d3fb3a..ab035dda7 100644 --- a/project-manager/src/main.rs +++ b/project-manager/src/main.rs @@ -18,6 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. +#![allow(deprecated)] + //! Project manager is used to create, import, rename, delete, run and edit projects built with Fyrox. mod manager; @@ -114,25 +116,25 @@ fn main() { let mut time_step = 1.0 / 60.0; event_loop - .run(move |event, window_target| { + .run(move |event, active_event_loop| { if project_manager.mode.is_build() { // Keep updating with reduced rate to keep printing to the build log, but do not // eat as much time as in normal update mode. time_step = 1.0 / 10.0; - window_target.set_control_flow(ControlFlow::wait_duration( + active_event_loop.set_control_flow(ControlFlow::wait_duration( Duration::from_secs_f32(time_step), )); } else { // Wait for an event. - window_target.set_control_flow(ControlFlow::Wait); + active_event_loop.set_control_flow(ControlFlow::Wait); time_step = 1.0 / 60.0; } match event { Event::Resumed => { engine - .initialize_graphics_context(window_target) + .initialize_graphics_context(active_event_loop) .expect("Unable to initialize graphics context!"); let graphics_context = engine.graphics_context.as_initialized_mut(); graphics_context @@ -168,7 +170,7 @@ fn main() { engine.update( time_step, - ApplicationLoopController::WindowTarget(window_target), + ApplicationLoopController::ActiveEventLoop(active_event_loop), &mut 0.0, Default::default(), ); @@ -192,7 +194,7 @@ fn main() { WindowEvent::Focused(focus) => { project_manager.focused = focus; } - WindowEvent::CloseRequested => window_target.exit(), + WindowEvent::CloseRequested => active_event_loop.exit(), WindowEvent::Resized(size) => { if let Err(e) = engine.set_frame_size(size.into()) { Log::writeln(