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

Align Scene::write_to_world_with to match DynamicScene::write_to_world_with #13714

Merged
merged 4 commits into from
Jun 10, 2024

Conversation

dmyyy
Copy link
Contributor

@dmyyy dmyyy commented Jun 6, 2024

Objective

Scene and DynamicScene work with InstanceInfo at different levels of abstraction

  • Scene::write_to_world_with returns an InstanceInfo whereas DynamicScene::write_to_world_with returns (). Instances are created one level higher at the SceneSpawner API level.
  • DynamicScene::write_to_world_with takes the entity_map as an argument whereas the Scene version is less flexible and creates a new one for you. No reason this needs to be the case.

Solution

I propose changing Scene::write_to_world_with to match the API we have for DynamicScene. Returning the InstanceInfo as we do today just seems like a leaky abstraction - it's only used in spawn_sync_internal. Being able to pass in an entity_map gives you more flexibility with how you write entities to a world.

This also moves InstanceInfo out of Scene which is cleaner conceptually. If someone wants to work with instances then they should work with SceneSpawner - I see write_to_world_with as a lower-level API to be used with exclusive world access.

Testing

Code is just shifting things around.

Changelog

Changed Scene::write_to_world_with to take entity_map as an argument and no longer return an InstanceInfo

Migration Guide

Scene::write_to_world_with no longer returns an InstanceInfo.

Before

scene.write_to_world_with(world, &registry)

After

let mut entity_map = EntityHashMap::default();
scene.write_to_world_with(world, &mut entity_map, &registry)

@alice-i-cecile alice-i-cecile added C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use 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 Jun 6, 2024
Copy link
Contributor

github-actions bot commented Jun 6, 2024

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Could you add some context on what users should update when this change get released in a new version of Bevy?
It will be used to help writing the migration guide for the version. Putting it after a ## Migration Guide will help it get automatically picked up by our tooling.

@alice-i-cecile
Copy link
Member

At some point it might make sense to use a trait to capture the API of these two types like we do in bevy_color: their type signatures should generally line up.

@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jun 6, 2024
@dmyyy
Copy link
Contributor Author

dmyyy commented Jun 6, 2024

@alice-i-cecile Any chance this makes it for 0.14? Or are things locked in place with the release candidate out now?

@alice-i-cecile
Copy link
Member

If you can convince others that this is relatively important, we will be able to cherrypick this up until 0.14.0 itself is released.

@NthTensor NthTensor added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 9, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 10, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jun 10, 2024
…orld_with` (#13714)

# Objective

`Scene` and `DynamicScene` work with `InstanceInfo` at different levels
of abstraction
- `Scene::write_to_world_with` returns an `InstanceInfo` whereas
`DynamicScene::write_to_world_with` returns `()`. Instances are created
one level higher at the `SceneSpawner` API level.
- `DynamicScene::write_to_world_with` takes the `entity_map` as an
argument whereas the `Scene` version is less flexible and creates a new
one for you. No reason this needs to be the case.

## Solution

I propose changing `Scene::write_to_world_with` to match the API we have
for `DynamicScene`. Returning the `InstanceInfo` as we do today just
seems like a leaky abstraction - it's only used in
`spawn_sync_internal`. Being able to pass in an entity_map gives you
more flexibility with how you write entities to a world.

This also moves `InstanceInfo` out of `Scene` which is cleaner
conceptually. If someone wants to work with instances then they should
work with `SceneSpawner` - I see `write_to_world_with` as a lower-level
API to be used with exclusive world access.

## Testing

Code is just shifting things around.

## Changelog

Changed `Scene::write_to_world_with` to take `entity_map` as an argument
and no longer return an `InstanceInfo`

## Migration Guide

`Scene::write_to_world_with` no longer returns an `InstanceInfo`. 

Before
```rust
scene.write_to_world_with(world, &registry)
```
After
```rust
let mut entity_map = EntityHashMap::default();
scene.write_to_world_with(world, &mut entity_map, &registry)
```
Merged via the queue into bevyengine:main with commit 1f61c26 Jun 10, 2024
28 checks passed
@pcwalton
Copy link
Contributor

This broke deferred_rendering among many other test cases. See #13796.

alice-i-cecile pushed a commit to alice-i-cecile/bevy that referenced this pull request Jun 10, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jun 10, 2024
…to_world_with (#13800)

# Objective

- #13714 broke scenes pretty
seriously
- Fixes #13796

## Solution

Revert it. We can redo this PR once the behavior is fixed.

Co-authored-by: Dmytro Banin <dima_banin@hotmail.com>
alice-i-cecile pushed a commit to Kurble/bevy that referenced this pull request Jul 15, 2024
…orld_with` (bevyengine#13855)

# Objective

Fixes a regression in [previously merged but then reverted
pr](bevyengine#13714) that aligns
lower-level `Scene` API with that in `DynamicScene`. Please look at the
original pr for more details.

The problem was `spawn_sync_internal` is used in `spawn_queued_scenes`.
Since instance creation was moved up a level we need to make sure we add
a specific instance to `SceneSpawner::spawned_instances` when using
`spawn_sync_internal` (just like we do for `DynamicScene`).

Please look at the last commit when reviewing.

## Testing

`alien_cake_addict` and `deferred_rendering` examples look as expected.

## Changelog

Changed `Scene::write_to_world_with` to take `entity_map` as an argument
and no longer return an `InstanceInfo`

## Migration Guide

`Scene::write_to_world_with` no longer returns an `InstanceInfo`. 

Before
```rust
scene.write_to_world_with(world, &registry)
```
After
```rust
let mut entity_map = EntityHashMap::default();
scene.write_to_world_with(world, &mut entity_map, &registry)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Scenes Serialized ECS data stored on the disk C-Code-Quality A section of code that is hard to understand or change C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples 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 X-Uncontroversial This work is generally agreed upon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants