Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor system sets #320

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 125 additions & 20 deletions .cargo/config_fast_builds.toml
Original file line number Diff line number Diff line change
@@ -1,40 +1,145 @@
# Rename 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.
# Copy this file to `config.toml` to speed up your builds.
#
# # Faster linker
#
# One of the slowest aspects of compiling large Rust programs is the linking time. This file configures an
# alternate linker that may improve build times. When choosing a new linker, you have two options:
#
# ## LLD
#
# LLD is a linker from the LLVM project that supports Linux, Windows, MacOS, and WASM. It has the greatest
# platform support and the easiest installation process. It is enabled by default in this file for Linux
# and Windows. On MacOS, the default linker yields higher performance than LLD and is used instead.
#
# To install, please scroll to the corresponding table for your target (eg. `[target.x86_64-pc-windows-msvc]`
# for Windows) and follow the steps under `LLD linker`.
#
# For more information, please see LLD's website at <https://lld.llvm.org>.
#
# ## Mold
#
# Mold is a newer linker written by one of the authors of LLD. It boasts even greater performance, specifically
# through its high parallelism, though it only supports Linux.
#
# Mold is disabled by default in this file. If you wish to enable it, follow the installation instructions for
# your corresponding target, disable LLD by commenting out its `-Clink-arg=...` line, and enable Mold by
# *uncommenting* its `-Clink-arg=...` line.
#
# There is a fork of Mold named Sold that supports MacOS, but it is unmaintained and is about the same speed as
# the default ld64 linker. For this reason, it is not included in this file.
#
# For more information, please see Mold's repository at <https://github.com/rui314/mold>.
#
# # Nightly configuration
#
# Be warned that the following features require nightly Rust, which is expiremental and may contain bugs. If you
# are having issues, skip this section and use stable Rust instead.
#
# There are a few unstable features that can improve performance. To use them, first install nightly Rust
# through Rustup:
#
# ```
# rustup toolchain install nightly
# ```
#
# Finally, uncomment the lines under the `Nightly` heading for your corresponding target table (eg.
# `[target.x86_64-unknown-linux-gnu]` for Linux) to enable the following features:
#
# ## `share-generics`
#
# Usually rustc builds each crate separately, then combines them all together at the end. `share-generics` forces
# crates to share monomorphized generic code, so they do not duplicate work.
#
# In other words, instead of crate 1 generating `Foo<String>` and crate 2 generating `Foo<String>` separately,
# only one crate generates `Foo<String>` and the other adds on to the pre-exiting work.
#
# Note that you may have some issues with this flag on Windows. If compiling fails due to the 65k symbol limit,
# you may have to disable this setting. For more information and possible solutions to this error, see
# <https://github.com/bevyengine/bevy/issues/1110>.
#
# ## `threads`
#
# This option enables rustc's parallel frontend, which improves performance when parsing, type checking, borrow
# checking, and more. We currently set `threads=0`, which defaults to the amount of cores in your CPU.
#
# For more information, see the blog post at <https://blog.rust-lang.org/2023/11/09/parallel-rustc.html>.

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = [
"-Clink-arg=-fuse-ld=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.
# LLD linker
#
# You may need to install it:
#
# - Ubuntu: `sudo apt-get install lld clang`
# - Fedora: `sudo dnf install lld clang`
# - Arch: `sudo pacman -S lld clang`
"-Clink-arg=-fuse-ld=lld",
# Mold linker
#
# You may need to install it:
#
# - Ubuntu: `sudo apt-get install mold clang`
# - Fedora: `sudo dnf install mold clang`
# - Arch: `sudo pacman -S mold clang`
# "-Clink-arg=-fuse-ld=/usr/bin/mold",

# Nightly
# "-Zshare-generics=y",
# "-Zthreads=0",
]

# 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 = [
"-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.
# LLD linker
#
# The default ld64 linker is faster, you should continue using it instead.
#
# You may need to install it:
#
# Brew: `brew install llvm`
# Manually: <https://lld.llvm.org/MachO/index.html>
# "-Clink-arg=-fuse-ld=/usr/local/opt/llvm/bin/ld64.lld",

# Nightly
# "-Zshare-generics=y",
# "-Zthreads=0",
]

[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.
# LLD linker
#
# The default ld64 linker is faster, you should continue using it instead.
#
# You may need to install it:
#
# Brew: `brew install llvm`
# Manually: <https://lld.llvm.org/MachO/index.html>
# "-Clink-arg=-fuse-ld=/opt/homebrew/opt/llvm/bin/ld64.lld",

# Nightly
# "-Zshare-generics=y",
# "-Zthreads=0",
]

[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe" # Use LLD Linker
# LLD linker
#
# You may need to install it:
#
# ```
# cargo install -f cargo-binutils
# rustup component add llvm-tools
# ```
linker = "rust-lld.exe"
rustflags = [
"-Zshare-generics=n", # (Nightly)
"-Zthreads=0", # (Nightly) Use improved multithreading with the recommended amount of threads.
# Nightly
# "-Zshare-generics=y",
# "-Zthreads=0",
]

# 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
# [profile.dev]
# debug = 1
25 changes: 0 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ oxidized_navigation = { version = "0.10", features = ["xpbd"] }
iyes_progress = "0.11"
leafwing-input-manager = { version = "0.13", features = ["egui"] }
bevy_dolly = "0.0.3"
bevy_mod_sysfail = "7"
bevy_editor_pls = { version = "0.8.1", optional = true }
bevy_hanabi = { version = "0.11", default-features = false, features = ["3d"] }
bevy_yarnspinner = "0.2"
Expand Down
10 changes: 4 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@ https://user-images.githubusercontent.com/9047632/226387411-70f662de-0681-47ff-b

## What does this template give you?

- A 3D character controller via [`bevy-tnua`](https://crates.io/crates/bevy-tnua)
- Integration with Blender as an editor via
the [`Blender_bevy_components_workflow`](https://github.com/kaosat-dev/Blender_bevy_components_workflow) set of tools
- Physics via [`bevy_xpbd`](https://crates.io/crates/bevy_xpbd_3d)
- A 3D character controller via [`bevy-tnua`](https://crates.io/crates/bevy-tnua)
- Audio via [`bevy_kira_audio`](https://crates.io/crates/bevy_kira_audio)
- Pathfinding via [`oxidized_navigation`](https://crates.io/crates/oxidized_navigation)
- [`bevy_editor_pls`](https://crates.io/crates/bevy_editor_pls) bound to 'Q'
- Custom editor found in the windows selection for `bevy_editor_pls`.
- Custom editor found in the windows selection for `bevy_editor_pls`.
- Animations
- Dialogs via [`Yarn Spinner for Rust`](https://crates.io/crates/bevy_yarnspinner)
- Shaders, using the code from [DGriffin's tutorial](https://www.youtube.com/watch?v=O6A_nVmpvhc)
- GLTF imports, including auto-insertion of markers via the GLTF extras field
- Smooth cameras via [`bevy_dolly`](https://crates.io/crates/bevy_dolly)
- Simple error handling via [`bevy_mod_sysfail`](https://crates.io/crates/bevy_mod_sysfail)
- Particle effects via [`bevy_hanabi`](https://crates.io/crates/bevy_hanabi)
- Procedural skies via [`bevy_atmosphere`](https://crates.io/crates/bevy_atmosphere)
- Grass via [`warbler_grass`](https://crates.io/crates/warbler_grass)
- Integration with Blender as an editor via
the [`Blender_bevy_components_workflow`](https://github.com/kaosat-dev/Blender_bevy_components_workflow) set of tools

## Usage

Expand Down
15 changes: 7 additions & 8 deletions src/bevy_config.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::Context;
use crate::util::error;
use bevy::render::settings::{WgpuFeatures, WgpuSettings};
use bevy::render::RenderPlugin;
use bevy::{prelude::*, window::PrimaryWindow, winit::WinitWindows};
use bevy_mod_sysfail::prelude::*;
use std::io::Cursor;
use winit::window::Icon;

Expand All @@ -24,7 +23,7 @@ pub(super) fn plugin(app: &mut App) {
)
.insert_resource(Msaa::Sample4)
.insert_resource(ClearColor(Color::rgb(0.4, 0.4, 0.4)))
.add_systems(Startup, set_window_icon);
.add_systems(Startup, set_window_icon.pipe(error));
}

fn create_wgpu_settings() -> WgpuSettings {
Expand All @@ -36,15 +35,14 @@ fn create_wgpu_settings() -> WgpuSettings {
}

// Sets the icon on Windows and X11
#[sysfail(Log<anyhow::Error, Error>)]
fn set_window_icon(
windows: NonSend<WinitWindows>,
primary_windows: Query<Entity, With<PrimaryWindow>>,
) {
) -> anyhow::Result<()> {
let primary_entity = primary_windows.single();
let primary = windows
.get_window(primary_entity)
.context("Failed to get primary window")?;
let Some(primary) = windows.get_window(primary_entity) else {
return Ok(());
};
let icon_buf = Cursor::new(include_bytes!(
"../build/macos/AppIcon.iconset/icon_256x256.png"
));
Expand All @@ -55,4 +53,5 @@ fn set_window_icon(
let icon = Icon::from_rgba(rgba, width, height)?;
primary.set_window_icon(Some(icon));
};
Ok(())
}
10 changes: 5 additions & 5 deletions src/dev/dev_editor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{player_control::camera::ForceCursorGrabMode, GameState};
use crate::player_control::camera::ForceCursorGrabMode;
use crate::util::error;
use anyhow::Context;
use bevy::{prelude::*, window::CursorGrabMode};
use bevy_editor_pls::{
Expand All @@ -7,7 +8,6 @@ use bevy_editor_pls::{
AddEditorWindow,
};
use bevy_egui::egui;
use bevy_mod_sysfail::prelude::*;
use bevy_xpbd_3d::prelude::PhysicsGizmos;
use serde::{Deserialize, Serialize};

Expand All @@ -16,7 +16,7 @@ pub(super) fn plugin(app: &mut App) {
.add_editor_window::<DevEditorWindow>()
.add_systems(
Update,
(handle_debug_render, set_cursor_grab_mode).run_if(in_state(GameState::Playing)),
(handle_debug_render.pipe(error), set_cursor_grab_mode),
);
}

Expand Down Expand Up @@ -51,12 +51,11 @@ pub(crate) struct DevEditorState {
pub(crate) navmesh_render_enabled: bool,
}

#[sysfail(Log<anyhow::Error, Error>)]
fn handle_debug_render(
state: Res<Editor>,
mut last_enabled: Local<bool>,
mut config_store: ResMut<GizmoConfigStore>,
) {
) -> anyhow::Result<()> {
let current_enabled = state
.window_state::<DevEditorWindow>()
.context("Failed to read dev window state")?
Expand All @@ -67,6 +66,7 @@ fn handle_debug_render(
*last_enabled = current_enabled;
let config = config_store.config_mut::<PhysicsGizmos>().0;
config.enabled = current_enabled;
Ok(())
}

fn set_cursor_grab_mode(
Expand Down
2 changes: 0 additions & 2 deletions src/file_system_interaction/asset_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use bevy_asset_loader::prelude::*;
use bevy_common_assets::toml::TomlAssetPlugin;
use bevy_egui::{egui, egui::ProgressBar, EguiContexts};
use bevy_kira_audio::AudioSource;
use bevy_mod_sysfail::prelude::*;
use iyes_progress::{ProgressCounter, ProgressPlugin};

/// Loads resources and assets for the game.
Expand Down Expand Up @@ -95,7 +94,6 @@ fn show_progress(
}
}

#[sysfail(Log<anyhow::Error, Error>)]
fn update_config(
mut commands: Commands,
config: Res<Assets<GameConfig>>,
Expand Down
14 changes: 8 additions & 6 deletions src/level_instantiation/on_spawn/collider.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{movement::physics::CollisionLayer, GameState};
use crate::util::error;
use crate::{movement::physics::CollisionLayer, GameSystemSet};
use anyhow::Context;
use bevy::prelude::*;
use bevy_mod_sysfail::prelude::*;
use bevy_xpbd_3d::prelude::{Collider as XpbdCollider, *};
use oxidized_navigation::NavMeshAffector;
use serde::{Deserialize, Serialize};
Expand All @@ -12,18 +12,19 @@ use std::iter;
struct Collider;

pub(super) fn plugin(app: &mut App) {
app.register_type::<Collider>()
.add_systems(Update, spawn.run_if(in_state(GameState::Playing)));
app.register_type::<Collider>().add_systems(
Update,
spawn.pipe(error).in_set(GameSystemSet::ColliderSpawn),
);
}

#[sysfail(Log<anyhow::Error, Error>)]
fn spawn(
collider_marker: Query<Entity, With<Collider>>,
mut commands: Commands,
children: Query<&Children>,
meshes: Res<Assets<Mesh>>,
mesh_handles: Query<&Handle<Mesh>>,
) {
) -> anyhow::Result<()> {
#[cfg(feature = "tracing")]
let _span = info_span!("read_colliders").entered();
for parent in collider_marker.iter() {
Expand All @@ -49,4 +50,5 @@ fn spawn(
.remove::<Collider>()
.insert(RigidBody::Static);
}
Ok(())
}
Loading