diff --git a/experiment/index.html b/experiment/index.html index 039c80a329..bd503d55bd 100644 --- a/experiment/index.html +++ b/experiment/index.html @@ -2,35 +2,54 @@ - - + async function run() { + const t0 = performance.now(); + console.log("Started loading WASM"); + let response = await fetch('./experiment_bg.wasm'); + const contentLength = response.headers.get('Content-Length'); + const reader = response.body.getReader(); + let receivedLength = 0; + let chunks = []; + while (true) { + const {done, value} = await reader.read(); + if (done) { + break; + } + chunks.push(value); + receivedLength += value.length; + document.getElementById("progress_text").innerText = prettyPrintBytes(receivedLength) + " / " + prettyPrintBytes(contentLength); + document.getElementById("progress_bar").style.width = (100.0 * receivedLength / contentLength) + "%"; + } + document.getElementById("progress_text").innerText = "Loaded " + prettyPrintBytes(contentLength) + ", now initializing WASM module"; + let blob = new Blob(chunks); + let buffer = await blob.arrayBuffer(); + const t1 = performance.now(); + console.log(`It took ${t1 - t0} ms to download WASM, now initializing it`); + await init(buffer); + } + + run(); +
-

Loading 15 minute Santa...

-
-
-
-
-
-

this may take up to 30 seconds

+

Loading 15 minute Santa...

+
+
+
+

If you think something has broken, check your browser's developer console (Ctrl+Shift+I or similar)

-

(your browser must support WebGL and WebAssembly)

+

(Your browser must support WebGL and WebAssembly)

diff --git a/widgetry/src/backend_glow_native.rs b/widgetry/src/backend_glow_native.rs index d7067418fa..70af759c54 100644 --- a/widgetry/src/backend_glow_native.rs +++ b/widgetry/src/backend_glow_native.rs @@ -1,9 +1,14 @@ use glow::HasContext; +use abstutil::Timer; + use crate::backend_glow::{GfxCtxInnards, PrerenderInnards}; use crate::ScreenDims; -pub fn setup(window_title: &str) -> (PrerenderInnards, winit::event_loop::EventLoop<()>) { +pub fn setup( + window_title: &str, + timer: &mut Timer, +) -> (PrerenderInnards, winit::event_loop::EventLoop<()>) { let event_loop = winit::event_loop::EventLoop::new(); let window = winit::window::WindowBuilder::new() .with_title(window_title) @@ -83,7 +88,9 @@ pub fn setup(window_title: &str) -> (PrerenderInnards, winit::event_loop::EventL ); } + timer.start("load textures"); crate::backend_glow::load_textures(&gl, "system/assets/textures/spritesheet.png", 64).unwrap(); + timer.stop("load textures"); ( PrerenderInnards::new(gl, program, WindowAdapter(windowed_context)), diff --git a/widgetry/src/backend_glow_wasm.rs b/widgetry/src/backend_glow_wasm.rs index 51fed440fe..ea0c98e874 100644 --- a/widgetry/src/backend_glow_wasm.rs +++ b/widgetry/src/backend_glow_wasm.rs @@ -3,10 +3,15 @@ use std::rc::Rc; use wasm_bindgen::JsCast; use winit::platform::web::WindowExtWebSys; +use abstutil::Timer; + use crate::backend_glow::{GfxCtxInnards, PrerenderInnards}; use crate::ScreenDims; -pub fn setup(window_title: &str) -> (PrerenderInnards, winit::event_loop::EventLoop<()>) { +pub fn setup( + window_title: &str, + timer: &mut Timer, +) -> (PrerenderInnards, winit::event_loop::EventLoop<()>) { info!("Setting up widgetry"); // This doesn't seem to work for the shader panics here, but later it does work. Huh. @@ -113,7 +118,9 @@ pub fn setup(window_title: &str) -> (PrerenderInnards, winit::event_loop::EventL ); } + timer.start("load textures"); crate::backend_glow::load_textures(&gl, "system/assets/textures/spritesheet.png", 64).unwrap(); + timer.stop("load textures"); ( PrerenderInnards::new(gl, program, WindowAdapter(winit_window)), diff --git a/widgetry/src/runner.rs b/widgetry/src/runner.rs index 7420fba43c..5da93dfff6 100644 --- a/widgetry/src/runner.rs +++ b/widgetry/src/runner.rs @@ -5,6 +5,7 @@ use image::{GenericImageView, Pixel}; use instant::Instant; use winit::window::Icon; +use abstutil::Timer; use geom::Duration; use crate::app_state::App; @@ -189,7 +190,8 @@ pub fn run< settings: Settings, make_app: F, ) -> ! { - let (prerender_innards, event_loop) = crate::backend::setup(&settings.window_title); + let mut timer = Timer::new("setup widgetry"); + let (prerender_innards, event_loop) = crate::backend::setup(&settings.window_title, &mut timer); if let Some(ref path) = settings.window_icon { if !cfg!(target_arch = "wasm32") { @@ -218,6 +220,7 @@ pub fn run< let mut canvas = Canvas::new(initial_size); prerender.window_resized(initial_size); + timer.start("setup app"); let (shared_app_state, states) = make_app(&mut EventCtx { fake_mouseover: true, input: UserInput::new(Event::NoOp, &canvas), @@ -226,10 +229,12 @@ pub fn run< style: &mut style, updates_requested: vec![], }); + timer.stop("setup app"); let app = App { shared_app_state, states, }; + timer.done(); let mut state = State { canvas, app, style };