~starkingdoms/starkingdoms

21dabbfd8242e9683659b8b069385a5841be300a — core 8 months ago b2a99d1
asset system platformification
M Cargo.lock => Cargo.lock +23 -195
@@ 609,31 609,6 @@ dependencies = [
 "async-lock",
 "blocking",
 "futures-lite",
<<<<<<< HEAD
 "once_cell",
 "tokio",
]

[[package]]
name = "async-io"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af"
dependencies = [
 "async-lock",
 "autocfg",
 "cfg-if",
 "concurrent-queue",
 "futures-lite",
 "log",
 "parking",
 "polling",
 "rustix 0.37.20",
 "slab",
 "socket2",
 "waker-fn",
=======
>>>>>>> rust-rendering-2
]

[[package]]


@@ 1706,9 1681,9 @@ dependencies = [

[[package]]
name = "bytemuck_derive"
version = "1.9.2"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ff22c2722516255d1823ce3cc4bc0b154dbc9364be5c905d6baa6eccbbc8774"
checksum = "7ecc273b49b3205b83d648f0690daa588925572cc5063745bfe547fe7ec8e1a1"
dependencies = [
 "proc-macro2",
 "quote",


@@ 1952,9 1927,9 @@ dependencies = [

[[package]]
name = "clap"
version = "4.5.32"
version = "4.5.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83"
checksum = "e958897981290da2a852763fe9cdb89cd36977a5d729023127095fa94d95e2ff"
dependencies = [
 "clap_builder",
 "clap_derive",


@@ 1962,9 1937,9 @@ dependencies = [

[[package]]
name = "clap_builder"
version = "4.5.32"
version = "4.5.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8"
checksum = "83b0f35019843db2160b5bb19ae09b4e6411ac33fc6a712003c33e03090e2489"
dependencies = [
 "anstream",
 "anstyle",


@@ 2860,9 2835,9 @@ dependencies = [

[[package]]
name = "event-listener-strategy"
version = "0.5.3"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c3e4e0dd3673c1139bf041f3008816d9cf2946bbfac2945c09e523b8d7b05b2"
checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"
dependencies = [
 "event-listener 5.4.0",
 "pin-project-lite",


@@ 3662,9 3637,9 @@ dependencies = [

[[package]]
name = "icu_locid_transform_data"
version = "1.5.0"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e"
checksum = "7515e6d781098bf9f7205ab3fc7e9709d34554ae0b21ddbcb5febfa4bc7df11d"

[[package]]
name = "icu_normalizer"


@@ 3686,9 3661,9 @@ dependencies = [

[[package]]
name = "icu_normalizer_data"
version = "1.5.0"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516"
checksum = "c5e8338228bdc8ab83303f16b797e177953730f601a96c25d10cb3ab0daa0cb7"

[[package]]
name = "icu_properties"


@@ 3707,9 3682,9 @@ dependencies = [

[[package]]
name = "icu_properties_data"
version = "1.5.0"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569"
checksum = "85fb8799753b75aee8d2a21d7c14d9f38921b54b3dbda10f5a3c7a7b82dba5e2"

[[package]]
name = "icu_provider"


@@ 3774,9 3749,9 @@ dependencies = [

[[package]]
name = "image"
version = "0.25.5"
version = "0.25.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6f44aed642f18953a158afeb30206f4d50da59fbc66ecb53c66488de73563b"
checksum = "db35664ce6b9810857a38a906215e75a9c879f0696556a39f59c62829710251a"
dependencies = [
 "bytemuck",
 "byteorder-lite",


@@ 4132,17 4107,7 @@ dependencies = [

[[package]]
name = "linux-raw-sys"
<<<<<<< HEAD
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"

[[package]]
name = "linux-raw-sys"
version = "0.3.8"
=======
version = "0.4.15"
>>>>>>> rust-rendering-2
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"



@@ 4991,9 4956,9 @@ dependencies = [

[[package]]
name = "once_cell"
version = "1.21.1"
version = "1.21.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc"
checksum = "c2806eaa3524762875e21c3dcd057bc4b7bfa01ce4da8d46be1cd43649e1cc6b"

[[package]]
name = "oorandom"


@@ 5069,27 5034,7 @@ dependencies = [
name = "parry2d"
version = "0.13.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
<<<<<<< HEAD
checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
dependencies = [
 "backtrace",
 "cfg-if",
 "libc",
 "petgraph",
 "redox_syscall 0.3.5",
 "smallvec",
 "thread-id",
 "windows-targets 0.48.0",
]

[[package]]
name = "parry2d-f64"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f612055f319eb83e67841fdf00248eee26045a1759b5d94fa9c6ecce7c1e78d"
=======
checksum = "9fd94bf962ead112f14223469aac6f76e3c24e2c399e348f638924498b238c56"
>>>>>>> rust-rendering-2
dependencies = [
 "approx",
 "arrayvec",


@@ 5381,43 5326,8 @@ dependencies = [
]

[[package]]
<<<<<<< HEAD
name = "procfs"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1de8dacb0873f77e6aefc6d71e044761fcc68060290f5b1089fcdf84626bb69"
dependencies = [
 "bitflags",
 "byteorder",
 "hex",
 "lazy_static",
 "rustix 0.36.15",
]

[[package]]
name = "prometheus"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c"
dependencies = [
 "cfg-if",
 "fnv",
 "lazy_static",
 "libc",
 "memchr",
 "parking_lot 0.12.1",
 "procfs",
 "protobuf 2.28.0",
 "thiserror",
]

[[package]]
name = "protobuf"
version = "2.28.0"
=======
name = "profiling"
version = "1.0.16"
>>>>>>> rust-rendering-2
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afbdc74edc00b6f6a218ca6a5364d6226a259d4b8ea1af4a0ea063f27e179f4d"
dependencies = [


@@ 5452,9 5362,9 @@ checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"

[[package]]
name = "quick-xml"
version = "0.37.2"
version = "0.37.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "165859e9e55f79d67b96c5d96f4e88b6f2695a1972849c15a6a3f5c59fc2c003"
checksum = "bf763ab1c7a3aa408be466efc86efe35ed1bd3dd74173ed39d6b0d0a6f0ba148"
dependencies = [
 "memchr",
]


@@ 5863,35 5773,13 @@ dependencies = [

[[package]]
name = "rustix"
<<<<<<< HEAD
version = "0.36.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c37f1bd5ef1b5422177b7646cba67430579cfe2ace80f284fee876bca52ad941"
dependencies = [
 "bitflags",
 "errno",
 "io-lifetimes",
 "libc",
 "linux-raw-sys 0.1.4",
 "windows-sys 0.45.0",
]

[[package]]
name = "rustix"
version = "0.37.20"
=======
version = "0.38.44"
>>>>>>> rust-rendering-2
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
dependencies = [
 "bitflags 2.9.0",
 "errno",
 "libc",
<<<<<<< HEAD
 "linux-raw-sys 0.3.8",
 "windows-sys 0.48.0",
=======
 "linux-raw-sys 0.4.15",
 "windows-sys 0.59.0",
]


@@ 5907,7 5795,6 @@ dependencies = [
 "libc",
 "linux-raw-sys 0.9.3",
 "windows-sys 0.59.0",
>>>>>>> rust-rendering-2
]

[[package]]


@@ 5933,9 5820,9 @@ checksum = "917ce264624a4b4db1c364dcc35bfca9ded014d0a958cd47ad3e960e988ea51c"

[[package]]
name = "rustls-webpki"
version = "0.103.0"
version = "0.103.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0aa4eeac2588ffff23e9d7a7e9b3f971c5fb5b7ebc9452745e0c232c64f83b2f"
checksum = "fef8b8769aaccf73098557a87cd1816b4f9c7c16811c9c77142aa695c16f2c03"
dependencies = [
 "ring",
 "rustls-pki-types",


@@ 6385,7 6272,7 @@ dependencies = [
 "glow 0.16.0",
 "glutin",
 "glutin-winit",
 "image 0.25.5",
 "image 0.25.6",
 "nalgebra 0.33.2",
 "poll-promise",
 "pollster",


@@ 6428,21 6315,6 @@ dependencies = [
name = "starkingdoms-server"
version = "0.1.0-alpha1"
dependencies = [
<<<<<<< HEAD
 "async-std",
 "async-tungstenite",
 "cargo_metadata",
 "futures",
 "lazy_static",
 "log",
 "nalgebra",
 "parking_lot 0.12.1",
 "prometheus",
 "protobuf 3.2.0",
 "rand",
 "rapier2d-f64",
 "reqwest",
=======
 "bevy",
 "bevy_rapier2d",
 "crossbeam-channel",


@@ 6450,7 6322,6 @@ dependencies = [
 "hmac",
 "jwt",
 "rand 0.8.5",
>>>>>>> rust-rendering-2
 "serde",
 "serde_json",
 "sha2",


@@ 6617,16 6488,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf"
dependencies = [
 "fastrand",
<<<<<<< HEAD
 "redox_syscall 0.3.5",
 "rustix 0.37.20",
 "windows-sys 0.48.0",
=======
 "getrandom 0.3.2",
 "once_cell",
 "rustix 1.0.3",
 "windows-sys 0.59.0",
>>>>>>> rust-rendering-2
]

[[package]]


@@ 7841,9 7706,6 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
<<<<<<< HEAD
 "windows-targets 0.48.0",
=======
 "windows-implement 0.48.0",
 "windows-interface 0.48.0",
 "windows-targets 0.48.5",


@@ 7958,7 7820,6 @@ checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10"
dependencies = [
 "windows-result",
 "windows-targets 0.52.6",
>>>>>>> rust-rendering-2
]

[[package]]


@@ 8013,43 7874,11 @@ dependencies = [
]

[[package]]
<<<<<<< HEAD
name = "windows-sys"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
dependencies = [
 "windows-targets 0.42.2",
]

[[package]]
name = "windows-sys"
version = "0.48.0"
=======
name = "windows-targets"
version = "0.48.5"
>>>>>>> rust-rendering-2
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
<<<<<<< HEAD
 "windows-targets 0.48.0",
]

[[package]]
name = "windows-targets"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
dependencies = [
 "windows_aarch64_gnullvm 0.42.2",
 "windows_aarch64_msvc 0.42.2",
 "windows_i686_gnu 0.42.2",
 "windows_i686_msvc 0.42.2",
 "windows_x86_64_gnu 0.42.2",
 "windows_x86_64_gnullvm 0.42.2",
 "windows_x86_64_msvc 0.42.2",
=======
 "windows_aarch64_gnullvm 0.48.5",
 "windows_aarch64_msvc 0.48.5",
 "windows_i686_gnu 0.48.5",


@@ 8057,7 7886,6 @@ dependencies = [
 "windows_x86_64_gnu 0.48.5",
 "windows_x86_64_gnullvm 0.48.5",
 "windows_x86_64_msvc 0.48.5",
>>>>>>> rust-rendering-2
]

[[package]]

R crates/client/src/rendering/assets_native.rs => crates/client/src/native/assets.rs +0 -0
M crates/client/src/native/mod.rs => crates/client/src/native/mod.rs +2 -0
@@ 1,3 1,5 @@
pub mod assets;

/// --- IMPORTANT: THIS IS A DUAL TARGET CRATE ---
/// THIS WILL ONLY EXECUTE ON NATIVE
/// DO ONLY PLATFORM SPECIFIC INITIALIZATION HERE

A crates/client/src/rendering/assets.rs => crates/client/src/rendering/assets.rs +29 -0
@@ 0,0 1,29 @@
use std::fmt::Display;
use std::fmt::Write;

#[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(Debug, Clone)]
pub struct ImgData {
    pub bytes: Vec<u8>,
    pub width: u32,
    pub height: u32,
}

pub trait AssetLoader {
    fn new() -> Self;
    fn get(&self, local_path: impl Into<String>) -> Option<ImgData>;
}
\ No newline at end of file

M crates/client/src/rendering/mod.rs => crates/client/src/rendering/mod.rs +1 -7
@@ 2,7 2,6 @@ use std::collections::HashMap;
use std::num::NonZeroU32;
use std::sync::Arc;

use assets::Assets;
use bevy_ecs::entity::Entity;
use bevy_ecs::event::Events;
use bevy_ecs::query::With;


@@ 48,11 47,6 @@ use crate::networking::process_packets;
use crate::networking::ws::Ws;
use crate::ui::{draw_ui, init_ui};

#[cfg(not(target_arch = "wasm32"))]
#[path = "assets_native.rs"]
pub mod assets;
#[cfg(target_arch = "wasm32")]
#[path = "assets_wasm.rs"]
pub mod assets;

#[derive(Default)]


@@ 559,7 553,7 @@ impl ApplicationHandler for App {
            gl.uniform_matrix_4_f32_slice(view_loc.as_ref(), true, view);

            if !self.textures.contains_key("starfield.svg") {
                let assets = self.world.resource::<Assets>();
                let assets = self.world.resource::<crate::platform::assets::Assets>();
                match assets.get("starfield.svg") {
                    Some(image) => {
                        let texture_object = gl.create_texture().expect("Failed to create texture object");

R crates/client/src/rendering/assets_wasm.rs => crates/client/src/wasm/assets.rs +4 -25
@@ 8,28 8,7 @@ use bevy_ecs::system::Resource;
use image::EncodableLayout;
use poll_promise::Promise;
use resvg::{tiny_skia, usvg};

#[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(Debug, Clone)]
pub struct ImgData {
    pub bytes: Vec<u8>,
    pub width: u32,
    pub height: u32,
}
use crate::rendering::assets::AssetLoader;

#[derive(Resource)]
pub struct Assets {


@@ 37,14 16,14 @@ pub struct Assets {
    textures: Arc<Mutex<HashMap<String, ImgData>>>,
}

impl Assets {
    pub fn new() -> Self {
impl AssetLoader for Assets {
    fn new() -> Self {
        Assets {
            textures: Arc::new(Mutex::new(HashMap::new())),
            texture_promises: Arc::new(Mutex::new(HashMap::new())),
        }
    }
    pub fn get(&self, local_path: impl Into<String>) -> Option<ImgData> {
    fn get(&self, local_path: impl Into<String>) -> Option<ImgData> {
        let local_path = local_path.into();
        let contains_texture = { self.textures.lock().unwrap().contains_key(&local_path) };
        let contains_texture_promise = {

M crates/client/src/wasm/mod.rs => crates/client/src/wasm/mod.rs +2 -0
@@ 4,6 4,8 @@ use tracing_subscriber::prelude::*;
use tracing_web::{performance_layer, MakeWebConsoleWriter};
use wasm_bindgen::prelude::wasm_bindgen;

pub mod assets;

/// --- IMPORTANT: THIS IS A DUAL TARGET CRATE ---
/// THIS WILL ONLY EXECUTE ON WEBASSEMBLY
/// DO ONLY PLATFORM SPECIFIC INITIALIZATION HERE