~starkingdoms/starkingdoms

ref: 93b350fc44934524b95c9f80884d921c53fe7981 starkingdoms/crates/client/src/wasm/mod.rs -rw-r--r-- 1.3 KiB
93b350fc — ghostly_zsh chassis change merge 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use tracing::Level;
use tracing_subscriber::fmt::format::Pretty;
use tracing_subscriber::prelude::*;
use tracing_web::{performance_layer, MakeWebConsoleWriter};
use wasm_bindgen::prelude::wasm_bindgen;

pub mod assets;
pub mod websocket;

/// --- IMPORTANT: THIS IS A DUAL TARGET CRATE ---
/// THIS WILL ONLY EXECUTE ON WEBASSEMBLY
/// DO ONLY PLATFORM SPECIFIC INITIALIZATION HERE
/// FOR ACTUAL PROGRAM LOGIC, EDIT `crate::start`
/// DO NOT RENAME
#[wasm_bindgen(start)]
pub fn entrypoint() {
    // Panic handler
    console_error_panic_hook::set_once();

    /* ----- Logging setup ----- */
    let fmt_layer = tracing_subscriber::fmt::layer()
        .with_ansi(false) // not supported in browsers
        .without_time() // std::time doesn't exist in wasm
        .with_writer(MakeWebConsoleWriter::new().with_max_level(Level::DEBUG)); // wgpu spams the console, and this is slow as hell

    let perf_layer = performance_layer() // enable performance tracing
        .with_details_from_fields(Pretty::default()); // ... with pretty fields

    tracing_subscriber::registry()
        .with(fmt_layer)
        .with(perf_layer)
        .init(); // register the logger

    // All done with platform-specific initialization, call back into the common code path
    crate::start();
}