Skip to content

Conversation

cBournhonesque
Copy link
Contributor

@cBournhonesque cBournhonesque commented Mar 25, 2024

Adopted from and closes #9914 by @djeedai

Objective

Fix the use of TypeRegistry instead of TypeRegistryArc in dynamic scene and its serializer.

Rename DynamicScene::serialize_ron() into serialize() to highlight the fact this is not about serializing to RON specifically, but rather about serializing to the official Bevy scene format (.scn / .scn.ron) which the SceneLoader can deserialize (and which happens to be based in RON, but that not the object here). Also make the link with the documentation of SceneLoader so users understand the full serializing cycle of a Bevy dynamic scene.

Document SceneSerializer with an example showing how to serialize to a custom format (here: RON), which is easily transposed to serializing into any other format.

Fixes #9520

Changelog

Changed

Migration Guide

  • SceneSerializer and all related serializing helper types now take a &TypeRegistry instead of a &TypeRegistryArc. You can upgrade by getting the former from the latter with TypeRegistryArc::read(), e.g.
      let registry_arc: TypeRegistryArc = [...];
    - let serializer = SceneSerializer(&scene, &registry_arc);
    + let registry = registry_arc.read();
    + let serializer = SceneSerializer(&scene, &registry);
  • Rename DynamicScene::serialize_ron() to serialize().

djeedai and others added 8 commits September 24, 2023 16:16
Fix the use of `TypeRegistry` instead of `TypeRegistryArc` in dynamic
scene and its serializer.

Rename `DynamicScene::serialize_ron()` into `serialize()` to highlight
the fact this is less about serializing to RON and more about
serializing to the official Bevy scene format (`.scn` / `.scn.ron`)
which the `SceneLoader` can deserialize. The fact the format is based on
RON is not the object here.

Document `SceneSerializer` with an example showing how to serialize to
RON, which is easily transposed to serializing into any other format.
Also make the link with the documentation of `SceneLoader` so users
understand the full serializing cycle of a Bevy dynamic scene.

Fixes bevyengine#9520
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types A-Scenes Serialized ECS data stored on the disk M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide labels Mar 25, 2024
Copy link
Member

@james7132 james7132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No real objections other than the potential cost of allocation for the serialization. LGTM.

#[cfg(feature = "serialize")]
pub fn serialize_ron(&self, registry: &TypeRegistryArc) -> Result<String, ron::Error> {
pub fn serialize(&self, registry: &TypeRegistry) -> Result<String, ron::Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would support serializing the results to an arbitary output stream (i..e std::io::Write) instead of materializing the results to a string then writing that string out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably done in a different PR, right? The output type change seems unrelated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, different PR

@djeedai
Copy link
Contributor

djeedai commented Mar 26, 2024

CI seems to have a bug, @mockersf do you know about this? Looking at CI miri, it complains about duplicate sysroot. Unrelated to this PR.

@james7132 james7132 added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 27, 2024
@james7132 james7132 added this pull request to the merge queue Mar 28, 2024
Merged via the queue into bevyengine:main with commit 760c645 Mar 28, 2024
@djeedai
Copy link
Contributor

djeedai commented Mar 29, 2024

Thanks @cBournhonesque for fixing this!

zhaop added a commit to zhaop/bevy_editor_pls that referenced this pull request Jun 24, 2024
zhaop added a commit to zhaop/bevy_editor_pls that referenced this pull request Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types A-Scenes Serialized ECS data stored on the disk C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SceneSerializer needlessly uses specifically &TypeRegistryArc
5 participants