mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
deploy: 816ae46943
This commit is contained in:
parent
6471113f2f
commit
58509082ca
@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The build time in RFC2822, UTC."><meta name="keywords" content="rust, rustlang, rust-lang, BUILT_TIME_UTC"><title>BUILT_TIME_UTC in game::pregame::built_info - Rust</title><link rel="stylesheet" type="text/css" href="../../../normalize.css"><link rel="stylesheet" type="text/css" href="../../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../../ayu.css" disabled ><script id="default-settings"></script><script src="../../../storage.js"></script><script src="../../../crates.js"></script><noscript><link rel="stylesheet" href="../../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../../favicon.svg">
|
||||
<link rel="alternate icon" type="image/png" href="../../../favicon-16x16.png">
|
||||
<link rel="alternate icon" type="image/png" href="../../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../../down-arrow.svg");}</style></head><body class="rustdoc constant"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../../game/index.html'><div class='logo-container rust-logo'><img src='../../../rust-logo.png' alt='logo'></div></a><div class="sidebar-elems"><p class="location"><a href="../../index.html">game</a>::<wbr><a href="../index.html">pregame</a>::<wbr><a href="index.html">built_info</a></p><div id="sidebar-vars" data-name="BUILT_TIME_UTC" data-ty="constant" data-relpath=""></div><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||||
<a id="settings-menu" href="../../../settings.html"><img src="../../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Constant <a href="../../index.html">game</a>::<wbr><a href="../index.html">pregame</a>::<wbr><a href="index.html">built_info</a>::<wbr><a class="constant" href="">BUILT_TIME_UTC</a><button id="copy-path" onclick="copy_path(this)">⎘</button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../../src/game/home/runner/work/abstreet/abstreet/target/debug/build/game-b46195c1bf7e0216/out/built.rs.html#78" title="goto source code">[src]</a></span></h1><pre class="rust const">pub const BUILT_TIME_UTC: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a> = r"Fri, 16 Jul 2021 06:15:27 +0000";</pre><div class="docblock"><p>The build time in RFC2822, UTC.</p>
|
||||
<a id="settings-menu" href="../../../settings.html"><img src="../../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Constant <a href="../../index.html">game</a>::<wbr><a href="../index.html">pregame</a>::<wbr><a href="index.html">built_info</a>::<wbr><a class="constant" href="">BUILT_TIME_UTC</a><button id="copy-path" onclick="copy_path(this)">⎘</button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../../src/game/home/runner/work/abstreet/abstreet/target/debug/build/game-b46195c1bf7e0216/out/built.rs.html#78" title="goto source code">[src]</a></span></h1><pre class="rust const">pub const BUILT_TIME_UTC: &<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a> = r"Fri, 16 Jul 2021 18:32:29 +0000";</pre><div class="docblock"><p>The build time in RFC2822, UTC.</p>
|
||||
</div></section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../../" data-current-crate="game" data-search-index-js="../../../search-index.js" data-search-js="../../../search.js"></div>
|
||||
<script src="../../../main.js"></script></body></html>
|
@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Loading large resources (like maps, scenarios, and prebaked data) requires different strategies on native and web. Both cases are wrapped up as a State that runs a callback when done."><meta name="keywords" content="rust, rustlang, rust-lang, load"><title>map_gui::load - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg">
|
||||
<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png">
|
||||
<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../map_gui/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a><p class="location">Module load</p><div class="sidebar-elems"><div class="block items"><ul><li><a href="#modules">Modules</a></li><li><a href="#structs">Structs</a></li></ul></div><p class="location"><a href="../index.html">map_gui</a></p><div id="sidebar-vars" data-name="load" data-ty="mod" data-relpath="../"></div><script defer src="../sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button>
|
||||
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Module <a href="../index.html">map_gui</a>::<wbr><a class="mod" href="">load</a><button id="copy-path" onclick="copy_path(this)">⎘</button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../src/map_gui/load.rs.html#1-598" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Loading large resources (like maps, scenarios, and prebaked data) requires different strategies
|
||||
<a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class="fqn"><span class="in-band">Module <a href="../index.html">map_gui</a>::<wbr><a class="mod" href="">load</a><button id="copy-path" onclick="copy_path(this)">⎘</button></span><span class="out-of-band"><span id="render-detail"><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span><a class="srclink" href="../../src/map_gui/load.rs.html#1-700" title="goto source code">[src]</a></span></h1><div class="docblock"><p>Loading large resources (like maps, scenarios, and prebaked data) requires different strategies
|
||||
on native and web. Both cases are wrapped up as a State that runs a callback when done.</p>
|
||||
</div><h2 id="modules" class="section-header"><a href="#modules">Modules</a></h2>
|
||||
<table><tr class="module-item"><td><a class="mod" href="native_loader/index.html" title="map_gui::load::native_loader mod">native_loader</a></td><td class="docblock-short"></td></tr></table><h2 id="structs" class="section-header"><a href="#structs">Structs</a></h2>
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -178,7 +178,7 @@
|
||||
<span class="kw">pub</span> <span class="kw">const</span> <span class="ident">RUSTDOC_VERSION</span>: <span class="kw-2">&</span><span class="ident">str</span> <span class="op">=</span> <span class="string">r"rustdoc 1.53.0 (53cb7b09b 2021-06-17)"</span>;
|
||||
<span class="attribute">#[<span class="ident">doc</span><span class="op">=</span><span class="string">r#"The build time in RFC2822, UTC."#</span>]</span>
|
||||
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">dead_code</span>)]</span>
|
||||
<span class="kw">pub</span> <span class="kw">const</span> <span class="ident">BUILT_TIME_UTC</span>: <span class="kw-2">&</span><span class="ident">str</span> <span class="op">=</span> <span class="string">r"Fri, 16 Jul 2021 06:15:27 +0000"</span>;
|
||||
<span class="kw">pub</span> <span class="kw">const</span> <span class="ident">BUILT_TIME_UTC</span>: <span class="kw-2">&</span><span class="ident">str</span> <span class="op">=</span> <span class="string">r"Fri, 16 Jul 2021 18:32:29 +0000"</span>;
|
||||
<span class="attribute">#[<span class="ident">doc</span><span class="op">=</span><span class="string">r#"The target architecture, given by `CARGO_CFG_TARGET_ARCH`."#</span>]</span>
|
||||
<span class="attribute">#[<span class="ident">allow</span>(<span class="ident">dead_code</span>)]</span>
|
||||
<span class="kw">pub</span> <span class="kw">const</span> <span class="ident">CFG_TARGET_ARCH</span>: <span class="kw-2">&</span><span class="ident">str</span> <span class="op">=</span> <span class="string">r"x86_64"</span>;
|
||||
|
@ -599,6 +599,108 @@
|
||||
<span id="596">596</span>
|
||||
<span id="597">597</span>
|
||||
<span id="598">598</span>
|
||||
<span id="599">599</span>
|
||||
<span id="600">600</span>
|
||||
<span id="601">601</span>
|
||||
<span id="602">602</span>
|
||||
<span id="603">603</span>
|
||||
<span id="604">604</span>
|
||||
<span id="605">605</span>
|
||||
<span id="606">606</span>
|
||||
<span id="607">607</span>
|
||||
<span id="608">608</span>
|
||||
<span id="609">609</span>
|
||||
<span id="610">610</span>
|
||||
<span id="611">611</span>
|
||||
<span id="612">612</span>
|
||||
<span id="613">613</span>
|
||||
<span id="614">614</span>
|
||||
<span id="615">615</span>
|
||||
<span id="616">616</span>
|
||||
<span id="617">617</span>
|
||||
<span id="618">618</span>
|
||||
<span id="619">619</span>
|
||||
<span id="620">620</span>
|
||||
<span id="621">621</span>
|
||||
<span id="622">622</span>
|
||||
<span id="623">623</span>
|
||||
<span id="624">624</span>
|
||||
<span id="625">625</span>
|
||||
<span id="626">626</span>
|
||||
<span id="627">627</span>
|
||||
<span id="628">628</span>
|
||||
<span id="629">629</span>
|
||||
<span id="630">630</span>
|
||||
<span id="631">631</span>
|
||||
<span id="632">632</span>
|
||||
<span id="633">633</span>
|
||||
<span id="634">634</span>
|
||||
<span id="635">635</span>
|
||||
<span id="636">636</span>
|
||||
<span id="637">637</span>
|
||||
<span id="638">638</span>
|
||||
<span id="639">639</span>
|
||||
<span id="640">640</span>
|
||||
<span id="641">641</span>
|
||||
<span id="642">642</span>
|
||||
<span id="643">643</span>
|
||||
<span id="644">644</span>
|
||||
<span id="645">645</span>
|
||||
<span id="646">646</span>
|
||||
<span id="647">647</span>
|
||||
<span id="648">648</span>
|
||||
<span id="649">649</span>
|
||||
<span id="650">650</span>
|
||||
<span id="651">651</span>
|
||||
<span id="652">652</span>
|
||||
<span id="653">653</span>
|
||||
<span id="654">654</span>
|
||||
<span id="655">655</span>
|
||||
<span id="656">656</span>
|
||||
<span id="657">657</span>
|
||||
<span id="658">658</span>
|
||||
<span id="659">659</span>
|
||||
<span id="660">660</span>
|
||||
<span id="661">661</span>
|
||||
<span id="662">662</span>
|
||||
<span id="663">663</span>
|
||||
<span id="664">664</span>
|
||||
<span id="665">665</span>
|
||||
<span id="666">666</span>
|
||||
<span id="667">667</span>
|
||||
<span id="668">668</span>
|
||||
<span id="669">669</span>
|
||||
<span id="670">670</span>
|
||||
<span id="671">671</span>
|
||||
<span id="672">672</span>
|
||||
<span id="673">673</span>
|
||||
<span id="674">674</span>
|
||||
<span id="675">675</span>
|
||||
<span id="676">676</span>
|
||||
<span id="677">677</span>
|
||||
<span id="678">678</span>
|
||||
<span id="679">679</span>
|
||||
<span id="680">680</span>
|
||||
<span id="681">681</span>
|
||||
<span id="682">682</span>
|
||||
<span id="683">683</span>
|
||||
<span id="684">684</span>
|
||||
<span id="685">685</span>
|
||||
<span id="686">686</span>
|
||||
<span id="687">687</span>
|
||||
<span id="688">688</span>
|
||||
<span id="689">689</span>
|
||||
<span id="690">690</span>
|
||||
<span id="691">691</span>
|
||||
<span id="692">692</span>
|
||||
<span id="693">693</span>
|
||||
<span id="694">694</span>
|
||||
<span id="695">695</span>
|
||||
<span id="696">696</span>
|
||||
<span id="697">697</span>
|
||||
<span id="698">698</span>
|
||||
<span id="699">699</span>
|
||||
<span id="700">700</span>
|
||||
</pre><div class="example-wrap"><pre class="rust ">
|
||||
<span class="doccomment">//! Loading large resources (like maps, scenarios, and prebaked data) requires different strategies</span>
|
||||
<span class="doccomment">//! on native and web. Both cases are wrapped up as a State that runs a callback when done.</span>
|
||||
@ -794,10 +896,14 @@
|
||||
<span class="kw">mod</span> <span class="ident">wasm_loader</span> {
|
||||
<span class="kw">use</span> <span class="ident">std::io::Read</span>;
|
||||
|
||||
<span class="kw">use</span> <span class="ident">wasm_bindgen::JsCast</span>;
|
||||
<span class="kw">use</span> <span class="ident">futures::StreamExt</span>;
|
||||
<span class="kw">use</span> <span class="ident">wasm_bindgen</span>::{<span class="ident">JsCast</span>, <span class="ident">UnwrapThrowExt</span>};
|
||||
<span class="kw">use</span> <span class="ident">wasm_bindgen_futures::JsFuture</span>;
|
||||
<span class="kw">use</span> <span class="ident">wasm_streams::ReadableStream</span>;
|
||||
<span class="kw">use</span> <span class="ident">web_sys</span>::{<span class="ident">Request</span>, <span class="ident">RequestInit</span>, <span class="ident">RequestMode</span>, <span class="ident">Response</span>};
|
||||
|
||||
<span class="kw">use</span> <span class="ident">abstutil::prettyprint_usize</span>;
|
||||
|
||||
<span class="kw">use</span> <span class="kw">super</span>::<span class="kw-2">*</span>;
|
||||
|
||||
<span class="doccomment">/// Loads a JSON or bincoded file, then deserializes it</span>
|
||||
@ -812,6 +918,11 @@
|
||||
<span class="ident">panel</span>: <span class="ident">Panel</span>,
|
||||
<span class="ident">started</span>: <span class="ident">Instant</span>,
|
||||
<span class="ident">url</span>: <span class="ident">String</span>,
|
||||
|
||||
<span class="ident">total_bytes</span>: <span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span>,
|
||||
<span class="ident">read_bytes</span>: <span class="ident">usize</span>,
|
||||
<span class="ident">got_total_bytes</span>: <span class="ident">oneshot::Receiver</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span>,
|
||||
<span class="ident">got_read_bytes</span>: <span class="ident">mpsc::Receiver</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span>,
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><span class="op"><</span><span class="ident">A</span>: <span class="ident">AppLike</span> <span class="op">+</span> <span class="lifetime">'static</span>, <span class="ident">T</span>: <span class="lifetime">'static</span> <span class="op">+</span> <span class="ident">DeserializeOwned</span><span class="op">></span> <span class="ident">FileLoader</span><span class="op"><</span><span class="ident">A</span>, <span class="ident">T</span><span class="op">></span> {
|
||||
@ -836,6 +947,8 @@
|
||||
<span class="comment">// Make the HTTP request nonblockingly. When the response is received, send it through</span>
|
||||
<span class="comment">// the channel.</span>
|
||||
<span class="kw">let</span> (<span class="ident">tx</span>, <span class="ident">rx</span>) <span class="op">=</span> <span class="ident">oneshot::channel</span>();
|
||||
<span class="kw">let</span> (<span class="ident">tx_total_bytes</span>, <span class="ident">got_total_bytes</span>) <span class="op">=</span> <span class="ident">oneshot::channel</span>();
|
||||
<span class="kw">let</span> (<span class="kw-2">mut</span> <span class="ident">tx_read_bytes</span>, <span class="ident">got_read_bytes</span>) <span class="op">=</span> <span class="ident">mpsc::channel</span>(<span class="number">10</span>);
|
||||
<span class="kw">let</span> <span class="ident">url_copy</span> <span class="op">=</span> <span class="ident">url</span>.<span class="ident">clone</span>();
|
||||
<span class="macro">debug!</span>(<span class="string">"Loading {}"</span>, <span class="ident">url_copy</span>);
|
||||
<span class="ident">wasm_bindgen_futures::spawn_local</span>(<span class="kw">async</span> <span class="kw">move</span> {
|
||||
@ -849,9 +962,30 @@
|
||||
<span class="prelude-val">Ok</span>(<span class="ident">resp_value</span>) <span class="op">=</span><span class="op">></span> {
|
||||
<span class="kw">let</span> <span class="ident">resp</span>: <span class="ident">Response</span> <span class="op">=</span> <span class="ident">resp_value</span>.<span class="ident">dyn_into</span>().<span class="ident">unwrap</span>();
|
||||
<span class="kw">if</span> <span class="ident">resp</span>.<span class="ident">ok</span>() {
|
||||
<span class="kw">let</span> <span class="ident">buf</span> <span class="op">=</span> <span class="ident">JsFuture::from</span>(<span class="ident">resp</span>.<span class="ident">array_buffer</span>().<span class="ident">unwrap</span>()).<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="kw">let</span> <span class="ident">array</span> <span class="op">=</span> <span class="ident">js_sys::Uint8Array::new</span>(<span class="kw-2">&</span><span class="ident">buf</span>);
|
||||
<span class="ident">tx</span>.<span class="ident">send</span>(<span class="prelude-val">Ok</span>(<span class="ident">array</span>.<span class="ident">to_vec</span>())).<span class="ident">unwrap</span>();
|
||||
<span class="kw">let</span> <span class="ident">total_bytes</span> <span class="op">=</span> <span class="ident">resp</span>
|
||||
.<span class="ident">headers</span>()
|
||||
.<span class="ident">get</span>(<span class="string">"Content-Length"</span>)
|
||||
.<span class="ident">unwrap</span>()
|
||||
.<span class="ident">unwrap</span>()
|
||||
.<span class="ident">parse</span>::<span class="op"><</span><span class="ident">usize</span><span class="op">></span>()
|
||||
.<span class="ident">unwrap</span>();
|
||||
<span class="ident">tx_total_bytes</span>.<span class="ident">send</span>(<span class="ident">total_bytes</span>).<span class="ident">unwrap</span>();
|
||||
|
||||
<span class="kw">let</span> <span class="ident">raw_body</span> <span class="op">=</span> <span class="ident">resp</span>.<span class="ident">body</span>().<span class="ident">unwrap_throw</span>();
|
||||
<span class="kw">let</span> <span class="ident">body</span> <span class="op">=</span> <span class="ident">ReadableStream::from_raw</span>(<span class="ident">raw_body</span>.<span class="ident">dyn_into</span>().<span class="ident">unwrap_throw</span>());
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">body</span>.<span class="ident">into_stream</span>();
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffer</span> <span class="op">=</span> <span class="ident">Vec::new</span>();
|
||||
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="ident">chunk</span>)) <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">next</span>().<span class="kw">await</span> {
|
||||
<span class="kw">let</span> <span class="ident">array</span> <span class="op">=</span> <span class="ident">js_sys::Uint8Array::new</span>(<span class="kw-2">&</span><span class="ident">chunk</span>);
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Err</span>(<span class="ident">err</span>) <span class="op">=</span>
|
||||
<span class="ident">tx_read_bytes</span>.<span class="ident">try_send</span>(<span class="ident">array</span>.<span class="ident">byte_length</span>() <span class="kw">as</span> <span class="ident">usize</span>)
|
||||
{
|
||||
<span class="macro">warn!</span>(<span class="string">"Couldn't send update on bytes: {}"</span>, <span class="ident">err</span>);
|
||||
}
|
||||
<span class="comment">// TODO Can we avoid this clone?</span>
|
||||
<span class="ident">buffer</span>.<span class="ident">extend</span>(<span class="ident">array</span>.<span class="ident">to_vec</span>());
|
||||
}
|
||||
<span class="ident">tx</span>.<span class="ident">send</span>(<span class="prelude-val">Ok</span>(<span class="ident">buffer</span>)).<span class="ident">unwrap</span>();
|
||||
} <span class="kw">else</span> {
|
||||
<span class="kw">let</span> <span class="ident">status</span> <span class="op">=</span> <span class="ident">resp</span>.<span class="ident">status</span>();
|
||||
<span class="kw">let</span> <span class="ident">err</span> <span class="op">=</span> <span class="ident">resp</span>.<span class="ident">status_text</span>();
|
||||
@ -870,12 +1004,25 @@
|
||||
<span class="ident">panel</span>: <span class="ident">ctx</span>.<span class="ident">make_loading_screen</span>(<span class="ident">Text::from</span>(<span class="macro">format!</span>(<span class="string">"Loading {}..."</span>, <span class="ident">url</span>))),
|
||||
<span class="ident">started</span>: <span class="ident">Instant::now</span>(),
|
||||
<span class="ident">url</span>,
|
||||
<span class="ident">total_bytes</span>: <span class="prelude-val">None</span>,
|
||||
<span class="ident">read_bytes</span>: <span class="number">0</span>,
|
||||
<span class="ident">got_total_bytes</span>,
|
||||
<span class="ident">got_read_bytes</span>,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><span class="op"><</span><span class="ident">A</span>: <span class="ident">AppLike</span> <span class="op">+</span> <span class="lifetime">'static</span>, <span class="ident">T</span>: <span class="lifetime">'static</span> <span class="op">+</span> <span class="ident">DeserializeOwned</span><span class="op">></span> <span class="ident">State</span><span class="op"><</span><span class="ident">A</span><span class="op">></span> <span class="kw">for</span> <span class="ident">FileLoader</span><span class="op"><</span><span class="ident">A</span>, <span class="ident">T</span><span class="op">></span> {
|
||||
<span class="kw">fn</span> <span class="ident">event</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>, <span class="ident">ctx</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">EventCtx</span>, <span class="ident">app</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">A</span>) <span class="op">-</span><span class="op">></span> <span class="ident">Transition</span><span class="op"><</span><span class="ident">A</span><span class="op">></span> {
|
||||
<span class="kw">if</span> <span class="self">self</span>.<span class="ident">total_bytes</span>.<span class="ident">is_none</span>() {
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(<span class="ident">total</span>)) <span class="op">=</span> <span class="self">self</span>.<span class="ident">got_total_bytes</span>.<span class="ident">try_recv</span>() {
|
||||
<span class="self">self</span>.<span class="ident">total_bytes</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">total</span>);
|
||||
}
|
||||
}
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">read</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">got_read_bytes</span>.<span class="ident">try_next</span>().<span class="ident">ok</span>().<span class="ident">and_then</span>(<span class="op">|</span><span class="ident">value</span><span class="op">|</span> <span class="ident">value</span>) {
|
||||
<span class="self">self</span>.<span class="ident">read_bytes</span> <span class="op">+</span><span class="op">=</span> <span class="ident">read</span>;
|
||||
}
|
||||
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">maybe_resp</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">response</span>.<span class="ident">try_recv</span>().<span class="ident">unwrap</span>() {
|
||||
<span class="comment">// TODO We stop drawing and start blocking at this point. It can take a</span>
|
||||
<span class="comment">// while. Any way to make it still be nonblockingish? Maybe put some of the work</span>
|
||||
@ -898,13 +1045,21 @@
|
||||
<span class="kw">return</span> (<span class="self">self</span>.<span class="ident">on_load</span>.<span class="ident">take</span>().<span class="ident">unwrap</span>())(<span class="ident">ctx</span>, <span class="ident">app</span>, <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">timer</span>, <span class="ident">result</span>);
|
||||
}
|
||||
|
||||
<span class="self">self</span>.<span class="ident">panel</span> <span class="op">=</span> <span class="ident">ctx</span>.<span class="ident">make_loading_screen</span>(<span class="ident">Text::from_multiline</span>(<span class="macro">vec!</span>[
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">lines</span> <span class="op">=</span> <span class="macro">vec!</span>[
|
||||
<span class="ident">Line</span>(<span class="macro">format!</span>(<span class="string">"Loading {}..."</span>, <span class="self">self</span>.<span class="ident">url</span>)),
|
||||
<span class="ident">Line</span>(<span class="macro">format!</span>(
|
||||
<span class="string">"Time spent: {}"</span>,
|
||||
<span class="ident">Duration::realtime_elapsed</span>(<span class="self">self</span>.<span class="ident">started</span>)
|
||||
)),
|
||||
]));
|
||||
];
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">total</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">total_bytes</span> {
|
||||
<span class="ident">lines</span>.<span class="ident">push</span>(<span class="ident">Line</span>(<span class="macro">format!</span>(
|
||||
<span class="string">"Read {} / {} bytes"</span>,
|
||||
<span class="ident">prettyprint_usize</span>(<span class="self">self</span>.<span class="ident">read_bytes</span>),
|
||||
<span class="ident">prettyprint_usize</span>(<span class="ident">total</span>)
|
||||
)));
|
||||
}
|
||||
<span class="self">self</span>.<span class="ident">panel</span> <span class="op">=</span> <span class="ident">ctx</span>.<span class="ident">make_loading_screen</span>(<span class="ident">Text::from_multiline</span>(<span class="ident">lines</span>));
|
||||
|
||||
<span class="comment">// Until the response is received, just ask winit to regularly call event(), so we can</span>
|
||||
<span class="comment">// keep polling the channel.</span>
|
||||
@ -929,6 +1084,11 @@
|
||||
<span class="ident">panel</span>: <span class="ident">Panel</span>,
|
||||
<span class="ident">started</span>: <span class="ident">Instant</span>,
|
||||
<span class="ident">url</span>: <span class="ident">String</span>,
|
||||
|
||||
<span class="ident">total_bytes</span>: <span class="prelude-ty">Option</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span>,
|
||||
<span class="ident">read_bytes</span>: <span class="ident">usize</span>,
|
||||
<span class="ident">got_total_bytes</span>: <span class="ident">oneshot::Receiver</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span>,
|
||||
<span class="ident">got_read_bytes</span>: <span class="ident">mpsc::Receiver</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span>,
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><span class="op"><</span><span class="ident">A</span>: <span class="ident">AppLike</span> <span class="op">+</span> <span class="lifetime">'static</span><span class="op">></span> <span class="ident">RawFileLoader</span><span class="op"><</span><span class="ident">A</span><span class="op">></span> {
|
||||
@ -953,6 +1113,8 @@
|
||||
<span class="comment">// Make the HTTP request nonblockingly. When the response is received, send it through</span>
|
||||
<span class="comment">// the channel.</span>
|
||||
<span class="kw">let</span> (<span class="ident">tx</span>, <span class="ident">rx</span>) <span class="op">=</span> <span class="ident">oneshot::channel</span>();
|
||||
<span class="kw">let</span> (<span class="ident">tx_total_bytes</span>, <span class="ident">got_total_bytes</span>) <span class="op">=</span> <span class="ident">oneshot::channel</span>();
|
||||
<span class="kw">let</span> (<span class="kw-2">mut</span> <span class="ident">tx_read_bytes</span>, <span class="ident">got_read_bytes</span>) <span class="op">=</span> <span class="ident">mpsc::channel</span>(<span class="number">10</span>);
|
||||
<span class="kw">let</span> <span class="ident">url_copy</span> <span class="op">=</span> <span class="ident">url</span>.<span class="ident">clone</span>();
|
||||
<span class="macro">debug!</span>(<span class="string">"Loading {}"</span>, <span class="ident">url_copy</span>);
|
||||
<span class="ident">wasm_bindgen_futures::spawn_local</span>(<span class="kw">async</span> <span class="kw">move</span> {
|
||||
@ -966,9 +1128,30 @@
|
||||
<span class="prelude-val">Ok</span>(<span class="ident">resp_value</span>) <span class="op">=</span><span class="op">></span> {
|
||||
<span class="kw">let</span> <span class="ident">resp</span>: <span class="ident">Response</span> <span class="op">=</span> <span class="ident">resp_value</span>.<span class="ident">dyn_into</span>().<span class="ident">unwrap</span>();
|
||||
<span class="kw">if</span> <span class="ident">resp</span>.<span class="ident">ok</span>() {
|
||||
<span class="kw">let</span> <span class="ident">buf</span> <span class="op">=</span> <span class="ident">JsFuture::from</span>(<span class="ident">resp</span>.<span class="ident">array_buffer</span>().<span class="ident">unwrap</span>()).<span class="kw">await</span>.<span class="ident">unwrap</span>();
|
||||
<span class="kw">let</span> <span class="ident">array</span> <span class="op">=</span> <span class="ident">js_sys::Uint8Array::new</span>(<span class="kw-2">&</span><span class="ident">buf</span>);
|
||||
<span class="ident">tx</span>.<span class="ident">send</span>(<span class="prelude-val">Ok</span>(<span class="ident">array</span>.<span class="ident">to_vec</span>())).<span class="ident">unwrap</span>();
|
||||
<span class="kw">let</span> <span class="ident">total_bytes</span> <span class="op">=</span> <span class="ident">resp</span>
|
||||
.<span class="ident">headers</span>()
|
||||
.<span class="ident">get</span>(<span class="string">"Content-Length"</span>)
|
||||
.<span class="ident">unwrap</span>()
|
||||
.<span class="ident">unwrap</span>()
|
||||
.<span class="ident">parse</span>::<span class="op"><</span><span class="ident">usize</span><span class="op">></span>()
|
||||
.<span class="ident">unwrap</span>();
|
||||
<span class="ident">tx_total_bytes</span>.<span class="ident">send</span>(<span class="ident">total_bytes</span>).<span class="ident">unwrap</span>();
|
||||
|
||||
<span class="kw">let</span> <span class="ident">raw_body</span> <span class="op">=</span> <span class="ident">resp</span>.<span class="ident">body</span>().<span class="ident">unwrap_throw</span>();
|
||||
<span class="kw">let</span> <span class="ident">body</span> <span class="op">=</span> <span class="ident">ReadableStream::from_raw</span>(<span class="ident">raw_body</span>.<span class="ident">dyn_into</span>().<span class="ident">unwrap_throw</span>());
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">stream</span> <span class="op">=</span> <span class="ident">body</span>.<span class="ident">into_stream</span>();
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">buffer</span> <span class="op">=</span> <span class="ident">Vec::new</span>();
|
||||
<span class="kw">while</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(<span class="ident">chunk</span>)) <span class="op">=</span> <span class="ident">stream</span>.<span class="ident">next</span>().<span class="kw">await</span> {
|
||||
<span class="kw">let</span> <span class="ident">array</span> <span class="op">=</span> <span class="ident">js_sys::Uint8Array::new</span>(<span class="kw-2">&</span><span class="ident">chunk</span>);
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Err</span>(<span class="ident">err</span>) <span class="op">=</span>
|
||||
<span class="ident">tx_read_bytes</span>.<span class="ident">try_send</span>(<span class="ident">array</span>.<span class="ident">byte_length</span>() <span class="kw">as</span> <span class="ident">usize</span>)
|
||||
{
|
||||
<span class="macro">warn!</span>(<span class="string">"Couldn't send update on bytes: {}"</span>, <span class="ident">err</span>);
|
||||
}
|
||||
<span class="comment">// TODO Can we avoid this clone?</span>
|
||||
<span class="ident">buffer</span>.<span class="ident">extend</span>(<span class="ident">array</span>.<span class="ident">to_vec</span>());
|
||||
}
|
||||
<span class="ident">tx</span>.<span class="ident">send</span>(<span class="prelude-val">Ok</span>(<span class="ident">buffer</span>)).<span class="ident">unwrap</span>();
|
||||
} <span class="kw">else</span> {
|
||||
<span class="kw">let</span> <span class="ident">status</span> <span class="op">=</span> <span class="ident">resp</span>.<span class="ident">status</span>();
|
||||
<span class="kw">let</span> <span class="ident">err</span> <span class="op">=</span> <span class="ident">resp</span>.<span class="ident">status_text</span>();
|
||||
@ -987,12 +1170,25 @@
|
||||
<span class="ident">panel</span>: <span class="ident">ctx</span>.<span class="ident">make_loading_screen</span>(<span class="ident">Text::from</span>(<span class="macro">format!</span>(<span class="string">"Loading {}..."</span>, <span class="ident">url</span>))),
|
||||
<span class="ident">started</span>: <span class="ident">Instant::now</span>(),
|
||||
<span class="ident">url</span>,
|
||||
<span class="ident">total_bytes</span>: <span class="prelude-val">None</span>,
|
||||
<span class="ident">read_bytes</span>: <span class="number">0</span>,
|
||||
<span class="ident">got_total_bytes</span>,
|
||||
<span class="ident">got_read_bytes</span>,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl</span><span class="op"><</span><span class="ident">A</span>: <span class="ident">AppLike</span> <span class="op">+</span> <span class="lifetime">'static</span><span class="op">></span> <span class="ident">State</span><span class="op"><</span><span class="ident">A</span><span class="op">></span> <span class="kw">for</span> <span class="ident">RawFileLoader</span><span class="op"><</span><span class="ident">A</span><span class="op">></span> {
|
||||
<span class="kw">fn</span> <span class="ident">event</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>, <span class="ident">ctx</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">EventCtx</span>, <span class="ident">app</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">A</span>) <span class="op">-</span><span class="op">></span> <span class="ident">Transition</span><span class="op"><</span><span class="ident">A</span><span class="op">></span> {
|
||||
<span class="kw">if</span> <span class="self">self</span>.<span class="ident">total_bytes</span>.<span class="ident">is_none</span>() {
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(<span class="ident">total</span>)) <span class="op">=</span> <span class="self">self</span>.<span class="ident">got_total_bytes</span>.<span class="ident">try_recv</span>() {
|
||||
<span class="self">self</span>.<span class="ident">total_bytes</span> <span class="op">=</span> <span class="prelude-val">Some</span>(<span class="ident">total</span>);
|
||||
}
|
||||
}
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">read</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">got_read_bytes</span>.<span class="ident">try_next</span>().<span class="ident">ok</span>().<span class="ident">and_then</span>(<span class="op">|</span><span class="ident">value</span><span class="op">|</span> <span class="ident">value</span>) {
|
||||
<span class="self">self</span>.<span class="ident">read_bytes</span> <span class="op">+</span><span class="op">=</span> <span class="ident">read</span>;
|
||||
}
|
||||
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">maybe_resp</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">response</span>.<span class="ident">try_recv</span>().<span class="ident">unwrap</span>() {
|
||||
<span class="kw">let</span> <span class="ident">bytes</span> <span class="op">=</span> <span class="kw">if</span> <span class="self">self</span>.<span class="ident">url</span>.<span class="ident">ends_with</span>(<span class="string">".gz"</span>) {
|
||||
<span class="ident">maybe_resp</span>.<span class="ident">and_then</span>(<span class="op">|</span><span class="ident">gzipped</span><span class="op">|</span> {
|
||||
@ -1009,13 +1205,21 @@
|
||||
<span class="kw">return</span> (<span class="self">self</span>.<span class="ident">on_load</span>.<span class="ident">take</span>().<span class="ident">unwrap</span>())(<span class="ident">ctx</span>, <span class="ident">app</span>, <span class="ident">bytes</span>);
|
||||
}
|
||||
|
||||
<span class="self">self</span>.<span class="ident">panel</span> <span class="op">=</span> <span class="ident">ctx</span>.<span class="ident">make_loading_screen</span>(<span class="ident">Text::from_multiline</span>(<span class="macro">vec!</span>[
|
||||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">lines</span> <span class="op">=</span> <span class="macro">vec!</span>[
|
||||
<span class="ident">Line</span>(<span class="macro">format!</span>(<span class="string">"Loading {}..."</span>, <span class="self">self</span>.<span class="ident">url</span>)),
|
||||
<span class="ident">Line</span>(<span class="macro">format!</span>(
|
||||
<span class="string">"Time spent: {}"</span>,
|
||||
<span class="ident">Duration::realtime_elapsed</span>(<span class="self">self</span>.<span class="ident">started</span>)
|
||||
)),
|
||||
]));
|
||||
];
|
||||
<span class="kw">if</span> <span class="kw">let</span> <span class="prelude-val">Some</span>(<span class="ident">total</span>) <span class="op">=</span> <span class="self">self</span>.<span class="ident">total_bytes</span> {
|
||||
<span class="ident">lines</span>.<span class="ident">push</span>(<span class="ident">Line</span>(<span class="macro">format!</span>(
|
||||
<span class="string">"Read {} / {} bytes"</span>,
|
||||
<span class="ident">prettyprint_usize</span>(<span class="self">self</span>.<span class="ident">read_bytes</span>),
|
||||
<span class="ident">prettyprint_usize</span>(<span class="ident">total</span>)
|
||||
)));
|
||||
}
|
||||
<span class="self">self</span>.<span class="ident">panel</span> <span class="op">=</span> <span class="ident">ctx</span>.<span class="ident">make_loading_screen</span>(<span class="ident">Text::from_multiline</span>(<span class="ident">lines</span>));
|
||||
|
||||
<span class="comment">// Until the response is received, just ask winit to regularly call event(), so we can</span>
|
||||
<span class="comment">// keep polling the channel.</span>
|
||||
|
Loading…
Reference in New Issue
Block a user