Skip to content

Commit

Permalink
wasm32-unknown-unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Nov 19, 2021
1 parent 10e8e6b commit c36b8c4
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 6 deletions.
21 changes: 19 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ rust-ini = "0.17"
serde = "1.0"
serde_derive = "1.0"
serde_scan = "0.4"
wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "47fd776", features = [] }
wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "47fd776", 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 = "eda078d", features = ["wgsl-in"] }
Expand All @@ -84,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"]
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
90 changes: 90 additions & 0 deletions bin/road/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#![allow(irrefutable_let_patterns)]


use log::info;

#[cfg(target_arch = "wasm32")]
extern crate console_error_panic_hook;

#[cfg(target_arch = "wasm32")]
use std::{fs::File, io::Write};

#[path = "../boilerplate.rs"]
mod boilerplate;
mod game;
Expand All @@ -10,6 +17,13 @@ mod physics;
fn main() {
use std::env;

#[cfg(target_arch = "wasm32")] {
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",
uses_level: true,
Expand All @@ -34,3 +48,79 @@ fn main() {

harness.main_loop(game);
}

#[cfg(target_arch = "wasm32")]
fn settings() -> Vec<u8> {
"
(
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()
}
25 changes: 25 additions & 0 deletions html5/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>

<body>
<canvas data-raw-handle="1"></canvas>
<script type="module">
import init from "./road.js";

function load() {
init().then(async (m) => {
console.log("ready");
}).catch(console.error);
}

window.load = load;
</script>

<button onclick="javascript:load()">GO!</button>
</body>

</html>
6 changes: 4 additions & 2 deletions src/config/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub enum Backend {
impl Backend {
pub fn to_wgpu(&self) -> wgpu::Backends {
match *self {
Backend::Auto => wgpu::Backends::PRIMARY,
Backend::Auto => wgpu::Backends::all(),
Backend::Metal => wgpu::Backends::METAL,
Backend::Vulkan => wgpu::Backends::VULKAN,
Backend::DX12 => wgpu::Backends::DX12,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c36b8c4

Please sign in to comment.