From 90584babb6e51a14cab4e02ae9c2401ae69aeb38 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Tue, 28 May 2024 16:55:51 -0700 Subject: [PATCH] Macos builds working Includes fmod (dynamic linking) and pretty dmg installer --- .cargo/config.toml | 2 - .gitattributes | 4 +- .gitignore | 9 + Cargo.lock | 3 +- Cargo.toml | 5 +- build.rs | 3 + lib/macos/libfmod.dylib | 3 + lib/macos/libfmodstudio.dylib | 3 + packages/.gitkeep | 0 .../Martian Chess.app/Contents/Info.plist | 32 ++ scripts/build-macos.sh | 5 + scripts/icons-macos.sh | 34 ++ scripts/package-macos.sh | 51 +++ src/ai.rs | 279 ++++++------ src/audio.rs | 14 +- src/credits.rs | 31 +- src/debug.rs | 9 +- src/display3d.rs | 355 +++++++-------- src/game.rs | 428 +++++++++--------- src/hit3d.rs | 6 +- src/intro.rs | 16 +- src/loading.rs | 18 +- src/main.rs | 19 +- src/menu.rs | 12 +- src/prelude.rs | 2 +- src/tutorial.rs | 46 +- src/ui.rs | 2 +- 27 files changed, 778 insertions(+), 613 deletions(-) create mode 100755 lib/macos/libfmod.dylib create mode 100755 lib/macos/libfmodstudio.dylib create mode 100644 packages/.gitkeep create mode 100644 platforms/macos/Martian Chess.app/Contents/Info.plist create mode 100755 scripts/build-macos.sh create mode 100755 scripts/icons-macos.sh create mode 100755 scripts/package-macos.sh diff --git a/.cargo/config.toml b/.cargo/config.toml index 387a86b..bf08606 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -14,14 +14,12 @@ rustflags = [ # `brew install llvm` [target.x86_64-apple-darwin] rustflags = [ - "-Clink-arg=-fuse-ld=/usr/local/opt/llvm/bin/ld64.lld", # Use LLD Linker "-Zshare-generics=y", # (Nightly) Make the current crate share its generic instantiations "-Zthreads=0", # (Nightly) Use improved multithreading with the recommended amount of threads. ] [target.aarch64-apple-darwin] rustflags = [ - "-Clink-arg=-fuse-ld=/opt/homebrew/opt/llvm/bin/ld64.lld", # Use LLD Linker "-Zshare-generics=y", # (Nightly) Make the current crate share its generic instantiations "-Zthreads=0", # (Nightly) Use improved multithreading with the recommended amount of threads. ] diff --git a/.gitattributes b/.gitattributes index 24ff661..59b34a9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,3 @@ -fmodstudio/linux filter=lfs diff=lfs merge=lfs -text -fmodstudio/windows filter=lfs diff=lfs merge=lfs -text assets/ filter=lfs diff=lfs merge=lfs -text *.so filter=lfs diff=lfs merge=lfs -text *.so.* filter=lfs diff=lfs merge=lfs -text @@ -18,3 +16,5 @@ assets/ filter=lfs diff=lfs merge=lfs -text *.lib filter=lfs diff=lfs merge=lfs -text *.gltf filter=lfs diff=lfs merge=lfs -text *.mp4 filter=lfs diff=lfs merge=lfs -text +*.dylib filter=lfs diff=lfs merge=lfs -text +*.dylib filter=lfs diff=lfs merge=lfs -text diff --git a/.gitignore b/.gitignore index 25da8e0..9a05c74 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,12 @@ temp/ *.zip *.tar.gz + +.DS_Store +*.dmg + +!platforms/macos/Martian\ Chess.app/Contents/Info.plist +platforms/macos +icon_*.png +*.iconset +*.icns diff --git a/Cargo.lock b/Cargo.lock index 1042f0a..8ec84f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -655,8 +655,7 @@ dependencies = [ [[package]] name = "bevy_fmod" version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52cb5dfc9e27a6b8be8cabb6925ba1731e2a7f02bdc0bc774ba3b6b652613f46" +source = "git+https://github.com/Salzian/bevy_fmod.git?branch=main#bba24000626d251b1e1582d8b3863caa6dc701a6" dependencies = [ "anyhow", "bevy", diff --git a/Cargo.toml b/Cargo.toml index 3abf606..2dc3116 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,12 @@ [package] name = "martian-chess" +description = "Martian Chess videogame" version = "0.1.0" edition = "2021" build = "build.rs" [dependencies] -bevy_fmod = { version = "0.4" } +bevy_fmod = { git = "https://github.com/Salzian/bevy_fmod.git", branch = "main" } bevy = { version = "0.13", features = ["jpeg", "hdr", "serialize"] } serde = "1" toml = { version = "0.8", features = ["parse"] } @@ -30,4 +31,4 @@ opt-level = "z" strip = true panic = "abort" lto = true -codegen-units = 1 \ No newline at end of file +codegen-units = 1 diff --git a/build.rs b/build.rs index 38403d6..3f67097 100644 --- a/build.rs +++ b/build.rs @@ -2,6 +2,9 @@ fn main() { #[cfg(target_os = "linux")] println!("cargo:rustc-link-search=lib/linux"); + #[cfg(target_os = "macos")] + println!("cargo:rustc-link-search=lib/macos"); + #[cfg(target_os = "windows")] println!("cargo:rustc-link-search=lib/windows"); diff --git a/lib/macos/libfmod.dylib b/lib/macos/libfmod.dylib new file mode 100755 index 0000000..cb45241 --- /dev/null +++ b/lib/macos/libfmod.dylib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67b100ecefc7822a3ee870f85f727aaddc55486fd89610791af54384a8dd0caa +size 2586704 diff --git a/lib/macos/libfmodstudio.dylib b/lib/macos/libfmodstudio.dylib new file mode 100755 index 0000000..6590292 --- /dev/null +++ b/lib/macos/libfmodstudio.dylib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04124d66fffac1b5afe4e8c85844c9274702b37a5b81586409ee7d7598802fdd +size 2239280 diff --git a/packages/.gitkeep b/packages/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/platforms/macos/Martian Chess.app/Contents/Info.plist b/platforms/macos/Martian Chess.app/Contents/Info.plist new file mode 100644 index 0000000..f731273 --- /dev/null +++ b/platforms/macos/Martian Chess.app/Contents/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + Martian Chess + CFBundleExecutable + MartianChess + CFBundleIconFile + MartianChess.icns + CFBundleIdentifier + your.domain.bevy-game + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + MartianChess + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.1.0 + LSApplicationCategoryType + public.app-category.games + LSMinimumSystemVersion + 10.9 + CFBundleSupportedPlatforms + + MacOSX + + + diff --git a/scripts/build-macos.sh b/scripts/build-macos.sh new file mode 100755 index 0000000..3ab1059 --- /dev/null +++ b/scripts/build-macos.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +# Generate x86 and arm builds +cargo build --release --target aarch64-apple-darwin +cargo build --release --target x86_64-apple-darwin diff --git a/scripts/icons-macos.sh b/scripts/icons-macos.sh new file mode 100755 index 0000000..d7c2acf --- /dev/null +++ b/scripts/icons-macos.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# https://gist.github.com/ansarizafar/6fa64f44aa933794c4d6638eec32b9aa + +BASE="media/MartianChess.png" +OUT_DIR="media/MartianChess.iconset" +mkdir -p $OUT_DIR + +# 1024x1024 +sips "$BASE" -Z 1024 -o $OUT_DIR/icon_512x512@2.png + +# 512x512 +sips "$BASE" -Z 512 -o $OUT_DIR/icon_512x512.png +sips "$BASE" -Z 512 -o $OUT_DIR/icon_256x256@2.png + +# 256x256 +sips "$BASE" -Z 256 -o $OUT_DIR/icon_256x256.png +sips "$BASE" -Z 256 -o $OUT_DIR/icon_128x128@2.png + +# 128x128 +sips "$BASE" -Z 128 -o $OUT_DIR/icon_128x128.png +sips "$BASE" -Z 128 -o $OUT_DIR/icon_64x64@2.png + +# 64x64 +sips "$BASE" -Z 64 -o $OUT_DIR/icon_64x64.png +sips "$BASE" -Z 64 -o $OUT_DIR/icon_32x32@2.png + +# 32x32 +sips "$BASE" -Z 32 -o $OUT_DIR/icon_32x32.png +sips "$BASE" -Z 32 -o $OUT_DIR/icon_16x16@2.png + +# 16x16 +sips "$BASE" -Z 16 -o $OUT_DIR/icon_16x16.png + +iconutil -c icns $OUT_DIR diff --git a/scripts/package-macos.sh b/scripts/package-macos.sh new file mode 100755 index 0000000..e8f81c3 --- /dev/null +++ b/scripts/package-macos.sh @@ -0,0 +1,51 @@ +#!/bin/bash +# https://github.com/create-dmg/create-dmg/tree/master?tab=readme-ov-file#create-dmg + +NAME='Martian Chess.app' +APP="platforms/macos/$NAME" +CONTENTS="$APP/Contents" +GAME="$CONTENTS/MacOS" +RESOURCES="$CONTENTS/Resources" +FRAMEWORKS="$CONTENTS/Frameworks" + +mkdir -p "$APP" +mkdir -p "$GAME" +mkdir -p "$RESOURCES" +mkdir -p "$FRAMEWORKS" + +# Copy icons to package +cp -f media/MartianChess.icns "$RESOURCES" + +# Generate cross-architecture binary +rm -f "$GAME/MartianChess" +lipo "target/x86_64-apple-darwin/release/martian-chess" \ + "target/aarch64-apple-darwin/release/martian-chess" \ + -create -output "$GAME/MartianChess" + +# Copy assets +rm -rf "$GAME/assets" +cp -r assets "$GAME/" + +# Copy fmod libraries +cp -f lib/macos/libfmod.dylib "$FRAMEWORKS/" +cp -f lib/macos/libfmodstudio.dylib "$FRAMEWORKS/" + +# Update dynamic linking search paths +install_name_tool -change @rpath/libfmod.dylib "@loader_path/../Frameworks/libfmod.dylib" "$GAME/MartianChess" +install_name_tool -change @rpath/libfmodstudio.dylib "@loader_path/../Frameworks/libfmodstudio.dylib" "$GAME/MartianChess" + +# Build dmg file +rm -f packages/martian_chess.dmg +create-dmg \ + --volname "Martian Chess" \ + --volicon "media/MartianChess.icns" \ + --window-pos 200 120 \ + --window-size 800 400 \ + --app-drop-link 600 200 \ + --icon-size 100 \ + --icon "$NAME" 200 190 \ + --hide-extension "$NAME" \ + --app-drop-link 600 185 \ + "packages/Martian Chess.dmg" \ + ./platforms/macos/ + diff --git a/src/ai.rs b/src/ai.rs index b3a965e..094c251 100644 --- a/src/ai.rs +++ b/src/ai.rs @@ -5,42 +5,41 @@ pub(crate) struct AiPlugin; impl Plugin for AiPlugin { fn build(&self, app: &mut App) { app.init_state::() - .init_resource::() - .init_state::() - // Bogo AI Systems - .add_systems( - Update, - ( - bogo_ai_thinking - .run_if(in_state(AiDrama::Thinking)), - bogo_ai_holding - .run_if(in_state(AiDrama::Holding)), - ) - .run_if(in_state(PlayState::AiBogo)) - .run_if(in_state(GameState::Play)) - .run_if(in_state(TurnState(Side::A))) - .run_if(in_state(TutorialState::None) - .or_else(in_state(TutorialState::Empty)) - .or_else(in_state(TutorialState::PieceEnd)) - ) - ); - } + .init_resource::() + .init_state::() + // Bogo AI Systems + .add_systems( + Update, + ( + bogo_ai_thinking.run_if(in_state(AiDrama::Thinking)), + bogo_ai_holding.run_if(in_state(AiDrama::Holding)), + ) + .run_if(in_state(PlayState::AiBogo)) + .run_if(in_state(GameState::Play)) + .run_if(in_state(TurnState(Side::A))) + .run_if( + in_state(TutorialState::None) + .or_else(in_state(TutorialState::Empty)) + .or_else(in_state(TutorialState::PieceEnd)), + ), + ); + } } #[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone, Component)] pub(crate) enum PlayState { - Human, - #[default] - AiBogo, + Human, + #[default] + AiBogo, } #[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone)] enum AiDrama { - // Before AI picks up a piece - #[default] - Thinking, - // When AI picks up piece - Holding, + // Before AI picks up a piece + #[default] + Thinking, + // When AI picks up piece + Holding, } /// The move the AI will commit @@ -49,124 +48,126 @@ struct AiMove(Move); // Bogo AI logic fn bogo_ai_thinking( - board: Res, - query: Query<(Entity, &BoardIndex), With>, - time: Res