From 30f8b190bc4cf225a3a6b045add105de21b9c55b Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 9 May 2024 14:03:32 +0200 Subject: [PATCH] add more improvements and build --- .github/workflows/gh-pages._yml | 60 +++++++++ .github/workflows/release.yml | 230 ++++++++++++++++++++++++++++++++ .github/workflows/wasm.yml | 53 ++++++++ Cargo.lock | 95 ++++++++++++- Cargo.toml | 17 ++- src/egui_block_input.rs | 46 +++++++ src/flower.rs | 27 +++- src/main.rs | 9 +- src/setup.rs | 8 +- src/ui.rs | 56 +++++++- wasm/index.html | 24 ++++ wasm/restart-audio-context.js | 57 ++++++++ wasm/style.css | 12 ++ 13 files changed, 672 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/gh-pages._yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/wasm.yml create mode 100644 src/egui_block_input.rs create mode 100644 wasm/index.html create mode 100644 wasm/restart-audio-context.js create mode 100644 wasm/style.css diff --git a/.github/workflows/gh-pages._yml b/.github/workflows/gh-pages._yml new file mode 100644 index 0000000..76c7910 --- /dev/null +++ b/.github/workflows/gh-pages._yml @@ -0,0 +1,60 @@ +on: + push: + branches: [] +permissions: + contents: read + pages: write + id-token: write + + # Allow one concurrent deployment +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + test: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Install latest nightly + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + target: wasm32-unknown-unknown + + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: cache-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} + restore-keys: | + cache-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }} + cache-${{ runner.os }}-cargo + + - name: Install wasm-bindgen-cli + run: cargo install wasm-bindgen-cli + + - name: Run build + run: RUSTFLAGS=--cfg=web_sys_unstable_apis cargo build --profile wasm-release --target wasm32-unknown-unknown + - name: WASM + run: wasm-bindgen --out-dir out/ --target web ./target/wasm32-unknown-unknown/release/Flower.wasm + - name: Copy Assets + run: | + cp -r assets out/. + + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: 'out' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v1 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ea77b9d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,230 @@ +name: Release + +on: + push: + tags: + - '*' + +env: + # update with the name of the main binary + binary: Simulation + add_binaries_to_github_release: true + #itch_target: / + + +jobs: + # Build for Linux + release-linux: + runs-on: ubuntu-latest + + steps: + - uses: olegtarasov/get-tag@v2.1.2 + id: get_version + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-unknown-linux-gnu + toolchain: 1.73.0 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + + - name: install dependencies + run: | + sudo apt-get update; sudo apt-get install pkg-config libx11-dev libasound2-dev libudev-dev libxcb-render0-dev libxcb-shape0-dev libxcb-xfixes0-dev + + - name: Build + run: | + cargo build --release --target x86_64-unknown-linux-gnu + + - name: Prepare package + run: | + mkdir linux + cp target/x86_64-unknown-linux-gnu/release/${{ env.binary }} linux/ + cp -r assets linux/ + + - name: Package as a zip + working-directory: ./linux + run: | + zip --recurse-paths ../${{ env.binary }}.zip . + + - name: Upload binaries to artifacts + uses: actions/upload-artifact@v3 + with: + path: ${{ env.binary }}.zip + name: linux + retention-days: 1 + + - name: Upload binaries to release + if: ${{ env.add_binaries_to_github_release == 'true' }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.binary }}.zip + asset_name: ${{ env.binary }}-linux-${{ steps.get_version.outputs.tag }}.zip + tag: ${{ github.ref }} + overwrite: true + + # Build for Windows + release-windows: + runs-on: windows-latest + + steps: + - uses: olegtarasov/get-tag@v2.1.2 + id: get_version + - uses: actions/checkout@v4 + with: + submodules: true + - uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-pc-windows-msvc + toolchain: 1.73.0 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + + - name: Build + run: | + cargo build --release --target x86_64-pc-windows-msvc + + - name: Build Horizon Ui + run: | + cd .\horizon-ui + ./gradlew obfuscate + cd .. + + - name: Prepare package + run: | + mkdir windows + cp target/x86_64-pc-windows-msvc/release/${{ env.binary }}.exe windows/ + cp -r assets windows/ + cp .\horizon-ui\build\compose\jars\horizon-ui-windows-x64-1.0.0.min.jar windows/horizon-ui.jar + + - name: Package as a zip + run: | + Compress-Archive -Path windows/* -DestinationPath ${{ env.binary }}.zip + + - name: Upload binaries to artifacts + uses: actions/upload-artifact@v3 + with: + path: ${{ env.binary }}.zip + name: windows + retention-days: 1 + + - name: Upload binaries to release + if: ${{ env.add_binaries_to_github_release == 'true' }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.binary }}.zip + asset_name: ${{ env.binary }}-windows-${{ steps.get_version.outputs.tag }}.zip + tag: ${{ github.ref }} + overwrite: true + + # Build for MacOS x86_64 + release-macOS-intel: + runs-on: macOS-latest + + steps: + - uses: olegtarasov/get-tag@v2.1.2 + id: get_version + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: x86_64-apple-darwin + toolchain: 1.73.0 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + - name: Environment Setup + run: | + export CFLAGS="-fno-stack-check" + export MACOSX_DEPLOYMENT_TARGET="10.9" + + - name: Build + run: | + cargo build --release --target x86_64-apple-darwin + + - name: Prepare Package + run: | + mkdir -p ${{ env.binary }}.app/Contents/MacOS + cp target/x86_64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/ + cp -r assets ${{ env.binary }}.app/Contents/MacOS/ + hdiutil create -fs HFS+ -volname "${{ env.binary }}" -srcfolder ${{ env.binary }}.app ${{ env.binary }}-macOS-intel.dmg + + - name: Upload binaries to artifacts + uses: actions/upload-artifact@v3 + with: + path: ${{ env.binary }}-macOS-intel.dmg + name: macOS-intel + retention-days: 1 + + - name: Upload binaries to release + if: ${{ env.add_binaries_to_github_release == 'true' }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.binary }}-macOS-intel.dmg + asset_name: ${{ env.binary }}-macOS-intel-${{ steps.get_version.outputs.tag }}.dmg + tag: ${{ github.ref }} + overwrite: true + + # Build for MacOS Apple Silicon + release-macOS-apple-silicon: + runs-on: macOS-latest + + steps: + - uses: olegtarasov/get-tag@v2.1.2 + id: get_version + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: aarch64-apple-darwin + toolchain: 1.73.0 + + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + - name: Environment + # macOS 11 was the first version to support ARM + run: | + export MACOSX_DEPLOYMENT_TARGET="11" + + - name: Build + run: | + cargo build --release --target aarch64-apple-darwin + + - name: Prepare Package + run: | + mkdir -p ${{ env.binary }}.app/Contents/MacOS + cp target/aarch64-apple-darwin/release/${{ env.binary }} ${{ env.binary }}.app/Contents/MacOS/ + cp -r assets ${{ env.binary }}.app/Contents/MacOS/ + hdiutil create -fs HFS+ -volname "${{ env.binary }}-macOS-apple-silicon" -srcfolder ${{ env.binary }}.app ${{ env.binary }}-macOS-apple-silicon.dmg + + - name: Upload binaries to artifacts + uses: actions/upload-artifact@v3 + with: + path: ${{ env.binary }}-macOS-apple-silicon.dmg + name: macOS-apple-silicon + retention-days: 1 + + - name: Upload binaries to release + if: ${{ env.add_binaries_to_github_release == 'true' }} + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.binary }}-macOS-apple-silicon.dmg + asset_name: ${{ env.binary }}-macOS-apple-silicon-${{ steps.get_version.outputs.tag }}.dmg + tag: ${{ github.ref }} + overwrite: true \ No newline at end of file diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml new file mode 100644 index 0000000..4c1cb5c --- /dev/null +++ b/.github/workflows/wasm.yml @@ -0,0 +1,53 @@ +name: Release + +on: + push: + branches: + - main + +env: + # update with the name of the main binary + binary: Simulation + #itch_target: / + +concurrency: + group: "pages" + cancel-in-progress: true + +permissions: + contents: read + pages: write + id-token: write + +jobs: + # Build for wasm + release-wasm: + runs-on: ubuntu-latest + + steps: + - uses: olegtarasov/get-tag@v2.1.2 + id: get_version + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + toolchain: 1.73.0 + - name: install wasm-bindgen-cli + run: | + cargo install wasm-bindgen-cli --version 0.2.87 + - name: Build + run: | + cargo build --release --target wasm32-unknown-unknown + - name: Prepare package + run: | + wasm-bindgen --no-typescript --out-name Simulation --out-dir wasm --target web target/wasm32-unknown-unknown/release/${{ env.binary }}.wasm + cp -r assets wasm/ + - name: Setup Pages + uses: actions/configure-pages@v3 + - name: Upload artifact + uses: actions/upload-pages-artifact@v1 + with: + path: 'wasm' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v1 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 67c2ee6..6fc6b84 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,7 +7,9 @@ name = "Flower" version = "0.1.0" dependencies = [ "bevy", - "bevy_egui", + "bevy_egui 0.27.0", + "bevy_pancam", + "meval", ] [[package]] @@ -527,6 +529,17 @@ dependencies = [ "syn 2.0.61", ] +[[package]] +name = "bevy_egui" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b84bfb8d4104a1467910cf2090bc6a6d394ebde39c0dbc02397b45aa9ef88e80" +dependencies = [ + "bevy", + "egui 0.26.2", + "web-sys", +] + [[package]] name = "bevy_egui" version = "0.27.0" @@ -537,7 +550,7 @@ dependencies = [ "bevy", "console_log", "crossbeam-channel", - "egui", + "egui 0.27.2", "js-sys", "log", "thread_local", @@ -754,6 +767,16 @@ dependencies = [ "glam", ] +[[package]] +name = "bevy_pancam" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6e50ba0b6cf11b847ef589ddc50646880dcb0a316b2653edcf231ef26202b32" +dependencies = [ + "bevy", + "bevy_egui 0.25.0", +] + [[package]] name = "bevy_pbr" version = "0.13.2" @@ -1300,7 +1323,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" dependencies = [ - "nom", + "nom 7.1.3", ] [[package]] @@ -1622,6 +1645,15 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" +[[package]] +name = "ecolor" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03cfe80b1890e1a8cdbffc6044d6872e814aaf6011835a2a5e2db0e5c5c4ef4e" +dependencies = [ + "bytemuck", +] + [[package]] name = "ecolor" version = "0.27.2" @@ -1631,6 +1663,17 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "egui" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180f595432a5b615fc6b74afef3955249b86cfea72607b40740a4cd60d5297d0" +dependencies = [ + "ahash", + "epaint 0.26.2", + "nohash-hasher", +] + [[package]] name = "egui" version = "0.27.2" @@ -1638,7 +1681,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "584c5d1bf9a67b25778a3323af222dbe1a1feb532190e103901187f92c7fe29a" dependencies = [ "ahash", - "epaint", + "epaint 0.27.2", "nohash-hasher", ] @@ -1648,6 +1691,15 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +[[package]] +name = "emath" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6916301ecf80448f786cdf3eb51d9dbdd831538732229d49119e2d4312eaaf09" +dependencies = [ + "bytemuck", +] + [[package]] name = "emath" version = "0.27.2" @@ -1689,6 +1741,21 @@ dependencies = [ "syn 2.0.61", ] +[[package]] +name = "epaint" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77b9fdf617dd7f58b0c8e6e9e4a1281f730cde0831d40547da446b2bb76a47af" +dependencies = [ + "ab_glyph", + "ahash", + "bytemuck", + "ecolor 0.26.2", + "emath 0.26.2", + "nohash-hasher", + "parking_lot", +] + [[package]] name = "epaint" version = "0.27.2" @@ -1698,8 +1765,8 @@ dependencies = [ "ab_glyph", "ahash", "bytemuck", - "ecolor", - "emath", + "ecolor 0.27.2", + "emath 0.27.2", "nohash-hasher", "parking_lot", ] @@ -2496,6 +2563,16 @@ dependencies = [ "paste", ] +[[package]] +name = "meval" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f79496a5651c8d57cd033c5add8ca7ee4e3d5f7587a4777484640d9cb60392d9" +dependencies = [ + "fnv", + "nom 1.2.4", +] + [[package]] name = "minimal-lexical" version = "0.2.1" @@ -2601,6 +2678,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" +[[package]] +name = "nom" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce" + [[package]] name = "nom" version = "7.1.3" diff --git a/Cargo.toml b/Cargo.toml index 987e0c8..f34d966 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,21 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[profile.dev] +opt-level = 1 + +[profile.dev.package."*"] +opt-level = 3 + +[profile.release] +opt-level = 's' +lto = "thin" + [dependencies] bevy = { version = "0.13.2" } -bevy_egui = "0.27" \ No newline at end of file +bevy_egui = "0.27" +bevy_pancam = { version = "0.11.1", features = ["bevy_egui"] } +meval = "0.2" + +[features] +block_input = ["bevy_pancam/bevy_egui"] diff --git a/src/egui_block_input.rs b/src/egui_block_input.rs new file mode 100644 index 0000000..91a4509 --- /dev/null +++ b/src/egui_block_input.rs @@ -0,0 +1,46 @@ +use bevy::{input::{ButtonInput, InputSystem}, prelude::{KeyCode, MouseButton, Plugin, Res, ResMut, Resource}}; +use bevy::app::{PostUpdate, PreUpdate}; +use bevy::prelude::IntoSystemConfigs; +use bevy_egui::{EguiContexts, EguiSet}; + +//Block input when hovering over egui interfaces + +#[derive(Default, Resource)] +struct EguiBlockInputState { + wants_keyboard_input: bool, + wants_pointer_input: bool, +} + +pub struct BlockInputPlugin; + +impl Plugin for BlockInputPlugin { + + fn build(&self, app: &mut bevy::prelude::App) { + app + .init_resource::() + .add_systems(PreUpdate, egui_block_input.after(InputSystem)) + .add_systems( + PostUpdate, + egui_wants_input.after(EguiSet::ProcessOutput), + ); + } + +} + +fn egui_wants_input(mut state: ResMut, mut contexts: EguiContexts) { + state.wants_keyboard_input = contexts.ctx_mut().wants_keyboard_input(); + state.wants_pointer_input = contexts.ctx_mut().wants_pointer_input(); +} + +fn egui_block_input( + state: Res, + mut keys: ResMut>, + mut mouse_buttons: ResMut>, +) { + if state.wants_keyboard_input { + keys.reset_all(); + } + if state.wants_pointer_input { + mouse_buttons.reset_all(); + } +} \ No newline at end of file diff --git a/src/flower.rs b/src/flower.rs index 618bebe..2e31e0f 100644 --- a/src/flower.rs +++ b/src/flower.rs @@ -1,7 +1,7 @@ use std::f32::consts::PI; use bevy::{prelude::*, sprite::{Mesh2dHandle, MaterialMesh2dBundle}}; -use crate::constants::PHI; +use crate::{constants::PHI, ui::UiState}; pub struct FlowerPlugin; @@ -11,8 +11,9 @@ impl Plugin for FlowerPlugin { .insert_resource(NumberSeeds(50)) .insert_resource(SeedRadius(4.0)) .insert_resource(SeedDistance(4.0)) - .insert_resource(SeedRotation(1.0 / PHI)) - .add_systems(Startup, spawn_initial_flowers); + .insert_resource(SeedRotation(0.)) + .add_systems(Startup, spawn_initial_flowers) + .add_systems(Update, animate_flowers); } } @@ -40,6 +41,26 @@ fn spawn_initial_flowers( spawn_flowers(&mut commands, &mut meshes, &mut materials, num_seeds.0, seed_radius.0, seed_distance.0, seed_rotation.0); } +fn animate_flowers( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, + num_seeds: Res, + seed_radius: Res, + seed_distance: Res, + mut seed_rotation: ResMut, + ui_state: Res, + time: Res