diff --git a/Cargo.lock b/Cargo.lock index 4fb10dc4..9294c6f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -251,6 +251,16 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen", +] + [[package]] name = "copyless" version = "0.1.5" @@ -711,8 +721,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if 1.0.0", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -795,6 +807,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hexf-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" + [[package]] name = "humantime" version = "2.1.0" @@ -830,6 +848,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61124eeebbd69b8190558df225adf7e4caafce0d743919e5d6b19652314ec5ec" dependencies = [ "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] @@ -840,9 +861,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" [[package]] name = "js-sys" -version = "0.3.51" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83bdfbace3a0e81a4253f73b49e960b053e396a11012cbd49b9b74d6a2b67062" +checksum = "7cc9ffccd38c451a86bf13657df244e9c3f37493cce8e5e21e940963777acc84" dependencies = [ "wasm-bindgen", ] @@ -1016,18 +1037,19 @@ dependencies = [ [[package]] name = "naga" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "568344dfe26b6caee4003da5be57bf8c2ef16d9525a2a5561164bcc462687f92" +checksum = "eda66d09f712e1f0a6ab436137da4fac312f78301f6d4ac7cb8bfe96e988734f" dependencies = [ "bit-set", "bitflags", "codespan-reporting", "fxhash", + "hexf-parse", + "indexmap", "log", "num-traits", "petgraph", - "rose_tree", "spirv", "thiserror", ] @@ -1470,24 +1492,15 @@ checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157" [[package]] name = "ron" -version = "0.6.4" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064ea8613fb712a19faf920022ec8ddf134984f100090764a4e1d768f3827f1f" +checksum = "86018df177b1beef6c7c8ef949969c4f7cb9a9344181b92486b23c79995bdaa4" dependencies = [ "base64", "bitflags", "serde", ] -[[package]] -name = "rose_tree" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcd16c61e9205949fa4f8a22096705b4c2f8b8025b2ff67ff6c86afd854039ae" -dependencies = [ - "petgraph", -] - [[package]] name = "rust-ini" version = "0.17.0" @@ -1752,9 +1765,11 @@ dependencies = [ "bytemuck", "byteorder", "cgmath", + "console_error_panic_hook", "env_logger", "futures", "getopts", + "getrandom", "glsl-to-spirv", "log", "m3d", @@ -1771,6 +1786,7 @@ dependencies = [ "serde_scan", "splay", "tiff", + "wasm-bindgen", "wgpu", "winit", ] @@ -1800,9 +1816,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54ee1d4ed486f78874278e63e4069fc1ab9f6a18ca492076ffb90c5eb2997fd" +checksum = "632f73e236b219150ea279196e54e610f5dbafa5d61786303d4da54f84e47fce" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -1810,9 +1826,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b33f6a0694ccfea53d94db8b2ed1c3a8a4c86dd936b13b9f0a15ec4a451b900" +checksum = "a317bf8f9fba2476b4b2c85ef4c4af8ff39c3c7f0cdfeed4f82c34a880aa837b" dependencies = [ "bumpalo", "lazy_static", @@ -1837,9 +1853,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "088169ca61430fe1e58b8096c24975251700e7b1f6fd91cc9d59b04fb9b18bd4" +checksum = "d56146e7c495528bf6587663bea13a8eb588d39b36b679d83972e1a2dbbdacf9" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1847,9 +1863,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be2241542ff3d9f241f5e2cb6dd09b37efe786df8851c54957683a49f0987a97" +checksum = "7803e0eea25835f8abdc585cd3021b3deb11543c6fe226dcd30b228857c5c5ab" dependencies = [ "proc-macro2", "quote", @@ -1860,9 +1876,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.74" +version = "0.2.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7cff876b8f18eed75a66cf49b65e7f967cb354a7aa16003fb55dbfd25b44b4f" +checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" [[package]] name = "wayland-client" @@ -1939,9 +1955,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.51" +version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e828417b379f3df7111d3a2a9e5753706cae29c41f7c4029ee9fd77f3e09e582" +checksum = "38eb105f1c59d9eaa6b5cdc92b859d85b926e82cb2e0945cd0c9259faa6fe9fb" dependencies = [ "js-sys", "wasm-bindgen", @@ -1949,8 +1965,9 @@ dependencies = [ [[package]] name = "wgpu" -version = "0.10.1" -source = "git+https://github.com/gfx-rs/wgpu?rev=8f02b73#8f02b73655aff641361822a8ac0347fc47622b49" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1577ecc4f6992b9e965878ac594efb24eed2bdf089c11f45b3d1c5f216e2e30" dependencies = [ "arrayvec", "js-sys", @@ -1969,8 +1986,9 @@ dependencies = [ [[package]] name = "wgpu-core" -version = "0.10.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=8f02b73#8f02b73655aff641361822a8ac0347fc47622b49" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bdcbfa4885b32c2b1feb2faeb8b6a76065b752b8f08751b82f994e937687f46" dependencies = [ "arrayvec", "bitflags", @@ -1990,8 +2008,9 @@ dependencies = [ [[package]] name = "wgpu-hal" -version = "0.10.1" -source = "git+https://github.com/gfx-rs/wgpu?rev=8f02b73#8f02b73655aff641361822a8ac0347fc47622b49" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e493835d9edb153d5c8a9d8d016e1811dbe32ddb707a110be1453c7b051d3ec" dependencies = [ "arrayvec", "ash", @@ -2006,6 +2025,7 @@ dependencies = [ "gpu-alloc", "gpu-descriptor", "inplace_it", + "js-sys", "khronos-egl", "libloading 0.7.0", "log", @@ -2013,18 +2033,22 @@ dependencies = [ "naga", "objc", "parking_lot", + "profiling", "range-alloc", "raw-window-handle", "renderdoc-sys", "thiserror", + "wasm-bindgen", + "web-sys", "wgpu-types", "winapi", ] [[package]] name = "wgpu-types" -version = "0.10.0" -source = "git+https://github.com/gfx-rs/wgpu?rev=8f02b73#8f02b73655aff641361822a8ac0347fc47622b49" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e15e44ba88ec415466e18e91881319e7c9e96cb905dc623305168aea65b85ccc" dependencies = [ "bitflags", ] @@ -2087,7 +2111,9 @@ dependencies = [ "raw-window-handle", "scopeguard", "smithay-client-toolkit", + "wasm-bindgen", "wayland-client", + "web-sys", "winapi", "x11-dl", ] diff --git a/Cargo.toml b/Cargo.toml index ebef2d49..f7f66c47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -60,17 +60,20 @@ rust-ini = "0.17" serde = "1.0" serde_derive = "1.0" serde_scan = "0.4" -wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "8f02b73", features = [] } +#wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "8f02b73", features = [] } +wgpu = { version = "0.11", features = ["webgl"] } # binaries env_logger = "0.8" getopts = "0.2" obj = "0.10" png = "0.16" -winit = "0.25" +winit = { version = "0.25", features = ["web-sys"] } +wasm-bindgen = "0.2.78" +console_error_panic_hook = { version = "0.1.7" } [dev-dependencies] #naga = { git = "https://github.com/gfx-rs/naga", rev = "7613798", features = ["wgsl-in"] } -naga = { version = "0.6", features = ["wgsl-in"] } +naga = { version = "0.7", features = ["wgsl-in"] } [dependencies.profiling] version = "1.0.1" @@ -83,3 +86,6 @@ default-features = false #wgpu-hal = { path = "../wgpu/wgpu-hal" } #wgpu-core = { path = "../wgpu/wgpu-core" } #wgpu-types = { path = "../wgpu/wgpu-types" } + +[dependencies.getrandom] +features = ["js"] diff --git a/README.md b/README.md index 595b8fbe..d097fb8a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,16 @@ +# Web version of Vange-rs + +Compile Web (Debug): + +```sh +PATH=$PATH:/home/caiiiycuk/rust/rust/build/x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/bin/ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/caiiiycuk/rust/rust/build/x86_64-unknown-linux-gnu/stage0/lib/ cargo build --target wasm32-unknown-unknown --bin road --verbose && wasm-bindgen --out-dir html5/ --target web --keep-debug target/wasm32-unknown-unknown/debug/road.wasm +``` + +Compile native: +```sh +cargo build --bin road +``` + # Vange-rs ![Check](https://github.com/kvark/vange-rs/workflows/Check/badge.svg) [![Gitter](https://badges.gitter.im/kvark/vange-rs.svg)](https://gitter.im/vange-rs/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) diff --git a/bin/boilerplate.rs b/bin/boilerplate.rs index 2f5570a8..25a858d2 100644 --- a/bin/boilerplate.rs +++ b/bin/boilerplate.rs @@ -64,7 +64,7 @@ impl Harness { }; info!("Initializing the window"); - let instance = wgpu::Instance::new(settings.backend.to_wgpu()); + let instance = wgpu::Instance::new(wgpu::Backends::all() /* settings.backend.to_wgpu() */); let event_loop = EventLoop::new(); let window = WindowBuilder::new() .with_title(options.title) @@ -79,6 +79,7 @@ impl Harness { .run_until(instance.request_adapter(&wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::HighPerformance, compatible_surface: Some(&surface), + force_fallback_adapter: false, })) .expect("Unable to initialize GPU via the selected backend."); @@ -227,10 +228,9 @@ impl Harness { queue.submit(update_command_buffers); } - match surface.get_current_frame() { + match surface.get_current_texture() { Ok(frame) => { let view = frame - .output .texture .create_view(&wgpu::TextureViewDescriptor::default()); let targets = ScreenTargets { @@ -240,6 +240,7 @@ impl Harness { }; let render_command_buffer = app.draw(&device, targets, &spawner); queue.submit(Some(render_command_buffer)); + frame.present(); } Err(_) => {} }; diff --git a/bin/road/main.rs b/bin/road/main.rs index 57bd7f73..3d8906ef 100644 --- a/bin/road/main.rs +++ b/bin/road/main.rs @@ -1,7 +1,11 @@ #![allow(irrefutable_let_patterns)] +use std::{fs::File, io::Write}; + use log::info; +extern crate console_error_panic_hook; + #[path = "../boilerplate.rs"] mod boilerplate; mod game; @@ -9,6 +13,10 @@ mod physics; fn main() { use std::env; + console_error_panic_hook::set_once(); + + File::create("config/settings.ron").expect("Unable to create settings.ron") + .write(&settings()[..]).expect("Unable to write int settings.ron"); let (harness, settings) = boilerplate::Harness::init(boilerplate::HarnessOptions { title: "road", @@ -34,3 +42,78 @@ fn main() { harness.main_loop(game); } + +fn settings() -> Vec { +" +( + data_path: \"./data\", + game: ( + level: \"Fostral\", // see `wrlds.dat` for the list + cycle: \"Eleerection\", // see `bunches.prm` for the list, leave empty for bonus worlds + view: Perspective, // can be \"Flat\" or \"Perspective\" + camera: ( + angle: 60, + height: 300, + target_overhead: 200, + speed: 1, + depth_range: (10, 1000), + ), + other: ( + count: 10, // number of NPC vangers + spawn_at: Random, // Player + ), + physics: ( + max_quant: 0.1, + shape_sampling: 0, + gpu_collision: None, + //Some(( + // max_objects: 100, + // max_polygons_total: 1000, + // max_raster_size: (100, 100), + //)), + ), + ), + car: ( + id: \"OxidizeMonk\", + // \"IronShadow\", + color: Green, // Dummy, Red, Blue, Yellow, Gray + slots: [], + //slots: [\"HeavyLaser\", \"LightMissile\", \"LightFireBall\"], + ), + window: ( + title: \"Rusty Road\", + size: (640, 400), + reload_on_focus: false, + ), + backend: Auto, // Vulkan, Metal, DX12, DX11 + render: ( + wgpu_trace_path: \"\", + light: ( + pos: (1, 2, 4, 0), // w=0 for directional, w=1 for point light + color: (1, 1, 1, 1), + shadow: ( + size: 1024, + terrain: RayTraced, + ), + ), + fog: ( + color: (0.1, 0.2, 0.3, 1.0), + depth: 50, + ), + terrain: RayTraced, + // RayTraced, + // RayMipTraced (mip_count: 10, max_jumps: 25, max_steps: 100, debug: false), + // Scattered( density: (2, 2, 2) ), + // Sliced, + // Painted, + debug: ( + max_vertices: 512, + collision_shapes: false, + collision_map: false, + impulses: false, + ), + ), +) + +".as_bytes().to_owned() +} \ No newline at end of file diff --git a/html5/index.html b/html5/index.html new file mode 100644 index 00000000..bfeb053c --- /dev/null +++ b/html5/index.html @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/config/settings.rs b/src/config/settings.rs index 47730ad5..5274331d 100644 --- a/src/config/settings.rs +++ b/src/config/settings.rs @@ -194,8 +194,10 @@ impl Settings { .unwrap_or_else(|_| panic!("Unable to open game file: {}", path)) } + #[allow(unused_variables)] pub fn check_path(&self, path: &str) -> bool { - self.data_path.join(path).exists() + true + // self.data_path.join(path).exists() } pub fn open_palette(&self) -> File {