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

Add a scope API for world schedules #8387

Merged
merged 20 commits into from
Apr 16, 2023
Merged

Conversation

JoJoJet
Copy link
Member

@JoJoJet JoJoJet commented Apr 14, 2023

Objective

If you want to execute a schedule on the world using arbitrarily complex behavior, you currently need to use "hokey-pokey strats": remove the schedule from the world, do your thing, and add it back to the world. Not only is this cumbersome, it's potentially error-prone as one might forget to re-insert the schedule.

Solution

Add the World::{try}schedule_scope{ref} family of functions, which is a convenient abstraction over hokey pokey strats. This method essentially works the same way as World::resource_scope.

Example

// Run the schedule five times.
world.schedule_scope(MySchedule, |world, schedule| {
    for _ in 0..5 {
        schedule.run(world);
    }
});

Changelog

Added the World::schedule_scope family of methods, which provide a way to get mutable access to a world and one of its schedules at the same time.

@JoJoJet JoJoJet added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events labels Apr 14, 2023
@alice-i-cecile alice-i-cecile added C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed C-Feature A new feature, making something new possible labels Apr 14, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Very nice: I was hoping we'd get these.

@alice-i-cecile alice-i-cecile added this to the 0.11 milestone Apr 14, 2023
@james7132 james7132 added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Apr 15, 2023
@github-actions
Copy link
Contributor

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.

@james7132 james7132 removed the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Apr 15, 2023
@james7132 james7132 self-requested a review April 15, 2023 00:44
@hymm
Copy link
Contributor

hymm commented Apr 15, 2023

I'm not a big fan of the proliferation of the _ref functions, given the footgun with double boxing the label. Code quality looks good otherwise.

@JoJoJet
Copy link
Member Author

JoJoJet commented Apr 15, 2023

I'm not a big fan of the proliferation of the _ref functions, given the footgun with double boxing the label. Code quality looks good otherwise.

I agree. I think we should merge the ref variants with the owned versions of these functions, but I'm including them for now for consistency with how {try_}run_schedule already works.

@alice-i-cecile alice-i-cecile requested a review from hymm April 15, 2023 20:05
@alice-i-cecile alice-i-cecile 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 Apr 15, 2023
crates/bevy_ecs/src/world/mod.rs Outdated Show resolved Hide resolved
@james7132 james7132 enabled auto-merge April 16, 2023 04:57
@james7132 james7132 added this pull request to the merge queue Apr 16, 2023
Merged via the queue into bevyengine:main with commit 0174d63 Apr 16, 2023
@JoJoJet JoJoJet deleted the schedule-scope branch April 16, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Usability A targeted quality-of-life change that makes Bevy easier to use 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.

4 participants