diff --git a/app/src/client/mod.rs b/app/src/client/mod.rs index e1daf52a2f..b017228ccd 100644 --- a/app/src/client/mod.rs +++ b/app/src/client/mod.rs @@ -70,6 +70,7 @@ pub async fn run( .ui_renderer(true) .with_asset_cache(assets) .headless(headless) + .debug(is_debug) .update_title_with_fps_stats(false) .run(move |app, _runtime| { *app.world.resource_mut(window_title()) = "Ambient".to_string(); @@ -89,26 +90,34 @@ pub async fn run( } #[element_component] -fn TitleUpdater(hooks: &mut Hooks) -> Element { +fn TitleUpdater(hooks: &mut Hooks, debug: bool) -> Element { let (net, _) = use_remote_resource(hooks, client_network_stats()).expect("No game client"); let world = &hooks.world; let title = world.resource(window_title()); - let fps = world - .get_cloned(hooks.world.resource_entity(), fps_stats()) - .ok() - .filter(|f| !f.fps().is_nan()); - - let title = match (fps, net) { - (None, None) => title.clone(), - (Some(fps), None) => format!("{} [{}]", title, fps.dump_both()), - (None, Some(net)) => format!("{} [{}]", title, net), - (Some(fps), Some(net)) => format!("{} [{}, {}]", title, fps.dump_both(), net), - }; - world - .resource(window_ctl()) - .send(WindowCtl::SetTitle(title)) - .ok(); + + if debug { + let fps = world + .get_cloned(hooks.world.resource_entity(), fps_stats()) + .ok() + .filter(|f| !f.fps().is_nan()); + + let title = match (fps, net) { + (None, None) => title.clone(), + (Some(fps), None) => format!("{} [{}]", title, fps.dump_both()), + (None, Some(net)) => format!("{} [{}]", title, net), + (Some(fps), Some(net)) => format!("{} [{}, {}]", title, fps.dump_both(), net), + }; + world + .resource(window_ctl()) + .send(WindowCtl::SetTitle(title)) + .ok(); + } else { + world + .resource(window_ctl()) + .send(WindowCtl::SetTitle(title.clone())) + .ok(); + } Element::new() } @@ -173,7 +182,7 @@ fn MainApp( cert, create_rpc_registry: cb(shared::create_server_rpc_registry), inner: Dock::el(vec![ - TitleUpdater.el(), + TitleUpdater::el(show_debug), if let Some(golden_image_cmd) = golden_image_cmd.filter(|_| loaded) { GoldenImageTest::el(golden_image_output_dir, golden_image_cmd) } else { diff --git a/crates/app/src/lib.rs b/crates/app/src/lib.rs index b80d6e7e9f..dceeed2614 100644 --- a/crates/app/src/lib.rs +++ b/crates/app/src/lib.rs @@ -43,6 +43,7 @@ use winit::{ dpi::PhysicalPosition, event::{ElementState, Event, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent}, event_loop::{ControlFlow, EventLoop}, + platform::macos::WindowExtMacOS, window::{CursorGrabMode, Fullscreen, Window, WindowBuilder}, }; @@ -190,6 +191,7 @@ pub struct AppBuilder { pub main_renderer: bool, pub examples_systems: bool, pub headless: Option, + debug: bool, pub update_title_with_fps_stats: bool, #[cfg(target_os = "unknown")] pub parent_element: Option, @@ -221,6 +223,7 @@ impl AppBuilder { main_renderer: true, examples_systems: false, headless: None, + debug: false, update_title_with_fps_stats: true, #[cfg(target_os = "unknown")] parent_element: None, @@ -268,6 +271,11 @@ impl AppBuilder { self } + pub fn debug(mut self, debug: bool) -> Self { + self.debug = debug; + self + } + pub fn update_title_with_fps_stats(mut self, value: bool) -> Self { self.update_title_with_fps_stats = value; self @@ -290,6 +298,7 @@ impl AppBuilder { let settings = SettingsKey.get(&assets); + #[cfg(not(target_os = "windows"))] let (window, event_loop) = if self.headless.is_some() { (None, None) } else { @@ -299,6 +308,26 @@ impl AppBuilder { height: settings.resolution().1, }); let window = Arc::new(window.build(&event_loop).unwrap()); + window.set_simple_fullscreen(!self.debug); + (Some(window), Some(event_loop)) + }; + + #[cfg(target_os = "windows")] + let (window, event_loop) = if self.headless.is_some() { + (None, None) + } else { + let event_loop = self.event_loop.unwrap_or_else(EventLoop::new); + + let monitor = event_loop.primary_monitor().unwrap(); + let video_mode = monitor.video_modes().next().unwrap(); + let window = WindowBuilder::new() + .with_inner_size(winit::dpi::LogicalSize { + width: settings.resolution().0, + height: settings.resolution().1, + }) + .with_fullscreen(Some(Fullscreen::Exclusive(video_mode))); + let window = Arc::new(window.build(&event_loop).unwrap()); + window.set_simple_fullscreen(!self.debug); (Some(window), Some(event_loop)) }; @@ -588,6 +617,23 @@ impl App { }, control_flow, ); + } else if let Event::WindowEvent { + event: + WindowEvent::KeyboardInput { + input: + KeyboardInput { + state: ElementState::Pressed, + virtual_keycode: Some(VirtualKeyCode::Escape), + .. + }, + .. + }, + .. + } = &event + { + if let Some(window) = self.window.as_ref() { + window.set_simple_fullscreen(false); + } } else if let Some(event) = event.to_static() { self.handle_static_event(&event, control_flow); }