@@ -4,6 +4,7 @@ use bevy_ecs::{
4
4
system:: { ReadOnlySystemParamFetch , SystemParam , SystemParamItem , SystemState } ,
5
5
} ;
6
6
7
+ /// Implementation detail of [`Extract`]
7
8
pub struct MainWorldState < P : SystemParam > ( SystemState < P > ) ;
8
9
9
10
impl < P : SystemParam > FromWorld for MainWorldState < P > {
@@ -12,6 +13,42 @@ impl<P: SystemParam> FromWorld for MainWorldState<P> {
12
13
}
13
14
}
14
15
16
+ /// A helper for accessing [`MainWorld`] content using a system parameter.
17
+ ///
18
+ /// A [`SystemParam`] adapter which applies the contained `SystemParam` to the [`World`]
19
+ /// contained in [`MainWorld`]. This parameter only works for systems run
20
+ /// during [`RenderStage::Extract`].
21
+ ///
22
+ /// This requires that the contained [`SystemParam`] does not mutate the world, as it
23
+ /// uses [`Res<MainWorld>`](Res). To get access to the contained `SystemParam`'s item, you
24
+ /// must use [`Extract::value`]. This is required because of lifetime limitations in
25
+ /// the `SystemParam` api.
26
+ ///
27
+ /// ## Context
28
+ ///
29
+ /// [`RenderStage::Extract`] is used to extract (move) data from the simulation world ([`MainWorld`]) to the
30
+ /// render world. The render world drives rendering each frame (generally to a [Window]).
31
+ /// This design is used to allow performing calculations related to rendering a prior frame at the same
32
+ /// time as the next frame is simulated, which increases throughput (FPS).
33
+ ///
34
+ /// [`Extract`] is used to get data from the main world during [`RenderStage::Extract`].
35
+ ///
36
+ /// ## Examples
37
+ ///
38
+ /// ```rust
39
+ /// use bevy_ecs::prelude::*;
40
+ /// use bevy_render::Extract;
41
+ /// # #[derive(Component)]
42
+ /// # struct Cloud;
43
+ /// fn extract_clouds(mut commands: Commands, mut clouds: Extract<Query<Entity, With<Cloud>>>) {
44
+ /// for cloud in clouds.value().iter() {
45
+ /// commands.get_or_spawn(cloud).insert(Cloud);
46
+ /// }
47
+ /// }
48
+ /// ```
49
+ ///
50
+ /// [`RenderStage::Extract`]: crate::RenderStage::Extract
51
+ /// [Window]: bevy_window::Window
15
52
#[ derive( SystemParam ) ]
16
53
pub struct Extract < ' w , ' s , P : SystemParam + ' static >
17
54
where
0 commit comments