diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index ee3c6d848c5af..5f163f757d5e9 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -49,6 +49,9 @@ jobs: echo "" > 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: diff --git a/Cargo.toml b/Cargo.toml index 476c27e0977be..d3d23267ba1ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [ @@ -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"] diff --git a/crates/bevy_a11y/Cargo.toml b/crates/bevy_a11y/Cargo.toml index 1f13d6e8a52d8..4ee262fa22974 100644 --- a/crates/bevy_a11y/Cargo.toml +++ b/crates/bevy_a11y/Cargo.toml @@ -18,3 +18,7 @@ accesskit = "0.12" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_a11y/src/lib.rs b/crates/bevy_a11y/src/lib.rs index 53a515c7eeb6d..77f905b2b5450 100644 --- a/crates/bevy_a11y/src/lib.rs +++ b/crates/bevy_a11y/src/lib.rs @@ -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}, diff --git a/crates/bevy_animation/Cargo.toml b/crates/bevy_animation/Cargo.toml index 13787f46a12cd..52c2786b849c7 100644 --- a/crates/bevy_animation/Cargo.toml +++ b/crates/bevy_animation/Cargo.toml @@ -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 diff --git a/crates/bevy_animation/src/lib.rs b/crates/bevy_animation/src/lib.rs index d3dbed8406193..398463fd05a4e 100644 --- a/crates/bevy_animation/src/lib.rs +++ b/crates/bevy_animation/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Animation for the game engine Bevy mod animatable; diff --git a/crates/bevy_app/Cargo.toml b/crates/bevy_app/Cargo.toml index 28b272571edd3..984518d1ccdc6 100644 --- a/crates/bevy_app/Cargo.toml +++ b/crates/bevy_app/Cargo.toml @@ -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 diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index d87bcbde130a6..8cd087c8dedbb 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -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; diff --git a/crates/bevy_asset/Cargo.toml b/crates/bevy_asset/Cargo.toml index 62f499857d925..04398df8ec254 100644 --- a/crates/bevy_asset/Cargo.toml +++ b/crates/bevy_asset/Cargo.toml @@ -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 diff --git a/crates/bevy_asset/macros/Cargo.toml b/crates/bevy_asset/macros/Cargo.toml index 21d6b1fdcda1a..f178067cc19f3 100644 --- a/crates/bevy_asset/macros/Cargo.toml +++ b/crates/bevy_asset/macros/Cargo.toml @@ -20,3 +20,7 @@ quote = "1.0" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_asset/macros/src/lib.rs b/crates/bevy_asset/macros/src/lib.rs index 8dc8975f2352b..6c290367e64f2 100644 --- a/crates/bevy_asset/macros/src/lib.rs +++ b/crates/bevy_asset/macros/src/lib.rs @@ -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}; diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index e49db629362f0..e61e27e5dced1 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -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}, }; @@ -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>, @@ -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::(); - registration.insert::(FromType::::from_type()); - registration.insert::(FromType::::from_type()); - registration.insert::(FromType::::from_type()); - registration.insert::(FromType::::from_type()); - registration.insert::(FromType::::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::(); - TypeInfo::Value(info) - }) - } -} -impl Reflect for AssetPath<'static> { - #[inline] - fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { - Some(::type_info()) - } - #[inline] - fn into_any(self: Box) -> Box { - 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) -> Box { - 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 = value.clone(); - } else { - panic!("Value is not {}.", std::any::type_name::()); - } - } - #[inline] - fn set( - &mut self, - value: Box, - ) -> Result<(), Box> { - *self = ::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) -> ReflectOwned { - ReflectOwned::Value(self) - } - #[inline] - fn clone_value(&self) -> Box { - Box::new(self.clone()) - } - fn reflect_hash(&self) -> Option { - 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 { - let value = ::as_any(value); - if let Some(value) = ::downcast_ref::(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 { - Some(Clone::clone(::downcast_ref::< - AssetPath<'static>, - >(::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 { diff --git a/crates/bevy_asset/src/processor/mod.rs b/crates/bevy_asset/src/processor/mod.rs index b0724e4e17358..f3d373da063f9 100644 --- a/crates/bevy_asset/src/processor/mod.rs +++ b/crates/bevy_asset/src/processor/mod.rs @@ -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; @@ -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) { @@ -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, - ) -> BoxedFuture<'a, Result> { - 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 { + 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() { diff --git a/crates/bevy_asset/src/server/mod.rs b/crates/bevy_asset/src/server/mod.rs index 60536cc40509e..26b057bddf243 100644 --- a/crates/bevy_asset/src/server/mod.rs +++ b/crates/bevy_asset/src/server/mod.rs @@ -658,38 +658,42 @@ impl AssetServer { } pub(crate) fn load_folder_internal(&self, id: UntypedAssetId, path: AssetPath) { - fn load_folder<'a>( + async fn load_folder<'a>( source: AssetSourceId<'static>, path: &'a Path, reader: &'a dyn ErasedAssetReader, server: &'a AssetServer, handles: &'a mut Vec, - ) -> bevy_utils::BoxedFuture<'a, Result<(), AssetLoadError>> { - Box::pin(async move { - let is_dir = reader.is_directory(path).await?; - if is_dir { - let mut path_stream = reader.read_directory(path.as_ref()).await?; - while let Some(child_path) = path_stream.next().await { - if reader.is_directory(&child_path).await? { - load_folder(source.clone(), &child_path, reader, server, handles) - .await?; - } else { - let path = child_path.to_str().expect("Path should be a valid string."); - let asset_path = AssetPath::parse(path).with_source(source.clone()); - match server.load_untyped_async(asset_path).await { - Ok(handle) => handles.push(handle), - // skip assets that cannot be loaded - Err( - AssetLoadError::MissingAssetLoaderForTypeName(_) - | AssetLoadError::MissingAssetLoaderForExtension(_), - ) => {} - Err(err) => return Err(err), - } + ) -> Result<(), AssetLoadError> { + let is_dir = reader.is_directory(path).await?; + if is_dir { + let mut path_stream = reader.read_directory(path.as_ref()).await?; + while let Some(child_path) = path_stream.next().await { + if reader.is_directory(&child_path).await? { + Box::pin(load_folder( + source.clone(), + &child_path, + reader, + server, + handles, + )) + .await?; + } else { + let path = child_path.to_str().expect("Path should be a valid string."); + let asset_path = AssetPath::parse(path).with_source(source.clone()); + match server.load_untyped_async(asset_path).await { + Ok(handle) => handles.push(handle), + // skip assets that cannot be loaded + Err( + AssetLoadError::MissingAssetLoaderForTypeName(_) + | AssetLoadError::MissingAssetLoaderForExtension(_), + ) => {} + Err(err) => return Err(err), } } } - Ok(()) - }) + } + Ok(()) } let path = path.into_owned(); diff --git a/crates/bevy_audio/Cargo.toml b/crates/bevy_audio/Cargo.toml index 3f831ce3e4a2e..fc0bb3aaec3f5 100644 --- a/crates/bevy_audio/Cargo.toml +++ b/crates/bevy_audio/Cargo.toml @@ -52,4 +52,5 @@ android_shared_stdcxx = ["cpal/oboe-shared-stdcxx"] workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_audio/src/lib.rs b/crates/bevy_audio/src/lib.rs index 3f42acf3b6e22..aa58420e8ae9b 100644 --- a/crates/bevy_audio/src/lib.rs +++ b/crates/bevy_audio/src/lib.rs @@ -1,3 +1,6 @@ +#![forbid(unsafe_code)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Audio support for the game engine Bevy //! //! ```no_run @@ -19,8 +22,6 @@ //! }); //! } //! ``` -#![forbid(unsafe_code)] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] mod audio; mod audio_output; diff --git a/crates/bevy_color/Cargo.toml b/crates/bevy_color/Cargo.toml index 29bd0218ad1f3..733a0ad3cceb7 100644 --- a/crates/bevy_color/Cargo.toml +++ b/crates/bevy_color/Cargo.toml @@ -14,10 +14,17 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [ "bevy", ] } bytemuck = "1" -serde = "1.0" +serde = { version = "1.0", features = ["derive"], optional = true } thiserror = "1.0" wgpu = { version = "0.19.3", default-features = false } encase = { version = "0.7", default-features = false } +[features] +serialize = ["serde"] + [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_color/src/color.rs b/crates/bevy_color/src/color.rs index ad3c24f15f015..25ed54809ec77 100644 --- a/crates/bevy_color/src/color.rs +++ b/crates/bevy_color/src/color.rs @@ -2,7 +2,6 @@ use crate::{ Alpha, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Srgba, StandardColor, Xyza, }; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// An enumerated type that can represent any of the color types in this crate. /// @@ -12,8 +11,13 @@ use serde::{Deserialize, Serialize}; ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub enum Color { /// A color in the sRGB color space with alpha. Srgba(Srgba), diff --git a/crates/bevy_color/src/hsla.rs b/crates/bevy_color/src/hsla.rs index c9db008940a93..ac7cdf93dabb6 100644 --- a/crates/bevy_color/src/hsla.rs +++ b/crates/bevy_color/src/hsla.rs @@ -3,7 +3,6 @@ use crate::{ Xyza, }; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// Color in Hue-Saturation-Lightness (HSL) color space with alpha. /// Further information on this color model can be found on [Wikipedia](https://en.wikipedia.org/wiki/HSL_and_HSV). @@ -11,8 +10,13 @@ use serde::{Deserialize, Serialize}; ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Hsla { /// The hue channel. [0.0, 360.0] pub hue: f32, diff --git a/crates/bevy_color/src/hsva.rs b/crates/bevy_color/src/hsva.rs index 4423d047ac5b9..014b447cba980 100644 --- a/crates/bevy_color/src/hsva.rs +++ b/crates/bevy_color/src/hsva.rs @@ -1,6 +1,5 @@ use crate::{Alpha, ClampColor, Hue, Hwba, Lcha, LinearRgba, Mix, Srgba, StandardColor, Xyza}; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// Color in Hue-Saturation-Value (HSV) color space with alpha. /// Further information on this color model can be found on [Wikipedia](https://en.wikipedia.org/wiki/HSL_and_HSV). @@ -8,8 +7,13 @@ use serde::{Deserialize, Serialize}; ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Hsva { /// The hue channel. [0.0, 360.0] pub hue: f32, diff --git a/crates/bevy_color/src/hwba.rs b/crates/bevy_color/src/hwba.rs index 01221397804f7..41b4bd06be591 100644 --- a/crates/bevy_color/src/hwba.rs +++ b/crates/bevy_color/src/hwba.rs @@ -4,7 +4,6 @@ //! [_HWB - A More Intuitive Hue-Based Color Model_]: https://web.archive.org/web/20240226005220/http://alvyray.com/Papers/CG/HWB_JGTv208.pdf use crate::{Alpha, ClampColor, Hue, Lcha, LinearRgba, Mix, Srgba, StandardColor, Xyza}; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// Color in Hue-Whiteness-Blackness (HWB) color space with alpha. /// Further information on this color model can be found on [Wikipedia](https://en.wikipedia.org/wiki/HWB_color_model). @@ -12,8 +11,13 @@ use serde::{Deserialize, Serialize}; ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Hwba { /// The hue channel. [0.0, 360.0] pub hue: f32, diff --git a/crates/bevy_color/src/laba.rs b/crates/bevy_color/src/laba.rs index a227cc271e5d2..cec3019a319c3 100644 --- a/crates/bevy_color/src/laba.rs +++ b/crates/bevy_color/src/laba.rs @@ -3,15 +3,19 @@ use crate::{ Oklaba, Srgba, StandardColor, Xyza, }; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// Color in LAB color space, with alpha #[doc = include_str!("../docs/conversion.md")] ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Laba { /// The lightness channel. [0.0, 1.5] pub lightness: f32, diff --git a/crates/bevy_color/src/lcha.rs b/crates/bevy_color/src/lcha.rs index 7ba7dd154dcd4..75051a3ffe59e 100644 --- a/crates/bevy_color/src/lcha.rs +++ b/crates/bevy_color/src/lcha.rs @@ -1,14 +1,18 @@ use crate::{Alpha, ClampColor, Hue, Laba, LinearRgba, Luminance, Mix, Srgba, StandardColor, Xyza}; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// Color in LCH color space, with alpha #[doc = include_str!("../docs/conversion.md")] ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Lcha { /// The lightness channel. [0.0, 1.5] pub lightness: f32, diff --git a/crates/bevy_color/src/lib.rs b/crates/bevy_color/src/lib.rs index 139c381cd2062..eb637fe7650de 100644 --- a/crates/bevy_color/src/lib.rs +++ b/crates/bevy_color/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Representations of colors in various color spaces. //! //! This crate provides a number of color representations, including: @@ -140,7 +142,6 @@ where Self: core::fmt::Debug, Self: Clone + Copy, Self: PartialEq, - Self: serde::Serialize + for<'a> serde::Deserialize<'a>, Self: bevy_reflect::Reflect, Self: Default, Self: From + Into, diff --git a/crates/bevy_color/src/linear_rgba.rs b/crates/bevy_color/src/linear_rgba.rs index 5e450af72f31c..8f0cd071f1b33 100644 --- a/crates/bevy_color/src/linear_rgba.rs +++ b/crates/bevy_color/src/linear_rgba.rs @@ -5,15 +5,19 @@ use crate::{ use bevy_math::Vec4; use bevy_reflect::prelude::*; use bytemuck::{Pod, Zeroable}; -use serde::{Deserialize, Serialize}; /// Linear RGB color with alpha. #[doc = include_str!("../docs/conversion.md")] ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] #[repr(C)] pub struct LinearRgba { /// The red channel. [0.0, 1.0] diff --git a/crates/bevy_color/src/oklaba.rs b/crates/bevy_color/src/oklaba.rs index 5501e8e4c6ec8..06a2d6775349f 100644 --- a/crates/bevy_color/src/oklaba.rs +++ b/crates/bevy_color/src/oklaba.rs @@ -3,15 +3,19 @@ use crate::{ Hwba, Lcha, LinearRgba, Luminance, Mix, Srgba, StandardColor, Xyza, }; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// Color in Oklab color space, with alpha #[doc = include_str!("../docs/conversion.md")] ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Oklaba { /// The 'lightness' channel. [0.0, 1.0] pub lightness: f32, diff --git a/crates/bevy_color/src/oklcha.rs b/crates/bevy_color/src/oklcha.rs index 5a8ccc4b7a30f..949b80eb08450 100644 --- a/crates/bevy_color/src/oklcha.rs +++ b/crates/bevy_color/src/oklcha.rs @@ -3,15 +3,19 @@ use crate::{ LinearRgba, Luminance, Mix, Oklaba, Srgba, StandardColor, Xyza, }; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// Color in Oklch color space, with alpha #[doc = include_str!("../docs/conversion.md")] ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Oklcha { /// The 'lightness' channel. [0.0, 1.0] pub lightness: f32, diff --git a/crates/bevy_color/src/srgba.rs b/crates/bevy_color/src/srgba.rs index 8dee5039bb55a..31fafd0802dc7 100644 --- a/crates/bevy_color/src/srgba.rs +++ b/crates/bevy_color/src/srgba.rs @@ -4,7 +4,6 @@ use crate::{ }; use bevy_math::Vec4; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; use thiserror::Error; /// Non-linear standard RGB with alpha. @@ -12,8 +11,13 @@ use thiserror::Error; ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Srgba { /// The red channel. [0.0, 1.0] pub red: f32, diff --git a/crates/bevy_color/src/xyza.rs b/crates/bevy_color/src/xyza.rs index 008b42fb12b24..bc0c50e29b8bb 100644 --- a/crates/bevy_color/src/xyza.rs +++ b/crates/bevy_color/src/xyza.rs @@ -2,15 +2,19 @@ use crate::{ impl_componentwise_point, Alpha, ClampColor, LinearRgba, Luminance, Mix, StandardColor, }; use bevy_reflect::prelude::*; -use serde::{Deserialize, Serialize}; /// [CIE 1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space, also known as XYZ, with an alpha channel. #[doc = include_str!("../docs/conversion.md")] ///
#[doc = include_str!("../docs/diagrams/model_graph.svg")] ///
-#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)] -#[reflect(PartialEq, Serialize, Deserialize, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Reflect)] +#[reflect(PartialEq, Default)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] pub struct Xyza { /// The x-axis. [0.0, 1.0] pub x: f32, diff --git a/crates/bevy_core/Cargo.toml b/crates/bevy_core/Cargo.toml index 75ccb157ea0ae..d149581ebb93e 100644 --- a/crates/bevy_core/Cargo.toml +++ b/crates/bevy_core/Cargo.toml @@ -37,4 +37,5 @@ crossbeam-channel = "0.5.0" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index 8ccd3ee4d9408..610f9e7a24c92 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -1,6 +1,7 @@ -//! This crate provides core functionality for Bevy Engine. #![cfg_attr(docsrs, feature(doc_auto_cfg))] +//! This crate provides core functionality for Bevy Engine. + mod name; #[cfg(feature = "serialize")] mod serde; diff --git a/crates/bevy_core_pipeline/Cargo.toml b/crates/bevy_core_pipeline/Cargo.toml index e03b93e9d90ae..e6846d0ec161d 100644 --- a/crates/bevy_core_pipeline/Cargo.toml +++ b/crates/bevy_core_pipeline/Cargo.toml @@ -42,4 +42,5 @@ nonmax = "0.5" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_derive/Cargo.toml b/crates/bevy_derive/Cargo.toml index abf5e47f4bb0e..a936ac773a88c 100644 --- a/crates/bevy_derive/Cargo.toml +++ b/crates/bevy_derive/Cargo.toml @@ -19,3 +19,7 @@ syn = { version = "2.0", features = ["full"] } [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_derive/src/lib.rs b/crates/bevy_derive/src/lib.rs index fda825dc161a6..591bd9f7a84a1 100644 --- a/crates/bevy_derive/src/lib.rs +++ b/crates/bevy_derive/src/lib.rs @@ -1,5 +1,6 @@ // FIXME(3492): remove once docs are ready #![allow(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] extern crate proc_macro; diff --git a/crates/bevy_dev_tools/Cargo.toml b/crates/bevy_dev_tools/Cargo.toml index 62ab2c8fcc8ae..727ba84f80691 100644 --- a/crates/bevy_dev_tools/Cargo.toml +++ b/crates/bevy_dev_tools/Cargo.toml @@ -43,4 +43,5 @@ ron = { version = "0.8.0", optional = true } workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_dev_tools/src/lib.rs b/crates/bevy_dev_tools/src/lib.rs index 8bb9b0b7d2b98..031f627293485 100644 --- a/crates/bevy_dev_tools/src/lib.rs +++ b/crates/bevy_dev_tools/src/lib.rs @@ -1,6 +1,7 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! This crate provides additional utilities for the [Bevy game engine](https://bevyengine.org), //! focused on improving developer experience. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] use bevy_app::prelude::*; diff --git a/crates/bevy_diagnostic/Cargo.toml b/crates/bevy_diagnostic/Cargo.toml index d82a5f2e52c75..78f1d0bb005fb 100644 --- a/crates/bevy_diagnostic/Cargo.toml +++ b/crates/bevy_diagnostic/Cargo.toml @@ -38,4 +38,5 @@ sysinfo = { version = "0.30.0", optional = true, default-features = false } workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_diagnostic/src/lib.rs b/crates/bevy_diagnostic/src/lib.rs index dc21ec143f1c5..c3ad6427fc638 100644 --- a/crates/bevy_diagnostic/src/lib.rs +++ b/crates/bevy_diagnostic/src/lib.rs @@ -19,7 +19,7 @@ pub use entity_count_diagnostics_plugin::EntityCountDiagnosticsPlugin; pub use frame_time_diagnostics_plugin::FrameTimeDiagnosticsPlugin; pub use log_diagnostics_plugin::LogDiagnosticsPlugin; #[cfg(feature = "sysinfo_plugin")] -pub use system_information_diagnostics_plugin::SystemInformationDiagnosticsPlugin; +pub use system_information_diagnostics_plugin::{SystemInfo, SystemInformationDiagnosticsPlugin}; use bevy_app::prelude::*; @@ -28,12 +28,11 @@ use bevy_app::prelude::*; pub struct DiagnosticsPlugin; impl Plugin for DiagnosticsPlugin { - fn build(&self, _app: &mut App) { + fn build(&self, app: &mut App) { + app.init_resource::(); + #[cfg(feature = "sysinfo_plugin")] - _app.init_resource::().add_systems( - Startup, - system_information_diagnostics_plugin::internal::log_system_info, - ); + app.init_resource::(); } } diff --git a/crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs b/crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs index 0ffe3d479b2af..3709a6d05fd18 100644 --- a/crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs +++ b/crates/bevy_diagnostic/src/system_information_diagnostics_plugin.rs @@ -1,5 +1,6 @@ use crate::DiagnosticPath; use bevy_app::prelude::*; +use bevy_ecs::system::Resource; /// Adds a System Information Diagnostic, specifically `cpu_usage` (in %) and `mem_usage` (in %) /// @@ -24,10 +25,27 @@ impl Plugin for SystemInformationDiagnosticsPlugin { } impl SystemInformationDiagnosticsPlugin { + /// Total system cpu usage in % pub const CPU_USAGE: DiagnosticPath = DiagnosticPath::const_new("system/cpu_usage"); + /// Total system memory usage in % pub const MEM_USAGE: DiagnosticPath = DiagnosticPath::const_new("system/mem_usage"); } +/// A resource that stores diagnostic information about the system. +/// This information can be useful for debugging and profiling purposes. +/// +/// # See also +/// +/// [`SystemInformationDiagnosticsPlugin`] for more information. +#[derive(Debug, Resource)] +pub struct SystemInfo { + pub os: String, + pub kernel: String, + pub cpu: String, + pub core_count: String, + pub memory: String, +} + // NOTE: sysinfo fails to compile when using bevy dynamic or on iOS and does nothing on wasm #[cfg(all( any( @@ -45,7 +63,7 @@ pub mod internal { use crate::{Diagnostic, Diagnostics, DiagnosticsStore}; - use super::SystemInformationDiagnosticsPlugin; + use super::{SystemInfo, SystemInformationDiagnosticsPlugin}; const BYTES_TO_GIB: f64 = 1.0 / 1024.0 / 1024.0 / 1024.0; @@ -87,41 +105,33 @@ pub mod internal { }); } - #[derive(Debug)] - // This is required because the Debug trait doesn't detect it's used when it's only used in a print :( - #[allow(dead_code)] - struct SystemInfo { - os: String, - kernel: String, - cpu: String, - core_count: String, - memory: String, - } - - pub(crate) fn log_system_info() { - let sys = System::new_with_specifics( - RefreshKind::new() - .with_cpu(CpuRefreshKind::new()) - .with_memory(MemoryRefreshKind::new().with_ram()), - ); - - let info = SystemInfo { - os: System::long_os_version().unwrap_or_else(|| String::from("not available")), - kernel: System::kernel_version().unwrap_or_else(|| String::from("not available")), - cpu: sys - .cpus() - .first() - .map(|cpu| cpu.brand().trim().to_string()) - .unwrap_or_else(|| String::from("not available")), - core_count: sys - .physical_core_count() - .map(|x| x.to_string()) - .unwrap_or_else(|| String::from("not available")), - // Convert from Bytes to GibiBytes since it's probably what people expect most of the time - memory: format!("{:.1} GiB", sys.total_memory() as f64 * BYTES_TO_GIB), - }; - - info!("{:?}", info); + impl Default for SystemInfo { + fn default() -> Self { + let sys = System::new_with_specifics( + RefreshKind::new() + .with_cpu(CpuRefreshKind::new()) + .with_memory(MemoryRefreshKind::new().with_ram()), + ); + + let system_info = SystemInfo { + os: System::long_os_version().unwrap_or_else(|| String::from("not available")), + kernel: System::kernel_version().unwrap_or_else(|| String::from("not available")), + cpu: sys + .cpus() + .first() + .map(|cpu| cpu.brand().trim().to_string()) + .unwrap_or_else(|| String::from("not available")), + core_count: sys + .physical_core_count() + .map(|x| x.to_string()) + .unwrap_or_else(|| String::from("not available")), + // Convert from Bytes to GibiBytes since it's probably what people expect most of the time + memory: format!("{:.1} GiB", sys.total_memory() as f64 * BYTES_TO_GIB), + }; + + info!("{:?}", system_info); + system_info + } } } @@ -143,7 +153,16 @@ pub mod internal { // no-op } - pub(crate) fn log_system_info() { - // no-op + impl Default for super::SystemInfo { + fn default() -> Self { + let unknown = "Unknown".to_string(); + Self { + os: unknown.clone(), + kernel: unknown.clone(), + cpu: unknown.clone(), + core_count: unknown.clone(), + memory: unknown.clone(), + } + } } } diff --git a/crates/bevy_dylib/Cargo.toml b/crates/bevy_dylib/Cargo.toml index cd6c5c783659c..28535950c0b49 100644 --- a/crates/bevy_dylib/Cargo.toml +++ b/crates/bevy_dylib/Cargo.toml @@ -16,3 +16,7 @@ bevy_internal = { path = "../bevy_internal", version = "0.14.0-dev", default-fea [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_dylib/src/lib.rs b/crates/bevy_dylib/src/lib.rs index 9aefb17ace32f..116ba5067b1da 100644 --- a/crates/bevy_dylib/src/lib.rs +++ b/crates/bevy_dylib/src/lib.rs @@ -1,4 +1,4 @@ -#![allow(clippy::single_component_path_imports)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] //! Forces dynamic linking of Bevy. //! @@ -51,4 +51,5 @@ // Force linking of the main bevy crate #[allow(unused_imports)] +#[allow(clippy::single_component_path_imports)] use bevy_internal; diff --git a/crates/bevy_dynamic_plugin/Cargo.toml b/crates/bevy_dynamic_plugin/Cargo.toml index 67f22232c2f45..5e7d11754361b 100644 --- a/crates/bevy_dynamic_plugin/Cargo.toml +++ b/crates/bevy_dynamic_plugin/Cargo.toml @@ -18,3 +18,7 @@ thiserror = "1.0" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_dynamic_plugin/src/lib.rs b/crates/bevy_dynamic_plugin/src/lib.rs index 3a620cee1f6be..a675738a45944 100644 --- a/crates/bevy_dynamic_plugin/src/lib.rs +++ b/crates/bevy_dynamic_plugin/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Bevy's dynamic plugin loading functionality. //! //! This crate allows loading dynamic libraries (`.dylib`, `.so`) that export a single diff --git a/crates/bevy_ecs/Cargo.toml b/crates/bevy_ecs/Cargo.toml index 06e099b0059ce..6e54aaf7359a2 100644 --- a/crates/bevy_ecs/Cargo.toml +++ b/crates/bevy_ecs/Cargo.toml @@ -51,4 +51,5 @@ path = "examples/change_detection.rs" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_ecs/macros/Cargo.toml b/crates/bevy_ecs/macros/Cargo.toml index c9f3a5754c9ce..abc6647a8bc52 100644 --- a/crates/bevy_ecs/macros/Cargo.toml +++ b/crates/bevy_ecs/macros/Cargo.toml @@ -17,3 +17,7 @@ proc-macro2 = "1.0" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index 732cd3fd37e08..267969a55ed6b 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -1,5 +1,6 @@ // FIXME(3492): remove once docs are ready #![allow(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] extern crate proc_macro; diff --git a/crates/bevy_ecs/src/archetype.rs b/crates/bevy_ecs/src/archetype.rs index 6ab5bb2d420de..5f6302a2e1628 100644 --- a/crates/bevy_ecs/src/archetype.rs +++ b/crates/bevy_ecs/src/archetype.rs @@ -114,7 +114,10 @@ pub(crate) enum ComponentStatus { } pub(crate) struct AddBundle { + /// The target archetype after the bundle is added to the source archetype pub archetype_id: ArchetypeId, + /// For each component iterated in the same order as the source [`Bundle`](crate::bundle::Bundle), + /// indicate if the component is newly added to the target archetype or if it already existed pub bundle_status: Vec, } @@ -285,8 +288,12 @@ impl ArchetypeEntity { } } +/// Internal metadata for an [`Entity`] getting removed from an [`Archetype`]. pub(crate) struct ArchetypeSwapRemoveResult { + /// If the [`Entity`] was not the last in the [`Archetype`], it gets removed by swapping it out + /// with the last entity in the archetype. In that case, this field contains the swapped entity. pub(crate) swapped_entity: Option, + /// The [`TableRow`] where the removed entity's components are stored. pub(crate) table_row: TableRow, } diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index f3d42a66ef29b..82d9f521868fc 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -977,6 +977,8 @@ impl Bundles { } /// Initializes a new [`BundleInfo`] for a statically known type. + /// + /// Also initializes all the components in the bundle. pub(crate) fn init_info( &mut self, components: &mut Components, @@ -999,6 +1001,8 @@ impl Bundles { id } + /// # Safety + /// A `BundleInfo` with the given `BundleId` must have been initialized for this instance of `Bundles`. pub(crate) unsafe fn get_unchecked(&self, id: BundleId) -> &BundleInfo { self.bundle_infos.get_unchecked(id.0) } diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index d92029154f1a6..d307de9249206 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -1031,22 +1031,25 @@ impl<'w> EntityWorldMut<'w> { /// Remove the components of `bundle` from `entity`. /// - /// SAFETY: The components in `bundle_info` must exist. + /// SAFETY: + /// - A `BundleInfo` with the corresponding `BundleId` must have been initialized. #[allow(clippy::too_many_arguments)] unsafe fn remove_bundle(&mut self, bundle: BundleId) -> EntityLocation { let entity = self.entity; let world = &mut self.world; let location = self.location; + // SAFETY: the caller guarantees that the BundleInfo for this id has been initialized. let bundle_info = world.bundles.get_unchecked(bundle); // SAFETY: `archetype_id` exists because it is referenced in `location` which is valid - // and components in `bundle_info` must exist due to this functions safety invariants. + // and components in `bundle_info` must exist due to this function's safety invariants. let new_archetype_id = remove_bundle_from_archetype( &mut world.archetypes, &mut world.storages, &world.components, location.archetype_id, bundle_info, + // components from the bundle that are not present on the entity are ignored true, ) .expect("intersections should always return a result"); @@ -1117,8 +1120,7 @@ impl<'w> EntityWorldMut<'w> { let components = &mut self.world.components; let bundle_info = self.world.bundles.init_info::(components, storages); - // SAFETY: Components exist in `bundle_info` because `Bundles::init_info` - // initializes a: EntityLocation `BundleInfo` containing all components of the bundle type `T`. + // SAFETY: the `BundleInfo` is initialized above self.location = unsafe { self.remove_bundle(bundle_info) }; self @@ -1144,8 +1146,7 @@ impl<'w> EntityWorldMut<'w> { .collect::>(); let remove_bundle = self.world.bundles.init_dynamic_info(components, to_remove); - // SAFETY: Components exist in `remove_bundle` because `Bundles::init_dynamic_info` - // initializes a `BundleInfo` containing all components in the to_remove Bundle. + // SAFETY: the `BundleInfo` for the components to remove is initialized above self.location = unsafe { self.remove_bundle(remove_bundle) }; self } diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 3f87d8026db27..d245df8241930 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -18,7 +18,7 @@ pub use spawn_batch::*; use crate::{ archetype::{ArchetypeComponentId, ArchetypeId, ArchetypeRow, Archetypes}, - bundle::{Bundle, BundleInserter, BundleSpawner, Bundles}, + bundle::{Bundle, BundleInfo, BundleInserter, BundleSpawner, Bundles}, change_detection::{MutUntyped, TicksMut}, component::{ Component, ComponentDescriptor, ComponentHooks, ComponentId, ComponentInfo, ComponentTicks, @@ -1836,7 +1836,7 @@ impl World { } /// # Panics - /// panics if `component_id` is not registered in this world + /// Panics if `component_id` is not registered in this world #[inline] pub(crate) fn initialize_non_send_internal( &mut self, @@ -2085,6 +2085,20 @@ impl World { self.storages.resources.clear(); self.storages.non_send_resources.clear(); } + + /// Initializes all of the components in the given [`Bundle`] and returns both the component + /// ids and the bundle id. + /// + /// This is largely equivalent to calling [`init_component`](Self::init_component) on each + /// component in the bundle. + #[inline] + pub fn init_bundle(&mut self) -> &BundleInfo { + let id = self + .bundles + .init_info::(&mut self.components, &mut self.storages); + // SAFETY: We just initialised the bundle so its id should definitely be valid. + unsafe { self.bundles.get(id).debug_checked_unwrap() } + } } impl World { diff --git a/crates/bevy_encase_derive/Cargo.toml b/crates/bevy_encase_derive/Cargo.toml index d4b4b0a6ff4f3..ed50b8da959f1 100644 --- a/crates/bevy_encase_derive/Cargo.toml +++ b/crates/bevy_encase_derive/Cargo.toml @@ -17,3 +17,7 @@ encase_derive_impl = "0.7" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_encase_derive/src/lib.rs b/crates/bevy_encase_derive/src/lib.rs index e09bc4b247d1a..1fc888a61c8ae 100644 --- a/crates/bevy_encase_derive/src/lib.rs +++ b/crates/bevy_encase_derive/src/lib.rs @@ -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 encase_derive_impl::{implement, syn}; diff --git a/crates/bevy_gilrs/Cargo.toml b/crates/bevy_gilrs/Cargo.toml index bf0bd644abd26..ad98c34040016 100644 --- a/crates/bevy_gilrs/Cargo.toml +++ b/crates/bevy_gilrs/Cargo.toml @@ -22,3 +22,7 @@ thiserror = "1.0" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_gilrs/src/lib.rs b/crates/bevy_gilrs/src/lib.rs index dad8efe744a05..bd1ec09a2ae95 100644 --- a/crates/bevy_gilrs/src/lib.rs +++ b/crates/bevy_gilrs/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Systems and type definitions for gamepad handling in Bevy. //! //! This crate is built on top of [GilRs](gilrs), a library diff --git a/crates/bevy_gizmos/Cargo.toml b/crates/bevy_gizmos/Cargo.toml index 8b5bf14229eba..039151b1612c7 100644 --- a/crates/bevy_gizmos/Cargo.toml +++ b/crates/bevy_gizmos/Cargo.toml @@ -34,4 +34,5 @@ bytemuck = "1.0" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_gizmos/macros/Cargo.toml b/crates/bevy_gizmos/macros/Cargo.toml index d4cf3e3ad0828..dad07b319cae2 100644 --- a/crates/bevy_gizmos/macros/Cargo.toml +++ b/crates/bevy_gizmos/macros/Cargo.toml @@ -11,8 +11,6 @@ keywords = ["bevy"] [lib] proc-macro = true -[lints] -workspace = true [dependencies] bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.14.0-dev" } @@ -20,3 +18,10 @@ bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.14.0-dev" } syn = "2.0" proc-macro2 = "1.0" quote = "1.0" + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_gizmos/macros/src/lib.rs b/crates/bevy_gizmos/macros/src/lib.rs index eb2c598c90806..adce45a4d0e2a 100644 --- a/crates/bevy_gizmos/macros/src/lib.rs +++ b/crates/bevy_gizmos/macros/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Derive implementations for `bevy_gizmos`. use bevy_macro_utils::BevyManifest; diff --git a/crates/bevy_gizmos/src/lib.rs b/crates/bevy_gizmos/src/lib.rs index 9163a12bf669a..36d0a5520a61b 100755 --- a/crates/bevy_gizmos/src/lib.rs +++ b/crates/bevy_gizmos/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! This crate adds an immediate mode drawing api to Bevy for visual debugging. //! //! # Example @@ -13,7 +15,6 @@ //! ``` //! //! See the documentation on [Gizmos](crate::gizmos::Gizmos) for more examples. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] /// System set label for the systems handling the rendering of gizmos. #[derive(SystemSet, Clone, Debug, Hash, PartialEq, Eq)] diff --git a/crates/bevy_gltf/Cargo.toml b/crates/bevy_gltf/Cargo.toml index a7f94ef82d217..3fc387902f2c8 100644 --- a/crates/bevy_gltf/Cargo.toml +++ b/crates/bevy_gltf/Cargo.toml @@ -60,4 +60,5 @@ smallvec = "1.11" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_gltf/src/lib.rs b/crates/bevy_gltf/src/lib.rs index de4751a69767d..a2fce065df8a9 100644 --- a/crates/bevy_gltf/src/lib.rs +++ b/crates/bevy_gltf/src/lib.rs @@ -1,8 +1,9 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Plugin providing an [`AssetLoader`](bevy_asset::AssetLoader) and type definitions //! for loading glTF 2.0 (a standard 3D scene definition format) files in Bevy. //! //! The [glTF 2.0 specification](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html) defines the format of the glTF files. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] #[cfg(feature = "bevy_animation")] use bevy_animation::AnimationClip; diff --git a/crates/bevy_hierarchy/Cargo.toml b/crates/bevy_hierarchy/Cargo.toml index 9262ca8336dcc..74a9b434f3e3a 100644 --- a/crates/bevy_hierarchy/Cargo.toml +++ b/crates/bevy_hierarchy/Cargo.toml @@ -31,4 +31,5 @@ smallvec = { version = "1.11", features = ["union", "const_generics"] } workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_hierarchy/src/lib.rs b/crates/bevy_hierarchy/src/lib.rs index 464acada7ddf1..9ef22a7ab5547 100644 --- a/crates/bevy_hierarchy/src/lib.rs +++ b/crates/bevy_hierarchy/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Parent-child relationships for Bevy entities. //! //! You should use the tools in this crate @@ -44,7 +46,6 @@ //! [plugin]: HierarchyPlugin //! [query extension methods]: HierarchyQueryExt //! [world]: BuildWorldChildren -#![cfg_attr(docsrs, feature(doc_auto_cfg))] mod components; pub use components::*; diff --git a/crates/bevy_input/Cargo.toml b/crates/bevy_input/Cargo.toml index fbad74b9d5f88..d696e208f1fad 100644 --- a/crates/bevy_input/Cargo.toml +++ b/crates/bevy_input/Cargo.toml @@ -32,4 +32,5 @@ smol_str = "0.2" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_input/src/button_input.rs b/crates/bevy_input/src/button_input.rs index 821281293a07c..d4d4aca2f9b97 100644 --- a/crates/bevy_input/src/button_input.rs +++ b/crates/bevy_input/src/button_input.rs @@ -143,12 +143,14 @@ where self.just_released.extend(self.pressed.drain()); } - /// Returns `true` if the `input` has just been pressed. + /// Returns `true` if the `input` has been pressed during the current frame. + /// + /// Note: This function does not imply information regarding the current state of [`ButtonInput::pressed`] or [`ButtonInput::just_released`]. pub fn just_pressed(&self, input: T) -> bool { self.just_pressed.contains(&input) } - /// Returns `true` if any item in `inputs` has just been pressed. + /// Returns `true` if any item in `inputs` has been pressed during the current frame. pub fn any_just_pressed(&self, inputs: impl IntoIterator) -> bool { inputs.into_iter().any(|it| self.just_pressed(it)) } @@ -160,7 +162,9 @@ where self.just_pressed.remove(&input) } - /// Returns `true` if the `input` has just been released. + /// Returns `true` if the `input` has been released during the current frame. + /// + /// Note: This function does not imply information regarding the current state of [`ButtonInput::pressed`] or [`ButtonInput::just_pressed`]. pub fn just_released(&self, input: T) -> bool { self.just_released.contains(&input) } @@ -207,11 +211,15 @@ where } /// An iterator visiting every just pressed input in arbitrary order. + /// + /// Note: Returned elements do not imply information regarding the current state of [`ButtonInput::pressed`] or [`ButtonInput::just_released`]. pub fn get_just_pressed(&self) -> impl ExactSizeIterator { self.just_pressed.iter() } /// An iterator visiting every just released input in arbitrary order. + /// + /// Note: Returned elements do not imply information regarding the current state of [`ButtonInput::pressed`] or [`ButtonInput::just_pressed`]. pub fn get_just_released(&self) -> impl ExactSizeIterator { self.just_released.iter() } diff --git a/crates/bevy_input/src/lib.rs b/crates/bevy_input/src/lib.rs index 489e12b2f40bb..f2bd0d5f1e6c2 100644 --- a/crates/bevy_input/src/lib.rs +++ b/crates/bevy_input/src/lib.rs @@ -1,9 +1,10 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Input functionality for the [Bevy game engine](https://bevyengine.org/). //! //! # Supported input devices //! //! `bevy` currently supports keyboard, mouse, gamepad, and touch inputs. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] mod axis; mod button_input; diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index fc7eb39ff1ae9..1978d2b747038 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -73,6 +73,7 @@ serialize = [ "bevy_math/serialize", "bevy_scene?/serialize", "bevy_ui?/serialize", + "bevy_color?/serialize", ] multi-threaded = [ "bevy_asset?/multi-threaded", @@ -207,3 +208,7 @@ bevy_dev_tools = { path = "../bevy_dev_tools", optional = true, version = "0.14. [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_internal/src/lib.rs b/crates/bevy_internal/src/lib.rs index e7a46f246c808..434755f9c124f 100644 --- a/crates/bevy_internal/src/lib.rs +++ b/crates/bevy_internal/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! This module is separated into its own crate to enable simple dynamic linking for Bevy, and should not be used directly /// `use bevy::prelude::*;` to import common components, bundles, and plugins. diff --git a/crates/bevy_log/Cargo.toml b/crates/bevy_log/Cargo.toml index eaf53d1f6cdeb..33cee7bea4ef5 100644 --- a/crates/bevy_log/Cargo.toml +++ b/crates/bevy_log/Cargo.toml @@ -40,4 +40,5 @@ tracing-wasm = "0.2.1" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_log/src/lib.rs b/crates/bevy_log/src/lib.rs index b6576acb172d9..b4c9a34f6765e 100644 --- a/crates/bevy_log/src/lib.rs +++ b/crates/bevy_log/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! This crate provides logging functions and configuration for [Bevy](https://bevyengine.org) //! apps, and automatically configures platform specific log handlers (i.e. WASM or Android). //! @@ -9,7 +11,6 @@ //! //! For more fine-tuned control over logging behavior, set up the [`LogPlugin`] or //! `DefaultPlugins` during app initialization. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] #[cfg(feature = "trace")] use std::panic; diff --git a/crates/bevy_macro_utils/Cargo.toml b/crates/bevy_macro_utils/Cargo.toml index 6dc67396bb18b..408716edd4f62 100644 --- a/crates/bevy_macro_utils/Cargo.toml +++ b/crates/bevy_macro_utils/Cargo.toml @@ -19,3 +19,7 @@ proc-macro2 = "1.0" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_macro_utils/src/lib.rs b/crates/bevy_macro_utils/src/lib.rs index 443313f8e87bd..535d61a09fc57 100644 --- a/crates/bevy_macro_utils/src/lib.rs +++ b/crates/bevy_macro_utils/src/lib.rs @@ -1,4 +1,6 @@ #![deny(unsafe_code)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! A collection of helper types and functions for working on macros within the Bevy ecosystem. extern crate proc_macro; diff --git a/crates/bevy_math/Cargo.toml b/crates/bevy_math/Cargo.toml index 3423759ebec8c..28ab5d1cd321b 100644 --- a/crates/bevy_math/Cargo.toml +++ b/crates/bevy_math/Cargo.toml @@ -45,4 +45,5 @@ rand = ["dep:rand"] workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_math/src/lib.rs b/crates/bevy_math/src/lib.rs index 0d76500703818..4698604c8cf34 100644 --- a/crates/bevy_math/src/lib.rs +++ b/crates/bevy_math/src/lib.rs @@ -1,9 +1,10 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Provides math types and functionality for the Bevy game engine. //! //! The commonly used types are vectors like [`Vec2`] and [`Vec3`], //! matrices like [`Mat2`], [`Mat3`] and [`Mat4`] and orientation representations //! like [`Quat`]. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] mod affine3; mod aspect_ratio; diff --git a/crates/bevy_mikktspace/Cargo.toml b/crates/bevy_mikktspace/Cargo.toml index 78f66e821a82e..9119e80a83ab6 100644 --- a/crates/bevy_mikktspace/Cargo.toml +++ b/crates/bevy_mikktspace/Cargo.toml @@ -22,3 +22,7 @@ name = "generate" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_mikktspace/src/lib.rs b/crates/bevy_mikktspace/src/lib.rs index cbf2c0c7ad833..5f37ab2effb8a 100644 --- a/crates/bevy_mikktspace/src/lib.rs +++ b/crates/bevy_mikktspace/src/lib.rs @@ -6,6 +6,7 @@ )] // FIXME(3492): remove once docs are ready #![allow(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] use glam::{Vec2, Vec3}; diff --git a/crates/bevy_panic_handler/Cargo.toml b/crates/bevy_panic_handler/Cargo.toml index 24b96de3c2a4a..5a99d2bd338be 100644 --- a/crates/bevy_panic_handler/Cargo.toml +++ b/crates/bevy_panic_handler/Cargo.toml @@ -20,4 +20,5 @@ console_error_panic_hook = "0.1.6" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_panic_handler/src/lib.rs b/crates/bevy_panic_handler/src/lib.rs index 8e3705980de62..dec5c000a7413 100644 --- a/crates/bevy_panic_handler/src/lib.rs +++ b/crates/bevy_panic_handler/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! This crate provides panic handlers for [Bevy](https://bevyengine.org) //! apps, and automatically configures platform specifics (i.e. WASM or Android). //! @@ -5,7 +7,6 @@ //! //! For more fine-tuned control over panic behavior, disable the [`PanicHandlerPlugin`] or //! `DefaultPlugins` during app initialization. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] use bevy_app::{App, Plugin}; diff --git a/crates/bevy_pbr/Cargo.toml b/crates/bevy_pbr/Cargo.toml index 0b148fc2729bd..3bf23e9123d9c 100644 --- a/crates/bevy_pbr/Cargo.toml +++ b/crates/bevy_pbr/Cargo.toml @@ -46,4 +46,5 @@ nonmax = "0.5" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_pbr/src/light/directional_light.rs b/crates/bevy_pbr/src/light/directional_light.rs new file mode 100644 index 0000000000000..9c74971ca15a5 --- /dev/null +++ b/crates/bevy_pbr/src/light/directional_light.rs @@ -0,0 +1,83 @@ +use super::*; + +/// A Directional light. +/// +/// Directional lights don't exist in reality but they are a good +/// approximation for light sources VERY far away, like the sun or +/// the moon. +/// +/// The light shines along the forward direction of the entity's transform. With a default transform +/// this would be along the negative-Z axis. +/// +/// Valid values for `illuminance` are: +/// +/// | Illuminance (lux) | Surfaces illuminated by | +/// |-------------------|------------------------------------------------| +/// | 0.0001 | Moonless, overcast night sky (starlight) | +/// | 0.002 | Moonless clear night sky with airglow | +/// | 0.05–0.3 | Full moon on a clear night | +/// | 3.4 | Dark limit of civil twilight under a clear sky | +/// | 20–50 | Public areas with dark surroundings | +/// | 50 | Family living room lights | +/// | 80 | Office building hallway/toilet lighting | +/// | 100 | Very dark overcast day | +/// | 150 | Train station platforms | +/// | 320–500 | Office lighting | +/// | 400 | Sunrise or sunset on a clear day. | +/// | 1000 | Overcast day; typical TV studio lighting | +/// | 10,000–25,000 | Full daylight (not direct sun) | +/// | 32,000–100,000 | Direct sunlight | +/// +/// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lux) +/// +/// ## Shadows +/// +/// To enable shadows, set the `shadows_enabled` property to `true`. +/// +/// Shadows are produced via [cascaded shadow maps](https://developer.download.nvidia.com/SDK/10.5/opengl/src/cascaded_shadow_maps/doc/cascaded_shadow_maps.pdf). +/// +/// To modify the cascade set up, such as the number of cascades or the maximum shadow distance, +/// change the [`CascadeShadowConfig`] component of the [`DirectionalLightBundle`]. +/// +/// To control the resolution of the shadow maps, use the [`DirectionalLightShadowMap`] resource: +/// +/// ``` +/// # use bevy_app::prelude::*; +/// # use bevy_pbr::DirectionalLightShadowMap; +/// App::new() +/// .insert_resource(DirectionalLightShadowMap { size: 2048 }); +/// ``` +#[derive(Component, Debug, Clone, Reflect)] +#[reflect(Component, Default)] +pub struct DirectionalLight { + pub color: Color, + /// Illuminance in lux (lumens per square meter), representing the amount of + /// light projected onto surfaces by this light source. Lux is used here + /// instead of lumens because a directional light illuminates all surfaces + /// more-or-less the same way (depending on the angle of incidence). Lumens + /// can only be specified for light sources which emit light from a specific + /// area. + pub illuminance: f32, + pub shadows_enabled: bool, + pub shadow_depth_bias: f32, + /// A bias applied along the direction of the fragment's surface normal. It is scaled to the + /// shadow map's texel size so that it is automatically adjusted to the orthographic projection. + pub shadow_normal_bias: f32, +} + +impl Default for DirectionalLight { + fn default() -> Self { + DirectionalLight { + color: Color::WHITE, + illuminance: light_consts::lux::AMBIENT_DAYLIGHT, + shadows_enabled: false, + shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS, + shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS, + } + } +} + +impl DirectionalLight { + pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; + pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 1.8; +} diff --git a/crates/bevy_pbr/src/light/mod.rs b/crates/bevy_pbr/src/light/mod.rs index 5d6be4fcf48d3..c73dcaf525b2d 100644 --- a/crates/bevy_pbr/src/light/mod.rs +++ b/crates/bevy_pbr/src/light/mod.rs @@ -22,6 +22,12 @@ use crate::*; mod ambient_light; pub use ambient_light::AmbientLight; +mod point_light; +pub use point_light::PointLight; +mod spot_light; +pub use spot_light::SpotLight; +mod directional_light; +pub use directional_light::DirectionalLight; /// Constants for operating with the light units: lumens, and lux. pub mod light_consts { @@ -80,61 +86,6 @@ pub mod light_consts { } } -/// A light that emits light in all directions from a central point. -/// -/// Real-world values for `intensity` (luminous power in lumens) based on the electrical power -/// consumption of the type of real-world light are: -/// -/// | Luminous Power (lumen) (i.e. the intensity member) | Incandescent non-halogen (Watts) | Incandescent halogen (Watts) | Compact fluorescent (Watts) | LED (Watts | -/// |------|-----|----|--------|-------| -/// | 200 | 25 | | 3-5 | 3 | -/// | 450 | 40 | 29 | 9-11 | 5-8 | -/// | 800 | 60 | | 13-15 | 8-12 | -/// | 1100 | 75 | 53 | 18-20 | 10-16 | -/// | 1600 | 100 | 72 | 24-28 | 14-17 | -/// | 2400 | 150 | | 30-52 | 24-30 | -/// | 3100 | 200 | | 49-75 | 32 | -/// | 4000 | 300 | | 75-100 | 40.5 | -/// -/// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting) -#[derive(Component, Debug, Clone, Copy, Reflect)] -#[reflect(Component, Default)] -pub struct PointLight { - pub color: Color, - /// Luminous power in lumens, representing the amount of light emitted by this source in all directions. - pub intensity: f32, - pub range: f32, - pub radius: f32, - pub shadows_enabled: bool, - pub shadow_depth_bias: f32, - /// A bias applied along the direction of the fragment's surface normal. It is scaled to the - /// shadow map's texel size so that it can be small close to the camera and gets larger further - /// away. - pub shadow_normal_bias: f32, -} - -impl Default for PointLight { - fn default() -> Self { - PointLight { - color: Color::WHITE, - // 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's - // default "very overcast day" exposure level. For "indoor lighting" with a lower exposure, - // this would be way too bright. - intensity: 1_000_000.0, - range: 20.0, - radius: 0.0, - shadows_enabled: false, - shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS, - shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS, - } - } -} - -impl PointLight { - pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; - pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 0.6; -} - #[derive(Resource, Clone, Debug, Reflect)] #[reflect(Resource)] pub struct PointLightShadowMap { @@ -147,144 +98,6 @@ impl Default for PointLightShadowMap { } } -/// A light that emits light in a given direction from a central point. -/// Behaves like a point light in a perfectly absorbent housing that -/// shines light only in a given direction. The direction is taken from -/// the transform, and can be specified with [`Transform::looking_at`](Transform::looking_at). -#[derive(Component, Debug, Clone, Copy, Reflect)] -#[reflect(Component, Default)] -pub struct SpotLight { - pub color: Color, - /// Luminous power in lumens, representing the amount of light emitted by this source in all directions. - pub intensity: f32, - pub range: f32, - pub radius: f32, - pub shadows_enabled: bool, - pub shadow_depth_bias: f32, - /// A bias applied along the direction of the fragment's surface normal. It is scaled to the - /// shadow map's texel size so that it can be small close to the camera and gets larger further - /// away. - pub shadow_normal_bias: f32, - /// Angle defining the distance from the spot light direction to the outer limit - /// of the light's cone of effect. - /// `outer_angle` should be < `PI / 2.0`. - /// `PI / 2.0` defines a hemispherical spot light, but shadows become very blocky as the angle - /// approaches this limit. - pub outer_angle: f32, - /// Angle defining the distance from the spot light direction to the inner limit - /// of the light's cone of effect. - /// Light is attenuated from `inner_angle` to `outer_angle` to give a smooth falloff. - /// `inner_angle` should be <= `outer_angle` - pub inner_angle: f32, -} - -impl SpotLight { - pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; - pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 1.8; -} - -impl Default for SpotLight { - fn default() -> Self { - // a quarter arc attenuating from the center - Self { - color: Color::WHITE, - // 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's - // default "very overcast day" exposure level. For "indoor lighting" with a lower exposure, - // this would be way too bright. - intensity: 1_000_000.0, - range: 20.0, - radius: 0.0, - shadows_enabled: false, - shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS, - shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS, - inner_angle: 0.0, - outer_angle: std::f32::consts::FRAC_PI_4, - } - } -} - -/// A Directional light. -/// -/// Directional lights don't exist in reality but they are a good -/// approximation for light sources VERY far away, like the sun or -/// the moon. -/// -/// The light shines along the forward direction of the entity's transform. With a default transform -/// this would be along the negative-Z axis. -/// -/// Valid values for `illuminance` are: -/// -/// | Illuminance (lux) | Surfaces illuminated by | -/// |-------------------|------------------------------------------------| -/// | 0.0001 | Moonless, overcast night sky (starlight) | -/// | 0.002 | Moonless clear night sky with airglow | -/// | 0.05–0.3 | Full moon on a clear night | -/// | 3.4 | Dark limit of civil twilight under a clear sky | -/// | 20–50 | Public areas with dark surroundings | -/// | 50 | Family living room lights | -/// | 80 | Office building hallway/toilet lighting | -/// | 100 | Very dark overcast day | -/// | 150 | Train station platforms | -/// | 320–500 | Office lighting | -/// | 400 | Sunrise or sunset on a clear day. | -/// | 1000 | Overcast day; typical TV studio lighting | -/// | 10,000–25,000 | Full daylight (not direct sun) | -/// | 32,000–100,000 | Direct sunlight | -/// -/// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lux) -/// -/// ## Shadows -/// -/// To enable shadows, set the `shadows_enabled` property to `true`. -/// -/// Shadows are produced via [cascaded shadow maps](https://developer.download.nvidia.com/SDK/10.5/opengl/src/cascaded_shadow_maps/doc/cascaded_shadow_maps.pdf). -/// -/// To modify the cascade set up, such as the number of cascades or the maximum shadow distance, -/// change the [`CascadeShadowConfig`] component of the [`DirectionalLightBundle`]. -/// -/// To control the resolution of the shadow maps, use the [`DirectionalLightShadowMap`] resource: -/// -/// ``` -/// # use bevy_app::prelude::*; -/// # use bevy_pbr::DirectionalLightShadowMap; -/// App::new() -/// .insert_resource(DirectionalLightShadowMap { size: 2048 }); -/// ``` -#[derive(Component, Debug, Clone, Reflect)] -#[reflect(Component, Default)] -pub struct DirectionalLight { - pub color: Color, - /// Illuminance in lux (lumens per square meter), representing the amount of - /// light projected onto surfaces by this light source. Lux is used here - /// instead of lumens because a directional light illuminates all surfaces - /// more-or-less the same way (depending on the angle of incidence). Lumens - /// can only be specified for light sources which emit light from a specific - /// area. - pub illuminance: f32, - pub shadows_enabled: bool, - pub shadow_depth_bias: f32, - /// A bias applied along the direction of the fragment's surface normal. It is scaled to the - /// shadow map's texel size so that it is automatically adjusted to the orthographic projection. - pub shadow_normal_bias: f32, -} - -impl Default for DirectionalLight { - fn default() -> Self { - DirectionalLight { - color: Color::WHITE, - illuminance: light_consts::lux::AMBIENT_DAYLIGHT, - shadows_enabled: false, - shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS, - shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS, - } - } -} - -impl DirectionalLight { - pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; - pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 1.8; -} - /// Controls the resolution of [`DirectionalLight`] shadow maps. #[derive(Resource, Clone, Debug, Reflect)] #[reflect(Resource)] diff --git a/crates/bevy_pbr/src/light/point_light.rs b/crates/bevy_pbr/src/light/point_light.rs new file mode 100644 index 0000000000000..6ff5d39e4e8f1 --- /dev/null +++ b/crates/bevy_pbr/src/light/point_light.rs @@ -0,0 +1,56 @@ +use super::*; + +/// A light that emits light in all directions from a central point. +/// +/// Real-world values for `intensity` (luminous power in lumens) based on the electrical power +/// consumption of the type of real-world light are: +/// +/// | Luminous Power (lumen) (i.e. the intensity member) | Incandescent non-halogen (Watts) | Incandescent halogen (Watts) | Compact fluorescent (Watts) | LED (Watts | +/// |------|-----|----|--------|-------| +/// | 200 | 25 | | 3-5 | 3 | +/// | 450 | 40 | 29 | 9-11 | 5-8 | +/// | 800 | 60 | | 13-15 | 8-12 | +/// | 1100 | 75 | 53 | 18-20 | 10-16 | +/// | 1600 | 100 | 72 | 24-28 | 14-17 | +/// | 2400 | 150 | | 30-52 | 24-30 | +/// | 3100 | 200 | | 49-75 | 32 | +/// | 4000 | 300 | | 75-100 | 40.5 | +/// +/// Source: [Wikipedia](https://en.wikipedia.org/wiki/Lumen_(unit)#Lighting) +#[derive(Component, Debug, Clone, Copy, Reflect)] +#[reflect(Component, Default)] +pub struct PointLight { + pub color: Color, + /// Luminous power in lumens, representing the amount of light emitted by this source in all directions. + pub intensity: f32, + pub range: f32, + pub radius: f32, + pub shadows_enabled: bool, + pub shadow_depth_bias: f32, + /// A bias applied along the direction of the fragment's surface normal. It is scaled to the + /// shadow map's texel size so that it can be small close to the camera and gets larger further + /// away. + pub shadow_normal_bias: f32, +} + +impl Default for PointLight { + fn default() -> Self { + PointLight { + color: Color::WHITE, + // 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's + // default "very overcast day" exposure level. For "indoor lighting" with a lower exposure, + // this would be way too bright. + intensity: 1_000_000.0, + range: 20.0, + radius: 0.0, + shadows_enabled: false, + shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS, + shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS, + } + } +} + +impl PointLight { + pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; + pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 0.6; +} diff --git a/crates/bevy_pbr/src/light/spot_light.rs b/crates/bevy_pbr/src/light/spot_light.rs new file mode 100644 index 0000000000000..ab34196ff03fb --- /dev/null +++ b/crates/bevy_pbr/src/light/spot_light.rs @@ -0,0 +1,57 @@ +use super::*; + +/// A light that emits light in a given direction from a central point. +/// Behaves like a point light in a perfectly absorbent housing that +/// shines light only in a given direction. The direction is taken from +/// the transform, and can be specified with [`Transform::looking_at`](Transform::looking_at). +#[derive(Component, Debug, Clone, Copy, Reflect)] +#[reflect(Component, Default)] +pub struct SpotLight { + pub color: Color, + /// Luminous power in lumens, representing the amount of light emitted by this source in all directions. + pub intensity: f32, + pub range: f32, + pub radius: f32, + pub shadows_enabled: bool, + pub shadow_depth_bias: f32, + /// A bias applied along the direction of the fragment's surface normal. It is scaled to the + /// shadow map's texel size so that it can be small close to the camera and gets larger further + /// away. + pub shadow_normal_bias: f32, + /// Angle defining the distance from the spot light direction to the outer limit + /// of the light's cone of effect. + /// `outer_angle` should be < `PI / 2.0`. + /// `PI / 2.0` defines a hemispherical spot light, but shadows become very blocky as the angle + /// approaches this limit. + pub outer_angle: f32, + /// Angle defining the distance from the spot light direction to the inner limit + /// of the light's cone of effect. + /// Light is attenuated from `inner_angle` to `outer_angle` to give a smooth falloff. + /// `inner_angle` should be <= `outer_angle` + pub inner_angle: f32, +} + +impl SpotLight { + pub const DEFAULT_SHADOW_DEPTH_BIAS: f32 = 0.02; + pub const DEFAULT_SHADOW_NORMAL_BIAS: f32 = 1.8; +} + +impl Default for SpotLight { + fn default() -> Self { + // a quarter arc attenuating from the center + Self { + color: Color::WHITE, + // 1,000,000 lumens is a very large "cinema light" capable of registering brightly at Bevy's + // default "very overcast day" exposure level. For "indoor lighting" with a lower exposure, + // this would be way too bright. + intensity: 1_000_000.0, + range: 20.0, + radius: 0.0, + shadows_enabled: false, + shadow_depth_bias: Self::DEFAULT_SHADOW_DEPTH_BIAS, + shadow_normal_bias: Self::DEFAULT_SHADOW_NORMAL_BIAS, + inner_angle: 0.0, + outer_angle: std::f32::consts::FRAC_PI_4, + } + } +} diff --git a/crates/bevy_ptr/Cargo.toml b/crates/bevy_ptr/Cargo.toml index ae443652d11da..d76b911e78945 100644 --- a/crates/bevy_ptr/Cargo.toml +++ b/crates/bevy_ptr/Cargo.toml @@ -12,3 +12,7 @@ keywords = ["bevy", "no_std"] [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_ptr/src/lib.rs b/crates/bevy_ptr/src/lib.rs index d6c0322461528..19a34b412d251 100644 --- a/crates/bevy_ptr/src/lib.rs +++ b/crates/bevy_ptr/src/lib.rs @@ -1,5 +1,6 @@ #![doc = include_str!("../README.md")] #![no_std] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] use core::fmt::{self, Formatter, Pointer}; use core::{ diff --git a/crates/bevy_reflect/Cargo.toml b/crates/bevy_reflect/Cargo.toml index 5cb69dc88edbb..b9fe3e4bb6896 100644 --- a/crates/bevy_reflect/Cargo.toml +++ b/crates/bevy_reflect/Cargo.toml @@ -59,4 +59,5 @@ required-features = ["documentation"] workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_reflect/bevy_reflect_derive/Cargo.toml b/crates/bevy_reflect/bevy_reflect_derive/Cargo.toml index e076283ac8453..deee32d6664c4 100644 --- a/crates/bevy_reflect/bevy_reflect_derive/Cargo.toml +++ b/crates/bevy_reflect/bevy_reflect_derive/Cargo.toml @@ -26,3 +26,7 @@ uuid = { version = "1.1", features = ["v4"] } [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_reflect/bevy_reflect_derive/src/lib.rs b/crates/bevy_reflect/bevy_reflect_derive/src/lib.rs index 5be3723b7b0d9..743c558dded22 100644 --- a/crates/bevy_reflect/bevy_reflect_derive/src/lib.rs +++ b/crates/bevy_reflect/bevy_reflect_derive/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! This crate contains macros used by Bevy's `Reflect` API. //! //! The main export of this crate is the derive macro for [`Reflect`]. This allows diff --git a/crates/bevy_reflect/src/impls/std.rs b/crates/bevy_reflect/src/impls/std.rs index 3b50abb0d9fdf..f81db9d6c7506 100644 --- a/crates/bevy_reflect/src/impls/std.rs +++ b/crates/bevy_reflect/src/impls/std.rs @@ -1,17 +1,16 @@ use crate::std_traits::ReflectDefault; use crate::{self as bevy_reflect, ReflectFromPtr, ReflectFromReflect, ReflectOwned, TypeRegistry}; use crate::{ - impl_type_path, map_apply, map_partial_eq, Array, ArrayInfo, ArrayIter, DynamicEnum, - DynamicMap, Enum, EnumInfo, FromReflect, FromType, GetTypeRegistration, List, ListInfo, - ListIter, Map, MapInfo, MapIter, Reflect, ReflectDeserialize, ReflectKind, ReflectMut, - ReflectRef, ReflectSerialize, TupleVariantInfo, TypeInfo, TypePath, TypeRegistration, Typed, - UnitVariantInfo, UnnamedField, ValueInfo, VariantFieldIter, VariantInfo, VariantType, + impl_type_path, map_apply, map_partial_eq, Array, ArrayInfo, ArrayIter, DynamicMap, + FromReflect, FromType, GetTypeRegistration, List, ListInfo, ListIter, Map, MapInfo, MapIter, + Reflect, ReflectDeserialize, ReflectKind, ReflectMut, ReflectRef, ReflectSerialize, TypeInfo, + TypePath, TypeRegistration, Typed, ValueInfo, }; use crate::utility::{ reflect_hasher, GenericTypeInfoCell, GenericTypePathCell, NonGenericTypeInfoCell, }; -use bevy_reflect_derive::impl_reflect_value; +use bevy_reflect_derive::{impl_reflect, impl_reflect_value}; use std::fmt; use std::{ any::Any, @@ -996,252 +995,14 @@ impl GetTypeRegistr } } -impl GetTypeRegistration for Option { - fn get_type_registration() -> TypeRegistration { - TypeRegistration::of::>() - } - - fn register_type_dependencies(registry: &mut TypeRegistry) { - registry.register::(); +impl_reflect! { + #[type_path = "core::option"] + enum Option { + None, + Some(T), } } -impl Enum for Option { - fn field(&self, _name: &str) -> Option<&dyn Reflect> { - None - } - - fn field_at(&self, index: usize) -> Option<&dyn Reflect> { - match self { - Some(value) if index == 0 => Some(value), - _ => None, - } - } - - fn field_mut(&mut self, _name: &str) -> Option<&mut dyn Reflect> { - None - } - - fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect> { - match self { - Some(value) if index == 0 => Some(value), - _ => None, - } - } - - fn index_of(&self, _name: &str) -> Option { - None - } - - fn name_at(&self, _index: usize) -> Option<&str> { - None - } - - fn iter_fields(&self) -> VariantFieldIter { - VariantFieldIter::new(self) - } - - #[inline] - fn field_len(&self) -> usize { - match self { - Some(..) => 1, - None => 0, - } - } - - #[inline] - fn variant_name(&self) -> &str { - match self { - Some(..) => "Some", - None => "None", - } - } - - fn variant_index(&self) -> usize { - match self { - None => 0, - Some(..) => 1, - } - } - - #[inline] - fn variant_type(&self) -> VariantType { - match self { - Some(..) => VariantType::Tuple, - None => VariantType::Unit, - } - } - - fn clone_dynamic(&self) -> DynamicEnum { - DynamicEnum::from_ref::(self) - } -} - -impl Reflect for Option { - #[inline] - fn get_represented_type_info(&self) -> Option<&'static TypeInfo> { - Some(::type_info()) - } - - #[inline] - fn into_any(self: Box) -> Box { - self - } - - #[inline] - fn as_any(&self) -> &dyn Any { - self - } - - #[inline] - fn as_any_mut(&mut self) -> &mut dyn Any { - self - } - - #[inline] - fn into_reflect(self: Box) -> Box { - self - } - - fn as_reflect(&self) -> &dyn Reflect { - self - } - - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { - self - } - - #[inline] - fn apply(&mut self, value: &dyn Reflect) { - if let ReflectRef::Enum(value) = value.reflect_ref() { - if self.variant_name() == value.variant_name() { - // Same variant -> just update fields - for (index, field) in value.iter_fields().enumerate() { - if let Some(v) = self.field_at_mut(index) { - v.apply(field.value()); - } - } - } else { - // New variant -> perform a switch - match value.variant_name() { - "Some" => { - let field = T::take_from_reflect( - value - .field_at(0) - .unwrap_or_else(|| { - panic!( - "Field in `Some` variant of {} should exist", - Self::type_path() - ) - }) - .clone_value(), - ) - .unwrap_or_else(|_| { - panic!( - "Field in `Some` variant of {} should be of type {}", - Self::type_path(), - T::type_path() - ) - }); - *self = Some(field); - } - "None" => { - *self = None; - } - _ => panic!("Enum is not a {}.", Self::type_path()), - } - } - } - } - - #[inline] - fn set(&mut self, value: Box) -> Result<(), Box> { - *self = value.take()?; - Ok(()) - } - - fn reflect_kind(&self) -> ReflectKind { - ReflectKind::Enum - } - - fn reflect_ref(&self) -> ReflectRef { - ReflectRef::Enum(self) - } - - fn reflect_mut(&mut self) -> ReflectMut { - ReflectMut::Enum(self) - } - - fn reflect_owned(self: Box) -> ReflectOwned { - ReflectOwned::Enum(self) - } - - #[inline] - fn clone_value(&self) -> Box { - Box::new(Enum::clone_dynamic(self)) - } - - fn reflect_hash(&self) -> Option { - crate::enum_hash(self) - } - - fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option { - crate::enum_partial_eq(self, value) - } -} - -impl FromReflect for Option { - fn from_reflect(reflect: &dyn Reflect) -> Option { - if let ReflectRef::Enum(dyn_enum) = reflect.reflect_ref() { - match dyn_enum.variant_name() { - "Some" => { - let field = T::take_from_reflect( - dyn_enum - .field_at(0) - .unwrap_or_else(|| { - panic!( - "Field in `Some` variant of {} should exist", - Option::::type_path() - ) - }) - .clone_value(), - ) - .unwrap_or_else(|_| { - panic!( - "Field in `Some` variant of {} should be of type {}", - Option::::type_path(), - T::type_path() - ) - }); - Some(Some(field)) - } - "None" => Some(None), - name => panic!( - "variant with name `{}` does not exist on enum `{}`", - name, - Self::type_path() - ), - } - } else { - None - } - } -} - -impl Typed for Option { - fn type_info() -> &'static TypeInfo { - static CELL: GenericTypeInfoCell = GenericTypeInfoCell::new(); - CELL.get_or_insert::(|| { - let none_variant = VariantInfo::Unit(UnitVariantInfo::new("None")); - let some_variant = - VariantInfo::Tuple(TupleVariantInfo::new("Some", &[UnnamedField::new::(0)])); - TypeInfo::Enum(EnumInfo::new::(&[none_variant, some_variant])) - }) - } -} - -impl_type_path!(::core::option::Option); - impl TypePath for &'static T { fn type_path() -> &'static str { static CELL: GenericTypePathCell = GenericTypePathCell::new(); diff --git a/crates/bevy_reflect/src/lib.rs b/crates/bevy_reflect/src/lib.rs index cf4a181cbfc79..53ffa6be7a35c 100644 --- a/crates/bevy_reflect/src/lib.rs +++ b/crates/bevy_reflect/src/lib.rs @@ -1,5 +1,6 @@ // FIXME(3492): remove once docs are ready #![allow(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] //! Reflection in Rust. //! @@ -467,7 +468,6 @@ //! [orphan rule]: https://doc.rust-lang.org/book/ch10-02-traits.html#implementing-a-trait-on-a-type:~:text=But%20we%20can%E2%80%99t,implementation%20to%20use. //! [`bevy_reflect_derive/documentation`]: bevy_reflect_derive //! [derive `Reflect`]: derive@crate::Reflect -#![cfg_attr(docsrs, feature(doc_auto_cfg))] mod array; mod fields; diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 49079ed55802b..4c856e5ab5116 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -39,7 +39,9 @@ ios_simulator = [] # bevy bevy_app = { path = "../bevy_app", version = "0.14.0-dev" } bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" } -bevy_color = { path = "../bevy_color", version = "0.14.0-dev" } +bevy_color = { path = "../bevy_color", version = "0.14.0-dev", features = [ + "serialize", +] } bevy_core = { path = "../bevy_core", version = "0.14.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.14.0-dev" } bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.14.0-dev" } @@ -122,4 +124,5 @@ wasm-bindgen = "0.2" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_render/macros/Cargo.toml b/crates/bevy_render/macros/Cargo.toml index 231662720b351..f00570e012377 100644 --- a/crates/bevy_render/macros/Cargo.toml +++ b/crates/bevy_render/macros/Cargo.toml @@ -20,3 +20,7 @@ quote = "1.0" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_render/macros/src/lib.rs b/crates/bevy_render/macros/src/lib.rs index 43af3eff89b64..5398037e5b28e 100644 --- a/crates/bevy_render/macros/src/lib.rs +++ b/crates/bevy_render/macros/src/lib.rs @@ -1,5 +1,6 @@ // FIXME(3492): remove once docs are ready #![allow(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] mod as_bind_group; mod extract_component; diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 290b2cabcea73..0f673c10388ef 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -88,7 +88,7 @@ use std::{ pub struct RenderPlugin { pub render_creation: RenderCreation, /// If `true`, disables asynchronous pipeline compilation. - /// This has no effect on macOS, Wasm, or without the `multi-threaded` feature. + /// This has no effect on macOS, Wasm, iOS, or without the `multi-threaded` feature. pub synchronous_pipeline_compilation: bool, } diff --git a/crates/bevy_render/src/render_asset.rs b/crates/bevy_render/src/render_asset.rs index 0af7b877854dc..6bf5ce9a6ea11 100644 --- a/crates/bevy_render/src/render_asset.rs +++ b/crates/bevy_render/src/render_asset.rs @@ -7,13 +7,7 @@ use bevy_ecs::{ system::{StaticSystemParam, SystemParam, SystemParamItem, SystemState}, world::{FromWorld, Mut}, }; -use bevy_reflect::std_traits::ReflectDefault; -use bevy_reflect::{ - utility::{reflect_hasher, 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::{HashMap, HashSet}; use serde::{Deserialize, Serialize}; use std::marker::PhantomData; @@ -77,7 +71,8 @@ bitflags::bitflags! { /// [discussion about memory management](https://github.com/WebAssembly/design/issues/1397) for more /// details. #[repr(transparent)] - #[derive(Serialize, TypePath, Deserialize, Hash, Clone, Copy, PartialEq, Eq, Debug)] + #[derive(Serialize, Deserialize, Hash, Clone, Copy, PartialEq, Eq, Debug, Reflect)] + #[reflect_value(Serialize, Deserialize, Hash, PartialEq, Debug)] pub struct RenderAssetUsages: u8 { const MAIN_WORLD = 1 << 0; const RENDER_WORLD = 1 << 1; @@ -98,99 +93,6 @@ impl Default for RenderAssetUsages { } } -impl Reflect for RenderAssetUsages { - fn get_represented_type_info(&self) -> Option<&'static bevy_reflect::TypeInfo> { - Some(::type_info()) - } - fn into_any(self: Box) -> Box { - self - } - fn as_any(&self) -> &dyn std::any::Any { - self - } - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - self - } - fn into_reflect(self: Box) -> Box { - self - } - fn as_reflect(&self) -> &dyn Reflect { - self - } - fn as_reflect_mut(&mut self) -> &mut dyn Reflect { - self - } - fn apply(&mut self, value: &dyn Reflect) { - let value = value.as_any(); - if let Some(&value) = value.downcast_ref::() { - *self = value; - } else { - panic!("Value is not a {}.", Self::type_path()); - } - } - fn set(&mut self, value: Box) -> Result<(), Box> { - *self = value.take()?; - Ok(()) - } - fn reflect_kind(&self) -> bevy_reflect::ReflectKind { - ReflectKind::Value - } - fn reflect_ref(&self) -> bevy_reflect::ReflectRef { - ReflectRef::Value(self) - } - fn reflect_mut(&mut self) -> bevy_reflect::ReflectMut { - ReflectMut::Value(self) - } - fn reflect_owned(self: Box) -> bevy_reflect::ReflectOwned { - ReflectOwned::Value(self) - } - fn clone_value(&self) -> Box { - Box::new(*self) - } - fn reflect_hash(&self) -> Option { - use std::hash::Hash; - use std::hash::Hasher; - let mut hasher = reflect_hasher(); - Hash::hash(&std::any::Any::type_id(self), &mut hasher); - Hash::hash(self, &mut hasher); - Some(hasher.finish()) - } - fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option { - let value = value.as_any(); - if let Some(value) = value.downcast_ref::() { - Some(std::cmp::PartialEq::eq(self, value)) - } else { - Some(false) - } - } -} - -impl GetTypeRegistration for RenderAssetUsages { - fn get_type_registration() -> TypeRegistration { - let mut registration = TypeRegistration::of::(); - registration.insert::(FromType::::from_type()); - registration.insert::(FromType::::from_type()); - registration.insert::(FromType::::from_type()); - registration.insert::(FromType::::from_type()); - registration.insert::(FromType::::from_type()); - registration - } -} - -impl FromReflect for RenderAssetUsages { - fn from_reflect(reflect: &dyn Reflect) -> Option { - let raw_value = *reflect.as_any().downcast_ref::()?; - Self::from_bits(raw_value) - } -} - -impl Typed for RenderAssetUsages { - fn type_info() -> &'static TypeInfo { - static CELL: NonGenericTypeInfoCell = NonGenericTypeInfoCell::new(); - CELL.get_or_set(|| TypeInfo::Value(ValueInfo::new::())) - } -} - /// This plugin extracts the changed assets from the "app world" into the "render world" /// and prepares them for the GPU. They can then be accessed from the [`RenderAssets`] resource. /// diff --git a/crates/bevy_scene/Cargo.toml b/crates/bevy_scene/Cargo.toml index 061ec937513d4..7a3236be8ae35 100644 --- a/crates/bevy_scene/Cargo.toml +++ b/crates/bevy_scene/Cargo.toml @@ -40,4 +40,5 @@ rmp-serde = "1.1" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_scene/src/lib.rs b/crates/bevy_scene/src/lib.rs index 507e7cbcf619c..bcb554c3f59b5 100644 --- a/crates/bevy_scene/src/lib.rs +++ b/crates/bevy_scene/src/lib.rs @@ -1,9 +1,10 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! Provides scene definition, instantiation and serialization/deserialization. //! //! Scenes are collections of entities and their associated components that can be //! instantiated or removed from a world to allow composition. Scenes can be serialized/deserialized, //! for example to save part of the world state to a file. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] mod bundle; mod dynamic_scene; diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index ba2d5d0ed979f..a2ec75bfde094 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -39,3 +39,7 @@ radsort = "0.1" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_sprite/src/lib.rs b/crates/bevy_sprite/src/lib.rs index 685ecb0d4b54a..f7ccd2d8a187d 100644 --- a/crates/bevy_sprite/src/lib.rs +++ b/crates/bevy_sprite/src/lib.rs @@ -1,5 +1,6 @@ // FIXME(3492): remove once docs are ready #![allow(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] //! Provides 2D sprite rendering functionality. mod bundle; diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index 00cb03febad18..2110c0ec0a591 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -122,10 +122,9 @@ bitflags::bitflags! { // MSAA uses the highest 3 bits for the MSAA log2(sample count) to support up to 128x MSAA. pub struct SpritePipelineKey: u32 { const NONE = 0; - const COLORED = 1 << 0; - const HDR = 1 << 1; - const TONEMAP_IN_SHADER = 1 << 2; - const DEBAND_DITHER = 1 << 3; + const HDR = 1 << 0; + const TONEMAP_IN_SHADER = 1 << 1; + const DEBAND_DITHER = 1 << 2; const MSAA_RESERVED_BITS = Self::MSAA_MASK_BITS << Self::MSAA_SHIFT_BITS; const TONEMAP_METHOD_RESERVED_BITS = Self::TONEMAP_METHOD_MASK_BITS << Self::TONEMAP_METHOD_SHIFT_BITS; const TONEMAP_METHOD_NONE = 0 << Self::TONEMAP_METHOD_SHIFT_BITS; @@ -158,15 +157,6 @@ impl SpritePipelineKey { 1 << ((self.bits() >> Self::MSAA_SHIFT_BITS) & Self::MSAA_MASK_BITS) } - #[inline] - pub const fn from_colored(colored: bool) -> Self { - if colored { - SpritePipelineKey::COLORED - } else { - SpritePipelineKey::NONE - } - } - #[inline] pub const fn from_hdr(hdr: bool) -> Self { if hdr { @@ -495,16 +485,7 @@ pub fn queue_sprites( } } - let pipeline = pipelines.specialize( - &pipeline_cache, - &sprite_pipeline, - view_key | SpritePipelineKey::from_colored(false), - ); - let colored_pipeline = pipelines.specialize( - &pipeline_cache, - &sprite_pipeline, - view_key | SpritePipelineKey::from_colored(true), - ); + let pipeline = pipelines.specialize(&pipeline_cache, &sprite_pipeline, view_key); view_entities.clear(); view_entities.extend(visible_entities.entities.iter().map(|e| e.index() as usize)); @@ -524,27 +505,15 @@ pub fn queue_sprites( let sort_key = FloatOrd(extracted_sprite.transform.translation().z); // Add the item to the render phase - if extracted_sprite.color != LinearRgba::WHITE { - transparent_phase.add(Transparent2d { - draw_function: draw_sprite_function, - pipeline: colored_pipeline, - entity: *entity, - sort_key, - // batch_range and dynamic_offset will be calculated in prepare_sprites - batch_range: 0..0, - dynamic_offset: None, - }); - } else { - transparent_phase.add(Transparent2d { - draw_function: draw_sprite_function, - pipeline, - entity: *entity, - sort_key, - // batch_range and dynamic_offset will be calculated in prepare_sprites - batch_range: 0..0, - dynamic_offset: None, - }); - } + transparent_phase.add(Transparent2d { + draw_function: draw_sprite_function, + pipeline, + entity: *entity, + sort_key, + // batch_range and dynamic_offset will be calculated in prepare_sprites + batch_range: 0..0, + dynamic_offset: None, + }); } } } diff --git a/crates/bevy_tasks/Cargo.toml b/crates/bevy_tasks/Cargo.toml index ee73b120ac94b..b3a70bafbd4c3 100644 --- a/crates/bevy_tasks/Cargo.toml +++ b/crates/bevy_tasks/Cargo.toml @@ -29,4 +29,5 @@ web-time = { version = "0.2" } workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_text/Cargo.toml b/crates/bevy_text/Cargo.toml index 6fc3deb8a9778..cdd26c618e174 100644 --- a/crates/bevy_text/Cargo.toml +++ b/crates/bevy_text/Cargo.toml @@ -41,4 +41,5 @@ approx = "0.5.1" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_time/Cargo.toml b/crates/bevy_time/Cargo.toml index 5a7ccb9a577f1..a2ea432d86e1f 100644 --- a/crates/bevy_time/Cargo.toml +++ b/crates/bevy_time/Cargo.toml @@ -32,4 +32,5 @@ thiserror = "1.0" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_transform/Cargo.toml b/crates/bevy_transform/Cargo.toml index 5662117c684c7..13173244318ea 100644 --- a/crates/bevy_transform/Cargo.toml +++ b/crates/bevy_transform/Cargo.toml @@ -36,4 +36,5 @@ serialize = ["dep:serde", "bevy_math/serialize"] workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 92547a2fe3828..d7882c7da4d38 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -41,8 +41,10 @@ smallvec = "1.11" [features] serialize = ["serde", "smallvec/serde"] -[package.metadata.docs.rs] -all-features = true [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_ui/src/lib.rs b/crates/bevy_ui/src/lib.rs index 2ec6b130350c6..b9fffe39e63c7 100644 --- a/crates/bevy_ui/src/lib.rs +++ b/crates/bevy_ui/src/lib.rs @@ -1,11 +1,11 @@ // FIXME(3492): remove once docs are ready #![allow(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] //! This crate contains Bevy's UI system, which can be used to create UI for both 2D and 3D games //! # Basic usage //! Spawn UI elements with [`node_bundles::ButtonBundle`], [`node_bundles::ImageBundle`], [`node_bundles::TextBundle`] and [`node_bundles::NodeBundle`] //! This UI is laid out with the Flexbox and CSS Grid layout models (see ) -#![cfg_attr(docsrs, feature(doc_auto_cfg))] pub mod measurement; pub mod node_bundles; diff --git a/crates/bevy_ui/src/render/ui.wgsl b/crates/bevy_ui/src/render/ui.wgsl index 245f75eda6340..f5737f35ba514 100644 --- a/crates/bevy_ui/src/render/ui.wgsl +++ b/crates/bevy_ui/src/render/ui.wgsl @@ -113,9 +113,9 @@ fn sd_inset_rounded_box(point: vec2, size: vec2, radius: vec4, in r.w = r.w - max(inset.x, inset.w); let half_size = inner_size * 0.5; - let min = min(half_size.x, half_size.y); + let min_size = min(half_size.x, half_size.y); - r = min(max(r, vec4(0.0)), vec4(min)); + r = min(max(r, vec4(0.0)), vec4(min_size)); return sd_rounded_box(inner_point, inner_size, r); } diff --git a/crates/bevy_utils/Cargo.toml b/crates/bevy_utils/Cargo.toml index 88fe6dc0a574c..8b6ac50a76031 100644 --- a/crates/bevy_utils/Cargo.toml +++ b/crates/bevy_utils/Cargo.toml @@ -27,3 +27,7 @@ getrandom = { version = "0.2.0", features = ["js"] } [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_utils/macros/Cargo.toml b/crates/bevy_utils/macros/Cargo.toml index b30d885a1d018..998bf6e2ffec6 100644 --- a/crates/bevy_utils/macros/Cargo.toml +++ b/crates/bevy_utils/macros/Cargo.toml @@ -15,3 +15,7 @@ proc-macro2 = "1.0" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_utils/macros/src/lib.rs b/crates/bevy_utils/macros/src/lib.rs index 9b1fb1cfe5f25..23b11fd7cd2b1 100644 --- a/crates/bevy_utils/macros/src/lib.rs +++ b/crates/bevy_utils/macros/src/lib.rs @@ -1,5 +1,6 @@ // FIXME(3492): remove once docs are ready #![allow(missing_docs)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] use proc_macro::TokenStream; use quote::{format_ident, quote}; diff --git a/crates/bevy_utils/src/lib.rs b/crates/bevy_utils/src/lib.rs index d142f43fbc9ef..0f89cf9682b6d 100644 --- a/crates/bevy_utils/src/lib.rs +++ b/crates/bevy_utils/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! General utilities for first-party [Bevy] engine crates. //! //! [Bevy]: https://bevyengine.org/ diff --git a/crates/bevy_window/Cargo.toml b/crates/bevy_window/Cargo.toml index d455a2ebe834b..6555e8acb606f 100644 --- a/crates/bevy_window/Cargo.toml +++ b/crates/bevy_window/Cargo.toml @@ -34,4 +34,5 @@ smol_str = "0.2" workspace = true [package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] all-features = true diff --git a/crates/bevy_window/src/lib.rs b/crates/bevy_window/src/lib.rs index ff722ef9df243..cfee984087cae 100644 --- a/crates/bevy_window/src/lib.rs +++ b/crates/bevy_window/src/lib.rs @@ -1,10 +1,11 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! `bevy_window` provides a platform-agnostic interface for windowing in Bevy. //! //! This crate contains types for window management and events, //! used by windowing implementors such as `bevy_winit`. //! The [`WindowPlugin`] sets up some global window-related parameters and //! is part of the [`DefaultPlugins`](https://docs.rs/bevy/latest/bevy/struct.DefaultPlugins.html). -#![cfg_attr(docsrs, feature(doc_auto_cfg))] use bevy_a11y::Focus; diff --git a/crates/bevy_winit/Cargo.toml b/crates/bevy_winit/Cargo.toml index 063085b6a01b8..d617ba32970e8 100644 --- a/crates/bevy_winit/Cargo.toml +++ b/crates/bevy_winit/Cargo.toml @@ -50,8 +50,10 @@ wasm-bindgen = { version = "0.2" } web-sys = "0.3" crossbeam-channel = "0.5" -[package.metadata.docs.rs] -all-features = true [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index a50ecdf0c55e8..e5356826fa54d 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -1,10 +1,11 @@ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + //! `bevy_winit` provides utilities to handle window creation and the eventloop through [`winit`] //! //! Most commonly, the [`WinitPlugin`] is used as part of //! [`DefaultPlugins`](https://docs.rs/bevy/latest/bevy/struct.DefaultPlugins.html). //! The app's [runner](bevy_app::App::runner) is set by `WinitPlugin` and handles the `winit` [`EventLoop`]. //! See `winit_runner` for details. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] pub mod accessibility; mod converters; diff --git a/errors/Cargo.toml b/errors/Cargo.toml index 01fe856cc7ce5..d59a0b216a915 100644 --- a/errors/Cargo.toml +++ b/errors/Cargo.toml @@ -6,8 +6,13 @@ description = "Bevy's error codes" publish = false license = "MIT OR Apache-2.0" -[lints] -workspace = true [dependencies] bevy = { path = ".." } + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/examples/mobile/Cargo.toml b/examples/mobile/Cargo.toml index e1e768a2fcc75..b6bc2739b2701 100644 --- a/examples/mobile/Cargo.toml +++ b/examples/mobile/Cargo.toml @@ -34,3 +34,7 @@ label = "Bevy Example" [lints] workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/src/lib.rs b/src/lib.rs index c8a6964c57dd9..7301dfedf5591 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ #![allow(clippy::single_component_path_imports)] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] //! [![](https://bevyengine.org/assets/bevy_logo_docs.svg)](https://bevyengine.org) //! diff --git a/tools/build-templated-pages/Cargo.toml b/tools/build-templated-pages/Cargo.toml index 5b0e5e1eff65a..4079d49e6d121 100644 --- a/tools/build-templated-pages/Cargo.toml +++ b/tools/build-templated-pages/Cargo.toml @@ -6,8 +6,6 @@ description = "handle templated pages in Bevy repository" publish = false license = "MIT OR Apache-2.0" -[lints] -workspace = true [dependencies] toml_edit = { version = "0.22.7", default-features = false, features = [ @@ -17,3 +15,10 @@ tera = "1.15" serde = { version = "1.0", features = ["derive"] } bitflags = "2.3" hashbrown = { version = "0.14", features = ["serde"] } + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/tools/build-wasm-example/Cargo.toml b/tools/build-wasm-example/Cargo.toml index 511ca208d43af..969a4d3077abb 100644 --- a/tools/build-wasm-example/Cargo.toml +++ b/tools/build-wasm-example/Cargo.toml @@ -6,9 +6,14 @@ description = "Build an example for wasm" publish = false license = "MIT OR Apache-2.0" -[lints] -workspace = true [dependencies] xshell = "0.2" clap = { version = "4.0", features = ["derive"] } + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/tools/ci/Cargo.toml b/tools/ci/Cargo.toml index 7e6b3e8187205..dd3c0d265d4bf 100644 --- a/tools/ci/Cargo.toml +++ b/tools/ci/Cargo.toml @@ -6,9 +6,13 @@ description = "CI script for Bevy" publish = false license = "MIT OR Apache-2.0" -[lints] -workspace = true - [dependencies] xshell = "0.2" bitflags = "2.3" + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true diff --git a/tools/example-showcase/Cargo.toml b/tools/example-showcase/Cargo.toml index 184a002c0f86b..4058cdbed1387 100644 --- a/tools/example-showcase/Cargo.toml +++ b/tools/example-showcase/Cargo.toml @@ -6,8 +6,6 @@ description = "Run examples" publish = false license = "MIT OR Apache-2.0" -[lints] -workspace = true [dependencies] xshell = "0.2" @@ -17,3 +15,10 @@ toml_edit = { version = "0.22.7", default-features = false, features = [ "parse", ] } pbr = "1.1" + +[lints] +workspace = true + +[package.metadata.docs.rs] +rustdoc-args = ["-Zunstable-options", "--cfg", "docsrs"] +all-features = true