Skip to content

Commit 90659d4

Browse files
committed
Add some docs
1 parent 80babbf commit 90659d4

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

crates/bevy_render/src/extract_param.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use bevy_ecs::{
44
system::{ReadOnlySystemParamFetch, SystemParam, SystemParamItem, SystemState},
55
};
66

7+
/// Implementation detail of [`Extract`]
78
pub struct MainWorldState<P: SystemParam>(SystemState<P>);
89

910
impl<P: SystemParam> FromWorld for MainWorldState<P> {
@@ -12,6 +13,42 @@ impl<P: SystemParam> FromWorld for MainWorldState<P> {
1213
}
1314
}
1415

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
1552
#[derive(SystemParam)]
1653
pub struct Extract<'w, 's, P: SystemParam + 'static>
1754
where

crates/bevy_render/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ pub enum RenderStage {
8181
Cleanup,
8282
}
8383

84-
/// The Render App World. This is only available as a resource during the Extract step.
84+
/// The simulation [World] of the application, stored as a resource.
85+
/// This resource is only available during [`RenderStage::Extract`].
86+
/// See [`Extract`] for more details.
8587
#[derive(Default)]
8688
pub struct MainWorld(World);
8789

@@ -110,7 +112,7 @@ pub mod main_graph {
110112
pub struct RenderApp;
111113

112114
/// A "scratch" world used to avoid allocating new worlds every frame when
113-
/// swapping out the [`RenderWorld`].
115+
/// swapping out the [`MainWorld`] for [`RenderStage::Extract`].
114116
#[derive(Default)]
115117
struct ScratchMainWorld(World);
116118

0 commit comments

Comments
 (0)