Merge branch 'main' into construct_lighting_input

This commit is contained in:
TheBigCheese 2025-03-22 15:34:07 +00:00 committed by GitHub
commit c6d9cd488b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 94 additions and 100 deletions

View File

@ -18,28 +18,17 @@ bevy_reflect = [
"dep:bevy_reflect", "dep:bevy_reflect",
"bevy_app/bevy_reflect", "bevy_app/bevy_reflect",
"bevy_ecs/bevy_reflect", "bevy_ecs/bevy_reflect",
"bevy_input_focus/bevy_reflect",
] ]
## Adds serialization support through `serde`. ## Adds serialization support through `serde`.
serialize = [ serialize = ["dep:serde", "bevy_ecs/serialize", "accesskit/serde"]
"dep:serde",
"bevy_ecs/serialize",
"bevy_input_focus/serialize",
"accesskit/serde",
]
# Platform Compatibility # Platform Compatibility
## Allows access to the `std` crate. Enabling this feature will prevent compilation ## Allows access to the `std` crate. Enabling this feature will prevent compilation
## on `no_std` targets, but provides access to certain additional features on ## on `no_std` targets, but provides access to certain additional features on
## supported platforms. ## supported platforms.
std = [ std = ["bevy_app/std", "bevy_ecs/std", "bevy_reflect/std"]
"bevy_app/std",
"bevy_ecs/std",
"bevy_reflect/std",
"bevy_input_focus/std",
]
## `critical-section` provides the building blocks for synchronization primitives ## `critical-section` provides the building blocks for synchronization primitives
## on all platforms, including `no_std`. ## on all platforms, including `no_std`.
@ -47,19 +36,14 @@ critical-section = [
"bevy_app/critical-section", "bevy_app/critical-section",
"bevy_ecs/critical-section", "bevy_ecs/critical-section",
"bevy_reflect?/critical-section", "bevy_reflect?/critical-section",
"bevy_input_focus/critical-section",
] ]
## Uses the `libm` maths library instead of the one provided in `std` and `core`.
libm = ["bevy_input_focus/libm"]
[dependencies] [dependencies]
# bevy # bevy
bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false } bevy_app = { path = "../bevy_app", version = "0.16.0-dev", default-features = false }
bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" } bevy_derive = { path = "../bevy_derive", version = "0.16.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev", default-features = false } bevy_ecs = { path = "../bevy_ecs", version = "0.16.0-dev", default-features = false }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", default-features = false, optional = true } bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", default-features = false, optional = true }
bevy_input_focus = { path = "../bevy_input_focus", version = "0.16.0-dev", default-features = false }
# other # other
accesskit = { version = "0.17", default-features = false } accesskit = { version = "0.17", default-features = false }

View File

@ -12,7 +12,7 @@ keywords = ["bevy"]
trace = [] trace = []
webgl = [] webgl = []
webgpu = [] webgpu = []
dds = ["bevy_render/dds", "bevy_image/dds"] dds = ["bevy_render/dds", "bevy_image/dds", "bevy_core_pipeline/dds"]
smaa_luts = ["bevy_render/ktx2", "bevy_image/ktx2", "bevy_image/zstd"] smaa_luts = ["bevy_render/ktx2", "bevy_image/ktx2", "bevy_image/zstd"]
[dependencies] [dependencies]

View File

@ -942,7 +942,7 @@ impl Archetypes {
let archetypes = &mut self.archetypes; let archetypes = &mut self.archetypes;
let archetype_component_count = &mut self.archetype_component_count; let archetype_component_count = &mut self.archetype_component_count;
let component_index = &mut self.by_component; let component_index = &mut self.by_component;
let archetype_id = *self *self
.by_components .by_components
.entry(archetype_identity) .entry(archetype_identity)
.or_insert_with_key(move |identity| { .or_insert_with_key(move |identity| {
@ -975,8 +975,7 @@ impl Archetypes {
.zip(sparse_set_archetype_components), .zip(sparse_set_archetype_components),
)); ));
id id
}); })
archetype_id
} }
/// Returns the number of components that are stored in archetypes. /// Returns the number of components that are stored in archetypes.

View File

@ -1585,7 +1585,7 @@ impl Bundles {
storages: &mut Storages, storages: &mut Storages,
) -> BundleId { ) -> BundleId {
let bundle_infos = &mut self.bundle_infos; let bundle_infos = &mut self.bundle_infos;
let id = *self.bundle_ids.entry(TypeId::of::<T>()).or_insert_with(|| { *self.bundle_ids.entry(TypeId::of::<T>()).or_insert_with(|| {
let mut component_ids= Vec::new(); let mut component_ids= Vec::new();
T::component_ids(components, &mut |id| component_ids.push(id)); T::component_ids(components, &mut |id| component_ids.push(id));
let id = BundleId(bundle_infos.len()); let id = BundleId(bundle_infos.len());
@ -1597,8 +1597,7 @@ impl Bundles {
unsafe { BundleInfo::new(core::any::type_name::<T>(), storages, components, component_ids, id) }; unsafe { BundleInfo::new(core::any::type_name::<T>(), storages, components, component_ids, id) };
bundle_infos.push(bundle_info); bundle_infos.push(bundle_info);
id id
}); })
id
} }
/// Registers a new [`BundleInfo`], which contains both explicit and required components for a statically known type. /// Registers a new [`BundleInfo`], which contains both explicit and required components for a statically known type.

View File

@ -931,13 +931,9 @@ impl Image {
#[cfg(all(debug_assertions, feature = "dds"))] name: String, #[cfg(all(debug_assertions, feature = "dds"))] name: String,
buffer: &[u8], buffer: &[u8],
image_type: ImageType, image_type: ImageType,
#[expect( #[cfg_attr(
clippy::allow_attributes, not(any(feature = "basis-universal", feature = "dds", feature = "ktx2")),
reason = "`unused_variables` may not always lint" expect(unused_variables, reason = "only used with certain features")
)]
#[allow(
unused_variables,
reason = "`supported_compressed_formats` is needed where the image format is `Basis`, `Dds`, or `Ktx2`; if these are disabled, then `supported_compressed_formats` is unused."
)] )]
supported_compressed_formats: CompressedImageFormats, supported_compressed_formats: CompressedImageFormats,
is_srgb: bool, is_srgb: bool,

View File

@ -329,7 +329,6 @@ critical-section = [
# Uses the `libm` maths library instead of the one provided in `std` and `core`. # Uses the `libm` maths library instead of the one provided in `std` and `core`.
libm = [ libm = [
"bevy_a11y?/libm",
"bevy_color?/libm", "bevy_color?/libm",
"bevy_input/libm", "bevy_input/libm",
"bevy_input_focus?/libm", "bevy_input_focus?/libm",

View File

@ -1,12 +1,12 @@
//! Provides `Barrier` and `BarrierWaitResult` //! Provides `Barrier` and `BarrierWaitResult`
pub use barrier::{Barrier, BarrierWaitResult}; pub use implementation::{Barrier, BarrierWaitResult};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as barrier; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod barrier { mod implementation {
use core::fmt; use core::fmt;
/// Fallback implementation of `Barrier` from the standard library. /// Fallback implementation of `Barrier` from the standard library.

View File

@ -1,11 +1,11 @@
//! Provides `LazyLock` //! Provides `LazyLock`
pub use lazy_lock::LazyLock; pub use implementation::LazyLock;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as lazy_lock; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod lazy_lock { mod implementation {
pub use spin::Lazy as LazyLock; pub use spin::Lazy as LazyLock;
} }

View File

@ -1,12 +1,12 @@
//! Provides `Mutex` and `MutexGuard` //! Provides `Mutex` and `MutexGuard`
pub use mutex::{Mutex, MutexGuard}; pub use implementation::{Mutex, MutexGuard};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as mutex; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod mutex { mod implementation {
use crate::sync::{LockResult, TryLockError, TryLockResult}; use crate::sync::{LockResult, TryLockError, TryLockResult};
use core::fmt; use core::fmt;
@ -81,7 +81,7 @@ mod mutex {
} }
} }
impl<T: ?Sized + Default> Default for Mutex<T> { impl<T: Default> Default for Mutex<T> {
fn default() -> Mutex<T> { fn default() -> Mutex<T> {
Mutex::new(Default::default()) Mutex::new(Default::default())
} }

View File

@ -1,12 +1,12 @@
//! Provides `Once`, `OnceState`, `OnceLock` //! Provides `Once`, `OnceState`, `OnceLock`
pub use once::{Once, OnceLock, OnceState}; pub use implementation::{Once, OnceLock, OnceState};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as once; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod once { mod implementation {
use core::{ use core::{
fmt, fmt,
panic::{RefUnwindSafe, UnwindSafe}, panic::{RefUnwindSafe, UnwindSafe},
@ -145,6 +145,7 @@ mod once {
/// Creates a new `Once` value. /// Creates a new `Once` value.
/// ///
/// See the standard library for further details. /// See the standard library for further details.
#[expect(clippy::new_without_default, reason = "matching std::sync::Once")]
pub const fn new() -> Self { pub const fn new() -> Self {
Self { Self {
inner: OnceLock::new(), inner: OnceLock::new(),

View File

@ -1,12 +1,12 @@
//! Provides `LockResult`, `PoisonError`, `TryLockError`, `TryLockResult` //! Provides `LockResult`, `PoisonError`, `TryLockError`, `TryLockResult`
pub use poison::{LockResult, PoisonError, TryLockError, TryLockResult}; pub use implementation::{LockResult, PoisonError, TryLockError, TryLockResult};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as poison; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod poison { mod implementation {
use core::{error::Error, fmt}; use core::{error::Error, fmt};
/// Fallback implementation of `PoisonError` from the standard library. /// Fallback implementation of `PoisonError` from the standard library.

View File

@ -1,12 +1,12 @@
//! TODO: Implement `RwLock`, `RwLockReadGuard`, `RwLockWriteGuard` //! Provides `RwLock`, `RwLockReadGuard`, `RwLockWriteGuard`
pub use rwlock::{RwLock, RwLockReadGuard, RwLockWriteGuard}; pub use implementation::{RwLock, RwLockReadGuard, RwLockWriteGuard};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::sync as rwlock; use std::sync as implementation;
#[cfg(not(feature = "std"))] #[cfg(not(feature = "std"))]
mod rwlock { mod implementation {
use crate::sync::{LockResult, TryLockError, TryLockResult}; use crate::sync::{LockResult, TryLockError, TryLockResult};
use core::fmt; use core::fmt;

View File

@ -36,7 +36,7 @@ impl Instant {
let getter = ELAPSED_GETTER.load(Ordering::Acquire); let getter = ELAPSED_GETTER.load(Ordering::Acquire);
// SAFETY: Function pointer is always valid // SAFETY: Function pointer is always valid
let getter = unsafe { core::mem::transmute::<_, fn() -> Duration>(getter) }; let getter = unsafe { core::mem::transmute::<*mut (), fn() -> Duration>(getter) };
Self((getter)()) Self((getter)())
} }
@ -149,28 +149,29 @@ impl fmt::Debug for Instant {
} }
fn unset_getter() -> Duration { fn unset_getter() -> Duration {
let _nanos: u64; cfg_if::cfg_if! {
if #[cfg(target_arch = "x86")] {
#[cfg(target_arch = "x86")] // SAFETY: standard technique for getting a nanosecond counter on x86
unsafe { let nanos = unsafe {
_nanos = core::arch::x86::_rdtsc(); core::arch::x86::_rdtsc()
};
Duration::from_nanos(nanos)
} else if #[cfg(target_arch = "x86_64")] {
// SAFETY: standard technique for getting a nanosecond counter on x86_64
let nanos = unsafe {
core::arch::x86_64::_rdtsc()
};
Duration::from_nanos(nanos)
} else if #[cfg(target_arch = "aarch64")] {
// SAFETY: standard technique for getting a nanosecond counter of aarch64
let nanos = unsafe {
let mut ticks: u64;
core::arch::asm!("mrs {}, cntvct_el0", out(reg) ticks);
ticks
};
Duration::from_nanos(nanos)
} else {
panic!("An elapsed time getter has not been provided to `Instant`. Please use `Instant::set_elapsed(...)` before calling `Instant::now()`")
}
} }
#[cfg(target_arch = "x86_64")]
unsafe {
_nanos = core::arch::x86_64::_rdtsc();
}
#[cfg(target_arch = "aarch64")]
unsafe {
let mut ticks: u64;
core::arch::asm!("mrs {}, cntvct_el0", out(reg) ticks);
_nanos = ticks;
}
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
panic!("An elapsed time getter has not been provided to `Instant`. Please use `Instant::set_elapsed(...)` before calling `Instant::now()`");
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
return Duration::from_nanos(_nanos);
} }

View File

@ -19,19 +19,18 @@ use bevy_reflect::{
serde::{ReflectSerializer, TypedReflectDeserializer}, serde::{ReflectSerializer, TypedReflectDeserializer},
GetPath, PartialReflect, TypeRegistration, TypeRegistry, GetPath, PartialReflect, TypeRegistration, TypeRegistry,
}; };
use bevy_utils::default;
use serde::{de::DeserializeSeed as _, Deserialize, Serialize}; use serde::{de::DeserializeSeed as _, Deserialize, Serialize};
use serde_json::{Map, Value}; use serde_json::{Map, Value};
use crate::{ use crate::{
error_codes, error_codes,
schemas::{ schemas::{json_schema::JsonSchemaBevyType, open_rpc::OpenRpcDocument},
json_schema::JsonSchemaBevyType,
open_rpc::{OpenRpcDocument, ServerObject},
},
BrpError, BrpResult, BrpError, BrpResult,
}; };
#[cfg(feature = "http")]
use {crate::schemas::open_rpc::ServerObject, bevy_utils::default};
/// The method path for a `bevy/get` request. /// The method path for a `bevy/get` request.
pub const BRP_GET_METHOD: &str = "bevy/get"; pub const BRP_GET_METHOD: &str = "bevy/get";
@ -821,6 +820,8 @@ pub fn process_remote_list_methods_request(
world: &mut World, world: &mut World,
) -> BrpResult { ) -> BrpResult {
let remote_methods = world.resource::<crate::RemoteMethods>(); let remote_methods = world.resource::<crate::RemoteMethods>();
#[cfg(feature = "http")]
let servers = match ( let servers = match (
world.get_resource::<crate::http::HostAddress>(), world.get_resource::<crate::http::HostAddress>(),
world.get_resource::<crate::http::HostPort>(), world.get_resource::<crate::http::HostPort>(),
@ -837,6 +838,10 @@ pub fn process_remote_list_methods_request(
}]), }]),
_ => None, _ => None,
}; };
#[cfg(not(feature = "http"))]
let servers = None;
let doc = OpenRpcDocument { let doc = OpenRpcDocument {
info: Default::default(), info: Default::default(),
methods: remote_methods.into(), methods: remote_methods.into(),

View File

@ -1,4 +1,4 @@
use crate::{ron, DynamicSceneBuilder, Scene, SceneSpawnError}; use crate::{DynamicSceneBuilder, Scene, SceneSpawnError};
use bevy_asset::Asset; use bevy_asset::Asset;
use bevy_ecs::reflect::{ReflectMapEntities, ReflectResource}; use bevy_ecs::reflect::{ReflectMapEntities, ReflectResource};
use bevy_ecs::{ use bevy_ecs::{
@ -6,15 +6,18 @@ use bevy_ecs::{
reflect::{AppTypeRegistry, ReflectComponent}, reflect::{AppTypeRegistry, ReflectComponent},
world::World, world::World,
}; };
use bevy_reflect::{PartialReflect, TypePath, TypeRegistry}; use bevy_reflect::{PartialReflect, TypePath};
use crate::reflect_utils::clone_reflect_value; use crate::reflect_utils::clone_reflect_value;
#[cfg(feature = "serialize")]
use crate::serde::SceneSerializer;
use bevy_ecs::component::ComponentCloneBehavior; use bevy_ecs::component::ComponentCloneBehavior;
use bevy_ecs::relationship::RelationshipHookMode; use bevy_ecs::relationship::RelationshipHookMode;
#[cfg(feature = "serialize")] #[cfg(feature = "serialize")]
use serde::Serialize; use {
crate::{ron, serde::SceneSerializer},
bevy_reflect::TypeRegistry,
serde::Serialize,
};
/// A collection of serializable resources and dynamic entities. /// A collection of serializable resources and dynamic entities.
/// ///

View File

@ -27,7 +27,6 @@ pub mod serde;
/// Rusty Object Notation, a crate used to serialize and deserialize bevy scenes. /// Rusty Object Notation, a crate used to serialize and deserialize bevy scenes.
pub use bevy_asset::ron; pub use bevy_asset::ron;
use bevy_ecs::schedule::IntoScheduleConfigs;
pub use components::*; pub use components::*;
pub use dynamic_scene::*; pub use dynamic_scene::*;
pub use dynamic_scene_builder::*; pub use dynamic_scene_builder::*;
@ -48,7 +47,9 @@ pub mod prelude {
} }
use bevy_app::prelude::*; use bevy_app::prelude::*;
use bevy_asset::AssetApp;
#[cfg(feature = "serialize")]
use {bevy_asset::AssetApp, bevy_ecs::schedule::IntoScheduleConfigs};
/// Plugin that provides scene functionality to an [`App`]. /// Plugin that provides scene functionality to an [`App`].
#[derive(Default)] #[derive(Default)]

View File

@ -1,21 +1,27 @@
#[cfg(feature = "serialize")] use crate::ron;
use crate::serde::SceneDeserializer;
use crate::{ron, DynamicScene};
use bevy_asset::{io::Reader, AssetLoader, LoadContext};
use bevy_ecs::{ use bevy_ecs::{
reflect::AppTypeRegistry, reflect::AppTypeRegistry,
world::{FromWorld, World}, world::{FromWorld, World},
}; };
use bevy_reflect::TypeRegistryArc; use bevy_reflect::TypeRegistryArc;
#[cfg(feature = "serialize")]
use serde::de::DeserializeSeed;
use thiserror::Error; use thiserror::Error;
#[cfg(feature = "serialize")]
use {
crate::{serde::SceneDeserializer, DynamicScene},
bevy_asset::{io::Reader, AssetLoader, LoadContext},
serde::de::DeserializeSeed,
};
/// Asset loader for a Bevy dynamic scene (`.scn` / `.scn.ron`). /// Asset loader for a Bevy dynamic scene (`.scn` / `.scn.ron`).
/// ///
/// The loader handles assets serialized with [`DynamicScene::serialize`]. /// The loader handles assets serialized with [`DynamicScene::serialize`].
#[derive(Debug)] #[derive(Debug)]
pub struct SceneLoader { pub struct SceneLoader {
#[cfg_attr(
not(feature = "serialize"),
expect(dead_code, reason = "only used with `serialize` feature")
)]
type_registry: TypeRegistryArc, type_registry: TypeRegistryArc,
} }

View File

@ -160,12 +160,13 @@ pub fn time_system(
None => None, None => None,
}; };
#[cfg(not(feature = "std"))]
let sent_time = None;
match update_strategy.as_ref() { match update_strategy.as_ref() {
TimeUpdateStrategy::Automatic => { TimeUpdateStrategy::Automatic => {
#[cfg(feature = "std")]
real_time.update_with_instant(sent_time.unwrap_or_else(Instant::now)); real_time.update_with_instant(sent_time.unwrap_or_else(Instant::now));
#[cfg(not(feature = "std"))]
real_time.update_with_instant(Instant::now());
} }
TimeUpdateStrategy::ManualInstant(instant) => real_time.update_with_instant(*instant), TimeUpdateStrategy::ManualInstant(instant) => real_time.update_with_instant(*instant),
TimeUpdateStrategy::ManualDuration(duration) => real_time.update_with_duration(*duration), TimeUpdateStrategy::ManualDuration(duration) => real_time.update_with_duration(*duration),

View File

@ -29,8 +29,7 @@ impl<T: Default + Send> Parallel<T> {
/// If there is no thread-local value, it will be initialized to its default. /// If there is no thread-local value, it will be initialized to its default.
pub fn scope<R>(&self, f: impl FnOnce(&mut T) -> R) -> R { pub fn scope<R>(&self, f: impl FnOnce(&mut T) -> R) -> R {
let mut cell = self.locals.get_or_default().borrow_mut(); let mut cell = self.locals.get_or_default().borrow_mut();
let ret = f(cell.deref_mut()); f(cell.deref_mut())
ret
} }
/// Mutably borrows the thread-local value. /// Mutably borrows the thread-local value.