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.12 (#998)
Browse files Browse the repository at this point in the history
* Bump dependencies

* Trait bounds for manifests

* FixedTime changes

* Pool changes

* Deprecated EventReader::iter

* Find-and-replace error

* Deprecated methods

* try_insert was upstreamed

* try_remove unused

* Unbreak try_add_child

* Deprecation notices

* Fixed Time in integration tests

* Smol fixes

* Option<LoadState> changes

* add_asset migration

* Unused import

* Asset changes

* Missing import

* Update deny.toml

* bevy_mod_picking changes

* Unused imports

* Repair tests and benches

* Missing docs

* Ignore failing tests
  • Loading branch information
alice-i-cecile authored Nov 22, 2023
1 parent 7b2cf4e commit 2201597
Show file tree
Hide file tree
Showing 42 changed files with 1,726 additions and 592 deletions.
1,894 changes: 1,538 additions & 356 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ allow-registry = ["https://github.com/rust-lang/crates.io-index"]
# If you add something here please also add a comment explaining why it's necessary :)
# The key of this field is the repo's root URL
allow-git = [
# bevy_mod_picking: waiting on PR merge plus release for Bevy 0.10
"https://github.com/soerenmeier/bevy_mod_raycast"
# bevy_mod_billobard: waiting on PR merge
"https://github.com/robtfm/bevy_mod_billboard",
]
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.11"
bevy_framepace = "0.13.0"
bevy = "0.12"
bevy_framepace = "0.14.1"
emergence_lib = { path = "../emergence_lib", version = "0.1.0" }
21 changes: 12 additions & 9 deletions emergence_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,32 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.11"
bevy_mod_billboard = "0.4"
rand = { version = "0.8", features = ["small_rng"] }
rand_distr = "0.4"
noisy_bevy = "0.4"
leafwing-input-manager = "0.10"
emergence_macros = { path = "../emergence_macros", version = "0.6" }
indexmap = "1.9"
petitset = "0.2"
serde = "1.0"
leafwing_abilities = "0.5.0"
derive_more = "0.99.17"
hexx = { version = "0.10", features = ["ser_de"] }
bevy_mod_raycast = "0.14"
itertools = "0.10.5"
bevy_screen_diagnostics = "0.3"
anyhow = "1.0.69"
serde_json = "1.0.94"
# 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.13.0"

# Bevy deps
bevy = "0.12"
bevy_mod_billboard = { git = "https://github.com/robtfm/bevy_mod_billboard", branch = "bevy12" }
noisy_bevy = "0.5"
leafwing-input-manager = "0.11"
leafwing_abilities = "0.6.0"
hexx = { version = "0.11", features = ["ser_de"] }
bevy_mod_raycast = "0.16"
bevy_screen_diagnostics = "0.4"
bevy_framepace = "0.14.1"
thiserror = "1.0.50"

[dev-dependencies]
criterion = "0.4"
Expand Down
4 changes: 1 addition & 3 deletions emergence_lib/benches/water.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time::Duration;

use bevy::prelude::*;
use criterion::{criterion_group, criterion_main, Criterion};
use emergence_lib::{
Expand Down Expand Up @@ -41,7 +39,7 @@ fn criterion_benchmark(c: &mut Criterion) {
app.insert_resource(Ocean::default());
app.insert_resource(WaterConfig::IN_GAME);
app.insert_resource(InGameTime::default());
app.insert_resource(FixedTime::new(Duration::from_secs_f32(1. / 30.)));
app.insert_resource(Time::<Fixed>::from_hz(30.));

app.add_systems(FixedUpdate, update_water_depth);
// Run once to make sure system caches are populated
Expand Down
36 changes: 28 additions & 8 deletions emergence_lib/src/asset_management/manifest/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use std::{
path::{Path, PathBuf},
};

use thiserror::Error;

use bevy::{
asset::{AssetLoader, LoadContext, LoadedAsset},
asset::{Asset, AssetLoader, AsyncReadExt, LoadContext},
reflect::TypePath,
utils::BoxedFuture,
};
Expand All @@ -20,7 +22,7 @@ use super::Manifest;
///
/// The processing will primarily remove the string IDs and replace them by numbers.
pub trait IsRawManifest:
std::fmt::Debug + TypePath + TypeUuid + Send + Sync + for<'de> Deserialize<'de> + 'static
Asset + std::fmt::Debug + TypePath + TypeUuid + Send + Sync + for<'de> Deserialize<'de> + 'static
{
/// The file extension of this manifest type.
///
Expand Down Expand Up @@ -54,23 +56,41 @@ where
_phantom_manifest: PhantomData<M>,
}

/// An erorr produced when loading a raw manifest.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum RawManifestError {
/// An [IO](std::io) Error
#[error("Could not load asset: {0}")]
Io(#[from] std::io::Error),
/// A [RON](ron) Error
#[error("Could not parse JSON: {0}")]
JsonError(#[from] serde_json::Error),
}

impl<M> AssetLoader for RawManifestLoader<M>
where
M: IsRawManifest,
{
type Asset = M;
type Settings = ();
type Error = RawManifestError;

fn extensions(&self) -> &[&str] {
&[<M as IsRawManifest>::EXTENSION]
}

fn load<'a>(
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, anyhow::Result<(), anyhow::Error>> {
reader: &'a mut bevy::asset::io::Reader,
_settings: &'a Self::Settings,
_load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
Box::pin(async move {
let raw_manifest = serde_json::from_slice::<M>(bytes)?;
load_context.set_default_asset(LoadedAsset::<M>::new(raw_manifest));
Ok(())
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let custom_asset = serde_json::from_slice::<M>(&bytes)?;
Ok(custom_asset)
})
}
}
Expand Down
20 changes: 10 additions & 10 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::*, reflect::TypePath};
use bevy::prelude::*;

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

Expand Down Expand Up @@ -44,7 +44,7 @@ where
info!("Building RawManifestPlugin for {}", M::path().display());

app.init_asset_loader::<RawManifestLoader<M>>()
.add_asset::<M>()
.init_asset::<M>()
.add_asset_collection::<RawManifestHandle<M>>()
.add_systems(
OnExit(AssetState::LoadManifests),
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: TypePath>
pub struct RawManifestHandle<M: Asset>
where
M: IsRawManifest,
{
Expand All @@ -72,7 +72,7 @@ where
handle: Handle<M>,
}

impl<M: TypePath> Loadable for RawManifestHandle<M>
impl<M: Asset> Loadable for RawManifestHandle<M>
where
M: IsRawManifest,
{
Expand All @@ -85,7 +85,7 @@ where
world.insert_resource(Self { handle });
}

fn load_state(&self, asset_server: &AssetServer) -> bevy::asset::LoadState {
fn load_state(&self, asset_server: &AssetServer) -> Option<bevy::asset::LoadState> {
let load_state = asset_server.get_load_state(self.handle.clone_weak());

debug!("Load state: {load_state:?}");
Expand All @@ -95,7 +95,7 @@ where
}

/// Wait for the manifest to be fully loaded and then process it.
pub fn detect_manifest_creation<M: TypePath>(
pub fn detect_manifest_creation<M: Asset>(
mut commands: Commands,
raw_manifest_handle: Res<RawManifestHandle<M>>,
raw_manifests: Res<Assets<M>>,
Expand All @@ -117,16 +117,16 @@ pub fn detect_manifest_creation<M: TypePath>(
}

/// Update the manifest after the asset has been changed.
fn detect_manifest_modification<M: TypePath>(
fn detect_manifest_modification<M: Asset>(
mut ev_asset: EventReader<AssetEvent<M>>,
raw_manifests: Res<Assets<M>>,
mut manifest: ResMut<Manifest<M::Marker, M::Data>>,
) where
M: IsRawManifest,
{
for ev in ev_asset.iter() {
if let AssetEvent::Modified { handle } = ev {
let Some(raw_manifest) = raw_manifests.get(handle) else {
for ev in ev_asset.read() {
if let AssetEvent::Modified { id } = ev {
let Some(raw_manifest) = raw_manifests.get(*id) else {
warn!("Raw manifest modified, but asset not available!");
continue;
};
Expand Down
4 changes: 2 additions & 2 deletions emergence_lib/src/asset_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub trait Loadable: Resource + Sized {
}

/// How far along are we in loading these assets?
fn load_state(&self, asset_server: &AssetServer) -> LoadState;
fn load_state(&self, asset_server: &AssetServer) -> Option<LoadState>;

/// A system that checks if the asset collection of type `T` loaded.
fn check_loaded(
Expand All @@ -154,7 +154,7 @@ pub trait Loadable: Resource + Sized {
mut assets_to_load: ResMut<AssetsToLoad>,
) {
let load_state = asset_collection.load_state(&asset_server);
if load_state == LoadState::Loaded && assets_to_load.contains::<Self>() {
if load_state == Some(LoadState::Loaded) && assets_to_load.contains::<Self>() {
assets_to_load.remove::<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 @@ -18,7 +18,7 @@ use crate::terrain::terrain_manifest::TerrainManifest;
use crate::{self as emergence_lib, graphics::InheritedMaterial};
use bevy::prelude::*;
use bevy::utils::{Duration, HashMap};
use bevy_mod_raycast::RaycastMesh;
use bevy_mod_raycast::deferred::RaycastMesh;
use emergence_macros::IterableEnum;

use crate::{
Expand Down Expand Up @@ -472,7 +472,7 @@ pub(super) fn ghost_structure_lifecycle(
With<Ghost>,
>,
structure_manifest: Res<StructureManifest>,
time: Res<FixedTime>,
time: Res<Time>,
mut commands: Commands,
) {
for (
Expand Down Expand Up @@ -501,7 +501,7 @@ pub(super) fn ghost_structure_lifecycle(
let mut updated_progress = progress;

// Scale construction speed linearly with the number of workers present (and vigor)
updated_progress += workers_present.effective_workers() as u32 * time.period;
updated_progress += workers_present.effective_workers() as u32 * time.delta();

*crafting_state = if updated_progress >= required {
CraftingState::RecipeComplete
Expand Down
6 changes: 3 additions & 3 deletions emergence_lib/src/crafting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ struct CraftingQuery {

/// Progress the state of recipes that are being crafted.
fn progress_crafting(
time: Res<FixedTime>,
time: Res<Time>,
recipe_manifest: Res<RecipeManifest>,
item_manifest: Res<ItemManifest>,
terrain_query: Query<&ReceivedLight>,
Expand Down Expand Up @@ -192,12 +192,12 @@ fn progress_crafting(
// Many hands make light work!
if recipe.workers_required() > 0 {
updated_progress += Duration::from_secs_f32(
time.period.as_secs_f32()
time.delta().as_secs_f32()
* crafter.workers_present.effective_workers()
/ recipe.workers_required() as f32,
);
} else {
updated_progress += time.period;
updated_progress += time.delta();
}

if updated_progress >= required {
Expand Down
2 changes: 1 addition & 1 deletion emergence_lib/src/crafting/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl<T: Display + PartialOrd> Display for Threshold<T> {
}

/// The [`RecipeManifest`] as seen in the manifest file.
#[derive(Debug, Clone, Serialize, Deserialize, TypeUuid, TypePath, PartialEq)]
#[derive(Asset, Debug, Clone, Serialize, Deserialize, TypeUuid, TypePath, PartialEq)]
#[uuid = "c711b30c-c3ff-4b86-92d0-f1aff2ec7818"]
pub struct RawRecipeManifest {
/// The data for each item.
Expand Down
2 changes: 1 addition & 1 deletion emergence_lib/src/graphics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Plugin for GraphicsPlugin {
.add_systems(Update, render_litter_piles.in_set(GraphicsSet))
// Run these after Update to avoid panics due to despawned entities
.add_systems(PostUpdate, (inherit_materials, remove_ghostly_shadows))
.configure_set(
.configure_sets(
Update,
GraphicsSet
.run_if(in_state(AssetState::FullyLoaded))
Expand Down
4 changes: 2 additions & 2 deletions emergence_lib/src/graphics/overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ fn set_overlay_material(
signals: Res<Signals>,
map_geometry: Res<MapGeometry>,
tile_overlay: Res<TileOverlay>,
fixed_time: Res<FixedTime>,
time: Res<Time>,
) {
if tile_overlay.overlay_type == OverlayType::None {
return;
Expand Down Expand Up @@ -547,7 +547,7 @@ fn set_overlay_material(
water_volume_query.get(terrain_entity).unwrap();

let net_water = *current_water_volume - previous_water_volume.0;
let volume_per_second = net_water.volume() / fixed_time.period.as_secs_f32();
let volume_per_second = net_water.volume() / time.delta().as_secs_f32();

Some(tile_overlay.get_water_flux_material(volume_per_second))
}
Expand Down
2 changes: 1 addition & 1 deletion emergence_lib/src/items/inventory.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Storage of multiple items with a capacity.
use bevy::prelude::warn;
use bevy::log::warn;
use itertools::rev;
use serde::{Deserialize, Serialize};

Expand Down
3 changes: 2 additions & 1 deletion emergence_lib/src/items/item_manifest.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Defines write-only data for each variety of item.
use bevy::{
asset::Asset,
reflect::{Reflect, TypePath, TypeUuid},
utils::HashMap,
};
Expand Down Expand Up @@ -131,7 +132,7 @@ impl From<RawItemData> for ItemData {
}

/// The [`ItemManifest`] as seen in the manifest file.
#[derive(Debug, Clone, Serialize, Deserialize, TypeUuid, TypePath, PartialEq)]
#[derive(Asset, Debug, Clone, Serialize, Deserialize, TypeUuid, TypePath, PartialEq)]
#[uuid = "cd9f4571-b0c4-4641-8d27-1c9c5ad4c812"]
pub struct RawItemManifest {
/// The data for each item.
Expand Down
4 changes: 2 additions & 2 deletions emergence_lib/src/litter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub(super) fn carry_floating_litter_with_current(
)>,
water_height_query: Query<(&VoxelPos, &WaterDepth), Without<Drift>>,
net_query: Query<&Footprint, With<AbsorbsItems>>,
fixed_time: Res<FixedTime>,
time: Res<Time>,
mut map_geometry: ResMut<MapGeometry>,
) {
/// Controls how fast litter drifts with the current
Expand All @@ -214,7 +214,7 @@ pub(super) fn carry_floating_litter_with_current(
/// If this is larger than the maximum number of seconds that can be stored in a Duration, the app will panic.
const MAX_DRIFT_TIME: f32 = 10.0;

let delta_time = fixed_time.period;
let delta_time = time.delta();
let rng = &mut thread_rng();
let normal_distribution = Normal::new(0.0, DRIFT_DEVIATION).unwrap();

Expand Down
Loading

0 comments on commit 2201597

Please sign in to comment.