iT邦幫忙

2023 iThome 鐵人賽

DAY 10
0

Bevy 遊戲引擎實戰

今天開始來實際練習 Bevy,照著官方教學學習。

建立Rust專案

cargo new learn_bevy_game
cd learn_bevy_game

由於Rust在編譯Bevy時會花費很久M,可以啟用dynamic linking、安裝LLD linker和Nightly Rust Compiler來達到編譯加速

安裝LLD linker

brew install michaeleisel/zld/zld

建立新資料夾.cargo並在裡面新增config.toml

# Add the contents of this file to `config.toml` to enable "fast build" configuration. Please read the notes below.

# NOTE: For maximum performance, build using a nightly compiler
# If you are using rust stable, remove the "-Zshare-generics=y" below.

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]

# NOTE: 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]
rustflags = [
    "-C",
    "link-arg=-fuse-ld=/usr/local/opt/llvm/bin/ld64.lld",
    "-Zshare-generics=y",
]

[target.aarch64-apple-darwin]
rustflags = [
    "-C",
    "link-arg=-fuse-ld=/opt/homebrew/opt/llvm/bin/ld64.lld",
    "-Zshare-generics=y",
]

[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = ["-Zshare-generics=n"]

# Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only'
# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
#[profile.dev]
#debug = 1

使用Nightly Rust Compiler

新增rust-toolchain.toml

[toolchain]
channel = "nightly"

將bevy加入Cargo.toml

[package]
name = "learn_bevy_game"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.11.2"

Enable Bevy's Dynamic Linking Feature:

mkdir -p bevy/dynamic_linking
cargo run --features bevy/dynamic_linking

這邊會需要等一段時間,結束之後執行

cargo run

這邊也會編譯一段時間,之後再次編譯就會變快很多,今天先設定好環境明天再來開工。
設定後的專案結構
https://ithelp.ithome.com.tw/upload/images/20230924/20140358WGlKHlDffZ.png


上一篇
[Day 9] HoloCure 遊戲介紹
下一篇
[Day 11] 繼續Bevy遊戲引擎之旅
系列文
三十歲時在做什麼?有沒有空?可以來做遊戲嗎?30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言