Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine scene serialization sections #6

Merged
merged 4 commits into from
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 86 additions & 99 deletions content/learn/book/migration-guides/0.8-0.9/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ commands.entity(some_entity).remove_bundle::<SomeBundle>();
// New (0.9)
commands.entity(some_entity).remove::<SomeBundle>();
```

Replace `remove_bundle_intersection` with `remove_intersection`:

```rust
Expand Down Expand Up @@ -624,45 +625,88 @@ After:
);
```

### [Replace root list with struct](https://github.com/bevyengine/bevy/pull/6354)
### Scene serialization format improvements from [#6354](https://github.com/bevyengine/bevy/pull/6354), [#6345](https://github.com/bevyengine/bevy/pull/6345), and [#5723](https://github.com/bevyengine/bevy/pull/5723)

The scene file format now uses a struct as the root object rather than a list of entities. The list of entities is now found in the `entities` field of this struct.
* The root of the scene is now a struct rather than a list
* Components are now a map keyed by type name rather than a list
* Type information is now omitted when possible, making scenes much more compact

```rust
Scenes serialized with Bevy 0.8 will need to be recreated, but it is possible to hand-edit scenes to match the new format.

Here's an example scene in the old and new format:

```javascript
// Old (Bevy 0.8)
[
(
entity: 0,
components: [
// Components...
]
{
"type": "bevy_transform::components::transform::Transform",
"struct": {
"translation": {
"type": "glam::vec3::Vec3",
"value": (0.0, 0.0, 0.0),
},
"rotation": {
"type": "glam::quat::Quat",
"value": (0.0, 0.0, 0.0, 1.0),
},
"scale": {
"type": "glam::vec3::Vec3",
"value": (1.0, 1.0, 1.0),
},
},
},
{
"type": "scene::ComponentB",
"struct": {
"value": {
"type": "alloc::string::String",
"value": "hello",
},
},
},
{
"type": "scene::ComponentA",
"struct": {
"x": {
"type": "f32",
"value": 1.0,
},
"y": {
"type": "f32",
"value": 2.0,
},
},
},
],
),
(
entity: 1,
components: [
{
"type": "scene::ComponentA",
"struct": {
"x": {
"type": "f32",
"value": 3.0,
},
"y": {
"type": "f32",
"value": 4.0,
},
},
},
],
),
]

// New (Bevy 0.9)
(
entities: [
(
entity: 0,
components: [
// Components...
]
),
]
)
```

### [Use map for scene `components`](https://github.com/bevyengine/bevy/pull/6345)

The scene format now uses a map to represent the collection of components. Scene files will need to update from the old list format.

```rust
// Old (Bevy 0.8)
[
(
entity: 0,
components: [
{
entities: {
0: (
components: {
"bevy_transform::components::transform::Transform": (
translation: (
x: 0.0,
Expand All @@ -676,89 +720,32 @@ The scene format now uses a map to represent the collection of components. Scene
z: 1.0
),
),
},
{
"my_crate::Foo": (
text: "Hello World",
"scene::ComponentB": (
value: "hello",
),
},
{
"my_crate::Bar": (
baz: 123,
"scene::ComponentA": (
x: 1.0,
y: 2.0,
),
},
],
),
]

// New (Bevy 0.9)
[
(
entity: 0,
components: {
"bevy_transform::components::transform::Transform": (
translation: (
x: 0.0,
y: 0.0,
z: 0.0
),
rotation: (0.0, 0.0, 0.0, 1.0),
scale: (
x: 1.0,
y: 1.0,
z: 1.0
),
1: (
components: {
"scene::ComponentA": (
x: 3.0,
y: 4.0,
),
),
"my_crate::Foo": (
text: "Hello World",
),
"my_crate::Bar": (
baz: 123
),
},
),
]
},
),
}
)
```

### [Derive `Reflect` + `FromReflect` for input types](https://github.com/bevyengine/bevy/pull/6232)

* `Input<T>` now implements `Reflect` via `#[reflect]` instead of `#[reflect_value]`. This means it now exposes its private fields via the `Reflect` trait rather than being treated as a value type. For code that relies on the `Input<T>` struct being treated as a value type by reflection, it is still possible to wrap the `Input<T>` type with a wrapper struct and apply `#[reflect_value]` to it.
* As a reminder, private fields exposed via reflection are not subject to any stability guarantees.

### [Improve serialization format even more](https://github.com/bevyengine/bevy/pull/5723)

This PR reduces the verbosity of the scene format. Scenes will need to be updated accordingly:

```js
// Old format
{
"type": "my_game::item::Item",
"struct": {
"id": {
"type": "alloc::string::String",
"value": "bevycraft:stone",
},
"tags": {
"type": "alloc::vec::Vec<alloc::string::String>",
"list": [
{
"type": "alloc::string::String",
"value": "material"
},
],
},
}
}

// New format
{
"my_game::item::Item": (
id: "bevycraft:stone",
tags: ["material"]
)
}
```

### [Relax bounds on `Option<T>`](https://github.com/bevyengine/bevy/pull/5658)

If using `Option<T>` with Bevy’s reflection API, `T` now needs to implement `FromReflect` rather than just `Clone`. This can be achieved easily by simply deriving `FromReflect`:
Expand Down