@@ 2185,7 2185,7 @@ dependencies = [
"bitflags 1.3.2",
"core-foundation",
"core-graphics-types",
- "foreign-types",
+ "foreign-types 0.5.0",
"libc",
]
@@ 2885,12 2885,21 @@ checksum = "a0d2fde1f7b3d48b8395d5f2de76c18a528bd6a9cdde438df747bfcba3e05d6f"
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
dependencies = [
"foreign-types-macros",
- "foreign-types-shared",
+ "foreign-types-shared 0.3.1",
]
[[package]]
@@ 2906,6 2915,12 @@ dependencies = [
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
@@ 3416,6 3431,17 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 3450,6 3476,43 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 3604,6 3667,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 3997,7 4066,7 @@ dependencies = [
"bitflags 2.6.0",
"block",
"core-graphics-types",
- "foreign-types",
+ "foreign-types 0.5.0",
"log",
"objc",
"paste",
@@ 4012,7 4081,7 @@ dependencies = [
"bitflags 2.6.0",
"block",
"core-graphics-types",
- "foreign-types",
+ "foreign-types 0.5.0",
"log",
"objc",
"paste",
@@ 4191,6 4260,23 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 4699,6 4785,50 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 5337,6 5467,46 @@ 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 = "rgb"
version = "0.8.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 5453,6 5623,15 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 5500,6 5679,15 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 5535,6 5723,29 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 5871,6 6082,7 @@ dependencies = [
"image 0.25.5",
"nalgebra 0.33.2",
"pollster",
+ "reqwest",
"thiserror 2.0.9",
"tracing",
"tracing-subscriber",
@@ 5992,6 6204,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 6006,6 6224,27 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 6262,6 6501,16 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 6371,6 6620,12 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 6509,6 6764,12 @@ dependencies = [
]
[[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.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 6681,6 6942,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 6703,6 6970,15 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 7705,6 7981,16 @@ dependencies = [
]
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ 0,0 1,92 @@
+use std::{collections::HashMap, fmt::Display, sync::{Arc, Mutex}};
+
+use bevy_ecs::system::Resource;
+use futures::channel::oneshot::{Receiver, Sender};
+use image::EncodableLayout;
+use tracing::info;
+use wasm_bindgen_futures::spawn_local;
+
+use super::texture::{self, Texture};
+
+#[derive(Debug, Clone)]
+pub enum AssetError {
+ AssetNotFound,
+ ResponseNotOk(u16),
+}
+impl Display for AssetError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ AssetError::AssetNotFound => write!(f, "Asset not found"),
+ AssetError::ResponseNotOk(code) => write!(f, "Server response was not ok {}", code),
+ }
+ }
+}
+impl std::error::Error for AssetError {}
+
+#[derive(Resource)]
+pub struct Assets {
+ texture_receivers: Arc<Mutex<HashMap<String, Receiver<Vec<u8>>>>>,
+ textures: Arc<Mutex<HashMap<String, Vec<u8>>>>,
+}
+
+impl Assets {
+ pub fn new() -> Self {
+ Assets {
+ textures: Arc::new(Mutex::new(HashMap::new())),
+ texture_receivers: Arc::new(Mutex::new(HashMap::new())),
+ }
+ }
+ pub fn get(&self, local_path: impl Into<String>) -> Option<Vec<u8>> {
+ let (tx, rx) = futures::channel::oneshot::channel();
+ let local_path = local_path.into();
+ let contains_texture = {
+ self.textures.lock().unwrap().contains_key(&local_path)
+ };
+ let contains_texture_receiver = {
+ self.texture_receivers.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 {
+ let window = web_sys::window().unwrap();
+ let resp = match reqwest::get(format!("{}/src/textures/{}", window.location().origin().unwrap(), local_path)).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!();
+ },
+ };
+ let bytes = match resp.bytes().await {
+ Ok(bytes) => bytes,
+ Err(e) => todo!(),
+ }.to_vec();
+ textures.lock().unwrap().insert(local_path, bytes.clone());
+ tx.send(bytes).unwrap();
+ });
+ 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);
+ return Some(texture);
+ }
+ None
+ } else {
+ self.textures.lock().unwrap().get(&local_path).cloned()
+ }
+ }
+}
@@ 1,4 1,5 @@
use crate::ecs::{Camera, Rotation, Scale, Shear, SpriteTexture, Translation};
+use crate::rendering::assets::Assets;
use crate::rendering::mipmap::MipGenerator;
use crate::rendering::renderer::RenderInitRes::{Initialized, NotReadyYet};
use crate::rendering::texture;
@@ 266,16 267,33 @@ impl<T: UiRenderable> Renderer<T> {
self.queue.write_buffer(&self.frame_uniform, 0, &frame_uniform);
for (pos, shear, scale, tex, rot) in sprites_to_render {
- let tex = self.textures.entry(tex.texture.clone()).or_insert_with(|| {
+ let tex = self.textures.entry(tex.texture.clone()).or_insert({
info!("loading texture {}", &tex.texture);
- let b: &[u8] = match tex.texture.as_str() {
+ let assets = self.world.get_resource::<Assets>().unwrap();
+ let b = match tex.texture.as_str() {
+ "f" => match assets.get("f.png") {
+ Some(b) => b,
+ None => continue,
+ }
+ "happy-tree" => match assets.get("happy-tree.png") {
+ Some(b) => b,
+ None => continue,
+ }
+ "uv" => match assets.get("uv.png") {
+ Some(b) => b,
+ None => continue,
+ }
+ u => panic!("unknown texture {u}, has it been added in rendering::renderer::<impl Renderer>::render()?")
+ };
+ tracing::warn!("{:?}", b);
+ /*let b: &[u8] = match tex.texture.as_str() {
"f" => include_bytes!("../textures/f.png"),
"happy-tree" => include_bytes!("../textures/happy-tree.png"),
"uv" => include_bytes!("../textures/uv.png"),
u => panic!("unknown texture {u}, has it been added in rendering::renderer::<impl Renderer>::render()?")
- };
+ };*/
texture::Texture::new(
- b,
+ &b,
&tex.texture,
&self.device,
&self.queue,