created to teach natepiano how to code games, visualizations and simulations in bevy using the awesome programming language, rust. i started with this tutorial, added bevy_rapier3d for physics as well as a few other dependencies you can find in cargo.toml. the goal is to make this interesting, playable, beautiful and fun.
install rust (from https://www.rust-lang.org/tools/install)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
use sccache to make follow on compiles faster as it will cache locally anything you've already built. this comes in handy if you get other projects that all need to compile with bevy or anything you commonly depend on in these projects
cargo install sccache
and to enable it globally create / edit your $HOME/.cargo/config.toml by adding this to it - make sure you're using your local path - on my system it is:
[build]
rustc-wrapper = ".cargo/bin/sccache"
note: apparently it inserts your home directory in front of this path, so you don't have to include it explicitly
git clone https://github.com/pianonate/nateroids
run it - the first time will take a while even if you have sccache installed as you have to populate the cache, n'est-ce pas?
cargo run
start playing! (gawd i like it that rust has such minimal rigamarole)
you can build a release version locally this way:
cargo build --release
or run it
cargo run --release
or you can target wasm to run it in a browser. you can use http-server (or something equivalent) to serve the wasm target locally. you can install http-server with npm or use whatever server you prefer - i've tested the wasm target with http-server and chrome and this combination works. ymmv.
RUSTFLAGS="--cfg=web_sys_unstable_apis" cargo build --release --target wasm32-unknown-unknown
wasm-bindgen --out-name nateroids --out-dir target/wasm32 --target web target/wasm32-unknown-unknown/release/nateroids.wasm
http-server -c-1 -o ./
one of the dependencies which is only conditionally compile into dev builds is called bevy-inspector-egui. In turn, bevy-inspector-egui depends on bevy-egui - and bevy-inspector-egui exposes a "manage-clipboard" feature from bevy-egui. This "manage-clipboard feature causes an error when we build with "--target wasm32-unknown-unknown".
The error is raised because "manage-clipboard" is considered an unsafe api. the RUSTFLAGS=" --cfg=web_sys_unstable_apis" suppresses this error but it's annoying. i need to figure out a solution. Especially given that I use conditional compilation to exclude the inspector code as it is only for dev. So the actual code is not included in any kind of --release build.
With this RUSTFLAGS, it works for now. There's probably a cargo trick to disable the feature from the dependency, but it's beyond me right now without doing a whole log of rigamarole...would love to clean this up...also...someone saw the same issue but it's not yet pulled into the code base
use the nightly rustfmt in order to pick up all the features in the rustfmt.toml - do this once:
rustup toolchain install nightly
rustup component add rustfmt --toolchain nightly
then run this any time you want your code formatted - at least before committing
cargo +nightly fmt
why unstable_features = true
doesn't work i don't know - it's also only available in the nightly...
- bevy - home to all things bevy
- bevy cheatbook - super useful
- blender - in case you want to mangle some meshes
- rapier physics - so we don't have to code the physics
- tainted coders - has a lot of inside baseball about bevy