[Merged by Bors] - Add macro to implement reflect for struct types and migrate glam types#4540
[Merged by Bors] - Add macro to implement reflect for struct types and migrate glam types#4540PROMETHIA-27 wants to merge 57 commits intobevyengine:mainfrom
Conversation
To be compatible with non-constructible foreign types
for compatibility with non-default non-constructible foreign types
To address issues where `use bevy_reflect::Struct` is ambiguous when called from bevy_reflect
|
I could be wrong, but I believe this would break current scene formats which expect a tuple-like value: {
"type": "glam::vec3::Vec3",
"value": (1.0, 1.0, 1.0),
},This would then become: {
"type": "glam::vec3::Vec3",
"struct": {
"x": {
"type": "f32",
"value": 1.0
},
// ...
},
},This is probably okay, but worth mentioning in the migration guide at least. |
|
That makes sense. I'm having trouble confirming it from looking at bevy_serde, but I will try to test this soon. Will add it to the description. |
There was a problem hiding this comment.
Overall, I think this is a good change. I was torn at first because I like the one-line tuples defined in the scene format, but I realize now that we can just define custom serde implementations if we really wanted to keep them like that. So I'm on board!
Left a few suggestions and some points for discussion.
One last thing I think this PR really needs is a set of tests. Could you also add some of those?
|
I've verified that this change alters how glam types are serialized like you mentioned. If they're serialized directly, they work as normal (e.g. using |
Yep this is currently the case. I addressed this in #4561 to hopefully allow custom implementations to be used. But either way I think you’re okay not worrying about serialization 🙂 |
|
Nice! I'll keep working on the other suggestions in the meantime then. |
Co-authored-by: MrGVSV <49806985+MrGVSV@users.noreply.github.com>
…METHIA-27/bevy into glam-vec_struct_reflect_type
alice-i-cecile
left a comment
There was a problem hiding this comment.
This looks good. One nit about naming conventions; I didn't recognize ctor at a glance.
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
|
bors r+ |
#4540) # Objective Relevant issue: #4474 Currently glam types implement Reflect as a value, which is problematic for reflection, making scripting/editor work much more difficult. This PR re-implements them as structs. ## Solution Added a new proc macro, `impl_reflect_struct`, which replaces `impl_reflect_value` and `impl_from_reflect_value` for glam types. This macro could also be used for other types, but I don't know of any that would require it. It's specifically useful for foreign types that cannot derive Reflect normally. --- ## Changelog ### Added - `impl_reflect_struct` proc macro ### Changed - Glam reflect impls have been replaced with `impl_reflect_struct` - from_reflect's `impl_struct` altered to take an optional custom constructor, allowing non-default non-constructible foreign types to use it - Calls to `impl_struct` altered to conform to new signature - Altered glam types (All vec/mat combinations) have a different serialization structure, as they are reflected differently now. ## Migration Guide This will break altered glam types serialized to RON scenes, as they will expect to be serialized/deserialized as structs rather than values now. A future PR to add custom serialization for non-value types is likely on the way to restore previous behavior. Additionally, calls to `impl_struct` must add a `None` parameter to the end of the call to restore previous behavior. Co-authored-by: PROMETHIA-27 <42193387+PROMETHIA-27@users.noreply.github.com>
bevyengine#4540) # Objective Relevant issue: bevyengine#4474 Currently glam types implement Reflect as a value, which is problematic for reflection, making scripting/editor work much more difficult. This PR re-implements them as structs. ## Solution Added a new proc macro, `impl_reflect_struct`, which replaces `impl_reflect_value` and `impl_from_reflect_value` for glam types. This macro could also be used for other types, but I don't know of any that would require it. It's specifically useful for foreign types that cannot derive Reflect normally. --- ## Changelog ### Added - `impl_reflect_struct` proc macro ### Changed - Glam reflect impls have been replaced with `impl_reflect_struct` - from_reflect's `impl_struct` altered to take an optional custom constructor, allowing non-default non-constructible foreign types to use it - Calls to `impl_struct` altered to conform to new signature - Altered glam types (All vec/mat combinations) have a different serialization structure, as they are reflected differently now. ## Migration Guide This will break altered glam types serialized to RON scenes, as they will expect to be serialized/deserialized as structs rather than values now. A future PR to add custom serialization for non-value types is likely on the way to restore previous behavior. Additionally, calls to `impl_struct` must add a `None` parameter to the end of the call to restore previous behavior. Co-authored-by: PROMETHIA-27 <42193387+PROMETHIA-27@users.noreply.github.com>
bevyengine#4540) # Objective Relevant issue: bevyengine#4474 Currently glam types implement Reflect as a value, which is problematic for reflection, making scripting/editor work much more difficult. This PR re-implements them as structs. ## Solution Added a new proc macro, `impl_reflect_struct`, which replaces `impl_reflect_value` and `impl_from_reflect_value` for glam types. This macro could also be used for other types, but I don't know of any that would require it. It's specifically useful for foreign types that cannot derive Reflect normally. --- ## Changelog ### Added - `impl_reflect_struct` proc macro ### Changed - Glam reflect impls have been replaced with `impl_reflect_struct` - from_reflect's `impl_struct` altered to take an optional custom constructor, allowing non-default non-constructible foreign types to use it - Calls to `impl_struct` altered to conform to new signature - Altered glam types (All vec/mat combinations) have a different serialization structure, as they are reflected differently now. ## Migration Guide This will break altered glam types serialized to RON scenes, as they will expect to be serialized/deserialized as structs rather than values now. A future PR to add custom serialization for non-value types is likely on the way to restore previous behavior. Additionally, calls to `impl_struct` must add a `None` parameter to the end of the call to restore previous behavior. Co-authored-by: PROMETHIA-27 <42193387+PROMETHIA-27@users.noreply.github.com>
bevyengine#4540) # Objective Relevant issue: bevyengine#4474 Currently glam types implement Reflect as a value, which is problematic for reflection, making scripting/editor work much more difficult. This PR re-implements them as structs. ## Solution Added a new proc macro, `impl_reflect_struct`, which replaces `impl_reflect_value` and `impl_from_reflect_value` for glam types. This macro could also be used for other types, but I don't know of any that would require it. It's specifically useful for foreign types that cannot derive Reflect normally. --- ## Changelog ### Added - `impl_reflect_struct` proc macro ### Changed - Glam reflect impls have been replaced with `impl_reflect_struct` - from_reflect's `impl_struct` altered to take an optional custom constructor, allowing non-default non-constructible foreign types to use it - Calls to `impl_struct` altered to conform to new signature - Altered glam types (All vec/mat combinations) have a different serialization structure, as they are reflected differently now. ## Migration Guide This will break altered glam types serialized to RON scenes, as they will expect to be serialized/deserialized as structs rather than values now. A future PR to add custom serialization for non-value types is likely on the way to restore previous behavior. Additionally, calls to `impl_struct` must add a `None` parameter to the end of the call to restore previous behavior. Co-authored-by: PROMETHIA-27 <42193387+PROMETHIA-27@users.noreply.github.com>
Objective
Relevant issue: #4474
Currently glam types implement Reflect as a value, which is problematic for reflection, making scripting/editor work much more difficult. This PR re-implements them as structs.
Solution
Added a new proc macro,
impl_reflect_struct, which replacesimpl_reflect_valueandimpl_from_reflect_valuefor glam types. This macro could also be used for other types, but I don't know of any that would require it. It's specifically useful for foreign types that cannot derive Reflect normally.Changelog
Added
impl_reflect_structproc macroChanged
impl_reflect_structimpl_structaltered to take an optional custom constructor, allowing non-default non-constructible foreign types to use itimpl_structaltered to conform to new signatureMigration Guide
This will break altered glam types serialized to RON scenes, as they will expect to be serialized/deserialized as structs rather than values now. A future PR to add custom serialization for non-value types is likely on the way to restore previous behavior. Additionally, calls to
impl_structmust add aNoneparameter to the end of the call to restore previous behavior.