Reorder impl to be the same as the trait (#11076)

# Objective

- Make the implementation order consistent between all sources to fit
the order in the trait.

## Solution

- Change the implementation order.
This commit is contained in:
Tygyh 2023-12-24 18:43:55 +01:00 committed by GitHub
parent 7b8305e5b4
commit 1568d4a415
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 353 additions and 353 deletions

View File

@ -155,40 +155,6 @@ impl AssetWriter for FileAssetWriter {
})
}
fn remove_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir_all(full_path).await?;
Ok(())
})
}
fn remove_empty_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir(full_path).await?;
Ok(())
})
}
fn remove_assets_in_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir_all(&full_path).await?;
async_fs::create_dir_all(&full_path).await?;
Ok(())
})
}
fn rename<'a>(
&'a self,
old_path: &'a Path,
@ -222,4 +188,38 @@ impl AssetWriter for FileAssetWriter {
Ok(())
})
}
fn remove_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir_all(full_path).await?;
Ok(())
})
}
fn remove_empty_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir(full_path).await?;
Ok(())
})
}
fn remove_assets_in_directory<'a>(
&'a self,
path: &'a Path,
) -> BoxedFuture<'a, Result<(), AssetWriterError>> {
Box::pin(async move {
let full_path = self.root_path.join(path);
async_fs::remove_dir_all(&full_path).await?;
async_fs::create_dir_all(&full_path).await?;
Ok(())
})
}
}

View File

@ -320,6 +320,40 @@ impl AssetApp for App {
self
}
fn register_asset_processor<P: Process>(&mut self, processor: P) -> &mut Self {
if let Some(asset_processor) = self.world.get_resource::<AssetProcessor>() {
asset_processor.register_processor(processor);
}
self
}
fn register_asset_source(
&mut self,
id: impl Into<AssetSourceId<'static>>,
source: AssetSourceBuilder,
) -> &mut Self {
let id = id.into();
if self.world.get_resource::<AssetServer>().is_some() {
error!("{} must be registered before `AssetPlugin` (typically added as part of `DefaultPlugins`)", id);
}
{
let mut sources = self
.world
.get_resource_or_insert_with(AssetSourceBuilders::default);
sources.insert(id, source);
}
self
}
fn set_default_asset_processor<P: Process>(&mut self, extension: &str) -> &mut Self {
if let Some(asset_processor) = self.world.get_resource::<AssetProcessor>() {
asset_processor.set_default_processor::<P>(extension);
}
self
}
fn init_asset_loader<L: AssetLoader + FromWorld>(&mut self) -> &mut Self {
let loader = L::from_world(&mut self.world);
self.register_asset_loader(loader)
@ -372,40 +406,6 @@ impl AssetApp for App {
.preregister_loader::<L>(extensions);
self
}
fn register_asset_processor<P: Process>(&mut self, processor: P) -> &mut Self {
if let Some(asset_processor) = self.world.get_resource::<AssetProcessor>() {
asset_processor.register_processor(processor);
}
self
}
fn set_default_asset_processor<P: Process>(&mut self, extension: &str) -> &mut Self {
if let Some(asset_processor) = self.world.get_resource::<AssetProcessor>() {
asset_processor.set_default_processor::<P>(extension);
}
self
}
fn register_asset_source(
&mut self,
id: impl Into<AssetSourceId<'static>>,
source: AssetSourceBuilder,
) -> &mut Self {
let id = id.into();
if self.world.get_resource::<AssetServer>().is_some() {
error!("{} must be registered before `AssetPlugin` (typically added as part of `DefaultPlugins`)", id);
}
{
let mut sources = self
.world
.get_resource_or_insert_with(AssetSourceBuilders::default);
sources.insert(id, source);
}
self
}
}
/// A system set that holds all "track asset" operations.

View File

@ -97,6 +97,10 @@ where
})
}
fn extensions(&self) -> &[&str] {
<L as AssetLoader>::extensions(self)
}
fn deserialize_meta(&self, meta: &[u8]) -> Result<Box<dyn AssetMetaDyn>, DeserializeMetaError> {
let meta = AssetMeta::<L, ()>::deserialize(meta)?;
Ok(Box::new(meta))
@ -109,10 +113,6 @@ where
}))
}
fn extensions(&self) -> &[&str] {
<L as AssetLoader>::extensions(self)
}
fn type_name(&self) -> &'static str {
std::any::type_name::<L>()
}
@ -121,13 +121,13 @@ where
TypeId::of::<L>()
}
fn asset_type_id(&self) -> TypeId {
TypeId::of::<L::Asset>()
}
fn asset_type_name(&self) -> &'static str {
std::any::type_name::<L::Asset>()
}
fn asset_type_id(&self) -> TypeId {
TypeId::of::<L::Asset>()
}
}
pub(crate) struct LabeledAsset {

View File

@ -128,11 +128,6 @@ pub trait AssetMetaDyn: Downcast + Send + Sync {
}
impl<L: AssetLoader, P: Process> AssetMetaDyn for AssetMeta<L, P> {
fn serialize(&self) -> Vec<u8> {
ron::ser::to_string_pretty(&self, PrettyConfig::default())
.expect("type is convertible to ron")
.into_bytes()
}
fn loader_settings(&self) -> Option<&dyn Settings> {
if let AssetAction::Load { settings, .. } = &self.asset {
Some(settings)
@ -147,6 +142,11 @@ impl<L: AssetLoader, P: Process> AssetMetaDyn for AssetMeta<L, P> {
None
}
}
fn serialize(&self) -> Vec<u8> {
ron::ser::to_string_pretty(&self, PrettyConfig::default())
.expect("type is convertible to ron")
.into_bytes()
}
fn processed_info(&self) -> &Option<ProcessedInfo> {
&self.processed_info
}

View File

@ -626,10 +626,6 @@ impl Reflect for AssetPath<'static> {
self
}
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone())
}
#[inline]
fn apply(&mut self, value: &dyn Reflect) {
let value = Reflect::as_any(value);
if let Some(value) = value.downcast_ref::<Self>() {
@ -655,6 +651,10 @@ impl Reflect for AssetPath<'static> {
fn reflect_owned(self: Box<Self>) -> ReflectOwned {
ReflectOwned::Value(self)
}
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone())
}
fn reflect_hash(&self) -> Option<u64> {
let mut hasher = bevy_reflect::utility::reflect_hasher();
Hash::hash(&::core::any::Any::type_id(self), &mut hasher);

View File

@ -97,8 +97,8 @@ pub trait Decodable: Send + Sync + 'static {
}
impl Decodable for AudioSource {
type Decoder = rodio::Decoder<Cursor<AudioSource>>;
type DecoderItem = <rodio::Decoder<Cursor<AudioSource>> as Iterator>::Item;
type Decoder = rodio::Decoder<Cursor<AudioSource>>;
fn decoder(&self) -> Self::Decoder {
rodio::Decoder::new(Cursor::new(self.clone())).unwrap()

View File

@ -431,9 +431,9 @@ fn prepare_line_gizmo_bind_group(
struct SetLineGizmoBindGroup<const I: usize>;
impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetLineGizmoBindGroup<I> {
type Param = SRes<LineGizmoUniformBindgroup>;
type ViewData = ();
type ItemData = Read<DynamicUniformIndex<LineGizmoUniform>>;
type Param = SRes<LineGizmoUniformBindgroup>;
#[inline]
fn render<'w>(
@ -454,9 +454,9 @@ impl<const I: usize, P: PhaseItem> RenderCommand<P> for SetLineGizmoBindGroup<I>
struct DrawLineGizmo;
impl<P: PhaseItem> RenderCommand<P> for DrawLineGizmo {
type Param = SRes<RenderAssets<LineGizmo>>;
type ViewData = ();
type ItemData = Read<Handle<LineGizmo>>;
type Param = SRes<RenderAssets<LineGizmo>>;
#[inline]
fn render<'w>(

View File

@ -167,6 +167,22 @@ impl<B: Material, E: MaterialExtension> Material for ExtendedMaterial<B, E> {
}
}
fn alpha_mode(&self) -> crate::AlphaMode {
B::alpha_mode(&self.base)
}
fn opaque_render_method(&self) -> crate::OpaqueRendererMethod {
B::opaque_render_method(&self.base)
}
fn depth_bias(&self) -> f32 {
B::depth_bias(&self.base)
}
fn reads_view_transmission_texture(&self) -> bool {
B::reads_view_transmission_texture(&self.base)
}
fn prepass_vertex_shader() -> ShaderRef {
match E::prepass_vertex_shader() {
ShaderRef::Default => B::prepass_vertex_shader(),
@ -195,22 +211,6 @@ impl<B: Material, E: MaterialExtension> Material for ExtendedMaterial<B, E> {
}
}
fn alpha_mode(&self) -> crate::AlphaMode {
B::alpha_mode(&self.base)
}
fn depth_bias(&self) -> f32 {
B::depth_bias(&self.base)
}
fn reads_view_transmission_texture(&self) -> bool {
B::reads_view_transmission_texture(&self.base)
}
fn opaque_render_method(&self) -> crate::OpaqueRendererMethod {
B::opaque_render_method(&self.base)
}
fn specialize(
pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,

View File

@ -750,6 +750,50 @@ impl From<&StandardMaterial> for StandardMaterialKey {
}
impl Material for StandardMaterial {
fn fragment_shader() -> ShaderRef {
PBR_SHADER_HANDLE.into()
}
#[inline]
fn alpha_mode(&self) -> AlphaMode {
self.alpha_mode
}
#[inline]
fn opaque_render_method(&self) -> OpaqueRendererMethod {
match self.opaque_render_method {
// For now, diffuse transmission doesn't work under deferred rendering as we don't pack
// the required data into the GBuffer. If this material is set to `Auto`, we report it as
// `Forward` so that it's rendered correctly, even when the `DefaultOpaqueRendererMethod`
// is set to `Deferred`.
//
// If the developer explicitly sets the `OpaqueRendererMethod` to `Deferred`, we assume
// they know what they're doing and don't override it.
OpaqueRendererMethod::Auto if self.diffuse_transmission > 0.0 => {
OpaqueRendererMethod::Forward
}
other => other,
}
}
#[inline]
fn depth_bias(&self) -> f32 {
self.depth_bias
}
#[inline]
fn reads_view_transmission_texture(&self) -> bool {
self.specular_transmission > 0.0
}
fn prepass_fragment_shader() -> ShaderRef {
PBR_PREPASS_SHADER_HANDLE.into()
}
fn deferred_fragment_shader() -> ShaderRef {
PBR_SHADER_HANDLE.into()
}
fn specialize(
_pipeline: &MaterialPipeline<Self>,
descriptor: &mut RenderPipelineDescriptor,
@ -775,48 +819,4 @@ impl Material for StandardMaterial {
}
Ok(())
}
fn prepass_fragment_shader() -> ShaderRef {
PBR_PREPASS_SHADER_HANDLE.into()
}
fn deferred_fragment_shader() -> ShaderRef {
PBR_SHADER_HANDLE.into()
}
fn fragment_shader() -> ShaderRef {
PBR_SHADER_HANDLE.into()
}
#[inline]
fn alpha_mode(&self) -> AlphaMode {
self.alpha_mode
}
#[inline]
fn depth_bias(&self) -> f32 {
self.depth_bias
}
#[inline]
fn reads_view_transmission_texture(&self) -> bool {
self.specular_transmission > 0.0
}
#[inline]
fn opaque_render_method(&self) -> OpaqueRendererMethod {
match self.opaque_render_method {
// For now, diffuse transmission doesn't work under deferred rendering as we don't pack
// the required data into the GBuffer. If this material is set to `Auto`, we report it as
// `Forward` so that it's rendered correctly, even when the `DefaultOpaqueRendererMethod`
// is set to `Deferred`.
//
// If the developer explicitly sets the `OpaqueRendererMethod` to `Deferred`, we assume
// they know what they're doing and don't override it.
OpaqueRendererMethod::Auto if self.diffuse_transmission > 0.0 => {
OpaqueRendererMethod::Forward
}
other => other,
}
}
}

View File

@ -297,16 +297,16 @@ impl Reflect for DynamicArray {
array_partial_eq(self, value)
}
#[inline]
fn is_dynamic(&self) -> bool {
true
}
fn debug(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "DynamicArray(")?;
array_debug(self, f)?;
write!(f, ")")
}
#[inline]
fn is_dynamic(&self) -> bool {
true
}
}
impl Array for DynamicArray {

View File

@ -1162,23 +1162,6 @@ impl<T: FromReflect + Clone + TypePath> List for Cow<'static, [T]> {
self.to_mut().get_mut(index).map(|x| x as &mut dyn Reflect)
}
fn len(&self) -> usize {
self.as_ref().len()
}
fn iter(&self) -> ListIter {
ListIter::new(self)
}
fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> {
// into_owned() is not unnecessary here because it avoids cloning whenever you have a Cow::Owned already
#[allow(clippy::unnecessary_to_owned)]
self.into_owned()
.into_iter()
.map(|value| value.clone_value())
.collect()
}
fn insert(&mut self, index: usize, element: Box<dyn Reflect>) {
let value = element.take::<T>().unwrap_or_else(|value| {
T::from_reflect(&*value).unwrap_or_else(|| {
@ -1210,9 +1193,30 @@ impl<T: FromReflect + Clone + TypePath> List for Cow<'static, [T]> {
.pop()
.map(|value| Box::new(value) as Box<dyn Reflect>)
}
fn len(&self) -> usize {
self.as_ref().len()
}
fn iter(&self) -> ListIter {
ListIter::new(self)
}
fn drain(self: Box<Self>) -> Vec<Box<dyn Reflect>> {
// into_owned() is not unnecessary here because it avoids cloning whenever you have a Cow::Owned already
#[allow(clippy::unnecessary_to_owned)]
self.into_owned()
.into_iter()
.map(|value| value.clone_value())
.collect()
}
}
impl<T: FromReflect + Clone + TypePath> Reflect for Cow<'static, [T]> {
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
Some(<Self as Typed>::type_info())
}
fn into_any(self: Box<Self>) -> Box<dyn Any> {
self
}
@ -1269,10 +1273,6 @@ impl<T: FromReflect + Clone + TypePath> Reflect for Cow<'static, [T]> {
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {
crate::list_partial_eq(self, value)
}
fn get_represented_type_info(&self) -> Option<&'static TypeInfo> {
Some(<Self as Typed>::type_info())
}
}
impl<T: FromReflect + Clone + TypePath> Typed for Cow<'static, [T]> {

View File

@ -1900,6 +1900,10 @@ bevy_reflect::tests::Test {
})
}
fn type_ident() -> Option<&'static str> {
Some("Foo")
}
fn crate_name() -> Option<&'static str> {
Some("bevy_reflect")
}
@ -1907,10 +1911,6 @@ bevy_reflect::tests::Test {
fn module_path() -> Option<&'static str> {
Some("bevy_reflect::tests")
}
fn type_ident() -> Option<&'static str> {
Some("Foo")
}
}
// Can use `TypePath`

View File

@ -248,10 +248,30 @@ impl Map for DynamicMap {
.map(move |index| &mut *self.values.get_mut(index).unwrap().1)
}
fn get_at(&self, index: usize) -> Option<(&dyn Reflect, &dyn Reflect)> {
self.values
.get(index)
.map(|(key, value)| (&**key, &**value))
}
fn get_at_mut(&mut self, index: usize) -> Option<(&dyn Reflect, &mut dyn Reflect)> {
self.values
.get_mut(index)
.map(|(key, value)| (&**key, &mut **value))
}
fn len(&self) -> usize {
self.values.len()
}
fn iter(&self) -> MapIter {
MapIter::new(self)
}
fn drain(self: Box<Self>) -> Vec<(Box<dyn Reflect>, Box<dyn Reflect>)> {
self.values
}
fn clone_dynamic(&self) -> DynamicMap {
DynamicMap {
represented_type: self.represented_type,
@ -264,22 +284,6 @@ impl Map for DynamicMap {
}
}
fn iter(&self) -> MapIter {
MapIter::new(self)
}
fn get_at(&self, index: usize) -> Option<(&dyn Reflect, &dyn Reflect)> {
self.values
.get(index)
.map(|(key, value)| (&**key, &**value))
}
fn get_at_mut(&mut self, index: usize) -> Option<(&dyn Reflect, &mut dyn Reflect)> {
self.values
.get_mut(index)
.map(|(key, value)| (&**key, &mut **value))
}
fn insert_boxed(
&mut self,
key: Box<dyn Reflect>,
@ -306,10 +310,6 @@ impl Map for DynamicMap {
let (_key, value) = self.values.remove(index);
Some(value)
}
fn drain(self: Box<Self>) -> Vec<(Box<dyn Reflect>, Box<dyn Reflect>)> {
self.values
}
}
impl Reflect for DynamicMap {

View File

@ -49,14 +49,14 @@ impl StructLikeInfo for StructInfo {
self.type_path()
}
fn field_at(&self, index: usize) -> Option<&NamedField> {
self.field_at(index)
}
fn get_field(&self, name: &str) -> Option<&NamedField> {
self.field(name)
}
fn field_at(&self, index: usize) -> Option<&NamedField> {
self.field_at(index)
}
fn get_field_len(&self) -> usize {
self.field_len()
}
@ -88,14 +88,14 @@ impl StructLikeInfo for StructVariantInfo {
self.name()
}
fn field_at(&self, index: usize) -> Option<&NamedField> {
self.field_at(index)
}
fn get_field(&self, name: &str) -> Option<&NamedField> {
self.field(name)
}
fn field_at(&self, index: usize) -> Option<&NamedField> {
self.field_at(index)
}
fn get_field_len(&self) -> usize {
self.field_len()
}
@ -573,19 +573,19 @@ impl<'a, 'de> Visitor<'de> for StructVisitor<'a> {
formatter.write_str("reflected struct value")
}
fn visit_map<V>(self, mut map: V) -> Result<Self::Value, V::Error>
where
V: MapAccess<'de>,
{
visit_struct(&mut map, self.struct_info, self.registration, self.registry)
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
visit_struct_seq(&mut seq, self.struct_info, self.registration, self.registry)
}
fn visit_map<V>(self, mut map: V) -> Result<Self::Value, V::Error>
where
V: MapAccess<'de>,
{
visit_struct(&mut map, self.struct_info, self.registration, self.registry)
}
}
struct TupleStructVisitor<'a> {
@ -831,6 +831,19 @@ impl<'de> DeserializeSeed<'de> for VariantDeserializer {
formatter.write_str("expected either a variant index or variant name")
}
fn visit_u32<E>(self, variant_index: u32) -> Result<Self::Value, E>
where
E: Error,
{
self.0.variant_at(variant_index as usize).ok_or_else(|| {
Error::custom(format_args!(
"no variant found at index `{}` on enum `{}`",
variant_index,
self.0.type_path()
))
})
}
fn visit_str<E>(self, variant_name: &str) -> Result<Self::Value, E>
where
E: Error,
@ -844,19 +857,6 @@ impl<'de> DeserializeSeed<'de> for VariantDeserializer {
))
})
}
fn visit_u32<E>(self, variant_index: u32) -> Result<Self::Value, E>
where
E: Error,
{
self.0.variant_at(variant_index as usize).ok_or_else(|| {
Error::custom(format_args!(
"no variant found at index `{}` on enum `{}`",
variant_index,
self.0.type_path()
))
})
}
}
deserializer.deserialize_identifier(VariantVisitor(self.enum_info))
@ -876,19 +876,19 @@ impl<'a, 'de> Visitor<'de> for StructVariantVisitor<'a> {
formatter.write_str("reflected struct variant value")
}
fn visit_map<V>(self, mut map: V) -> Result<Self::Value, V::Error>
where
V: MapAccess<'de>,
{
visit_struct(&mut map, self.struct_info, self.registration, self.registry)
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
visit_struct_seq(&mut seq, self.struct_info, self.registration, self.registry)
}
fn visit_map<V>(self, mut map: V) -> Result<Self::Value, V::Error>
where
V: MapAccess<'de>,
{
visit_struct(&mut map, self.struct_info, self.registration, self.registry)
}
}
struct TupleVariantVisitor<'a> {
@ -925,6 +925,15 @@ impl<'a, 'de> Visitor<'de> for OptionVisitor<'a> {
formatter.write_str(self.enum_info.type_path())
}
fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: Error,
{
let mut option = DynamicEnum::default();
option.set_variant("None", ());
Ok(option)
}
fn visit_some<D>(self, deserializer: D) -> Result<Self::Value, D::Error>
where
D: serde::Deserializer<'de>,
@ -951,15 +960,6 @@ impl<'a, 'de> Visitor<'de> for OptionVisitor<'a> {
))),
}
}
fn visit_none<E>(self) -> Result<Self::Value, E>
where
E: Error,
{
let mut option = DynamicEnum::default();
option.set_variant("None", ());
Ok(option)
}
}
fn visit_struct<'de, T, V>(

View File

@ -426,9 +426,22 @@ impl Reflect for DynamicStruct {
self
}
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone_dynamic())
fn apply(&mut self, value: &dyn Reflect) {
if let ReflectRef::Struct(struct_value) = value.reflect_ref() {
for (i, value) in struct_value.iter_fields().enumerate() {
let name = struct_value.name_at(i).unwrap();
if let Some(v) = self.field_mut(name) {
v.apply(value);
}
}
} else {
panic!("Attempted to apply non-struct type to struct type.");
}
}
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
*self = value.take()?;
Ok(())
}
#[inline]
@ -446,22 +459,9 @@ impl Reflect for DynamicStruct {
ReflectOwned::Struct(self)
}
fn apply(&mut self, value: &dyn Reflect) {
if let ReflectRef::Struct(struct_value) = value.reflect_ref() {
for (i, value) in struct_value.iter_fields().enumerate() {
let name = struct_value.name_at(i).unwrap();
if let Some(v) = self.field_mut(name) {
v.apply(value);
}
}
} else {
panic!("Attempted to apply non-struct type to struct type.");
}
}
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
*self = value.take()?;
Ok(())
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone_dynamic())
}
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {

View File

@ -335,9 +335,13 @@ impl Reflect for DynamicTuple {
self
}
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone_dynamic())
fn apply(&mut self, value: &dyn Reflect) {
tuple_apply(self, value);
}
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
*self = value.take()?;
Ok(())
}
#[inline]
@ -355,13 +359,9 @@ impl Reflect for DynamicTuple {
ReflectOwned::Tuple(self)
}
fn apply(&mut self, value: &dyn Reflect) {
tuple_apply(self, value);
}
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
*self = value.take()?;
Ok(())
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone_dynamic())
}
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {

View File

@ -329,9 +329,21 @@ impl Reflect for DynamicTupleStruct {
self
}
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone_dynamic())
fn apply(&mut self, value: &dyn Reflect) {
if let ReflectRef::TupleStruct(tuple_struct) = value.reflect_ref() {
for (i, value) in tuple_struct.iter_fields().enumerate() {
if let Some(v) = self.field_mut(i) {
v.apply(value);
}
}
} else {
panic!("Attempted to apply non-TupleStruct type to TupleStruct type.");
}
}
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
*self = value.take()?;
Ok(())
}
#[inline]
@ -349,21 +361,9 @@ impl Reflect for DynamicTupleStruct {
ReflectOwned::TupleStruct(self)
}
fn apply(&mut self, value: &dyn Reflect) {
if let ReflectRef::TupleStruct(tuple_struct) = value.reflect_ref() {
for (i, value) in tuple_struct.iter_fields().enumerate() {
if let Some(v) = self.field_mut(i) {
v.apply(value);
}
}
} else {
panic!("Attempted to apply non-TupleStruct type to TupleStruct type.");
}
}
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>> {
*self = value.take()?;
Ok(())
#[inline]
fn clone_value(&self) -> Box<dyn Reflect> {
Box::new(self.clone_dynamic())
}
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool> {

View File

@ -32,6 +32,14 @@ pub trait RenderGraphApp {
}
impl RenderGraphApp for App {
fn add_render_sub_graph(&mut self, sub_graph_name: &'static str) -> &mut Self {
let mut render_graph = self.world.get_resource_mut::<RenderGraph>().expect(
"RenderGraph not found. Make sure you are using add_render_sub_graph on the RenderApp",
);
render_graph.add_sub_graph(sub_graph_name, RenderGraph::default());
self
}
fn add_render_graph_node<T: Node + FromWorld>(
&mut self,
sub_graph_name: &'static str,
@ -81,12 +89,4 @@ impl RenderGraphApp for App {
}
self
}
fn add_render_sub_graph(&mut self, sub_graph_name: &'static str) -> &mut Self {
let mut render_graph = self.world.get_resource_mut::<RenderGraph>().expect(
"RenderGraph not found. Make sure you are using add_render_sub_graph on the RenderApp",
);
render_graph.add_sub_graph(sub_graph_name, RenderGraph::default());
self
}
}

View File

@ -236,6 +236,28 @@ impl<'a, 'de> Visitor<'de> for SceneVisitor<'a> {
formatter.write_str("scene struct")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let resources = seq
.next_element_seed(SceneMapDeserializer {
registry: self.type_registry,
})?
.ok_or_else(|| Error::missing_field(SCENE_RESOURCES))?;
let entities = seq
.next_element_seed(SceneEntitiesDeserializer {
type_registry: self.type_registry,
})?
.ok_or_else(|| Error::missing_field(SCENE_ENTITIES))?;
Ok(DynamicScene {
resources,
entities,
})
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
@ -271,28 +293,6 @@ impl<'a, 'de> Visitor<'de> for SceneVisitor<'a> {
entities,
})
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let resources = seq
.next_element_seed(SceneMapDeserializer {
registry: self.type_registry,
})?
.ok_or_else(|| Error::missing_field(SCENE_RESOURCES))?;
let entities = seq
.next_element_seed(SceneEntitiesDeserializer {
type_registry: self.type_registry,
})?
.ok_or_else(|| Error::missing_field(SCENE_ENTITIES))?;
Ok(DynamicScene {
resources,
entities,
})
}
}
/// Handles deserialization for a collection of entities.
@ -455,6 +455,20 @@ impl<'a, 'de> Visitor<'de> for SceneMapVisitor<'a> {
formatter.write_str("map of reflect types")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let mut dynamic_properties = Vec::new();
while let Some(entity) =
seq.next_element_seed(UntypedReflectDeserializer::new(self.registry))?
{
dynamic_properties.push(entity);
}
Ok(dynamic_properties)
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
where
A: MapAccess<'de>,
@ -478,20 +492,6 @@ impl<'a, 'de> Visitor<'de> for SceneMapVisitor<'a> {
Ok(entries)
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: SeqAccess<'de>,
{
let mut dynamic_properties = Vec::new();
while let Some(entity) =
seq.next_element_seed(UntypedReflectDeserializer::new(self.registry))?
{
dynamic_properties.push(entity);
}
Ok(dynamic_properties)
}
}
#[cfg(test)]

View File

@ -86,15 +86,15 @@ pub trait BuildChildrenTransformExt {
fn remove_parent_in_place(&mut self) -> &mut Self;
}
impl<'w, 's, 'a> BuildChildrenTransformExt for EntityCommands<'w, 's, 'a> {
fn remove_parent_in_place(&mut self) -> &mut Self {
let child = self.id();
self.commands().add(RemoveParentInPlace { child });
self
}
fn set_parent_in_place(&mut self, parent: Entity) -> &mut Self {
let child = self.id();
self.commands().add(AddChildInPlace { child, parent });
self
}
fn remove_parent_in_place(&mut self) -> &mut Self {
let child = self.id();
self.commands().add(RemoveParentInPlace { child });
self
}
}

View File

@ -211,6 +211,11 @@ pub struct PassHasher {
}
impl Hasher for PassHasher {
#[inline]
fn finish(&self) -> u64 {
self.hash
}
fn write(&mut self, _bytes: &[u8]) {
panic!("can only hash u64 using PassHasher");
}
@ -219,11 +224,6 @@ impl Hasher for PassHasher {
fn write_u64(&mut self, i: u64) {
self.hash = i;
}
#[inline]
fn finish(&self) -> u64 {
self.hash
}
}
/// A [`HashMap`] pre-configured to use [`Hashed`] keys and [`PassHash`] passthrough hashing.
@ -281,6 +281,11 @@ pub struct EntityHasher {
}
impl Hasher for EntityHasher {
#[inline]
fn finish(&self) -> u64 {
self.hash
}
fn write(&mut self, _bytes: &[u8]) {
panic!("can only hash u64 using EntityHasher");
}
@ -317,11 +322,6 @@ impl Hasher for EntityHasher {
// This is `(MAGIC * index + generation) << 32 + index`, in a single instruction.
self.hash = bits.wrapping_mul(UPPER_PHI);
}
#[inline]
fn finish(&self) -> u64 {
self.hash
}
}
/// A [`HashMap`] pre-configured to use [`EntityHash`] hashing.

View File

@ -61,10 +61,10 @@ fn setup(
struct CustomMaterial {}
impl Material2d for CustomMaterial {
fn fragment_shader() -> ShaderRef {
fn vertex_shader() -> ShaderRef {
"shaders/custom_gltf_2d.wgsl".into()
}
fn vertex_shader() -> ShaderRef {
fn fragment_shader() -> ShaderRef {
"shaders/custom_gltf_2d.wgsl".into()
}

View File

@ -72,10 +72,10 @@ impl Source for SineDecoder {
// Finally `Decodable` can be implemented for our `SineAudio`.
impl Decodable for SineAudio {
type Decoder = SineDecoder;
type DecoderItem = <SineDecoder as Iterator>::Item;
type Decoder = SineDecoder;
fn decoder(&self) -> Self::Decoder {
SineDecoder::new(self.frequency)
}