Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
Update to Bevy 0.11 (#992)
Browse files Browse the repository at this point in the history
* Bump crate versions

* Update Cargo.lock

* add_systems migration

* State field is private

* Remove uses of CoreSchedule

* ReflectFromReflect fix

* More add_systems fixes

* Migrate startup systems

* apply_system_buffers -> apply_deferred

* Reflect for Actionlike types

* Bump debug tools crate

* Debug tools import cleanup

* More scheduling cleanup

* Style field cleanup

* Remove neglected debug_tools crate

* Manifests need TypePath

* Typo

* Commands::write -> apply

* Typos

* More Style breaking changes

* Update bevy_mod_billboard crate

* More manifest + TypePath fixes

* Bump hexx

* hexx migration

* Assorted small fixes

* Fix deprecations

* Autoderef please

* Typo

* Synchronize hashbrown version

* Fix timing of spawning overlay entities to avoid a panic

* Fix overlays

* Clippy

* Cargo fmt

* Cargo doc fixes
  • Loading branch information
alice-i-cecile authored Oct 12, 2023
1 parent 29903e4 commit 7e5aaa6
Show file tree
Hide file tree
Showing 65 changed files with 1,166 additions and 1,587 deletions.
1,556 changes: 691 additions & 865 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
[workspace]
resolver = "2"

members = [
"emergence_game",
"emergence_lib",
"emergence_macros",
"tools/ci",
"tools/debug_tools",
]
members = ["emergence_game", "emergence_lib", "emergence_macros", "tools/ci"]
default-members = ["emergence_game", "emergence_lib"]

# Enable max optimizations for dependencies, but not for our code:
Expand Down
4 changes: 2 additions & 2 deletions emergence_game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.10"
bevy_framepace = "0.12.0"
bevy = "0.11"
bevy_framepace = "0.13.0"
emergence_lib = { path = "../emergence_lib", version = "0.1.0" }
12 changes: 6 additions & 6 deletions emergence_game/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ fn main() {
..Default::default()
}))
// This is turned on and off in the world gen state management code.
.add_plugin(FramepacePlugin)
.add_plugin(emergence_lib::asset_management::AssetManagementPlugin)
.add_plugin(emergence_lib::simulation::SimulationPlugin {
.add_plugins(FramepacePlugin)
.add_plugins(emergence_lib::asset_management::AssetManagementPlugin)
.add_plugins(emergence_lib::simulation::SimulationPlugin {
gen_config: GenerationConfig::standard(),
})
.add_plugin(emergence_lib::player_interaction::InteractionPlugin)
.add_plugin(emergence_lib::graphics::GraphicsPlugin)
.add_plugin(emergence_lib::ui::UiPlugin)
.add_plugins(emergence_lib::player_interaction::InteractionPlugin)
.add_plugins(emergence_lib::graphics::GraphicsPlugin)
.add_plugins(emergence_lib::ui::UiPlugin)
.run();
}
31 changes: 14 additions & 17 deletions emergence_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,30 @@ edition = "2021"

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

[features]
# If this feature is enabled, egui will have priority over actions when processing inputs
debug_tools = ['dep:debug_tools']

[dependencies]
bevy = "0.10"
bevy_mod_billboard = "0.3"
rand = { version="0.8", features=["small_rng"] }
bevy = "0.11"
bevy_mod_billboard = "0.4"
rand = { version = "0.8", features = ["small_rng"] }
rand_distr = "0.4"
noisy_bevy = "0.3"
leafwing-input-manager = "0.9"
noisy_bevy = "0.4"
leafwing-input-manager = "0.10"
emergence_macros = { path = "../emergence_macros", version = "0.6" }
indexmap = "1.9"
debug_tools = { path = "../tools/debug_tools", optional = true }
petitset = "0.2"
serde = "1.0.152"
leafwing_abilities = "0.4.0"
serde = "1.0"
leafwing_abilities = "0.5.0"
derive_more = "0.99.17"
hexx = { version = "0.7", features = ["ser_de"] }
bevy_mod_raycast = "0.8"
hexx = { version = "0.10", features = ["ser_de"] }
bevy_mod_raycast = "0.14"
itertools = "0.10.5"
bevy_screen_diagnostics = "0.2"
bevy_screen_diagnostics = "0.3"
anyhow = "1.0.69"
serde_json = "1.0.94"
hashbrown = { version = "0.12", features = ["rayon"] }
# This must match the version specified in the bevy_utils crate
# See: https://crates.io/crates/bevy_utils/dependencies
hashbrown = { version = "0.14", features = ["rayon"] }
rayon = "1.7.0"
bevy_framepace = "0.12.0"
bevy_framepace = "0.13.0"

[dev-dependencies]
criterion = "0.4"
Expand Down
6 changes: 2 additions & 4 deletions emergence_lib/benches/water.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ fn criterion_benchmark(c: &mut Criterion) {
app.insert_resource(InGameTime::default());
app.insert_resource(FixedTime::new(Duration::from_secs_f32(1. / 30.)));

app.add_system(update_water_depth);
app.add_systems(FixedUpdate, update_water_depth);
// Run once to make sure system caches are populated
app.update();

c.bench_function("compute_water_depth", |b| b.iter(|| app.update()));

let mut schedule = Schedule::default();
schedule.add_system(horizontal_water_movement);
app.world.add_schedule(schedule, CoreSchedule::Outer);
app.add_systems(FixedUpdate, horizontal_water_movement);

c.bench_function("lateral_water_movement", |b| b.iter(|| app.update()));
}
Expand Down
7 changes: 2 additions & 5 deletions emergence_lib/src/asset_management/manifest/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<T> Eq for Id<T> {}

impl<T> PartialOrd for Id<T> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.value.partial_cmp(&other.value)
Some(self.cmp(other))
}
}

Expand All @@ -96,10 +96,7 @@ impl<T> Hash for Id<T> {

impl<T> Clone for Id<T> {
fn clone(&self) -> Self {
Self {
value: self.value,
_phantom: PhantomData,
}
*self
}
}

Expand Down
5 changes: 3 additions & 2 deletions emergence_lib/src/asset_management/manifest/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::{

use bevy::{
asset::{AssetLoader, LoadContext, LoadedAsset},
reflect::TypePath,
utils::BoxedFuture,
};

Expand All @@ -19,7 +20,7 @@ use super::Manifest;
///
/// The processing will primarily remove the string IDs and replace them by numbers.
pub trait IsRawManifest:
std::fmt::Debug + TypeUuid + Send + Sync + for<'de> Deserialize<'de> + 'static
std::fmt::Debug + TypePath + TypeUuid + Send + Sync + for<'de> Deserialize<'de> + 'static
{
/// The file extension of this manifest type.
///
Expand Down Expand Up @@ -80,7 +81,7 @@ where
{
fn default() -> Self {
Self {
_phantom_manifest: PhantomData::default(),
_phantom_manifest: PhantomData,
}
}
}
27 changes: 15 additions & 12 deletions emergence_lib/src/asset_management/manifest/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::marker::PhantomData;

use bevy::prelude::*;
use bevy::{prelude::*, reflect::TypePath};

use crate::asset_management::{AssetCollectionExt, AssetState, Loadable};

Expand All @@ -27,7 +27,7 @@ where
/// Create a new raw manifest plugin.
pub(crate) fn new() -> Self {
Self {
_phantom_data: PhantomData::default(),
_phantom_data: PhantomData,
}
}
}
Expand All @@ -46,12 +46,12 @@ where
app.init_asset_loader::<RawManifestLoader<M>>()
.add_asset::<M>()
.add_asset_collection::<RawManifestHandle<M>>()
.add_system(
detect_manifest_creation::<M>
.in_set(DetectManifestCreationSet)
.in_schedule(OnExit(AssetState::LoadManifests)),
.add_systems(
OnExit(AssetState::LoadManifests),
detect_manifest_creation::<M>.in_set(DetectManifestCreationSet),
)
.add_system(
.add_systems(
Update,
detect_manifest_modification::<M>
.run_if(resource_exists::<Manifest<M::Marker, M::Data>>()),
);
Expand All @@ -62,7 +62,7 @@ where
///
/// This is necessary to stop the asset from being discarded.
#[derive(Debug, Clone, Resource)]
pub struct RawManifestHandle<M>
pub struct RawManifestHandle<M: TypePath>
where
M: IsRawManifest,
{
Expand All @@ -72,7 +72,7 @@ where
handle: Handle<M>,
}

impl<M> Loadable for RawManifestHandle<M>
impl<M: TypePath> Loadable for RawManifestHandle<M>
where
M: IsRawManifest,
{
Expand All @@ -95,15 +95,18 @@ where
}

/// Wait for the manifest to be fully loaded and then process it.
pub fn detect_manifest_creation<M>(
pub fn detect_manifest_creation<M: TypePath>(
mut commands: Commands,
raw_manifest_handle: Res<RawManifestHandle<M>>,
raw_manifests: Res<Assets<M>>,
) where
M: IsRawManifest,
{
let Some(raw_manifest) = raw_manifests.get(&raw_manifest_handle.handle) else {
error!("Raw manifest for {} created, but asset not available!", M::path().display());
error!(
"Raw manifest for {} created, but asset not available!",
M::path().display()
);
return;
};

Expand All @@ -114,7 +117,7 @@ pub fn detect_manifest_creation<M>(
}

/// Update the manifest after the asset has been changed.
fn detect_manifest_modification<M>(
fn detect_manifest_modification<M: TypePath>(
mut ev_asset: EventReader<AssetEvent<M>>,
raw_manifests: Res<Assets<M>>,
mut manifest: ResMut<Manifest<M::Marker, M::Data>>,
Expand Down
26 changes: 16 additions & 10 deletions emergence_lib/src/asset_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ impl Plugin for AssetManagementPlugin {
fn build(&self, app: &mut App) {
app.add_state::<AssetState>()
.init_resource::<AssetsToLoad>()
.add_system(check_manifests_loaded.run_if(in_state(AssetState::LoadManifests)))
.add_system(check_assets_loaded.run_if(in_state(AssetState::LoadAssets)))
.add_systems(
Update,
check_manifests_loaded.run_if(in_state(AssetState::LoadManifests)),
)
.add_systems(
Update,
check_assets_loaded.run_if(in_state(AssetState::LoadAssets)),
)
// This is needed to ensure that the manifest resources are actually created in time for AssetState::Loading
// BLOCKED: this can be removed in Bevy 0.11, as schedules will automatically flush the commands.
.add_system(
apply_system_buffers
.after(DetectManifestCreationSet)
.in_schedule(OnExit(AssetState::LoadManifests)),
.add_systems(
OnExit(AssetState::LoadManifests),
apply_deferred.after(DetectManifestCreationSet),
);
}
}
Expand Down Expand Up @@ -166,11 +171,12 @@ impl AssetCollectionExt for App {
info!("Adding asset collection: {}", std::any::type_name::<T>());

// Begin the loading process
self.add_system(T::initialize.in_schedule(OnEnter(T::STAGE)));
self.add_system(T::register_assets_to_load.in_schedule(OnEnter(T::STAGE)));

self.add_systems(
OnEnter(T::STAGE),
(T::initialize, T::register_assets_to_load),
);
// Poll each asset collection
self.add_system(T::check_loaded.run_if(in_state(T::STAGE)));
self.add_systems(Update, T::check_loaded.run_if(in_state(T::STAGE)));

self
}
Expand Down
6 changes: 3 additions & 3 deletions emergence_lib/src/construction/ghosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ pub struct GhostPlugin;
impl Plugin for GhostPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<GhostHandles>().add_systems(
FixedUpdate,
(
validate_ghost_structures,
ghost_structure_signals.after(validate_ghost_structures),
ghost_structure_lifecycle.after(validate_ghost_structures),
)
.in_set(SimulationSet)
.in_schedule(CoreSchedule::FixedUpdate),
.in_set(SimulationSet),
);
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ impl FromWorld for GhostHandles {
}

/// A marker component that indicates that a structure or terrain element is planned to be built, rather than actually existing.
#[derive(Reflect, FromReflect, Component, Clone, Copy, Debug)]
#[derive(Reflect, Component, Clone, Copy, Debug)]
pub(crate) struct Ghost;

/// A marker component indicating that this structure should be rendered in a transparent style.
Expand Down
15 changes: 7 additions & 8 deletions emergence_lib/src/construction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ pub(crate) struct ConstructionPlugin;

impl Plugin for ConstructionPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(ghosts::GhostPlugin)
.add_plugin(zoning::ZoningPlugin)
app.add_plugins(ghosts::GhostPlugin)
.add_plugins(zoning::ZoningPlugin)
// Must run after crafting emitters in order to wipe out their signals
.add_system(
.add_systems(
FixedUpdate,
set_emitter_for_structures_to_be_demolished
.after(crate::crafting::set_crafting_emitter)
.in_set(SimulationSet)
.in_schedule(CoreSchedule::FixedUpdate),
.in_set(SimulationSet),
)
.add_systems(
(terraforming_lifecycle, terraforming_signals)
.in_set(SimulationSet)
.in_schedule(CoreSchedule::FixedUpdate),
FixedUpdate,
(terraforming_lifecycle, terraforming_signals).in_set(SimulationSet),
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions emergence_lib/src/construction/terraform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ struct TerraformCommand {
}

impl Command for TerraformCommand {
fn write(self, world: &mut World) {
fn apply(self, world: &mut World) {
let map_geometry = world.resource::<MapGeometry>();
let starting_height = map_geometry.get_height(self.hex).unwrap();
let final_height = self.action.final_height(starting_height);
Expand Down Expand Up @@ -299,7 +299,7 @@ struct CancelTerraformCommand {
}

impl Command for CancelTerraformCommand {
fn write(self, world: &mut World) {
fn apply(self, world: &mut World) {
let map_geometry = world.resource::<MapGeometry>();
let terrain_entity = map_geometry.get_terrain(self.hex).unwrap();
let mut terraforming_action = world.get_mut::<TerraformingAction>(terrain_entity).unwrap();
Expand All @@ -326,7 +326,7 @@ struct ApplyTerraformingCommand {
}

impl Command for ApplyTerraformingCommand {
fn write(self, world: &mut World) {
fn apply(self, world: &mut World) {
// Just using system state makes satisfying the borrow checker a lot easier
let mut system_state = SystemState::<(
ResMut<MapGeometry>,
Expand Down
3 changes: 2 additions & 1 deletion emergence_lib/src/construction/zoning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ pub(super) struct ZoningPlugin;
impl Plugin for ZoningPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Update,
(mark_for_demolition, set_zoning)
.in_set(InteractionSystem::ApplyZoning)
.in_set(PlayerModifiesWorld)
.after(InteractionSystem::SelectTiles)
.after(InteractionSystem::SetClipboard),
)
.add_system(cleanup_previews.after(set_zoning));
.add_systems(Update, cleanup_previews.after(set_zoning));
}
}

Expand Down
Loading

0 comments on commit 7e5aaa6

Please sign in to comment.