Skip to content

Commit 102020b

Browse files
committed
Rework docs to remove most of render from bevy_extract
1 parent 4dd4b93 commit 102020b

6 files changed

Lines changed: 68 additions & 68 deletions

File tree

crates/bevy_extract/src/extract_component.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use core::marker::PhantomData;
1414

1515
pub use bevy_extract_macros::ExtractComponent;
1616

17-
/// Describes how a component gets extracted for rendering.
17+
/// Describes how a component gets extracted for processing.
1818
///
19-
/// Therefore the component is transferred from the "app world" into the "render
19+
/// Therefore the component is transferred from the "app world" into the "sub
2020
/// world" in the [`ExtractSchedule`] step. This functionality is enabled by
2121
/// adding [`ExtractComponentPlugin`] with the component type.
2222
///
@@ -32,20 +32,20 @@ pub trait ExtractComponent<L: AppLabel, F = ()>: SyncComponent<L, F> {
3232
type QueryFilter: QueryFilter;
3333
/// The output from extraction, i.e. [`ExtractComponent::extract_component`].
3434
///
35-
/// The output components won't be removed automatically from the render world if the implementing component is removed,
35+
/// The output components won't be removed automatically from the sub world if the implementing component is removed,
3636
/// unless you set them in the [`SyncComponent::Target`].
3737
type Out: Bundle<Effect: NoBundleEffect>;
3838
// TODO: https://github.com/rust-lang/rust/issues/29661
3939
// type Out: Bundle<Effect: NoBundleEffect> = Self;
4040

41-
/// Defines how the component is transferred into the "render world".
41+
/// Defines how the component is transferred into the "sub world".
4242
///
4343
/// Returning `None` based on the queried item will remove the [`SyncComponent::Target`] from the entity in
44-
/// the render world.
44+
/// the sub world.
4545
fn extract_component(item: QueryItem<'_, '_, Self::QueryData>) -> Option<Self::Out>;
4646
}
4747

48-
/// This plugin extracts the components into the render world for synced
48+
/// This plugin extracts the components into the sub world for synced
4949
/// entities. To do so, it sets up the [`ExtractSchedule`] step for the
5050
/// specified [`ExtractComponent`].
5151
///
@@ -87,11 +87,11 @@ impl<
8787
fn build(&self, app: &mut App) {
8888
app.add_plugins(SyncComponentPlugin::<L, C, F>::default());
8989

90-
if let Some(render_app) = app.get_sub_app_mut(L::default()) {
90+
if let Some(sub_app) = app.get_sub_app_mut(L::default()) {
9191
if self.only_extract_visible {
92-
render_app.add_systems(ExtractSchedule, extract_visible_components::<L, C, F>);
92+
sub_app.add_systems(ExtractSchedule, extract_visible_components::<L, C, F>);
9393
} else {
94-
render_app.add_systems(ExtractSchedule, extract_components::<L, C, F>);
94+
sub_app.add_systems(ExtractSchedule, extract_components::<L, C, F>);
9595
}
9696
}
9797
}

crates/bevy_extract/src/extract_param.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use core::ops::{Deref, DerefMut};
2323
/// ## Context
2424
///
2525
/// [`ExtractSchedule`] is used to extract (move) data from the simulation world ([`MainWorld`]) to the
26-
/// render world. The render world drives rendering each frame (generally to a `Window`).
27-
/// This design is used to allow performing calculations related to rendering a prior frame at the same
26+
/// sub world. The sub world drives processing each frame (generally to a `Window`).
27+
/// This design is used to allow performing calculations related to processing a prior frame at the same
2828
/// time as the next frame is simulated, which increases throughput (FPS).
2929
///
3030
/// [`Extract`] is used to get data from the main world during [`ExtractSchedule`].

crates/bevy_extract/src/extract_plugin.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use bevy_utils::default;
1818
pub struct ExtractPlugin<L: AppLabel + Default> {
1919
/// Function that gets run at the beginning of each extraction.
2020
///
21-
/// Gets the main world and render world as arguments (in that order).
21+
/// Gets the main world and sub world as arguments (in that order).
2222
pub pre_extract: fn(&mut World, &mut World),
2323

2424
marker: PhantomData<L>,
@@ -54,68 +54,68 @@ impl<L: AppLabel + Default + Copy + Eq> Plugin for ExtractPlugin<L> {
5454
app.add_plugins(SyncWorldPlugin::<L>::default());
5555
app.init_resource::<ScratchMainWorld>();
5656

57-
let mut render_app = SubApp::new();
57+
let mut sub_app = SubApp::new();
5858

5959
let mut extract_schedule = Schedule::new(ExtractSchedule);
6060
// We skip applying any commands during the ExtractSchedule
61-
// so commands can be applied on the render thread.
61+
// so commands can be applied on the sub thread.
6262
extract_schedule.set_build_settings(ScheduleBuildSettings {
6363
auto_insert_apply_deferred: false,
6464
..default()
6565
});
6666
extract_schedule.set_apply_final_deferred(false);
6767

68-
render_app
68+
sub_app
6969
.add_schedule((self.base_schedule)())
7070
.add_schedule(extract_schedule)
7171
.allow_ambiguous_resource::<MainWorld>()
7272
.add_systems(
7373
self.schedule_label,
7474
(
75-
// This set applies the commands from the extract schedule while the render schedule
75+
// This set applies the commands from the extract schedule while the sub schedule
7676
// is running in parallel with the main app.
7777
apply_extract_commands.in_set(self.extract_set),
7878
despawn_temporary_entities::<L>.in_set(self.despawn_set),
7979
),
8080
);
8181

8282
let pre_extract = self.pre_extract;
83-
render_app.set_extract(move |main_world, render_world| {
84-
pre_extract(main_world, render_world);
83+
sub_app.set_extract(move |main_world, sub_world| {
84+
pre_extract(main_world, sub_world);
8585

8686
{
8787
#[cfg(feature = "trace")]
8888
let _stage_span = bevy_log::info_span!("entity_sync").entered();
89-
entity_sync_system::<L>(main_world, render_world);
89+
entity_sync_system::<L>(main_world, sub_world);
9090
}
9191

9292
// run extract schedule
93-
extract(main_world, render_world);
93+
extract(main_world, sub_world);
9494
});
9595

96-
app.insert_sub_app(L::default(), render_app);
96+
app.insert_sub_app(L::default(), sub_app);
9797
}
9898
}
9999

100-
/// Schedule in which data from the main world is 'extracted' into the render world.
100+
/// Schedule in which data from the main world is 'extracted' into the sub world.
101101
///
102102
/// This step should be kept as short as possible to increase the "pipelining potential" for
103-
/// running the next frame while rendering the current frame.
103+
/// running the next frame while processing the current frame.
104104
///
105-
/// This schedule is run on the render world, but it also has access to the main world.
105+
/// This schedule is run on the sub world, but it also has access to the main world.
106106
/// See [`MainWorld`] and [`Extract`](crate::Extract) for details on how to access main world data from this schedule.
107107
#[derive(ScheduleLabel, PartialEq, Eq, Debug, Clone, Hash, Default)]
108108
pub struct ExtractSchedule;
109109

110110
/// Applies the commands from the extract schedule. This happens during
111-
/// the render schedule rather than during extraction to allow the commands to run in parallel with the
112-
/// main app when pipelined rendering is enabled.
113-
fn apply_extract_commands(render_world: &mut World) {
114-
render_world.resource_scope(|render_world, mut schedules: Mut<Schedules>| {
111+
/// the sub schedule rather than during extraction to allow the commands to run in parallel with the
112+
/// main app when pipelined processing is enabled.
113+
fn apply_extract_commands(sub_world: &mut World) {
114+
sub_world.resource_scope(|sub_world, mut schedules: Mut<Schedules>| {
115115
schedules
116116
.get_mut(ExtractSchedule)
117117
.unwrap()
118-
.apply_deferred(render_world);
118+
.apply_deferred(sub_world);
119119
});
120120
}
121121
/// The simulation [`World`] of the application, stored as a resource.
@@ -131,17 +131,17 @@ pub struct MainWorld(World);
131131
#[derive(Resource, Default)]
132132
struct ScratchMainWorld(World);
133133

134-
/// Executes the [`ExtractSchedule`] step of the renderer.
135-
/// This updates the render world with the extracted ECS data of the current frame.
136-
pub fn extract(main_world: &mut World, render_world: &mut World) {
137-
// temporarily add the app world to the render world as a resource
134+
/// Executes the [`ExtractSchedule`] step of the processor.
135+
/// This updates the sub world with the extracted ECS data of the current frame.
136+
pub fn extract(main_world: &mut World, sub_world: &mut World) {
137+
// temporarily add the app world to the sub world as a resource
138138
let scratch_world = main_world.remove_resource::<ScratchMainWorld>().unwrap();
139139
let inserted_world = core::mem::replace(main_world, scratch_world.0);
140-
render_world.insert_resource(MainWorld(inserted_world));
141-
render_world.run_schedule(ExtractSchedule);
140+
sub_world.insert_resource(MainWorld(inserted_world));
141+
sub_world.run_schedule(ExtractSchedule);
142142

143143
// move the app world back, as if nothing happened.
144-
let inserted_world = render_world.remove_resource::<MainWorld>().unwrap();
144+
let inserted_world = sub_world.remove_resource::<MainWorld>().unwrap();
145145
let scratch_world = core::mem::replace(main_world, inserted_world.0);
146146
main_world.insert_resource(ScratchMainWorld(scratch_world));
147147
}
@@ -172,7 +172,7 @@ mod test {
172172
pub struct MySchedule;
173173

174174
impl MySchedule {
175-
/// Sets up the base structure of the rendering [`Schedule`].
175+
/// Sets up the base structure of the processing [`Schedule`].
176176
///
177177
/// The sets defined in this enum are configured to run in order.
178178
pub fn base_schedule() -> Schedule {
@@ -232,13 +232,13 @@ mod test {
232232
commands.spawn((RenderComponent, RenderComponentSeparate));
233233
});
234234

235-
let render_app = app.get_sub_app_mut(ExtractApp).unwrap();
235+
let sub_app = app.get_sub_app_mut(ExtractApp).unwrap();
236236

237237
// Normally RenderPlugin sets the RenderRecovery schedule as update, but for
238238
// testing we just use the Render schedule directly.
239-
render_app.update_schedule = Some(MySchedule.intern());
239+
sub_app.update_schedule = Some(MySchedule.intern());
240240

241-
render_app.world_mut().add_observer(
241+
sub_app.world_mut().add_observer(
242242
|event: On<Add, (RenderComponent, RenderComponentExtra)>, mut commands: Commands| {
243243
// Simulate data that's not extracted
244244
commands
@@ -251,8 +251,8 @@ mod test {
251251

252252
// Check that all components have been extracted
253253
{
254-
let render_app = app.get_sub_app_mut(ExtractApp).unwrap();
255-
render_app
254+
let sub_app = app.get_sub_app_mut(ExtractApp).unwrap();
255+
sub_app
256256
.world_mut()
257257
.run_system_cached(
258258
|entity: Single<(
@@ -286,8 +286,8 @@ mod test {
286286

287287
// Check that the extracted components have been removed
288288
{
289-
let render_app = app.get_sub_app_mut(ExtractApp).unwrap();
290-
render_app
289+
let sub_app = app.get_sub_app_mut(ExtractApp).unwrap();
290+
sub_app
291291
.world_mut()
292292
.run_system_cached(
293293
|entity: Single<(

crates/bevy_extract/src/extract_resource.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use bevy_utils::once;
77

88
use crate::{Extract, ExtractSchedule};
99

10-
/// Describes how a resource gets extracted for rendering.
10+
/// Describes how a resource gets extracted for processing.
1111
///
12-
/// Therefore the resource is transferred from the "main world" into the "render world"
12+
/// Therefore the resource is transferred from the "main world" into the "sub world"
1313
/// in the [`ExtractSchedule`] step.
1414
///
1515
/// The marker type `F` is only used as a way to bypass the orphan rules. To
@@ -18,11 +18,11 @@ use crate::{Extract, ExtractSchedule};
1818
pub trait ExtractResource<L: AppLabel, F = ()>: Resource {
1919
type Source: Resource;
2020

21-
/// Defines how the resource is transferred into the "render world".
21+
/// Defines how the resource is transferred into the "sub world".
2222
fn extract_resource(source: &Self::Source) -> Self;
2323
}
2424

25-
/// This plugin extracts the resources into the "render world".
25+
/// This plugin extracts the resources into the "sub world".
2626
///
2727
/// Therefore it sets up the[`ExtractSchedule`] step
2828
/// for the specified [`Resource`].
@@ -47,11 +47,11 @@ impl<
4747
> Plugin for ExtractResourcePlugin<L, R, F>
4848
{
4949
fn build(&self, app: &mut App) {
50-
if let Some(render_app) = app.get_sub_app_mut(L::default()) {
51-
render_app.add_systems(ExtractSchedule, extract_resource::<L, R, F>);
50+
if let Some(sub_app) = app.get_sub_app_mut(L::default()) {
51+
sub_app.add_systems(ExtractSchedule, extract_resource::<L, R, F>);
5252
} else {
5353
once!(bevy_log::error!(
54-
"Render app did not exist when trying to add `extract_resource` for <{}>.",
54+
"Sub app did not exist when trying to add `extract_resource` for <{}>.",
5555
core::any::type_name::<R>()
5656
));
5757
}
@@ -73,7 +73,7 @@ pub fn extract_resource<L: AppLabel, R: ExtractResource<L, F, Mutability = Mutab
7373
#[cfg(debug_assertions)]
7474
if !main_resource.is_added() {
7575
once!(bevy_log::warn!(
76-
"Removing resource {} from render world not expected, adding using `Commands`.
76+
"Removing resource {} from sub world not expected, adding using `Commands`.
7777
This may decrease performance",
7878
core::any::type_name::<R>()
7979
));

crates/bevy_extract/src/sync_component.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bevy_ecs::{
1111

1212
use crate::sync_world::{EntityRecord, PendingSyncEntity, SyncToSubWorld};
1313

14-
/// Plugin that registers a component for automatic sync to the render world. See [`SyncWorldPlugin`] for more information.
14+
/// Plugin that registers a component for automatic sync to the sub world. See [`SyncWorldPlugin`] for more information.
1515
///
1616
/// This plugin is automatically added by [`ExtractComponentPlugin`], and only needs to be added for manual extraction implementations.
1717
///
@@ -22,7 +22,7 @@ use crate::sync_world::{EntityRecord, PendingSyncEntity, SyncToSubWorld};
2222
/// # Implementation details
2323
///
2424
/// It adds [`SyncToSubWorld`] as a required component to make the [`SyncWorldPlugin`] aware of the component, and
25-
/// handles cleanup of the component in the render world when it is removed from an entity.
25+
/// handles cleanup of the component in the sub world when it is removed from an entity.
2626
///
2727
/// [`ExtractComponentPlugin`]: crate::extract_component::ExtractComponentPlugin
2828
/// [`SyncWorldPlugin`]: crate::sync_world::SyncWorldPlugin
@@ -35,15 +35,15 @@ impl<L: AppLabel, C: SyncComponent<L, F>, F> Default for SyncComponentPlugin<L,
3535
}
3636

3737
/// Trait that links components from the main world with output components in
38-
/// the render world. It is used by [`SyncComponentPlugin`].
38+
/// the sub world. It is used by [`SyncComponentPlugin`].
3939
///
4040
/// The marker type `F` is only used as a way to bypass the orphan rules. To
4141
/// implement the trait for a foreign type you can use a local type as the
4242
/// marker, e.g. the type of the plugin that calls [`SyncComponentPlugin`].
4343
///
4444
/// [`ExtractComponent`]: crate::extract_component::ExtractComponent
4545
pub trait SyncComponent<L: AppLabel, F = ()>: Component {
46-
/// Describes what components should be removed from the render world if the
46+
/// Describes what components should be removed from the sub world if the
4747
/// implementing component is removed.
4848
type Target: Bundle<Effect: NoBundleEffect>;
4949
// TODO: https://github.com/rust-lang/rust/issues/29661

crates/bevy_extract/src/sync_world.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bevy_ecs::{
1616
use bevy_platform::collections::{HashMap, HashSet};
1717
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
1818

19-
/// A plugin that synchronizes entities with [`SyncToSubWorld`] between the main world and the render world.
19+
/// A plugin that synchronizes entities with [`SyncToSubWorld`] between the main world and the sub world.
2020
///
2121
/// All entities with the [`SyncToSubWorld`] component are kept in sync. It
2222
/// is automatically added as a required component by [`ExtractComponentPlugin`]
@@ -30,25 +30,25 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
3030
/// This is called "Pipelined Rendering", see [`PipelinedRenderingPlugin`] for more information.
3131
///
3232
/// [`SyncWorldPlugin`] is the first thing that runs every frame and it maintains an entity-to-entity mapping
33-
/// between the main world and the render world.
34-
/// It does so by spawning and despawning entities in the render world, to match spawned and despawned entities in the main world.
33+
/// between the main world and the sub world.
34+
/// It does so by spawning and despawning entities in the sub world, to match spawned and despawned entities in the main world.
3535
/// The link between synced entities is maintained by the [`SubEntity`] and [`MainEntity`] components.
3636
///
37-
/// The [`SubEntity`] contains the corresponding render world entity of a main world entity, while [`MainEntity`] contains
38-
/// the corresponding main world entity of a render world entity.
37+
/// The [`SubEntity`] contains the corresponding sub world entity of a main world entity, while [`MainEntity`] contains
38+
/// the corresponding main world entity of a sub world entity.
3939
/// For convenience, [`QueryData`](bevy_ecs::query::QueryData) implementations are provided for both components:
4040
/// adding [`MainEntity`] to a query (without a `&`) will return the corresponding main world [`Entity`],
41-
/// and adding [`SubEntity`] will return the corresponding render world [`Entity`].
41+
/// and adding [`SubEntity`] will return the corresponding sub world [`Entity`].
4242
/// If you have access to the component itself, the underlying entities can be accessed by calling `.id()`.
4343
///
4444
/// Synchronization is necessary preparation for extraction ([`ExtractSchedule`](crate::ExtractSchedule)), which copies over component data from the main
45-
/// to the render world for these entities.
45+
/// to the sub world for these entities.
4646
///
4747
/// ```text
4848
/// |--------------------------------------------------------------------|
4949
/// | | | Main world update |
5050
/// | sync | extract |---------------------------------------------------|
51-
/// | | | Render world update |
51+
/// | | | Sub world update |
5252
/// |--------------------------------------------------------------------|
5353
/// ```
5454
///
@@ -62,7 +62,7 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
6262
/// | ID: 18v1 | PointLight | SubEntity(ID: 5V1) | SyncToSubWorld |
6363
/// |-------------------------------------------------------------------|
6464
///
65-
/// |----------Render World-----------|
65+
/// |----------Sub world-----------|
6666
/// | Entity | Component |
6767
/// |---------------------------------|
6868
/// | ID: 3v1 | MainEntity(ID: 1V1) |
@@ -71,15 +71,15 @@ use bevy_reflect::{std_traits::ReflectDefault, Reflect};
7171
///
7272
/// ```
7373
///
74-
/// Note that this effectively establishes a link between the main world entity and the render world entity.
74+
/// Note that this effectively establishes a link between the main world entity and the sub world entity.
7575
/// Not every entity needs to be synchronized, however; only entities with the [`SyncToSubWorld`] component are synced.
7676
/// Adding [`SyncToSubWorld`] to a main world component will establish such a link.
77-
/// Once a synchronized main entity is despawned, its corresponding render entity will be automatically
77+
/// Once a synchronized main entity is despawned, its corresponding sub entity will be automatically
7878
/// despawned in the next `sync`.
7979
///
8080
/// The sync step does not copy any of component data between worlds, since its often not necessary to transfer over all
8181
/// the components of a main world entity.
82-
/// The render world probably cares about a `Position` component, but not a `Velocity` component.
82+
/// The sub world probably cares about a `Position` component, but not a `Velocity` component.
8383
/// The extraction happens in its own step, independently from, and after synchronization.
8484
///
8585
/// Moreover, [`SyncWorldPlugin`] only synchronizes *entities*. [`RenderAsset`]s like meshes and textures are handled

0 commit comments

Comments
 (0)