Skip to content

Commit

Permalink
Merge branch 'main' into example-game_menu-DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
awwsmm authored Mar 25, 2024
2 parents 2ac488f + 86bd648 commit 4b36402
Show file tree
Hide file tree
Showing 121 changed files with 718 additions and 921 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:
echo "<meta name=\"robots\" content=\"noindex\">" > header.html
- name: Build docs
env:
# needs to be in sync with [package.metadata.docs.rs]
RUSTDOCFLAGS: -Zunstable-options --cfg=docsrs
run: cargo doc --all-features --no-deps -p bevy -Zunstable-options -Zrustdoc-scrape-examples

# This adds the following:
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/bevyengine/bevy"
documentation = "https://docs.rs/bevy"
rust-version = "1.76.0"
rust-version = "1.77.0"

[workspace]
exclude = [
Expand Down Expand Up @@ -2821,5 +2821,6 @@ lto = "fat"
panic = "abort"

[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
all-features = true
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
4 changes: 4 additions & 0 deletions crates/bevy_a11y/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ accesskit = "0.12"

[lints]
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
all-features = true
5 changes: 3 additions & 2 deletions crates/bevy_a11y/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Accessibility for Bevy
#![forbid(unsafe_code)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

//! Accessibility for Bevy
use std::sync::{
atomic::{AtomicBool, Ordering},
Expand Down
4 changes: 4 additions & 0 deletions crates/bevy_animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ uuid = { version = "1.7", features = ["v4"] }

[lints]
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
all-features = true
2 changes: 2 additions & 0 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

//! Animation for the game engine Bevy
mod animatable;
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ web-sys = { version = "0.3", features = ["Window"] }
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
all-features = true
3 changes: 2 additions & 1 deletion crates/bevy_app/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This crate is about everything concerning the highest-level, application layer of a Bevy app.
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

//! This crate is about everything concerning the highest-level, application layer of a Bevy app.
mod app;
mod main_schedule;
mod plugin;
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ bevy_log = { path = "../bevy_log", version = "0.14.0-dev" }
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
all-features = true
4 changes: 4 additions & 0 deletions crates/bevy_asset/macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ quote = "1.0"

[lints]
workspace = true

[package.metadata.docs.rs]
rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"]
all-features = true
1 change: 1 addition & 0 deletions crates/bevy_asset/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// FIXME(3492): remove once docs are ready
#![allow(missing_docs)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]

use bevy_macro_utils::BevyManifest;
use proc_macro::{Span, TokenStream};
Expand Down
142 changes: 4 additions & 138 deletions crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
use crate::io::AssetSourceId;
use bevy_reflect::{
std_traits::ReflectDefault, utility::NonGenericTypeInfoCell, FromReflect, FromType,
GetTypeRegistration, Reflect, ReflectDeserialize, ReflectFromPtr, ReflectFromReflect,
ReflectKind, ReflectMut, ReflectOwned, ReflectRef, ReflectSerialize, TypeInfo, TypePath,
TypeRegistration, Typed, ValueInfo,
};
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_utils::CowArc;
use serde::{de::Visitor, Deserialize, Serialize};
use std::{
fmt::{Debug, Display},
hash::{Hash, Hasher},
hash::Hash,
ops::Deref,
path::{Path, PathBuf},
};
Expand Down Expand Up @@ -52,7 +47,8 @@ use thiserror::Error;
/// This means that the common case of `asset_server.load("my_scene.scn")` when it creates and
/// clones internal owned [`AssetPaths`](AssetPath).
/// This also means that you should use [`AssetPath::parse`] in cases where `&str` is the explicit type.
#[derive(Eq, PartialEq, Hash, Clone, Default)]
#[derive(Eq, PartialEq, Hash, Clone, Default, Reflect)]
#[reflect_value(Debug, PartialEq, Hash, Serialize, Deserialize)]
pub struct AssetPath<'a> {
source: AssetSourceId<'a>,
path: CowArc<'a, Path>,
Expand Down Expand Up @@ -572,136 +568,6 @@ impl<'de> Visitor<'de> for AssetPathVisitor {
}
}

// NOTE: We manually implement "reflect value" because deriving Reflect on `AssetPath` breaks dynamic linking
// See https://github.com/bevyengine/bevy/issues/9747
// NOTE: This could use `impl_reflect_value` if it supported static lifetimes.

impl GetTypeRegistration for AssetPath<'static> {
fn get_type_registration() -> TypeRegistration {
let mut registration = TypeRegistration::of::<Self>();
registration.insert::<ReflectFromPtr>(FromType::<Self>::from_type());
registration.insert::<ReflectFromReflect>(FromType::<Self>::from_type());
registration.insert::<ReflectSerialize>(FromType::<Self>::from_type());
registration.insert::<ReflectDeserialize>(FromType::<Self>::from_type());
registration.insert::<ReflectDefault>(FromType::<Self>::from_type());
registration
}
}

impl TypePath for AssetPath<'static> {
fn type_path() -> &'static str {
"bevy_asset::path::AssetPath<'static>"
}
fn short_type_path() -> &'static str {
"AssetPath<'static>"
}
fn type_ident() -> Option<&'static str> {
Some("AssetPath<'static>")
}
fn crate_name() -> Option<&'static str> {
None
}
fn module_path() -> Option<&'static str> {
None
}
}
impl Typed for AssetPath<'static> {
fn type_info() -> &'static TypeInfo {
static CELL: NonGenericTypeInfoCell = NonGenericTypeInfoCell::new();
CELL.get_or_set(|| {
let info = ValueInfo::new::<Self>();
TypeInfo::Value(info)
})
}
}
impl Reflect for AssetPath<'static> {
#[inline]
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
Some(<Self as Typed>::type_info())
}
#[inline]
fn into_any(self: Box<Self>) -> Box<dyn core::any::Any> {
self
}
#[inline]
fn as_any(&self) -> &dyn core::any::Any {
self
}
#[inline]
fn as_any_mut(&mut self) -> &mut dyn core::any::Any {
self
}
#[inline]
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect> {
self
}
#[inline]
fn as_reflect(&self) -> &dyn Reflect {
self
}
#[inline]
fn as_reflect_mut(&mut self) -> &mut dyn Reflect {
self
}
#[inline]
fn apply(&mut self, value: &dyn Reflect) {
let value = Reflect::as_any(value);
if let Some(value) = value.downcast_ref::<Self>() {
*self = value.clone();
} else {
panic!("Value is not {}.", std::any::type_name::<Self>());
}
}
#[inline]
fn set(
&mut self,
value: Box<dyn bevy_reflect::Reflect>,
) -> Result<(), Box<dyn bevy_reflect::Reflect>> {
*self = <dyn bevy_reflect::Reflect>::take(value)?;
Ok(())
}
fn reflect_kind(&self) -> ReflectKind {
ReflectKind::Value
}
fn reflect_ref(&self) -> ReflectRef {
ReflectRef::Value(self)
}
fn reflect_mut(&mut self) -> ReflectMut {
ReflectMut::Value(self)
}
fn reflect_owned(self: Box<Self>) -> ReflectOwned {
ReflectOwned::Value(self)
}
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone())
}
fn reflect_hash(&self) -> Option<u64> {
let mut hasher = bevy_reflect::utility::reflect_hasher();
Hash::hash(&::core::any::Any::type_id(self), &mut hasher);
Hash::hash(self, &mut hasher);
Some(Hasher::finish(&hasher))
}
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {
let value = <dyn Reflect>::as_any(value);
if let Some(value) = <dyn core::any::Any>::downcast_ref::<Self>(value) {
Some(PartialEq::eq(self, value))
} else {
Some(false)
}
}
fn debug(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
::core::fmt::Debug::fmt(self, f)
}
}
impl FromReflect for AssetPath<'static> {
fn from_reflect(reflect: &dyn Reflect) -> Option<Self> {
Some(Clone::clone(<dyn core::any::Any>::downcast_ref::<
AssetPath<'static>,
>(<dyn Reflect>::as_any(reflect))?))
}
}

/// Normalizes the path by collapsing all occurrences of '.' and '..' dot-segments where possible
/// as per [RFC 1808](https://datatracker.ietf.org/doc/html/rfc1808)
pub(crate) fn normalize_path(path: &Path) -> PathBuf {
Expand Down
78 changes: 39 additions & 39 deletions crates/bevy_asset/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
use bevy_ecs::prelude::*;
use bevy_tasks::IoTaskPool;
use bevy_utils::tracing::{debug, error, trace, warn};
use bevy_utils::{BoxedFuture, HashMap, HashSet};
use bevy_utils::{HashMap, HashSet};
use futures_io::ErrorKind;
use futures_lite::{AsyncReadExt, AsyncWriteExt, StreamExt};
use parking_lot::RwLock;
Expand Down Expand Up @@ -435,27 +435,25 @@ impl AssetProcessor {

#[allow(unused)]
#[cfg(all(not(target_arch = "wasm32"), feature = "multi-threaded"))]
fn process_assets_internal<'scope>(
async fn process_assets_internal<'scope>(
&'scope self,
scope: &'scope bevy_tasks::Scope<'scope, '_, ()>,
source: &'scope AssetSource,
path: PathBuf,
) -> BoxedFuture<'scope, Result<(), AssetReaderError>> {
Box::pin(async move {
if source.reader().is_directory(&path).await? {
let mut path_stream = source.reader().read_directory(&path).await?;
while let Some(path) = path_stream.next().await {
self.process_assets_internal(scope, source, path).await?;
}
} else {
// Files without extensions are skipped
let processor = self.clone();
scope.spawn(async move {
processor.process_asset(source, path).await;
});
) -> Result<(), AssetReaderError> {
if source.reader().is_directory(&path).await? {
let mut path_stream = source.reader().read_directory(&path).await?;
while let Some(path) = path_stream.next().await {
Box::pin(self.process_assets_internal(scope, source, path)).await?;
}
Ok(())
})
} else {
// Files without extensions are skipped
let processor = self.clone();
scope.spawn(async move {
processor.process_asset(source, path).await;
});
}
Ok(())
}

async fn try_reprocessing_queued(&self) {
Expand Down Expand Up @@ -514,34 +512,36 @@ impl AssetProcessor {

/// Retrieves asset paths recursively. If `clean_empty_folders_writer` is Some, it will be used to clean up empty
/// folders when they are discovered.
fn get_asset_paths<'a>(
async fn get_asset_paths<'a>(
reader: &'a dyn ErasedAssetReader,
clean_empty_folders_writer: Option<&'a dyn ErasedAssetWriter>,
path: PathBuf,
paths: &'a mut Vec<PathBuf>,
) -> BoxedFuture<'a, Result<bool, AssetReaderError>> {
Box::pin(async move {
if reader.is_directory(&path).await? {
let mut path_stream = reader.read_directory(&path).await?;
let mut contains_files = false;
while let Some(child_path) = path_stream.next().await {
contains_files =
get_asset_paths(reader, clean_empty_folders_writer, child_path, paths)
.await?
&& contains_files;
}
if !contains_files && path.parent().is_some() {
if let Some(writer) = clean_empty_folders_writer {
// it is ok for this to fail as it is just a cleanup job.
let _ = writer.remove_empty_directory(&path).await;
}
) -> Result<bool, AssetReaderError> {
if reader.is_directory(&path).await? {
let mut path_stream = reader.read_directory(&path).await?;
let mut contains_files = false;

while let Some(child_path) = path_stream.next().await {
contains_files |= Box::pin(get_asset_paths(
reader,
clean_empty_folders_writer,
child_path,
paths,
))
.await?;
}
if !contains_files && path.parent().is_some() {
if let Some(writer) = clean_empty_folders_writer {
// it is ok for this to fail as it is just a cleanup job.
let _ = writer.remove_empty_directory(&path).await;
}
Ok(contains_files)
} else {
paths.push(path);
Ok(true)
}
})
Ok(contains_files)
} else {
paths.push(path);
Ok(true)
}
}

for source in self.sources().iter_processed() {
Expand Down
Loading

0 comments on commit 4b36402

Please sign in to comment.