diff --git a/Cargo.lock b/Cargo.lock index d5c05cf..4be259a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1419,6 +1419,18 @@ dependencies = [ "thiserror", ] +[[package]] +name = "calloop-wayland-source" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" +dependencies = [ + "calloop", + "rustix", + "wayland-backend", + "wayland-client", +] + [[package]] name = "cc" version = "1.0.90" @@ -2708,6 +2720,15 @@ version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "memmap2" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" +dependencies = [ + "libc", +] + [[package]] name = "metal" version = "0.27.0" @@ -2745,6 +2766,15 @@ version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" +[[package]] +name = "mobile" +version = "0.1.0" +dependencies = [ + "bevy", + "cpal", + "ttt_ce", +] + [[package]] name = "naga" version = "0.19.2" @@ -3355,6 +3385,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43d84d1d7a6ac92673717f9f6d1518374ef257669c24ebc5ac25d5033828be58" +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.35" @@ -3608,12 +3647,31 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "sctk-adwaita" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b2eaf3a5b264a521b988b2e73042e742df700c4f962cde845d1541adb46550" +dependencies = [ + "ab_glyph", + "log", + "memmap2", + "smithay-client-toolkit", + "tiny-skia", +] + [[package]] name = "semver" version = "1.0.22" @@ -3718,6 +3776,31 @@ dependencies = [ "serde", ] +[[package]] +name = "smithay-client-toolkit" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "922fd3eeab3bd820d76537ce8f582b1cf951eceb5475c28500c7457d9d17f53a" +dependencies = [ + "bitflags 2.5.0", + "calloop", + "calloop-wayland-source", + "cursor-icon", + "libc", + "log", + "memmap2", + "rustix", + "thiserror", + "wayland-backend", + "wayland-client", + "wayland-csd-frame", + "wayland-cursor", + "wayland-protocols", + "wayland-protocols-wlr", + "wayland-scanner", + "xkeysym", +] + [[package]] name = "smol_str" version = "0.2.1" @@ -3754,6 +3837,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strict-num" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" + [[package]] name = "svg_fmt" version = "0.4.2" @@ -3929,6 +4018,31 @@ dependencies = [ "weezl", ] +[[package]] +name = "tiny-skia" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab" +dependencies = [ + "arrayref", + "arrayvec", + "bytemuck", + "cfg-if", + "log", + "tiny-skia-path", +] + +[[package]] +name = "tiny-skia-path" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93" +dependencies = [ + "arrayref", + "bytemuck", + "strict-num", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -4272,6 +4386,114 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "wayland-backend" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40" +dependencies = [ + "cc", + "downcast-rs", + "rustix", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" +dependencies = [ + "bitflags 2.5.0", + "rustix", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-csd-frame" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625c5029dbd43d25e6aa9615e88b829a5cad13b2819c4ae129fdbb7c31ab4c7e" +dependencies = [ + "bitflags 2.5.0", + "cursor-icon", + "wayland-backend", +] + +[[package]] +name = "wayland-cursor" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71ce5fa868dd13d11a0d04c5e2e65726d0897be8de247c0c5a65886e283231ba" +dependencies = [ + "rustix", + "wayland-client", + "xcursor", +] + +[[package]] +name = "wayland-protocols" +version = "0.31.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" +dependencies = [ + "bitflags 2.5.0", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-plasma" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" +dependencies = [ + "bitflags 2.5.0", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +dependencies = [ + "bitflags 2.5.0", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b3a62929287001986fb58c789dce9b67604a397c15c611ad9f747300b6c283" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + [[package]] name = "web-sys" version = "0.3.69" @@ -4754,6 +4976,7 @@ version = "0.29.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d59ad965a635657faf09c8f062badd885748428933dad8e8bdd64064d92e5ca" dependencies = [ + "ahash", "android-activity", "atomic-waker", "bitflags 2.5.0", @@ -4767,6 +4990,7 @@ dependencies = [ "js-sys", "libc", "log", + "memmap2", "ndk", "ndk-sys", "objc2 0.4.1", @@ -4776,10 +5000,16 @@ dependencies = [ "raw-window-handle 0.6.0", "redox_syscall 0.3.5", "rustix", + "sctk-adwaita", + "smithay-client-toolkit", "smol_str", "unicode-segmentation", "wasm-bindgen", "wasm-bindgen-futures", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-plasma", "web-sys", "web-time", "windows-sys 0.48.0", @@ -4838,6 +5068,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e63e71c4b8bd9ffec2c963173a4dc4cbde9ee96961d4fcb4429db9929b606c34" +[[package]] +name = "xcursor" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a0ccd7b4a5345edfcd0c3535718a4e9ff7798ffc536bb5b5a0e26ff84732911" + [[package]] name = "xi-unicode" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 8fe1ced..d6f4a87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,9 @@ authors = ["Mikolaj Wojciech 'Nimfer' Gorski"] # ToDo: you are the author ;) edition = "2021" exclude = ["dist", "build", "assets", "credits"] +[workspace] +members = ["mobile"] + [profile.dev.package."*"] opt-level = 3 @@ -53,6 +56,7 @@ bevy = { version = "0.13", default-features = false, features = [ "png", "hdr", "x11", + "wayland", "bevy_gizmos", "tonemapping_luts", "default_font", @@ -63,12 +67,13 @@ bevy_kira_audio = { version = "0.19" } bevy_asset_loader = { version = "0.20" } rand = { version = "0.8.3" } webbrowser = { version = "0.8", features = ["hardened"] } +bevy_editor_pls = "0.8.1" +bevy_xpbd_3d = {git = "https://git.opencodebox.com/MikolajG/bevy_xpbd", branch = "reflect-serialize"} # keep the following in sync with Bevy's dependencies winit = { version = "0.29", default-features = false } image = { version = "0.24", default-features = false } -bevy_editor_pls = "0.8.1" -bevy_xpbd_3d = {git = "https://git.opencodebox.com/MikolajG/bevy_xpbd", branch = "reflect-serialize"} + [build-dependencies] embed-resource = "1" diff --git a/mobile/.cargo/config.toml b/mobile/.cargo/config.toml new file mode 100644 index 0000000..19a6340 --- /dev/null +++ b/mobile/.cargo/config.toml @@ -0,0 +1,5 @@ +# Flag to notify the compiler we're building for the iOS simulator from an Apple silicon mac +# This needs some workarounds for now +# See https://github.com/bevyengine/bevy/pull/10178 - remove if it's not needed anymore. +[target.aarch64-apple-ios-sim] +rustflags = ["--cfg=ios_simulator"] diff --git a/mobile/.gitignore b/mobile/.gitignore new file mode 100644 index 0000000..b446ed7 --- /dev/null +++ b/mobile/.gitignore @@ -0,0 +1,3 @@ +mobile.xcodeproj/xcuserdata/ +mobile.xcodeproj/project.xcworkspace/ +build/ diff --git a/mobile/Cargo.toml b/mobile/Cargo.toml new file mode 100644 index 0000000..cfdb8a7 --- /dev/null +++ b/mobile/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "mobile" +version = "0.1.0" +edition = "2021" +publish = false + +[lib] +name = "mobile" +crate-type = ["staticlib", "cdylib"] + +[dependencies] +ttt_ce = { path = ".." } # ToDo +bevy = { version = "0.13", default-features = false } + +# As long as Kira doesn't expose a feature for this, we need to enable it +# See https://github.com/tesselode/kira/pull/51 +[target."cfg(target_os = \"android\")".dependencies.cpal] +version = "0.15" +features = ["oboe-shared-stdcxx"] + +[package.metadata.android] +package = "me.nikl.bevygame" # ToDo +apk_name = "BevyGame" # ToDo same as GAME_OSX_APP_NAME in release workflow +assets = "../assets" +strip = "strip" +resources = "../build/android/res" +build_targets = ["aarch64-linux-android"] + +[package.metadata.android.sdk] +target_sdk_version = 33 + +[package.metadata.android.application] +icon = "@mipmap/icon" +label = "Bevy Game" # ToDo diff --git a/mobile/Makefile b/mobile/Makefile new file mode 100644 index 0000000..4fb6908 --- /dev/null +++ b/mobile/Makefile @@ -0,0 +1,29 @@ +.PHONY: xcodebuild run install boot-sim generate clean + +DEVICE = ${DEVICE_ID} +ifndef DEVICE_ID + DEVICE=$(shell xcrun simctl list devices 'iOS' | grep -v 'unavailable' | grep -v '^--' | grep -v '==' | head -n 1 | grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})") +endif + +run: install + # Todo: change the bundle identifier (then remove this comment :P) + xcrun simctl launch --console $(DEVICE) me.nikl.bevygame + +boot-sim: + xcrun simctl boot $(DEVICE) || true + +install: xcodebuild-simulator boot-sim + xcrun simctl install $(DEVICE) build/Build/Products/Debug-iphonesimulator/mobile.app + +xcodebuild-simulator: + IOS_TARGETS=x86_64-apple-ios xcodebuild -scheme mobile -configuration Debug -derivedDataPath build -destination "id=$(DEVICE)" + +xcodebuild-iphone: + IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme mobile -configuration Debug -derivedDataPath build -arch arm64 + +xcodebuild-iphone-release: + IOS_TARGETS=aarch64-apple-ios xcodebuild -scheme mobile -configuration Release -derivedDataPath build -arch arm64 + +clean: + rm -r build + cargo clean diff --git a/mobile/build_rust_deps.sh b/mobile/build_rust_deps.sh new file mode 100644 index 0000000..af8e0a7 --- /dev/null +++ b/mobile/build_rust_deps.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +# based on https://github.com/mozilla/glean/blob/main/build-scripts/xc-universal-binary.sh + +set -eux + +PATH=$PATH:$HOME/.cargo/bin + +RELFLAG= +if [[ "$CONFIGURATION" != "Debug" ]]; then + RELFLAG="--profile dist" +fi + +set -euvx + +if [[ -n "${DEVELOPER_SDK_DIR:-}" ]]; then + # Assume we're in Xcode, which means we're probably cross-compiling. + # In this case, we need to add an extra library search path for build scripts and proc-macros, + # which run on the host instead of the target. + # (macOS Big Sur does not have linkable libraries in /usr/lib/.) + export LIBRARY_PATH="${DEVELOPER_SDK_DIR}/MacOSX.sdk/usr/lib:${LIBRARY_PATH:-}" +fi + +# add homebrew bin path, as it's the most commonly used package manager on macOS +# this is needed for cmake on apple arm processors as it's not available by default +export PATH="$PATH:/opt/homebrew/bin" + +IS_SIMULATOR=0 +if [ "${LLVM_TARGET_TRIPLE_SUFFIX-}" = "-simulator" ]; then + IS_SIMULATOR=1 +fi + +for arch in $ARCHS; do + case "$arch" in + x86_64) + if [ $IS_SIMULATOR -eq 0 ]; then + echo "Building for x86_64, but not a simulator build. What's going on?" >&2 + exit 2 + fi + + # Intel iOS simulator + export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios" + cargo rustc --crate-type staticlib --lib $RELFLAG --target x86_64-apple-ios + ;; + + arm64) + if [ $IS_SIMULATOR -eq 0 ]; then + # Hardware iOS targets + cargo rustc --crate-type staticlib --lib $RELFLAG --target aarch64-apple-ios + else + # M1 iOS simulator -- currently in Nightly only and requires to build `libstd` + cargo rustc --crate-type staticlib --lib $RELFLAG --target aarch64-apple-ios-sim + fi + esac +done diff --git a/mobile/ios-src/Assets.xcassets/AppIcon.appiconset/Contents.json b/mobile/ios-src/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..5a60908 --- /dev/null +++ b/mobile/ios-src/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,14 @@ +{ + "images" : [ + { + "filename" : "icon_1024x1024.png", + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/mobile/ios-src/Assets.xcassets/AppIcon.appiconset/icon_1024x1024.png b/mobile/ios-src/Assets.xcassets/AppIcon.appiconset/icon_1024x1024.png new file mode 100644 index 0000000..a79c37d Binary files /dev/null and b/mobile/ios-src/Assets.xcassets/AppIcon.appiconset/icon_1024x1024.png differ diff --git a/mobile/ios-src/Assets.xcassets/Contents.json b/mobile/ios-src/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/mobile/ios-src/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/mobile/ios-src/Info.plist b/mobile/ios-src/Info.plist new file mode 100644 index 0000000..f815a6b --- /dev/null +++ b/mobile/ios-src/Info.plist @@ -0,0 +1,35 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 0.1.1 + CFBundleIconName + AppIcon + CFBundleVersion + 0.1.1 + UILaunchStoryboardName + LaunchScreen + UIRequiresFullScreen + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + UIInterfaceOrientationPortraitUpsideDown + + + diff --git a/mobile/ios-src/LaunchScreen.storyboard b/mobile/ios-src/LaunchScreen.storyboard new file mode 100644 index 0000000..324de1d --- /dev/null +++ b/mobile/ios-src/LaunchScreen.storyboard @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mobile/ios-src/bindings.h b/mobile/ios-src/bindings.h new file mode 100644 index 0000000..a705f03 --- /dev/null +++ b/mobile/ios-src/bindings.h @@ -0,0 +1 @@ +void main_rs(void); diff --git a/mobile/ios-src/main.m b/mobile/ios-src/main.m new file mode 100644 index 0000000..7d152fb --- /dev/null +++ b/mobile/ios-src/main.m @@ -0,0 +1,6 @@ +#import "bindings.h" + +int main() { + main_rs(); + return 0; +} diff --git a/mobile/manifest.yaml b/mobile/manifest.yaml new file mode 100644 index 0000000..4be78a5 --- /dev/null +++ b/mobile/manifest.yaml @@ -0,0 +1,11 @@ +android: + gradle: true + # this assets configuration is currently only used without gradle! + #assets: + # - "../assets/*" + icon: "ios-src/Assets.xcassets/AppIcon.appiconset/icon_1024x1024.png" + manifest: + package: "me.nikl.bevygame" # Todo + version_code: 3 # Todo you should start at 1 + application: + label: "Bevy game" # Todo diff --git a/mobile/mobile.xcodeproj/project.pbxproj b/mobile/mobile.xcodeproj/project.pbxproj new file mode 100644 index 0000000..d98a2c0 --- /dev/null +++ b/mobile/mobile.xcodeproj/project.pbxproj @@ -0,0 +1,465 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 51; + objects = { + +/* Begin PBXBuildFile section */ + 134866208A035F8615C99114 /* Metal.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96A1E5B62F48B379829E8A0D /* Metal.framework */; }; + 2469A4292A6F9AC200ACF4EF /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2469A4282A6F9AC200ACF4EF /* Assets.xcassets */; }; + 2469A42B2A6FAC7000ACF4EF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2469A42A2A6FAC7000ACF4EF /* LaunchScreen.storyboard */; }; + 2604C99FAB5A8322EDCABB9F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FE71FBCAA714DB4F42459106 /* UIKit.framework */; }; + 442540D056ADB9AE61A0A590 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F1B41978FA53999AA836D0F /* Security.framework */; }; + 55892F1396056740E1AF9685 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = AF7DE91055EBD05ED77E57F9 /* main.m */; }; + 55B7188F81C3C4183F81D3AE /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = A39528EB2CCB182F5328223A /* libc++.tbd */; }; + 57CD6306253C7A940098CD4A /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57CD6305253C7A940098CD4A /* AudioToolbox.framework */; }; + 57CD630E253C80EC0098CD4A /* assets in Resources */ = {isa = PBXBuildFile; fileRef = 57CD630A253C7F5F0098CD4A /* assets */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 26BF2C4863C966DABAB40DC8 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8DBF1E2B5C613DA41701F6D9 /* Project object */; + proxyType = 1; + remoteGlobalIDString = D08AEBE0B1A9C9A7B8C7B33F; + remoteInfo = cargo_ios; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 160DB77300A3F1806F024D47 /* bindings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = bindings.h; sourceTree = ""; }; + 2469A4282A6F9AC200ACF4EF /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "ios-src/Assets.xcassets"; sourceTree = SOURCE_ROOT; }; + 2469A42A2A6FAC7000ACF4EF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = ios-src/LaunchScreen.storyboard; sourceTree = ""; }; + 55EAC02897847195D2F44C15 /* mobile.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = mobile.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 57CD6305253C7A940098CD4A /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; + 57CD630A253C7F5F0098CD4A /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = ../../assets; sourceTree = ""; }; + 8EE7F1E3B0303533925D7E33 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 96A1E5B62F48B379829E8A0D /* Metal.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Metal.framework; path = System/Library/Frameworks/Metal.framework; sourceTree = SDKROOT; }; + 9F1B41978FA53999AA836D0F /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; + A39528EB2CCB182F5328223A /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; }; + AF7DE91055EBD05ED77E57F9 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + FE71FBCAA714DB4F42459106 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + D5A822CB2D6847BA8800BE4C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 442540D056ADB9AE61A0A590 /* Security.framework in Frameworks */, + 134866208A035F8615C99114 /* Metal.framework in Frameworks */, + 2604C99FAB5A8322EDCABB9F /* UIKit.framework in Frameworks */, + 55B7188F81C3C4183F81D3AE /* libc++.tbd in Frameworks */, + 57CD6306253C7A940098CD4A /* AudioToolbox.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 321F7D6A765B38E746C35105 /* Products */ = { + isa = PBXGroup; + children = ( + 55EAC02897847195D2F44C15 /* mobile.app */, + ); + name = Products; + sourceTree = ""; + }; + 4F1D6F28B8A5D1927AB0ADED /* ios-src */ = { + isa = PBXGroup; + children = ( + 2469A4282A6F9AC200ACF4EF /* Assets.xcassets */, + 57CD630A253C7F5F0098CD4A /* assets */, + 160DB77300A3F1806F024D47 /* bindings.h */, + 8EE7F1E3B0303533925D7E33 /* Info.plist */, + AF7DE91055EBD05ED77E57F9 /* main.m */, + ); + path = "ios-src"; + sourceTree = ""; + }; + 8F2E3E6040EAD2EC9F3FA530 = { + isa = PBXGroup; + children = ( + 2469A42A2A6FAC7000ACF4EF /* LaunchScreen.storyboard */, + 4F1D6F28B8A5D1927AB0ADED /* ios-src */, + EB028409C2D0655412DA6E44 /* Frameworks */, + 321F7D6A765B38E746C35105 /* Products */, + ); + sourceTree = ""; + }; + EB028409C2D0655412DA6E44 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 57CD6305253C7A940098CD4A /* AudioToolbox.framework */, + A39528EB2CCB182F5328223A /* libc++.tbd */, + 96A1E5B62F48B379829E8A0D /* Metal.framework */, + 9F1B41978FA53999AA836D0F /* Security.framework */, + FE71FBCAA714DB4F42459106 /* UIKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXLegacyTarget section */ + D08AEBE0B1A9C9A7B8C7B33F /* cargo_ios */ = { + isa = PBXLegacyTarget; + buildArgumentsString = build_rust_deps.sh; + buildConfigurationList = AA00A0CFDB11F37F2BA3FC2E /* Build configuration list for PBXLegacyTarget "cargo_ios" */; + buildPhases = ( + FE045B3D04D57B713A565FF8 /* Sources */, + ); + buildToolPath = /bin/sh; + buildWorkingDirectory = .; + dependencies = ( + ); + name = cargo_ios; + passBuildSettingsInEnvironment = 1; + productName = cargo_ios; + }; +/* End PBXLegacyTarget section */ + +/* Begin PBXNativeTarget section */ + 3BDB8152E4962373181B4FE5 /* mobile */ = { + isa = PBXNativeTarget; + buildConfigurationList = E714A1AEAAE517C348B5BD27 /* Build configuration list for PBXNativeTarget "mobile" */; + buildPhases = ( + 9F13800790AD9DBC2BC0F116 /* Sources */, + D5A822CB2D6847BA8800BE4C /* Frameworks */, + 57CD630D253C80E60098CD4A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 19D4B9C22ADC6705B5132B4C /* PBXTargetDependency */, + ); + name = mobile; + productName = mobile; + productReference = 55EAC02897847195D2F44C15 /* mobile.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 8DBF1E2B5C613DA41701F6D9 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1240; + }; + buildConfigurationList = 9D43D41707A5C30B227B83F9 /* Build configuration list for PBXProject "mobile" */; + compatibilityVersion = "Xcode 10.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 8F2E3E6040EAD2EC9F3FA530; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 3BDB8152E4962373181B4FE5 /* mobile */, + D08AEBE0B1A9C9A7B8C7B33F /* cargo_ios */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 57CD630D253C80E60098CD4A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 2469A42B2A6FAC7000ACF4EF /* LaunchScreen.storyboard in Resources */, + 2469A4292A6F9AC200ACF4EF /* Assets.xcassets in Resources */, + 57CD630E253C80EC0098CD4A /* assets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 9F13800790AD9DBC2BC0F116 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 55892F1396056740E1AF9685 /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + FE045B3D04D57B713A565FF8 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 19D4B9C22ADC6705B5132B4C /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = D08AEBE0B1A9C9A7B8C7B33F /* cargo_ios */; + targetProxy = 26BF2C4863C966DABAB40DC8 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 4AD7BC6FDD56FF18FA6DA7D7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = ""; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "$(inherited)", + "DEBUG=1", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 5B14EC4ADC81FBF1F8CF20E9 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_CXX_LANGUAGE_STANDARD = "c++11"; + CLANG_CXX_LIBRARY = "libc++"; + CODE_SIGN_IDENTITY = ""; + DEVELOPMENT_TEAM = ""; + ENABLE_BITCODE = NO; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "ios-src/", + ); + INFOPLIST_FILE = "ios-src/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphoneos*][arch=arm64]" = ( + "$(inherited)", + "../target/aarch64-apple-ios/dist", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=arm64]" = ( + "$(inherited)", + "../target/aarch64-apple-ios-sim/dist", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=x86_64]" = ( + "$(inherited)", + "../target/x86_64-apple-ios/dist", + ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-lmobile", + "-lc++abi", + ); + PRODUCT_BUNDLE_IDENTIFIER /* Todo */ = me.nikl.bevygame; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 79E3C28F06346EA58420A93D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = ""; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_VERSION = 5.0; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 8265913A25816D964A847F1B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.rust.cargo-ios"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + A2D5B73DD30D562B6F366526 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_CXX_LANGUAGE_STANDARD = "c++11"; + CLANG_CXX_LIBRARY = "libc++"; + CODE_SIGN_IDENTITY = ""; + DEVELOPMENT_TEAM = ""; + ENABLE_BITCODE = NO; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "ios-src/", + ); + INFOPLIST_FILE = "ios-src/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphoneos*][arch=arm64]" = ( + "$(inherited)", + "../target/aarch64-apple-ios/debug", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=arm64]" = ( + "$(inherited)", + "../target/aarch64-apple-ios-sim/debug", + ); + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*][arch=x86_64]" = ( + "$(inherited)", + "../target/x86_64-apple-ios/debug", + ); + OTHER_LDFLAGS = ( + "$(inherited)", + "-lmobile", + "-lc++abi", + ); + PRODUCT_BUNDLE_IDENTIFIER /* Todo */ = me.nikl.bevygame; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + FEA9B18D9236F9F6DC6DF799 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.rust.cargo-ios"; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 9D43D41707A5C30B227B83F9 /* Build configuration list for PBXProject "mobile" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4AD7BC6FDD56FF18FA6DA7D7 /* Debug */, + 79E3C28F06346EA58420A93D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; + AA00A0CFDB11F37F2BA3FC2E /* Build configuration list for PBXLegacyTarget "cargo_ios" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8265913A25816D964A847F1B /* Debug */, + FEA9B18D9236F9F6DC6DF799 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; + E714A1AEAAE517C348B5BD27 /* Build configuration list for PBXNativeTarget "mobile" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A2D5B73DD30D562B6F366526 /* Debug */, + 5B14EC4ADC81FBF1F8CF20E9 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Debug; + }; +/* End XCConfigurationList section */ + }; + rootObject = 8DBF1E2B5C613DA41701F6D9 /* Project object */; +} diff --git a/mobile/mobile.xcodeproj/xcshareddata/xcschemes/mobile.xcscheme b/mobile/mobile.xcodeproj/xcshareddata/xcschemes/mobile.xcscheme new file mode 100644 index 0000000..495aaf6 --- /dev/null +++ b/mobile/mobile.xcodeproj/xcshareddata/xcschemes/mobile.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mobile/src/lib.rs b/mobile/src/lib.rs new file mode 100644 index 0000000..d32a94b --- /dev/null +++ b/mobile/src/lib.rs @@ -0,0 +1,20 @@ +use bevy::prelude::*; +use bevy::window::WindowMode; +use ttt_ce::GamePlugin; + +#[bevy_main] +fn main() { + App::new() + .add_plugins(( + DefaultPlugins.set(WindowPlugin { + primary_window: Some(Window { + resizable: false, + mode: WindowMode::BorderlessFullscreen, + ..default() + }), + ..default() + }), + GamePlugin, + )) + .run() +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d3df9e3 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,103 @@ +/* +Trouble in Terror Town: Community Edition +Copyright (C) 2024 Mikolaj Wojciech Gorski + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#![allow(clippy::type_complexity)] + +use bevy::prelude::*; +#[cfg(debug_assertions)] +use bevy::diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}; +use bevy_xpbd_3d::prelude::*; +use bevy_editor_pls::prelude::*; +mod charcacter_controller; +use charcacter_controller::*; + +pub struct GamePlugin; + +impl Plugin for GamePlugin { + fn build(&self, app: &mut App) { + app.add_plugins(( + PhysicsPlugins::default(), + CharacterControllerPlugin, + )) + .add_systems(Startup, setup) + .add_systems(Update, spawn_map); + + #[cfg(debug_assertions)] + { + app.add_plugins((FrameTimeDiagnosticsPlugin, EditorPlugin::default(), LogDiagnosticsPlugin::default())); + } + + app.world.init_resource::(); + } +} + +#[derive(Resource, Default, Debug)] +struct IsMapSpawned(bool); + +/// set up a simple 3D scene +fn setup( + mut commands: Commands, + mut meshes: ResMut>, + mut materials: ResMut>, +) { + + //player + commands.spawn((CharacterControllerBundle::new(Collider::capsule(1.0, 0.5), CharacterController::default()), PbrBundle{ + mesh: meshes.add(Capsule3d::new(0.5, 1.0)), + material: materials.add(Color::rgb_u8(124, 144, 255)), + transform: Transform::from_xyz(0.0, 5.0, 0.0), + ..default() + })); + // light + commands.spawn(PointLightBundle { + point_light: PointLight { + shadows_enabled: true, + ..default() + }, + transform: Transform::from_xyz(4.0, 8.0, 4.0), + ..default() + }); + // camera + commands.spawn(Camera3dBundle { + transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), + ..default() + }); +} + +fn spawn_map( + asset_server: Res, + mut is_map_spawned: ResMut, + mut commands: Commands, +){ + if is_map_spawned.0 {return;} + + let scene = asset_server.load("test_map.gltf#Scene0"); + + commands.spawn(( + SceneBundle { + scene: scene.clone(), + transform: Transform::from_xyz(0.0, 0.0, 0.0), + ..default() + }, + AsyncSceneCollider::new(Some(ComputedCollider::TriMesh)), + RigidBody::Static, + )); + + println!("map spawned!"); + + is_map_spawned.0 = true +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index e0facc7..c0ae3e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,94 +15,56 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -use bevy::{diagnostic::FrameTimeDiagnosticsPlugin, prelude::*, window::Cursor, winit::WinitWindows}; -use bevy_xpbd_3d::prelude::*; -use bevy_editor_pls::prelude::*; -mod charcacter_controller; -use charcacter_controller::*; +// disable console on windows for release builds +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] + +use bevy::asset::AssetMetaCheck; +use bevy::prelude::*; +use bevy::window::PrimaryWindow; +use bevy::winit::WinitWindows; +use bevy::DefaultPlugins; +use ttt_ce::GamePlugin; +use std::io::Cursor; +use winit::window::Icon; fn main() { - let mut app = App::new(); - - app - .add_plugins(( - DefaultPlugins.set(WindowPlugin { + App::new() + .insert_resource(Msaa::Off) + .insert_resource(AssetMetaCheck::Never) + .insert_resource(ClearColor(Color::rgb(0.4, 0.4, 0.4))) + .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { - cursor: Cursor::default(), - present_mode: bevy::window::PresentMode::AutoNoVsync, - mode: bevy::window::WindowMode::Windowed, - title: "Trouble in Terror Town: Community Edition".to_string(), - resizable: true, + title: "Bevy game".to_string(), // ToDo + // Bind to canvas included in `index.html` + canvas: Some("#bevy".to_owned()), + // Tells wasm not to override default event handling, like F5 and Ctrl+R + prevent_default_event_handling: false, ..default() }), ..default() - }), - PhysicsPlugins::default(), - EditorPlugin::default(), - FrameTimeDiagnosticsPlugin::default(), - CharacterControllerPlugin, - )) - .add_systems(Startup, setup) - .add_systems(Update, spawn_map); - - app.world.init_resource::(); - - app.run(); + })) + .add_plugins(GamePlugin) + .add_systems(Startup, set_window_icon) + .run(); } -#[derive(Resource, Default, Debug)] -struct IsMapSpawned(bool); - -/// set up a simple 3D scene -fn setup( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, +// Sets the icon on windows and X11 +fn set_window_icon( + windows: NonSend, + primary_window: Query>, ) { - - //player - commands.spawn((CharacterControllerBundle::new(Collider::capsule(1.0, 0.5), CharacterController::default()), PbrBundle{ - mesh: meshes.add(Capsule3d::new(0.5, 1.0)), - material: materials.add(Color::rgb_u8(124, 144, 255)), - transform: Transform::from_xyz(0.0, 5.0, 0.0), - ..default() - })); - // light - commands.spawn(PointLightBundle { - point_light: PointLight { - shadows_enabled: true, - ..default() - }, - transform: Transform::from_xyz(4.0, 8.0, 4.0), - ..default() - }); - // camera - commands.spawn(Camera3dBundle { - transform: Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y), - ..default() - }); -} - -fn spawn_map( - asset_server: Res, - mut is_map_spawned: ResMut, - mut commands: Commands, -){ - if is_map_spawned.0 {return;} - - let scene = asset_server.load("test_map.gltf#Scene0"); - - commands.spawn(( - SceneBundle { - scene: scene.clone(), - transform: Transform::from_xyz(0.0, 0.0, 0.0), - ..default() - }, - AsyncSceneCollider::new(Some(ComputedCollider::TriMesh)), - RigidBody::Static, + let primary_entity = primary_window.single(); + let Some(primary) = windows.get_window(primary_entity) else { + return; + }; + let icon_buf = Cursor::new(include_bytes!( + "../build/macos/AppIcon.iconset/icon_256x256.png" )); - - println!("map spawned!"); - - is_map_spawned.0 = true -} \ No newline at end of file + if let Ok(image) = image::load(icon_buf, image::ImageFormat::Png) { + let image = image.into_rgba8(); + let (width, height) = image.dimensions(); + let rgba = image.into_raw(); + let icon = Icon::from_rgba(rgba, width, height).unwrap(); + primary.set_window_icon(Some(icon)); + }; +}