From faeccd7a09d6871abd332a46eab892612acd3620 Mon Sep 17 00:00:00 2001 From: Nathan Stocks Date: Tue, 9 Mar 2021 23:39:41 +0000 Subject: [PATCH] Reflection cleanup (#1536) This is an effort to provide the correct `#[reflect_value(...)]` attributes where they are needed. Supersedes #1533 and resolves #1528. --- I am working under the following assumptions (thanks to @bjorn3 and @Davier for advice here): - Any `enum` that derives `Reflect` and one or more of { `Serialize`, `Deserialize`, `PartialEq`, `Hash` } needs a `#[reflect_value(...)]` attribute containing the same subset of { `Serialize`, `Deserialize`, `PartialEq`, `Hash` } that is present on the derive. - Same as above for `struct` and `#[reflect(...)]`, respectively. - If a `struct` is used as a component, it should also have `#[reflect(Component)]` - All reflected types should be registered in their plugins I treated the following as components (added `#[reflect(Component)]` if necessary): - `bevy_render` - `struct RenderLayers` - `bevy_transform` - `struct GlobalTransform` - `struct Parent` - `struct Transform` - `bevy_ui` - `struct Style` Not treated as components: - `bevy_math` - `struct Size` - `struct Rect` - Note: The updates for `Size` and `Rect` in `bevy::math::geometry` required using @Davier's suggestion to add `+ PartialEq` to the trait bound. I then registered the specific types used over in `bevy_ui` such as `Size`, etc. in `bevy_ui`'s plugin, since `bevy::math` does not contain a plugin. - `bevy_render` - `struct Color` - `struct PipelineSpecialization` - `struct ShaderSpecialization` - `enum PrimitiveTopology` - `enum IndexFormat` Not Addressed: - I am not searching for components in Bevy that are _not_ reflected. So if there are components that are not reflected that should be reflected, that will need to be figured out in another PR. - I only added `#[reflect(...)]` or `#[reflect_value(...)]` entries for the set of four traits { `Serialize`, `Deserialize`, `PartialEq`, `Hash` } _if they were derived via `#[derive(...)]`_. I did not look for manual trait implementations of the same set of four, nor did I consider any traits outside the four. Are those other possibilities something that needs to be looked into? --- crates/bevy_core/src/lib.rs | 3 ++ crates/bevy_math/src/geometry.rs | 30 +++++++++-------- crates/bevy_reflect/src/impls/std.rs | 32 +++++++++++++++++-- crates/bevy_reflect/src/lib.rs | 3 ++ .../src/camera/visible_entities.rs | 2 +- crates/bevy_render/src/color.rs | 3 +- crates/bevy_render/src/lib.rs | 10 ++++-- .../src/pipeline/pipeline_compiler.rs | 4 ++- .../src/pipeline/state_descriptors.rs | 4 ++- crates/bevy_sprite/src/lib.rs | 1 + .../src/components/global_transform.rs | 2 +- .../bevy_transform/src/components/parent.rs | 4 +-- .../src/components/transform.rs | 2 +- crates/bevy_ui/src/lib.rs | 16 ++++++++++ crates/bevy_ui/src/ui_node.rs | 1 + 15 files changed, 91 insertions(+), 26 deletions(-) diff --git a/crates/bevy_core/src/lib.rs b/crates/bevy_core/src/lib.rs index e26be88c13..13700a005b 100644 --- a/crates/bevy_core/src/lib.rs +++ b/crates/bevy_core/src/lib.rs @@ -18,6 +18,7 @@ pub mod prelude { use bevy_app::prelude::*; use bevy_ecs::{entity::Entity, system::IntoSystem}; +use bevy_utils::HashSet; use std::ops::Range; /// Adds core functionality to Apps. @@ -36,6 +37,8 @@ impl Plugin for CorePlugin { app.init_resource::