Skip to content

Commit b40bc9c

Browse files
committed
migrate to latest winit + glutin
1 parent d4d154c commit b40bc9c

File tree

7 files changed

+63
-86
lines changed

7 files changed

+63
-86
lines changed

editor/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21+
#![allow(deprecated)] // TODO
2122
#![allow(irrefutable_let_patterns)]
2223
#![allow(clippy::too_many_arguments)]
2324
#![allow(clippy::large_enum_variant)]
@@ -85,7 +86,7 @@ use crate::{
8586
SerializationContext,
8687
},
8788
event::{Event, WindowEvent},
88-
event_loop::{EventLoop, EventLoopWindowTarget},
89+
event_loop::EventLoop,
8990
fxhash::{FxHashMap, FxHashSet},
9091
graph::{BaseSceneGraph, SceneGraph},
9192
gui::{
@@ -174,6 +175,7 @@ use crate::{
174175
utils::doc::DocWindow,
175176
world::{graph::EditorSceneWrapper, menu::SceneNodeContextMenu, WorldViewer},
176177
};
178+
use fyrox::event_loop::ActiveEventLoop;
177179
use fyrox_build_tools::{build::BuildWindow, CommandDescriptor};
178180
pub use message::Message;
179181
use plugins::inspector::InspectorPlugin;
@@ -2901,10 +2903,10 @@ impl Editor {
29012903
||!self.loading_scenes.lock().is_empty()
29022904
}
29032905

2904-
fn on_resumed(&mut self, evt: &EventLoopWindowTarget<()>) {
2906+
fn on_resumed(&mut self, event_loop: &ActiveEventLoop) {
29052907
let engine = &mut self.engine;
29062908

2907-
engine.initialize_graphics_context(evt).unwrap();
2909+
engine.initialize_graphics_context(event_loop).unwrap();
29082910

29092911
let graphics_context = engine.graphics_context.as_initialized_mut();
29102912

@@ -3118,7 +3120,7 @@ fn set_ui_scaling(ui: &UserInterface, scale: f32) {
31183120
));
31193121
}
31203122

3121-
fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) {
3123+
fn update(editor: &mut Editor, event_loop: &ActiveEventLoop) {
31223124
let elapsed = editor.game_loop_data.clock.elapsed().as_secs_f32();
31233125
editor.game_loop_data.clock = Instant::now();
31243126
editor.game_loop_data.lag += elapsed;
@@ -3161,7 +3163,7 @@ fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) {
31613163

31623164
editor.engine.pre_update(
31633165
FIXED_TIMESTEP,
3164-
ApplicationLoopController::WindowTarget(window_target),
3166+
ApplicationLoopController::ActiveEventLoop(event_loop),
31653167
&mut editor.game_loop_data.lag,
31663168
switches,
31673169
);
@@ -3220,7 +3222,7 @@ fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) {
32203222
FIXED_TIMESTEP,
32213223
&Default::default(),
32223224
&mut editor.game_loop_data.lag,
3223-
ApplicationLoopController::WindowTarget(window_target),
3225+
ApplicationLoopController::ActiveEventLoop(event_loop),
32243226
);
32253227

32263228
if need_reload_plugins {
@@ -3234,7 +3236,7 @@ fn update(editor: &mut Editor, window_target: &EventLoopWindowTarget<()>) {
32343236

32353237
editor.engine.handle_plugins_hot_reloading(
32363238
FIXED_TIMESTEP,
3237-
ApplicationLoopController::WindowTarget(window_target),
3239+
ApplicationLoopController::ActiveEventLoop(event_loop),
32383240
&mut editor.game_loop_data.lag,
32393241
on_plugin_reloaded,
32403242
);

fyrox-graphics-gl/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repository = "https://github.com/FyroxEngine/Fyrox"
1313
rust-version = "1.86"
1414

1515
[dependencies]
16-
winit = { version = "0.29.2", features = ["serde"] }
16+
winit = { version = "0.30", features = ["serde"] }
1717
fyrox-graphics = { version = "1.0.0-rc.1", path = "../fyrox-graphics" }
1818
fyrox-core = { version = "1.0.0-rc.1", path = "../fyrox-core" }
1919
fxhash = "0.2.1"
@@ -22,9 +22,9 @@ glow = "0.16"
2222
serde = { version = "1.0.215", features = ["derive"] }
2323

2424
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
25-
glutin = "0.31"
26-
glutin-winit = "0.4.2"
27-
raw-window-handle = "0.5.0"
25+
glutin = "0.32"
26+
glutin-winit = "0.5"
27+
raw-window-handle = "0.6"
2828

2929
[target.'cfg(target_arch = "wasm32")'.dependencies]
3030
serde-wasm-bindgen = "0.6.3"

fyrox-graphics-gl/src/server.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1919
// SOFTWARE.
2020

21+
#![allow(deprecated)] // TODO
22+
2123
use crate::{
2224
buffer::GlBuffer,
2325
framebuffer::GlFrameBuffer,
@@ -65,10 +67,8 @@ use std::cell::{Cell, RefCell};
6567
use std::rc::{Rc, Weak};
6668
#[cfg(not(target_arch = "wasm32"))]
6769
use std::{ffi::CString, num::NonZeroU32};
68-
use winit::{
69-
event_loop::EventLoopWindowTarget,
70-
window::{Window, WindowBuilder},
71-
};
70+
use winit::event_loop::ActiveEventLoop;
71+
use winit::window::{Window, WindowAttributes};
7272

7373
impl ToGlConstant for PolygonFace {
7474
fn into_gl(self) -> u32 {
@@ -490,8 +490,8 @@ impl GlGraphicsServer {
490490
pub fn new(
491491
#[allow(unused_variables)] vsync: bool,
492492
#[allow(unused_variables)] msaa_sample_count: Option<u8>,
493-
window_target: &EventLoopWindowTarget<()>,
494-
window_builder: WindowBuilder,
493+
window_target: &ActiveEventLoop,
494+
mut window_attributes: WindowAttributes,
495495
named_objects: bool,
496496
) -> Result<(Window, SharedGraphicsServer), FrameworkError> {
497497
#[cfg(not(target_arch = "wasm32"))]
@@ -506,14 +506,14 @@ impl GlGraphicsServer {
506506
}
507507

508508
let (opt_window, gl_config) = DisplayBuilder::new()
509-
.with_window_builder(Some(window_builder))
509+
.with_window_attributes(Some(window_attributes))
510510
.build(window_target, template, |mut configs| {
511511
configs.next().unwrap()
512512
})?;
513513

514514
let window = opt_window.unwrap();
515515

516-
let raw_window_handle = window.raw_window_handle();
516+
let raw_window_handle = window.raw_window_handle().unwrap();
517517

518518
let gl_display = gl_config.display();
519519

@@ -536,7 +536,7 @@ impl GlGraphicsServer {
536536
.build(Some(raw_window_handle));
537537

538538
unsafe {
539-
let attrs = window.build_surface_attributes(Default::default());
539+
let attrs = window.build_surface_attributes(Default::default()).unwrap();
540540

541541
let gl_surface = gl_config
542542
.display()
@@ -588,8 +588,8 @@ impl GlGraphicsServer {
588588
platform::web::WindowExtWebSys,
589589
};
590590

591-
let inner_size = window_builder.window_attributes().inner_size;
592-
let window = window_builder.build(window_target).unwrap();
591+
let inner_size = window_attributes.inner_size;
592+
let window = window_target.create_window(window_attributes).unwrap();
593593

594594
let web_window = fyrox_core::web_sys::window().unwrap();
595595
let scale_factor = web_window.device_pixel_ratio();

fyrox-impl/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fxhash = "0.2.1"
4141
strum = "0.27"
4242
strum_macros = "0.27"
4343
clap = { version = "4", features = ["derive"] }
44-
winit = { version = "0.29.2", features = ["serde"] }
44+
winit = { version = "0.30", features = ["serde"] }
4545
half = { version = "2.2.1", features = ["bytemuck"] }
4646
base64 = "0.22.1"
4747
uvgen = "0.3.0"
@@ -83,4 +83,4 @@ enable_profiler = ["fyrox-core/enable_profiler"]
8383
mesh_analysis = []
8484

8585
[target.'cfg(target_os = "android")'.dependencies]
86-
winit = { version = "0.29.2", features = ["android-native-activity"] }
86+
winit = { version = "0.30", features = ["android-native-activity"] }

fyrox-impl/src/engine/executor.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use crate::{
3333
Engine, EngineInitParams, GraphicsContext, GraphicsContextParams, SerializationContext,
3434
},
3535
event::{Event, WindowEvent},
36-
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
36+
event_loop::{ControlFlow, EventLoop},
3737
plugin::Plugin,
3838
utils::translate_event,
3939
window::WindowAttributes,
@@ -48,6 +48,7 @@ use std::{
4848
ops::{Deref, DerefMut},
4949
sync::Arc,
5050
};
51+
use winit::event_loop::ActiveEventLoop;
5152

5253
#[derive(Parser, Debug, Default)]
5354
#[clap(author, version, about, long_about = None)]
@@ -316,16 +317,16 @@ fn run_normal(
316317
engine.enable_plugins(
317318
override_scene,
318319
true,
319-
ApplicationLoopController::WindowTarget(&event_loop),
320+
ApplicationLoopController::EventLoop(&event_loop),
320321
);
321322

322-
run_executor(event_loop, move |event, window_target| {
323-
window_target.set_control_flow(ControlFlow::Wait);
323+
run_executor(event_loop, move |event, active_event_loop| {
324+
active_event_loop.set_control_flow(ControlFlow::Wait);
324325

325326
engine.handle_os_event_by_plugins(
326327
&event,
327328
fixed_time_step,
328-
ApplicationLoopController::WindowTarget(window_target),
329+
ApplicationLoopController::ActiveEventLoop(active_event_loop),
329330
&mut lag,
330331
);
331332

@@ -337,12 +338,12 @@ fn run_normal(
337338
match event {
338339
Event::Resumed => {
339340
engine
340-
.initialize_graphics_context(window_target)
341+
.initialize_graphics_context(active_event_loop)
341342
.expect("Unable to initialize graphics context!");
342343

343344
engine.handle_graphics_context_created_by_plugins(
344345
fixed_time_step,
345-
ApplicationLoopController::WindowTarget(window_target),
346+
ApplicationLoopController::ActiveEventLoop(active_event_loop),
346347
&mut lag,
347348
);
348349
}
@@ -353,14 +354,14 @@ fn run_normal(
353354

354355
engine.handle_graphics_context_destroyed_by_plugins(
355356
fixed_time_step,
356-
ApplicationLoopController::WindowTarget(window_target),
357+
ApplicationLoopController::ActiveEventLoop(active_event_loop),
357358
&mut lag,
358359
);
359360
}
360361
Event::AboutToWait => {
361362
game_loop_iteration(
362363
&mut engine,
363-
ApplicationLoopController::WindowTarget(window_target),
364+
ApplicationLoopController::ActiveEventLoop(active_event_loop),
364365
&mut previous,
365366
&mut lag,
366367
fixed_time_step,
@@ -372,7 +373,7 @@ fn run_normal(
372373
}
373374
Event::WindowEvent { event, .. } => {
374375
match event {
375-
WindowEvent::CloseRequested => window_target.exit(),
376+
WindowEvent::CloseRequested => active_event_loop.exit(),
376377
WindowEvent::Resized(size) => {
377378
if let Err(e) = engine.set_frame_size(size.into()) {
378379
Log::writeln(
@@ -384,7 +385,7 @@ fn run_normal(
384385
WindowEvent::RedrawRequested => {
385386
engine.handle_before_rendering_by_plugins(
386387
fixed_time_step,
387-
ApplicationLoopController::WindowTarget(window_target),
388+
ApplicationLoopController::ActiveEventLoop(active_event_loop),
388389
&mut lag,
389390
);
390391

@@ -472,9 +473,10 @@ fn game_loop_iteration(
472473
}
473474
}
474475

476+
#[allow(deprecated)] // TODO
475477
fn run_executor<F>(event_loop: EventLoop<()>, callback: F)
476478
where
477-
F: FnMut(Event<()>, &EventLoopWindowTarget<()>) + 'static,
479+
F: FnMut(Event<()>, &ActiveEventLoop) + 'static,
478480
{
479481
#[cfg(target_arch = "wasm32")]
480482
{

fyrox-impl/src/engine/mod.rs

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ use crate::{
100100
Script, ScriptContext, ScriptDeinitContext, ScriptMessage, ScriptMessageContext,
101101
ScriptMessageKind, ScriptMessageSender, UniversalScriptContext,
102102
},
103-
window::{Window, WindowBuilder},
103+
window::Window,
104104
};
105105
use fxhash::{FxHashMap, FxHashSet};
106106
use fyrox_animation::AnimationTracksData;
107107
use fyrox_core::visitor::error::VisitError;
108+
use fyrox_core::warn;
108109
use fyrox_graphics::server::SharedGraphicsServer;
109110
use fyrox_graphics_gl::server::GlGraphicsServer;
110111
use fyrox_sound::{
@@ -127,9 +128,9 @@ use std::{
127128
time::Duration,
128129
};
129130
use uuid::Uuid;
131+
use winit::event_loop::{ActiveEventLoop, EventLoop};
130132
use winit::{
131133
dpi::{Position, Size},
132-
event_loop::EventLoopWindowTarget,
133134
window::Icon,
134135
window::WindowAttributes,
135136
};
@@ -1080,8 +1081,8 @@ pub type GraphicsServerConstructorResult = Result<(Window, SharedGraphicsServer)
10801081
/// as the server.
10811082
pub type GraphicsServerConstructorCallback = dyn Fn(
10821083
&GraphicsContextParams,
1083-
&EventLoopWindowTarget<()>,
1084-
WindowBuilder,
1084+
&ActiveEventLoop,
1085+
WindowAttributes,
10851086
bool,
10861087
) -> GraphicsServerConstructorResult;
10871088

@@ -1374,15 +1375,20 @@ pub enum ApplicationLoopController<'a> {
13741375
running: &'a Cell<bool>,
13751376
},
13761377
/// Normal application loop controller with full window, graphics, sound support.
1377-
WindowTarget(&'a EventLoopWindowTarget<()>),
1378+
ActiveEventLoop(&'a ActiveEventLoop),
1379+
/// Normal application loop controller without a window.
1380+
EventLoop(&'a EventLoop<()>),
13781381
}
13791382

13801383
impl ApplicationLoopController<'_> {
13811384
/// Asks the loop controller to end the application execution.
13821385
pub fn exit(&self) {
13831386
match self {
13841387
ApplicationLoopController::Headless { running } => running.set(false),
1385-
ApplicationLoopController::WindowTarget(window_target) => window_target.exit(),
1388+
ApplicationLoopController::ActiveEventLoop(event_loop) => event_loop.exit(),
1389+
ApplicationLoopController::EventLoop(_) => {
1390+
warn!("Can't exit the loop until it is activated!")
1391+
}
13861392
}
13871393
}
13881394
}
@@ -1488,48 +1494,13 @@ impl Engine {
14881494
/// graphics context at all (for example - if you're making game server).
14891495
pub fn initialize_graphics_context(
14901496
&mut self,
1491-
window_target: &EventLoopWindowTarget<()>,
1497+
event_loop: &ActiveEventLoop,
14921498
) -> Result<(), EngineError> {
14931499
if let GraphicsContext::Uninitialized(params) = &self.graphics_context {
1494-
let mut window_builder = WindowBuilder::new();
1495-
if let Some(inner_size) = params.window_attributes.inner_size {
1496-
window_builder = window_builder.with_inner_size(inner_size);
1497-
}
1498-
if let Some(min_inner_size) = params.window_attributes.min_inner_size {
1499-
window_builder = window_builder.with_min_inner_size(min_inner_size);
1500-
}
1501-
if let Some(max_inner_size) = params.window_attributes.max_inner_size {
1502-
window_builder = window_builder.with_min_inner_size(max_inner_size);
1503-
}
1504-
if let Some(position) = params.window_attributes.position {
1505-
window_builder = window_builder.with_position(position);
1506-
}
1507-
if let Some(resize_increments) = params.window_attributes.resize_increments {
1508-
window_builder = window_builder.with_resize_increments(resize_increments);
1509-
}
1510-
unsafe {
1511-
window_builder = window_builder
1512-
.with_parent_window(params.window_attributes.parent_window().cloned());
1513-
}
1514-
window_builder = window_builder
1515-
.with_resizable(params.window_attributes.resizable)
1516-
.with_enabled_buttons(params.window_attributes.enabled_buttons)
1517-
.with_title(params.window_attributes.title.clone())
1518-
.with_fullscreen(params.window_attributes.fullscreen().cloned())
1519-
.with_maximized(params.window_attributes.maximized)
1520-
.with_visible(params.window_attributes.visible)
1521-
.with_transparent(params.window_attributes.transparent)
1522-
.with_decorations(params.window_attributes.decorations)
1523-
.with_window_icon(params.window_attributes.window_icon.clone())
1524-
.with_theme(params.window_attributes.preferred_theme)
1525-
.with_content_protected(params.window_attributes.content_protected)
1526-
.with_window_level(params.window_attributes.window_level)
1527-
.with_active(params.window_attributes.active);
1528-
15291500
let (window, server) = params.graphics_server_constructor.0(
15301501
params,
1531-
window_target,
1532-
window_builder,
1502+
event_loop,
1503+
params.window_attributes.clone(),
15331504
params.named_objects,
15341505
)?;
15351506
let frame_size = (window.inner_size().width, window.inner_size().height);

0 commit comments

Comments
 (0)