migrate to latest winit + glutin

This commit is contained in:
Dmitry Stepanov
2025-08-27 23:42:08 +03:00
parent d4d154c4eb
commit b40bc9cefd
7 changed files with 63 additions and 86 deletions
+2 -2
View File
@@ -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"] }
+14 -12
View File
@@ -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<F>(event_loop: EventLoop<()>, callback: F)
where
F: FnMut(Event<()>, &EventLoopWindowTarget<()>) + 'static,
F: FnMut(Event<()>, &ActiveEventLoop) + 'static,
{
#[cfg(target_arch = "wasm32")]
{
+15 -44
View File
@@ -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<bool>,
},
/// 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);