From 3d4a62b90ca03a1a50f9c19f226cdebc37a0307b Mon Sep 17 00:00:00 2001 From: eri Date: Wed, 13 Dec 2023 01:19:33 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20quality=20of=20life=20=F0=9F=8C=B3=20fe?= =?UTF-8?q?at:=20tracing=20support=20feat:=20new=20run=20script=20change:?= =?UTF-8?q?=20dependencies=20now=20build=20without=20debug=20symbols=20by?= =?UTF-8?q?=20default=20change:=20hot=20reloading=20when=20on=20debug=20mo?= =?UTF-8?q?de=20change:=20embedded=20assets=20only=20on=20release=20change?= =?UTF-8?q?:=20now=20the=20default=20plugins=20are=20initialized=20in=20li?= =?UTF-8?q?b=20and=20not=20in=20main=20fix:=20serialize=20feature=20fix:?= =?UTF-8?q?=20embedded=20assets=20BEVY=5FASSET=5FPATH=20fix:=20bevy=20logo?= =?UTF-8?q?=20on=20splash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cargo/config.toml | 4 +- .github/workflows/release.yaml | 8 +-- .gitignore | 2 + Cargo.lock | 121 ++++++++++++++++---------------- Cargo.toml | 10 +-- README.md | 12 ++-- Trunk.toml | 2 +- assets/icons/bevy.png | Bin 15860 -> 15815 bytes examples/dvd.rs | 26 +------ examples/jump.rs | 26 +------ run | 49 +++++++++++++ src/lib.rs | 33 ++++++++- src/load.rs | 15 +++- src/main.rs | 26 +------ {build/wasm => wasm}/audio.js | 0 {build/wasm => wasm}/index.html | 2 +- {build/wasm => wasm}/style.css | 0 17 files changed, 186 insertions(+), 150 deletions(-) create mode 100755 run rename {build/wasm => wasm}/audio.js (100%) rename {build/wasm => wasm}/index.html (94%) rename {build/wasm => wasm}/style.css (100%) diff --git a/.cargo/config.toml b/.cargo/config.toml index 1a67a27..291c33d 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,6 +1,6 @@ # Fast build -# NOTE: For maximum performance, build using a nightly compiler +# [CHANGE]: For maximum performance, build using a nightly compiler # If you are using rust stable, remove the "-Zshare-generics=y" below. # You need to install mold for the fastest compile, else change /usr/bin/mold to lld @@ -11,7 +11,7 @@ rustflags = [ "-Zshare-generics=y" ] -# NOTE: You must install [Mach-O LLD Port](https://lld.llvm.org/MachO/index.html) on mac +# [CHANGE]: You must install [Mach-O LLD Port](https://lld.llvm.org/MachO/index.html) on mac # You can easily do this by installing llvm which includes lld with the "brew" package manager: `brew install llvm` [target.x86_64-apple-darwin] diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0d3f0e7..594691e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -61,16 +61,16 @@ jobs: - name: Optimize Wasm uses: NiklasEi/wasm-opt-action@v2 with: - file: build/wasm/dist/*.wasm + file: wasm/dist/*.wasm - name: Make paths relative run: | - sed -i 's/\/${{ env.binary }}/.\/${{ env.binary }}/g' build/wasm/dist/index.html + sed -i 's/\/${{ env.binary }}/.\/${{ env.binary }}/g' wasm/dist/index.html - name: Package as a zip - working-directory: ./build/wasm/dist + working-directory: ./wasm/dist run: | - zip --recurse-paths ../../../${{ env.binary }}.zip . + zip --recurse-paths ../../${{ env.binary }}.zip . - name: Upload binaries to artifacts uses: actions/upload-artifact@v3 diff --git a/.gitignore b/.gitignore index 2dda228..5775551 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ dist graphs .vscode .data +capture* +*.tracy diff --git a/Cargo.lock b/Cargo.lock index 6ce6e27..aca0df0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -270,11 +270,11 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" dependencies = [ - "async-lock 3.1.2", + "async-lock 3.2.0", "async-task", "concurrent-queue", "fastrand 2.0.1", - "futures-lite 2.0.1", + "futures-lite 2.1.0", "slab", ] @@ -301,9 +301,9 @@ dependencies = [ [[package]] name = "async-lock" -version = "3.1.2" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea8b3453dd7cc96711834b75400d671b73e3656975fa68d9f277163b7f7e316" +checksum = "7125e42787d53db9dd54261812ef17e937c95a51e4d291373b670342fa44310c" dependencies = [ "event-listener 4.0.0", "event-listener-strategy", @@ -407,14 +407,14 @@ checksum = "ec800b7cf98151b5dbff80f0eb6dffcb4bcfceef6e457888b395ead4eb7e75ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] name = "bevy-persistent" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d51157974298a77e8b7c4b3e55c482709c07c0c8f8773dfef8e6228a5e1f205b" +checksum = "c78908d97ba60107ec4d0b9e99c8a96fdefae8c723850af183a02442059fcbf9" dependencies = [ "bevy", "gloo-storage", @@ -523,7 +523,7 @@ checksum = "d43820afc6e2a7a9e09adb5f13a760bd9a973f391c106411f0bf229d9958c61d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -535,7 +535,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -584,7 +584,7 @@ checksum = "f484318350462c58ba3942a45a656c1fd6b6e484a6b6b7abc3a787ad1a51e500" dependencies = [ "bevy_macro_utils", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -641,7 +641,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -666,7 +666,7 @@ dependencies = [ "bevy", "cargo-emit", "futures-io", - "futures-lite 2.0.1", + "futures-lite 2.1.0", ] [[package]] @@ -852,7 +852,7 @@ dependencies = [ "proc-macro2", "quote", "rustc-hash", - "syn 2.0.39", + "syn 2.0.41", "toml_edit 0.20.7", ] @@ -950,7 +950,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", "uuid", ] @@ -1009,7 +1009,7 @@ dependencies = [ "bevy_macro_utils", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -1181,7 +1181,7 @@ checksum = "7aafecc952b6b8eb1a93c12590bd867d25df2f4ae1033a01dfdfc3c35ebccfff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -1243,7 +1243,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -1321,11 +1321,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" dependencies = [ "async-channel 2.1.1", - "async-lock 3.1.2", + "async-lock 3.2.0", "async-task", "fastrand 2.0.1", "futures-io", - "futures-lite 2.0.1", + "futures-lite 2.1.0", "piper", "tracing", ] @@ -1353,7 +1353,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -1467,9 +1467,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" +checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" dependencies = [ "crossbeam-utils", ] @@ -1717,7 +1717,7 @@ checksum = "3fe2568f851fd6144a45fa91cfed8fe5ca8fc0b56ba6797bfc1ed2771b90e37c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -1878,7 +1878,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -1931,14 +1931,13 @@ dependencies = [ [[package]] name = "futures-lite" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3831c2651acb5177cbd83943f3d9c8912c5ad03c76afcc0e9511ba568ec5ebb" +checksum = "aeee267a1883f7ebef3700f262d2d54de95dfaf38189015a74fdc4e0c7ad8143" dependencies = [ "fastrand 2.0.1", "futures-core", "futures-io", - "memchr", "parking", "pin-project-lite", ] @@ -1968,9 +1967,9 @@ dependencies = [ [[package]] name = "gilrs" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e9eec02069fcbd7abe00a28adf216547774889129a777cb5e53fdfb75d59f09" +checksum = "d8b2e57a9cb946b5d04ae8638c5f554abb5a9f82c4c950fd5b1fee6d119592fb" dependencies = [ "fnv", "gilrs-core", @@ -2083,7 +2082,7 @@ dependencies = [ "inflections", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -2211,7 +2210,7 @@ dependencies = [ [[package]] name = "hello-bevy" -version = "0.12.3" +version = "0.12.4" dependencies = [ "bevy", "bevy-inspector-egui", @@ -2345,9 +2344,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "iyes_progress" @@ -2483,9 +2482,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.150" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libloading" @@ -2625,9 +2624,9 @@ checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" [[package]] name = "mio" -version = "0.8.9" +version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +checksum = "8f3d0b296e374a4e6f3c7b0a1f5a51d748a0d34c85e7dc48fc3fa9a87657fe09" dependencies = [ "libc", "log", @@ -2860,7 +2859,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -2962,9 +2961,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "orbclient" @@ -3131,9 +3130,9 @@ dependencies = [ [[package]] name = "profiling" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f89dff0959d98c9758c88826cc002e2c3d0b9dfac4139711d1f30de442f1139b" +checksum = "1de09527cd2ea2c2d59fb6c2f8c1ab8c71709ed9d1b6d60b0e1c9fbb6fdcb33c" [[package]] name = "quote" @@ -3318,9 +3317,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" [[package]] name = "same-file" @@ -3354,7 +3353,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -3546,9 +3545,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" dependencies = [ "proc-macro2", "quote", @@ -3616,7 +3615,7 @@ checksum = "e4c60d69f36615a077cc7663b9cb8e42275722d23e58a7fa3d2c7f2915d09d04" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -3627,7 +3626,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -3741,7 +3740,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] [[package]] @@ -3823,9 +3822,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" [[package]] name = "unicode-ident" @@ -3937,7 +3936,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", "wasm-bindgen-shared", ] @@ -3971,7 +3970,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4405,9 +4404,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.5.19" +version = "0.5.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" +checksum = "6c830786f7720c2fd27a1a0e27a709dbd3c4d009b56d098fc742d4f4eab91fe2" dependencies = [ "memchr", ] @@ -4459,20 +4458,20 @@ checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" [[package]] name = "zerocopy" -version = "0.7.28" +version = "0.7.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d6f15f7ade05d2a4935e34a457b936c23dc70a05cc1d97133dc99e7a3fe0f0e" +checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.28" +version = "0.7.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbbad221e3f78500350ecbd7dfa4e63ef945c05f4c61cb7f4d3f84cd0bba649b" +checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.41", ] diff --git a/Cargo.toml b/Cargo.toml index d565f94..4f92449 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,29 +1,31 @@ [package] name = "hello-bevy" # [CHANGE]: Set your project name. -version = "0.12.3" +version = "0.12.4" edition = "2021" description = "a bevy game template" -exclude = ["build", "assets", ".data"] +exclude = ["assets", "wasm", ".data"] [profile.dev.package."*"] opt-level = 3 # Improves performance when developing, but slows down first compilation significantly +debug = false # Disabled debug symbols for dependencies [profile.dev] opt-level = 1 [features] dev = [ - "bevy/dynamic_linking", + "bevy/dynamic_linking", # Enables dynamic linking for faster compilation ] [dependencies] # The bevy engine <3 # Default feautres are disabled because we are using audio from a different source (kira) +# We also add trace_tracy for profiling bevy = { version = "0.12", default-features = false, features = [ "animation", "bevy_asset", "bevy_gilrs", "bevy_scene", "bevy_winit", "bevy_core_pipeline", "bevy_pbr", "bevy_gltf", "bevy_render", "bevy_sprite", "bevy_text", "bevy_ui", "multi-threaded", "png", "hdr", "x11", "bevy_gizmos", - "tonemapping_luts", "default_font", "webgl2", + "tonemapping_luts", "default_font", "webgl2", "serialize" ]} bevy_asset_loader = { version = "0.18", features = [ "progress_tracking" ] } # Better asset loader bevy_embedded_assets = { version = "0.9" } # Embed assets in binary diff --git a/README.md b/README.md index bf18b09..27be08d 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ an opinionated [bevy](https://github.com/bevyengine/bevy) template for my projec - debug features integrated (inspector, schedule graphs) - remapable input manager with gamepad support - asset loading with progress, audio, saving, menu... +- hot reloading and profiling when debugging ### how to use it โœจ @@ -30,19 +31,22 @@ this project is configured to use dynamic linking and fast recompiling by defaul in order to have the fastest compile, you may install [mold](https://github.com/rui314/mold) and use rust nightly (`rustup default nightly`). if you don't want some of these features, go to [.cargo/config](.cargo/config) and follow the instructions, or remove it to disable optimizations all together. -to run a debug build use: +to run a debug build use the provided script: ```sh -cargo run +./run [args...] # This calls cargo run with some extra options +./run [release|tracy] [args...] # You can also do a release build or a profiling one with tracy +cargo run # If you are not using unix, you can simply use cargo run (check the script for all the optional parameters) ``` and to start a local web build, use trunk: ```sh -trunk serve +./run web # This calls trunk serve +trunk serve # You can use it directly ``` -you can also play around with some of the included examples with `cargo run --example `. +you can also play around with some of the included examples with `./run --example ` (or `cargo run --example `). ### release ๐ŸŒป diff --git a/Trunk.toml b/Trunk.toml index 8d0f58a..adbb88a 100644 --- a/Trunk.toml +++ b/Trunk.toml @@ -1,2 +1,2 @@ [build] -target = "build/wasm/index.html" \ No newline at end of file +target = "wasm/index.html" diff --git a/assets/icons/bevy.png b/assets/icons/bevy.png index 8c9640bf2793cb892cbcd347a0d1037e132076d2..61eae4058d44fe51cdf6c80577a0dc95d525a554 100644 GIT binary patch delta 21 dcmexTeY|>t3KwH>kh>GZx^prwH%8C21psDm2_gUh delta 66 zcmX?J{iS+>iaBS2M`SSrgU~GyW<2}lUn2tpgJg+oL`iUdT1k0gQ7S`udAVL@UUqSE UVnM22eo^}DcQ#TR^=8@v06e!D7XSbN diff --git a/examples/dvd.rs b/examples/dvd.rs index 023da23..5072ccc 100644 --- a/examples/dvd.rs +++ b/examples/dvd.rs @@ -1,5 +1,5 @@ -use bevy::{prelude::*, sprite::MaterialMesh2dBundle, window::WindowResolution}; -use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode}; +use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; + use bevy_kira_audio::prelude::*; use bevy_persistent::Persistent; use hello_bevy::{ @@ -11,27 +11,7 @@ use hello_bevy::{ const SIZE: Vec2 = Vec2::new(600., 600.); fn main() { - App::new() - .add_plugins(( - EmbeddedAssetPlugin { - mode: PluginMode::ReplaceDefault, - }, - DefaultPlugins.set(WindowPlugin { - primary_window: Some(Window { - title: "DVD Screensaver".to_string(), - resolution: WindowResolution::new(SIZE.x, SIZE.y), - resizable: false, - canvas: Some("#bevy".to_string()), - prevent_default_event_handling: false, - ..default() - }), - ..default() - }), - GamePlugin, - SampleGamePlugin, - )) - // Run - .run(); + App::new().add_plugins((GamePlugin, SampleGamePlugin)).run(); } // ยทยทยทยทยทยท diff --git a/examples/jump.rs b/examples/jump.rs index 1cafcc7..11f3e85 100644 --- a/examples/jump.rs +++ b/examples/jump.rs @@ -1,7 +1,7 @@ #![allow(clippy::too_many_arguments)] -use bevy::{prelude::*, sprite::MaterialMesh2dBundle, window::WindowResolution}; -use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode}; +use bevy::{prelude::*, sprite::MaterialMesh2dBundle}; + use bevy_persistent::Persistent; use hello_bevy::{ config::{GameOptions, Keybinds}, @@ -21,27 +21,7 @@ const MOVE_CUTOFF: f32 = 100.; const MOVE_FACTOR: f32 = 0.85; fn main() { - App::new() - .add_plugins(( - EmbeddedAssetPlugin { - mode: PluginMode::ReplaceDefault, - }, - DefaultPlugins.set(WindowPlugin { - primary_window: Some(Window { - title: "Endless jump".to_string(), - resolution: WindowResolution::new(SIZE.x, SIZE.y), - resizable: false, - canvas: Some("#bevy".to_string()), - prevent_default_event_handling: false, - ..default() - }), - ..default() - }), - GamePlugin, - SampleGamePlugin, - )) - // Run - .run(); + App::new().add_plugins((GamePlugin, SampleGamePlugin)).run(); } // ยทยทยทยทยทยท diff --git a/run b/run new file mode 100755 index 0000000..7c95efb --- /dev/null +++ b/run @@ -0,0 +1,49 @@ +#!/bin/sh +# Usage: ./run.sh [check] [release|trace|web] [args...] + +# Hot reloading on debug builds +ARGS="--features bevy/file_watcher $@" + +# Add asset path to env +export BEVY_ASSET_PATH=$PWD/assets + +# Check build +if [ "$1" = "check" ]; then + shift + cargo fmt --all + cargo clippy --allow-dirty --allow-staged --fix + exit +fi + +# Local web build +if [ "$1" = "web" ]; then + shift + trunk serve $ARGS + exit +fi + +# Release mode +if [ "$1" = "release" ]; then + shift + ARGS="--release $@" +fi + +# Trace mode +if [ "$1" = "trace" ]; then + shift + ARGS="--release --features bevy/trace_tracy $@" + tracy-capture -o capture.tracy & +fi + +if [ "$1" = "ftrace" ]; then + shift + ARGS="--release --features bevy/trace_tracy $@" + TRACY=true + tracy-capture -o capture.tracy -f & +fi + +cargo run $ARGS + +if [ $TRACY ]; then + tracy capture.tracy +fi diff --git a/src/lib.rs b/src/lib.rs index 627d1cc..7f0625b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,9 +6,10 @@ pub mod load; mod menu; mod ui; -use bevy::prelude::*; +use bevy::{asset::AssetMetaCheck, prelude::*, window::WindowResolution}; // TODO: Option for pixel perfect upscaling camera +// TODO: Port improvements from the game jam // Game state #[derive(States, Debug, Default, Clone, Eq, PartialEq, Hash)] @@ -24,6 +25,35 @@ pub struct GamePlugin; impl Plugin for GamePlugin { fn build(&self, app: &mut App) { + // Fix web builds for now + app.insert_resource(AssetMetaCheck::Never); + + // Release only plugins (embedded assets) + #[cfg(not(debug_assertions))] + { + use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode}; + app.add_plugins(EmbeddedAssetPlugin { + mode: PluginMode::ReplaceDefault, + }); + } + + // Default plugins + app.add_plugins( + DefaultPlugins.set(WindowPlugin { + primary_window: Some(Window { + title: "Hello Bevy!".to_string(), // [CHANGE]: Game title + resolution: WindowResolution::new(600., 600.), + resizable: false, // Or use fit_canvas_to_parent: true for resizing on the web + canvas: Some("#bevy".to_string()), + prevent_default_event_handling: false, + ..default() + }), + ..default() + }), + //.set(ImagePlugin::default_nearest()), // [CHANGE]: Use if your game is pixel art + ); + + // Game app.add_state::().add_plugins(( load::LoadPlugin, ui::UIPlugin, @@ -33,6 +63,7 @@ impl Plugin for GamePlugin { audio::AudioPlugin, )); + // Debug only plugins #[cfg(debug_assertions)] { app.add_plugins(debug::DebugPlugin); diff --git a/src/load.rs b/src/load.rs index 408a987..eccc68c 100644 --- a/src/load.rs +++ b/src/load.rs @@ -27,7 +27,7 @@ impl Plugin for LoadPlugin { .add_plugins((ProgressPlugin::new(GameState::Loading) .continue_to(GameState::Menu) .track_assets(),)) - .add_systems(OnEnter(GameState::Loading), init_splash.after(init_ui)) + .add_systems(Update, init_splash.run_if(in_state(GameState::Loading))) .add_systems(OnExit(GameState::Loading), clear_loading) .add_systems( Update, @@ -77,7 +77,16 @@ struct ProgressBar; // Systems // ยทยทยทยทยทยทยท -fn init_splash(mut cmd: Commands, node: Query>, assets: Res) { +fn init_splash( + mut cmd: Commands, + node: Query>, + assets: Res, + mut has_init: Local, +) { + if *has_init { + return; + } + if let Ok(node) = node.get_single() { if let Some(mut node) = cmd.get_entity(node) { node.with_children(|parent| { @@ -94,6 +103,8 @@ fn init_splash(mut cmd: Commands, node: Query>, assets: Res }); }); } + + *has_init = true; } cmd.spawn(SplashTimer(Timer::from_seconds( diff --git a/src/main.rs b/src/main.rs index 7bb2d3c..2ccaea9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,28 +1,6 @@ -use bevy::{prelude::*, window::WindowResolution}; -use bevy_embedded_assets::{EmbeddedAssetPlugin, PluginMode}; +use bevy::prelude::*; use hello_bevy::GamePlugin; fn main() { - App::new() - .add_plugins(( - EmbeddedAssetPlugin { - // Embed assets in binary (else itch.io is broken right now) - mode: PluginMode::ReplaceDefault, - }, - DefaultPlugins.set(WindowPlugin { - primary_window: Some(Window { - title: "Hello Bevy!".to_string(), // [CHANGE]: Game title - resolution: WindowResolution::new(600., 600.), - resizable: false, // Or use fit_canvas_to_parent: true for resizing on the web - canvas: Some("#bevy".to_string()), - prevent_default_event_handling: false, - ..default() - }), - ..default() - }), - //.set(ImagePlugin::default_nearest()), // [CHANGE]: Use if your game is pixel art - GamePlugin, - )) - // Run - .run(); + App::new().add_plugins(GamePlugin).run(); } diff --git a/build/wasm/audio.js b/wasm/audio.js similarity index 100% rename from build/wasm/audio.js rename to wasm/audio.js diff --git a/build/wasm/index.html b/wasm/index.html similarity index 94% rename from build/wasm/index.html rename to wasm/index.html index 1b868fb..59db6fc 100644 --- a/build/wasm/index.html +++ b/wasm/index.html @@ -8,7 +8,7 @@ Hello Bevy - + diff --git a/build/wasm/style.css b/wasm/style.css similarity index 100% rename from build/wasm/style.css rename to wasm/style.css