From ba254ec74e51495678ac09f06342403ab08434a2 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Mon, 17 Mar 2025 22:17:35 -0500 Subject: [PATCH] sync, i guess --- Cargo.lock | 362 +++------------------ crates/client/Cargo.toml | 3 +- crates/client/src/networking/mod.rs | 12 +- crates/client/src/networking/ws_wasm.rs | 4 +- crates/client/src/rendering/assets_wasm.rs | 91 +++--- crates/client/src/rendering/renderer.rs | 11 +- crates/client/src/rendering/texture.rs | 2 +- 7 files changed, 111 insertions(+), 374 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a47363d41ea9e64c0300a14ef99fa137694b980c..e4515679c2d7eac3b97aeacb87a0097ffdef34e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2185,7 +2185,7 @@ dependencies = [ "bitflags 1.3.2", "core-foundation", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "libc", ] @@ -2655,6 +2655,20 @@ dependencies = [ "winit 0.30.8", ] +[[package]] +name = "ehttp" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a81c221a1e4dad06cb9c9deb19aea1193a5eea084e8cd42d869068132bf876" +dependencies = [ + "document-features", + "js-sys", + "ureq", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + [[package]] name = "either" version = "1.13.0" @@ -2927,15 +2941,6 @@ dependencies = [ "ttf-parser 0.24.1", ] -[[package]] -name = "foreign-types" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -dependencies = [ - "foreign-types-shared 0.1.1", -] - [[package]] name = "foreign-types" version = "0.5.0" @@ -2943,7 +2948,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ "foreign-types-macros", - "foreign-types-shared 0.3.1", + "foreign-types-shared", ] [[package]] @@ -2957,12 +2962,6 @@ dependencies = [ "syn 2.0.94", ] -[[package]] -name = "foreign-types-shared" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" - [[package]] name = "foreign-types-shared" version = "0.3.1" @@ -3474,17 +3473,6 @@ dependencies = [ "itoa", ] -[[package]] -name = "http-body" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" -dependencies = [ - "bytes", - "http 0.2.12", - "pin-project-lite", -] - [[package]] name = "httparse" version = "1.9.4" @@ -3519,43 +3507,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "hyper" -version = "0.14.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41dfc780fdec9373c01bae43289ea34c972e40ee3c9f6b3c8801a35f35586ce7" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http 0.2.12", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project-lite", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] -name = "hyper-tls" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" -dependencies = [ - "bytes", - "hyper", - "native-tls", - "tokio", - "tokio-native-tls", -] - [[package]] name = "iana-time-zone" version = "0.1.61" @@ -3726,12 +3677,6 @@ dependencies = [ "syn 2.0.94", ] -[[package]] -name = "ipnet" -version = "2.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" - [[package]] name = "is-terminal" version = "0.4.12" @@ -3821,9 +3766,9 @@ checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" [[package]] name = "js-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ "once_cell", "wasm-bindgen", @@ -4136,7 +4081,7 @@ dependencies = [ "bitflags 2.6.0", "block", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "log", "objc", "paste", @@ -4151,7 +4096,7 @@ dependencies = [ "bitflags 2.6.0", "block", "core-graphics-types", - "foreign-types 0.5.0", + "foreign-types", "log", "objc", "paste", @@ -4329,23 +4274,6 @@ dependencies = [ "syn 2.0.94", ] -[[package]] -name = "native-tls" -version = "0.2.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" -dependencies = [ - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "ndk" version = "0.8.0" @@ -4854,50 +4782,6 @@ version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" -[[package]] -name = "openssl" -version = "0.10.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" -dependencies = [ - "bitflags 2.6.0", - "cfg-if", - "foreign-types 0.3.2", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.94", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" -dependencies = [ - "cc", - "libc", - "pkg-config", - "vcpkg", -] - [[package]] name = "orbclient" version = "0.3.47" @@ -5147,6 +5031,18 @@ dependencies = [ "miniz_oxide 0.8.2", ] +[[package]] +name = "poll-promise" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6a58fecbf9da8965bcdb20ce4fd29788d1acee68ddbb64f0ba1b81bccdb7df" +dependencies = [ + "document-features", + "static_assertions", + "wasm-bindgen", + "wasm-bindgen-futures", +] + [[package]] name = "polling" version = "3.7.2" @@ -5542,46 +5438,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832" -[[package]] -name = "reqwest" -version = "0.11.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" -dependencies = [ - "base64 0.21.7", - "bytes", - "encoding_rs", - "futures-core", - "futures-util", - "h2", - "http 0.2.12", - "http-body", - "hyper", - "hyper-tls", - "ipnet", - "js-sys", - "log", - "mime", - "native-tls", - "once_cell", - "percent-encoding", - "pin-project-lite", - "rustls-pemfile", - "serde", - "serde_json", - "serde_urlencoded", - "sync_wrapper", - "system-configuration", - "tokio", - "tokio-native-tls", - "tower-service", - "url", - "wasm-bindgen", - "wasm-bindgen-futures", - "web-sys", - "winreg", -] - [[package]] name = "resvg" version = "0.44.0" @@ -5711,9 +5567,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.20" +version = "0.23.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5065c3f250cbd332cd894be57c40fa52387247659b14a2d6041d121547903b1b" +checksum = "47796c98c480fce5406ef69d1c76378375492c3b0a0de587be0c1d9feb12f395" dependencies = [ "log", "once_cell", @@ -5724,15 +5580,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "rustls-pemfile" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" -dependencies = [ - "base64 0.21.7", -] - [[package]] name = "rustls-pki-types" version = "1.10.1" @@ -5798,15 +5645,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" -dependencies = [ - "windows-sys 0.59.0", -] - [[package]] name = "scoped-futures" version = "0.1.3" @@ -5842,29 +5680,6 @@ dependencies = [ "tiny-skia", ] -[[package]] -name = "security-framework" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" -dependencies = [ - "bitflags 2.6.0", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "semver" version = "1.0.23" @@ -6214,11 +6029,12 @@ dependencies = [ "egui", "egui-wgpu", "egui-winit", + "ehttp", "futures", "image 0.25.5", "nalgebra 0.33.2", + "poll-promise", "pollster", - "reqwest", "resvg", "serde", "serde_json", @@ -6358,12 +6174,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "sync_wrapper" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" - [[package]] name = "sysinfo" version = "0.30.13" @@ -6378,27 +6188,6 @@ dependencies = [ "windows 0.52.0", ] -[[package]] -name = "system-configuration" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" -dependencies = [ - "bitflags 1.3.2", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "system-deps" version = "6.2.2" @@ -6656,16 +6445,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - [[package]] name = "tokio-postgres" version = "0.7.11" @@ -6775,12 +6554,6 @@ dependencies = [ "winnow 0.6.18", ] -[[package]] -name = "tower-service" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" - [[package]] name = "tracing" version = "0.1.40" @@ -6919,12 +6692,6 @@ dependencies = [ "cc", ] -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - [[package]] name = "ttf-parser" version = "0.24.1" @@ -7175,12 +6942,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version-compare" version = "0.2.0" @@ -7203,15 +6964,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -7226,20 +6978,21 @@ checksum = "b8dad83b4f25e74f184f64c43b150b91efe7647395b42289f38e50566d82855b" [[package]] name = "wasm-bindgen" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", @@ -7251,9 +7004,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.49" +version = "0.4.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" dependencies = [ "cfg-if", "js-sys", @@ -7264,9 +7017,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -7274,9 +7027,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", @@ -7287,9 +7040,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.99" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "wasm-pack" @@ -7434,9 +7190,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.76" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", @@ -8214,16 +7970,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "x11-dl" version = "2.21.0" diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 7e1c4ab9d0423d1502cf60cbd7c87a458f0dd83e..b91c58d9e38ebba65476497b692e2873cc8a7f57 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -34,7 +34,8 @@ console_error_panic_hook = "0.1" # Give useful information in the panic response wasm-bindgen = "0.2" web-sys = { version = "0.3", features = ["Window", "Location", "WebSocket", "MessageEvent"] } wasm-bindgen-futures = "0.4" -reqwest = "0.11" +ehttp = "0.5.0" +poll-promise = { version = "0.3.0", features = ["web"] } # Native dependencies [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/crates/client/src/networking/mod.rs b/crates/client/src/networking/mod.rs index 115a7b6f28dbfba46161f1c4ef64f77722f2fb6c..7c883a331a0ba4671c8844ae1638453e5f4dc00b 100644 --- a/crates/client/src/networking/mod.rs +++ b/crates/client/src/networking/mod.rs @@ -27,15 +27,13 @@ pub fn process_packets( if part.part_type == PartType::Hearty { let mut player_query = world.query_filtered::<(&mut Translation, &mut Rotation), With>(); let mut camera = world.resource_mut::(); - /*camera.x = part.transform.x; - camera.y = part.transform.y;*/ - camera.x = 0.0; - camera.y = 1.0; + camera.x = part.transform.x; + camera.y = part.transform.y; tracing::info!("camera real {:?}", camera); for (mut translation, mut rotation) in player_query.iter_mut(world) { - translation.x = 0.0; - translation.y = 1.0; - //rotation.radians = part.transform.rot; + translation.x = part.transform.x; + translation.y = part.transform.y; + rotation.radians = part.transform.rot; tracing::info!("part real {:?}", translation); } tracing::info!("part {:?}", part.transform); diff --git a/crates/client/src/networking/ws_wasm.rs b/crates/client/src/networking/ws_wasm.rs index 48a94ee8d14e786c14515728c747ee65ec8e10e5..ef5c7869fc7c53981822d1f4680ea3263a79b1fe 100644 --- a/crates/client/src/networking/ws_wasm.rs +++ b/crates/client/src/networking/ws_wasm.rs @@ -1,3 +1,5 @@ +use std::thread::yield_now; + use bevy_ecs::system::Resource; //use crossbeam::channel::{unbounded, Receiver, Sender}; use futures::{channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender}, SinkExt}; @@ -64,7 +66,7 @@ impl Ws { pub fn send_packet(&mut self, packet: Packet) { let socket = self.socket.0.clone(); spawn_local(async move { - while socket.ready_state() != 1 {} + while socket.ready_state() != 1 { yield_now(); } socket.send_with_str(&serde_json::to_string(&packet).expect("Couldn't convert packet to json")).expect("Couldn't send packet to server"); }); } diff --git a/crates/client/src/rendering/assets_wasm.rs b/crates/client/src/rendering/assets_wasm.rs index ab94ab82336c34166338f9142b4ff7ae43ed2ba5..56f2e032d06a6de1601179aed2f37d855aa6c547 100644 --- a/crates/client/src/rendering/assets_wasm.rs +++ b/crates/client/src/rendering/assets_wasm.rs @@ -1,8 +1,9 @@ -use std::{collections::HashMap, fmt::Display, sync::{Arc, Mutex}}; +use std::{collections::HashMap, fmt::Display, sync::{Arc, Mutex}, time::Duration}; use bevy_ecs::system::Resource; use futures::channel::oneshot::Receiver; use image::EncodableLayout; +use poll_promise::Promise; use resvg::{tiny_skia, usvg}; use wasm_bindgen_futures::spawn_local; @@ -30,7 +31,7 @@ pub struct ImgData { #[derive(Resource)] pub struct Assets { - texture_receivers: Arc>>>, + texture_promises: Arc>>>, textures: Arc>>, } @@ -38,54 +39,41 @@ impl Assets { pub fn new() -> Self { Assets { textures: Arc::new(Mutex::new(HashMap::new())), - texture_receivers: Arc::new(Mutex::new(HashMap::new())), + texture_promises: Arc::new(Mutex::new(HashMap::new())), } } pub fn get(&self, local_path: impl Into) -> Option { - let (tx, rx) = futures::channel::oneshot::channel(); let local_path = local_path.into(); + tracing::info!("contains texture"); let contains_texture = { self.textures.lock().unwrap().contains_key(&local_path) }; - let contains_texture_receiver = { - self.texture_receivers.lock().unwrap().contains_key(&local_path) + tracing::info!("contains texture promise"); + let contains_texture_promise = { + self.texture_promises.lock().unwrap().contains_key(&local_path) }; - if !contains_texture && !contains_texture_receiver { - let textures = self.textures.clone(); - { - self.texture_receivers.lock().unwrap().insert(local_path.clone(), rx); - } - spawn_local(async move { + if !contains_texture && !contains_texture_promise { + tracing::info!("insert receiver"); + let local_path_clone = local_path.clone(); + let request_promise = poll_promise::Promise::spawn_local(async move { + tracing::info!("in spawn local"); let window = web_sys::window().unwrap(); - let resp = match reqwest::get(format!("{}/src/textures/{}", window.location().origin().unwrap(), local_path)).await { + tracing::info!("after window"); + let request = ehttp::Request::get(format!("{}/src/textures/{}", window.location().origin().unwrap(), local_path_clone)); + let response = match ehttp::fetch_async(request).await { Ok(resp) => resp, Err(e) => { - if e.is_request() { - panic!("Error in request {}", e); - } else if e.is_body() { - panic!("Error in body {}", e); - } else if e.is_status() { - panic!("Bad status: {}", e.status().unwrap()); - } else if e.is_decode() { - panic!("Couldn't decode response's body {}", e); - } else if e.is_redirect() { - panic!("Response caused redirect loop {}", e); - } else if e.is_builder() { - panic!("Error in builder {}", e); - } - panic!(); + panic!("{}", e); }, }; - let bytes = match resp.bytes().await { - Ok(bytes) => bytes, - Err(e) => todo!(), - }.to_vec(); - if local_path.ends_with(".svg") { + tracing::info!("after response"); + tracing::info!("texture received"); + if local_path_clone.ends_with(".svg") { let opt = usvg::Options { default_size: usvg::Size::from_wh(20.0, 20.0).unwrap(), ..Default::default() }; - let tree = usvg::Tree::from_data(&bytes, &opt).expect(&format!("Couldn't parse svg {}", local_path)); + let tree = usvg::Tree::from_data(&response.bytes, &opt).expect(&format!("Couldn't parse svg {}", local_path_clone)); let tree_size = tree.size().to_int_size(); let size = usvg::Size::from_wh(100.0, 100.0).unwrap().to_int_size(); assert!(size.width() > 0 && size.height() > 0); @@ -97,34 +85,37 @@ impl Assets { height: size.height(), }; - { - textures.lock().unwrap().insert(local_path, data.clone()); - } - tx.send(data).unwrap(); - } else if local_path.ends_with(".png") { - let img = image::load_from_memory(&bytes).unwrap(); + data + } else if local_path_clone.ends_with(".png") { + let img = image::load_from_memory(&response.bytes).unwrap(); let rgba = img.to_rgba8(); let data = ImgData { bytes: rgba.as_bytes().to_vec(), width: rgba.width(), height: rgba.height(), }; - { - textures.lock().unwrap().insert(local_path, data.clone()); - } - tx.send(data).unwrap(); + data + } else { + panic!("Unsupported sprite type"); } }); + { + self.texture_promises.lock().unwrap().insert(local_path.clone(), request_promise); + } None } else if !contains_texture { - let mut texture_receivers = self.texture_receivers.lock().unwrap(); - let rx = texture_receivers.get_mut(&local_path).unwrap(); - if let Ok(Some(texture)) = rx.try_recv() { - self.texture_receivers.lock().unwrap().remove(&local_path); - self.textures.lock().unwrap().insert(local_path, texture.clone()); - return Some(texture); + tracing::info!("in contains texture"); + let mut texture_promises = self.texture_promises.lock().unwrap(); + tracing::info!("lock received"); + let promise = texture_promises.get_mut(&local_path).unwrap(); + tracing::info!("texture receiver gotten"); + let mut returned_value = None; + if let Some(texture) = promise.ready() { + self.textures.lock().unwrap().insert(local_path.clone(), texture.clone()); + returned_value = Some(texture.clone()); + texture_promises.remove(&local_path); } - None + return returned_value } else { self.textures.lock().unwrap().get(&local_path).cloned() } diff --git a/crates/client/src/rendering/renderer.rs b/crates/client/src/rendering/renderer.rs index 6db434c780dc215271c115082b29bd9f22bedaf8..1fafe12d99c91c4602d6bc94b86772532fbbcc7d 100644 --- a/crates/client/src/rendering/renderer.rs +++ b/crates/client/src/rendering/renderer.rs @@ -298,12 +298,12 @@ impl Renderer { self.queue.write_buffer(&self.frame_uniform, 0, &frame_uniform); - for (pos, shear, scale, tex, rot) in sprites_to_render { - let tex = match self.textures.entry(tex.texture.clone()) { + for (pos, shear, scale, sprite_tex, rot) in sprites_to_render { + let tex = match self.textures.entry(sprite_tex.texture.clone()) { Entry::Occupied(entry) => entry.into_mut(), Entry::Vacant(entry) => { let assets = self.world.get_resource::().unwrap(); - let b = match tex.texture.as_str() { + let b = match sprite_tex.texture.as_str() { "f" => match assets.get("f.png") { Some(b) => b, None => continue, @@ -368,15 +368,14 @@ impl Renderer { }; entry.insert(texture::Texture::new( b, - &tex.texture, + &sprite_tex.texture, &self.device, &self.queue, &mut self.mip_generator, )) } }; - - info!("render: {:?}", pos); + tracing::info!("{} {:?} {:?}", sprite_tex.texture, pos, tex.texture); let xy_matrix = pos.as_matrix(); let shear_matrix = shear.as_matrix(); let rot_matrix = rot.as_matrix(); diff --git a/crates/client/src/rendering/texture.rs b/crates/client/src/rendering/texture.rs index 7d8bba3f1b8457ff3253ff5f4b29c40bd10b8d29..b7da963f47f52ed1d5e9c8ff6c049b5cc3343b7b 100644 --- a/crates/client/src/rendering/texture.rs +++ b/crates/client/src/rendering/texture.rs @@ -69,7 +69,7 @@ impl Texture { let tex = Self { texture, sampler }; - mip_generator.generate_mips(&tex, device, queue); + //mip_generator.generate_mips(&tex, device, queue); tex }