Skip to content

Commit

Permalink
flip resource scope order (bevyengine#1793)
Browse files Browse the repository at this point in the history
I think [collection, thing_removed_from_collection] is a more natural order than [thing_removed_from_collection, collection]. Just a small tweak that I think we should include in 0.5.
  • Loading branch information
cart committed Apr 1, 2021
1 parent b657a9b commit f520a34
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ mod tests {
fn resource_scope() {
let mut world = World::default();
world.insert_resource::<i32>(0);
world.resource_scope(|mut value: Mut<i32>, world: &mut World| {
world.resource_scope(|world: &mut World, mut value: Mut<i32>| {
*value += 1;
assert!(!world.contains_resource::<i32>());
});
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,15 +658,15 @@ impl World {
/// world.insert_resource(A(1));
/// let entity = world.spawn().insert(B(1)).id();
///
/// world.resource_scope(|mut a: Mut<A>, world| {
/// world.resource_scope(|world, mut a: Mut<A>| {
/// let b = world.get_mut::<B>(entity).unwrap();
/// a.0 += b.0;
/// });
/// assert_eq!(world.get_resource::<A>().unwrap().0, 2);
/// ```
pub fn resource_scope<T: Component, U>(
&mut self,
f: impl FnOnce(Mut<T>, &mut World) -> U,
f: impl FnOnce(&mut World, Mut<T>) -> U,
) -> U {
let component_id = self
.components
Expand All @@ -692,7 +692,7 @@ impl World {
last_change_tick: self.last_change_tick(),
change_tick: self.change_tick(),
};
let result = f(value, self);
let result = f(self, value);
let resource_archetype = self.archetypes.resource_mut();
let unique_components = resource_archetype.unique_components_mut();
let column = unique_components
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/render_graph/nodes/pass_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
let query_state = self.query_state.get_or_insert_with(|| world.query());
let cameras = &self.cameras;
let commands = &mut self.commands;
world.resource_scope(|mut active_cameras: Mut<ActiveCameras>, world| {
world.resource_scope(|world, mut active_cameras: Mut<ActiveCameras>| {
let mut pipeline_camera_commands = HashMap::default();
let pipelines = world.get_resource::<Assets<PipelineDescriptor>>().unwrap();
let render_resource_context = &**world
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_scene/src/scene_spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl SceneSpawner {
scene_handle: &Handle<DynamicScene>,
entity_map: &mut EntityMap,
) -> Result<(), SceneSpawnError> {
world.resource_scope(|scenes: Mut<Assets<DynamicScene>>, world| {
world.resource_scope(|world, scenes: Mut<Assets<DynamicScene>>| {
let scene =
scenes
.get(scene_handle)
Expand Down Expand Up @@ -145,7 +145,7 @@ impl SceneSpawner {
};
let type_registry = world.get_resource::<TypeRegistryArc>().unwrap().clone();
let type_registry = type_registry.read();
world.resource_scope(|scenes: Mut<Assets<Scene>>, world| {
world.resource_scope(|world, scenes: Mut<Assets<Scene>>| {
let scene =
scenes
.get(&scene_handle)
Expand Down Expand Up @@ -297,7 +297,7 @@ impl SceneSpawner {
}

pub fn scene_spawner_system(world: &mut World) {
world.resource_scope(|mut scene_spawner: Mut<SceneSpawner>, world| {
world.resource_scope(|world, mut scene_spawner: Mut<SceneSpawner>| {
let scene_asset_events = world
.get_resource::<Events<AssetEvent<DynamicScene>>>()
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_wgpu/src/wgpu_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl WgpuRenderer {
}

pub fn run_graph(&mut self, world: &mut World) {
world.resource_scope(|mut render_graph: Mut<RenderGraph>, world| {
world.resource_scope(|world, mut render_graph: Mut<RenderGraph>| {
render_graph.prepare(world);
// stage nodes
let mut stager = DependentNodeStager::loose_grouping();
Expand Down

0 comments on commit f520a34

Please sign in to comment.