Skip to content

Commit

Permalink
Merge pull request #6 from deavid/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
deavid committed Mar 14, 2024
2 parents 041d8bf + b2cce5a commit bdb17ad
Show file tree
Hide file tree
Showing 20 changed files with 2,982 additions and 16,148 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.wasm32-unknown-unknown]
runner = "wasm-server-runner"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/target
perf.data
perf.data.old
unhaunter
unhaunter_game
trace-*.json
21 changes: 11 additions & 10 deletions Cargo.lock

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

30 changes: 24 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
[package]
name = "unhaunter"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
default-run = "unhaunter"
default-run = "unhaunter_game"
description = "2D isometric Game about investigating paranormal hauntings"
repository = "https://github.com/deavid/unhaunter/"
license = "Apache-2.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.13.0", features = ["trace"] }
bevy_framepace = "0.15"
rand = { version = "0.8", features = ["small_rng"] }
enum-iterator = "2.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
image = "0.25.0"
regex = "1.7.1"
tiled = "0.11.2"

clap = "4.4.8"
fastapprox = "0.3.1"
anyhow = "1.0.79"
Expand All @@ -25,6 +27,13 @@ hierarchical_pathfinding = "0.5.0"
walkdir = "2.5.0"
glob = "0.3.1"
thiserror = "1.0.58"
tiled = { version = "0.11.2", features = ["wasm"] }
wasm-bindgen = "0.2.92"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bevy_framepace = "0.15"

# [target.'cfg(target_arch = "wasm32")'.dependencies]

# Enable only a small amount of optimization in debug mode
[profile.dev]
Expand All @@ -34,11 +43,20 @@ opt-level = 2
[profile.dev.package."*"]
opt-level = 3

# These optimizations for release are trying to target mostly WASM
[profile.release]
# This causes slower compilation times in release
lto = "thin"
# Compiling to smaller sizes seems to help in WASM
opt-level = 'z'

[[bin]]
name = "unhaunter"
path = "src/main.rs"
name = "unhaunter_game"
path = "src/bin/unhaunter.rs"

[[bin]]
name = "materials"
path = "src/materials.rs"

[lib]
crate-type = ["cdylib", "rlib"]
66 changes: 65 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,68 @@ NOTE: bevy_framepace::framerate_limiter is intended to take the majority of the

There's additional info on profiling Bevy here:

https://github.com/bevyengine/bevy/blob/main/docs/profiling.md
https://github.com/bevyengine/bevy/blob/main/docs/profiling.md


## WASM Support

You can test this game in WASM by navigating to:

https://deavid.github.io/unhaunter/

However, Google Chrome is recommended.

Known issues:

* Firefox seems to have serious performance problems.
* Noticeable audio crackling.
* Map names appear by filenames not by their internal name.
* Map data is pre-backed in, does not react to new maps added into the folder.
* University/School map is very slow.

NOTE: Overall this is provided as a "demo" that is easy to access for those that
cannot build the game themselves. Unhaunter is not targeting WASM, and the
support will be minimal.

Building WASM locally:

https://bevy-cheatbook.github.io/platforms/wasm.html

Install deps

rustup target install wasm32-unknown-unknown
cargo install wasm-server-runner

Run with:

cargo run --target wasm32-unknown-unknown --release


Current problems:

* Slow?
* Regular filesystem operation do not work. Bevy Assets do work. Therefore map loading is borked.
* Instant::now does not work.
* Framepace does not work on the browser. Solved.
* Tiled library is never going to work, it opens the files it wants, whenever it wants. It will always fail on WASM.

Here's a sample on how to load custom assets, so we could load our own data:
https://bevyengine.org/examples/Assets/custom-asset/

But most likely this forces us to pre-bake the maps somehow.

Wait, tiled-rs DOES support wasm.

Update: It works now, but there's stutter. Mainly because there's only one thread
for executing; and on top of that there's a GC that when it runs it pauses the game.

---
Wasm bindgen:

wasm-pack build --release --target web

This will build in pkg/

And to test:

python3 -m http.server
Loading

0 comments on commit bdb17ad

Please sign in to comment.