Skip to content

Commit 2607987

Browse files
committed
Merge branch 'main' into query_entities
2 parents 9169590 + 50aa40e commit 2607987

File tree

21 files changed

+221
-116
lines changed

21 files changed

+221
-116
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3922,6 +3922,16 @@ description = "A simple 2D screen shake effect"
39223922
category = "Camera"
39233923
wasm = true
39243924

3925+
[[example]]
3926+
name = "2d_on_ui"
3927+
path = "examples/camera/2d_on_ui.rs"
3928+
doc-scrape-examples = true
3929+
3930+
[package.metadata.example.2d_on_ui]
3931+
name = "2D on Bevy UI"
3932+
description = "Shows how to render 2D objects on top of Bevy UI"
3933+
category = "Camera"
3934+
wasm = true
39253935

39263936
[package.metadata.example.fps_overlay]
39273937
name = "FPS overlay"

crates/bevy_anti_aliasing/src/experimental/mod.rs

Lines changed: 0 additions & 9 deletions
This file was deleted.

crates/bevy_anti_aliasing/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ use bevy_app::Plugin;
1010
use contrast_adaptive_sharpening::CasPlugin;
1111
use fxaa::FxaaPlugin;
1212
use smaa::SmaaPlugin;
13+
use taa::TemporalAntiAliasPlugin;
1314

1415
pub mod contrast_adaptive_sharpening;
15-
pub mod experimental;
1616
pub mod fxaa;
1717
pub mod smaa;
18-
19-
mod taa;
18+
pub mod taa;
2019

2120
#[derive(Default)]
2221
pub struct AntiAliasingPlugin;
2322
impl Plugin for AntiAliasingPlugin {
2423
fn build(&self, app: &mut bevy_app::App) {
25-
app.add_plugins((FxaaPlugin, CasPlugin, SmaaPlugin));
24+
app.add_plugins((FxaaPlugin, SmaaPlugin, TemporalAntiAliasPlugin, CasPlugin));
2625
}
2726
}

crates/bevy_anti_aliasing/src/taa/mod.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Plugin for TemporalAntiAliasPlugin {
6262
.add_systems(
6363
Render,
6464
(
65-
prepare_taa_jitter_and_mip_bias.in_set(RenderSystems::ManageViews),
65+
prepare_taa_jitter.in_set(RenderSystems::ManageViews),
6666
prepare_taa_pipelines.in_set(RenderSystems::Prepare),
6767
prepare_taa_history_textures.in_set(RenderSystems::PrepareResources),
6868
),
@@ -113,7 +113,6 @@ impl Plugin for TemporalAntiAliasPlugin {
113113
///
114114
/// # Usage Notes
115115
///
116-
/// The [`TemporalAntiAliasPlugin`] must be added to your app.
117116
/// Any camera with this component must also disable [`Msaa`] by setting it to [`Msaa::Off`].
118117
///
119118
/// [Currently](https://github.com/bevyengine/bevy/issues/8423), TAA cannot be used with [`bevy_render::camera::OrthographicProjection`].
@@ -126,11 +125,9 @@ impl Plugin for TemporalAntiAliasPlugin {
126125
///
127126
/// 1. Write particle motion vectors to the motion vectors prepass texture
128127
/// 2. Render particles after TAA
129-
///
130-
/// If no [`MipBias`] component is attached to the camera, TAA will add a `MipBias(-1.0)` component.
131128
#[derive(Component, Reflect, Clone)]
132129
#[reflect(Component, Default, Clone)]
133-
#[require(TemporalJitter, DepthPrepass, MotionVectorPrepass)]
130+
#[require(TemporalJitter, MipBias, DepthPrepass, MotionVectorPrepass)]
134131
#[doc(alias = "Taa")]
135132
pub struct TemporalAntiAliasing {
136133
/// Set to true to delete the saved temporal history (past frames).
@@ -345,16 +342,11 @@ impl SpecializedRenderPipeline for TaaPipeline {
345342
}
346343

347344
fn extract_taa_settings(mut commands: Commands, mut main_world: ResMut<MainWorld>) {
348-
let mut cameras_3d = main_world.query_filtered::<(
345+
let mut cameras_3d = main_world.query::<(
349346
RenderEntity,
350347
&Camera,
351348
&Projection,
352-
&mut TemporalAntiAliasing,
353-
), (
354-
With<Camera3d>,
355-
With<TemporalJitter>,
356-
With<DepthPrepass>,
357-
With<MotionVectorPrepass>,
349+
Option<&mut TemporalAntiAliasing>,
358350
)>();
359351

360352
for (entity, camera, camera_projection, mut taa_settings) in
@@ -364,46 +356,48 @@ fn extract_taa_settings(mut commands: Commands, mut main_world: ResMut<MainWorld
364356
let mut entity_commands = commands
365357
.get_entity(entity)
366358
.expect("Camera entity wasn't synced.");
367-
if camera.is_active && has_perspective_projection {
368-
entity_commands.insert(taa_settings.clone());
369-
taa_settings.reset = false;
359+
if taa_settings.is_some() && camera.is_active && has_perspective_projection {
360+
entity_commands.insert(taa_settings.as_deref().unwrap().clone());
361+
taa_settings.as_mut().unwrap().reset = false;
370362
} else {
371-
// TODO: needs better strategy for cleaning up
372363
entity_commands.remove::<(
373364
TemporalAntiAliasing,
374-
// components added in prepare systems (because `TemporalAntiAliasNode` does not query extracted components)
375365
TemporalAntiAliasHistoryTextures,
376366
TemporalAntiAliasPipelineId,
377367
)>();
378368
}
379369
}
380370
}
381371

382-
fn prepare_taa_jitter_and_mip_bias(
372+
fn prepare_taa_jitter(
383373
frame_count: Res<FrameCount>,
384-
mut query: Query<(Entity, &mut TemporalJitter, Option<&MipBias>), With<TemporalAntiAliasing>>,
385-
mut commands: Commands,
374+
mut query: Query<
375+
&mut TemporalJitter,
376+
(
377+
With<TemporalAntiAliasing>,
378+
With<Camera3d>,
379+
With<TemporalJitter>,
380+
With<DepthPrepass>,
381+
With<MotionVectorPrepass>,
382+
),
383+
>,
386384
) {
387-
// Halton sequence (2, 3) - 0.5, skipping i = 0
385+
// Halton sequence (2, 3) - 0.5
388386
let halton_sequence = [
387+
vec2(0.0, 0.0),
389388
vec2(0.0, -0.16666666),
390389
vec2(-0.25, 0.16666669),
391390
vec2(0.25, -0.3888889),
392391
vec2(-0.375, -0.055555552),
393392
vec2(0.125, 0.2777778),
394393
vec2(-0.125, -0.2777778),
395394
vec2(0.375, 0.055555582),
396-
vec2(-0.4375, 0.3888889),
397395
];
398396

399397
let offset = halton_sequence[frame_count.0 as usize % halton_sequence.len()];
400398

401-
for (entity, mut jitter, mip_bias) in &mut query {
399+
for mut jitter in &mut query {
402400
jitter.offset = offset;
403-
404-
if mip_bias.is_none() {
405-
commands.entity(entity).insert(MipBias(-1.0));
406-
}
407401
}
408402
}
409403

crates/bevy_app/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ tracing = { version = "0.1", default-features = false, optional = true }
8888
log = { version = "0.4", default-features = false }
8989
cfg-if = "1.0.0"
9090

91-
[target.'cfg(any(unix, windows))'.dependencies]
91+
[target.'cfg(any(all(unix, not(target_os = "horizon")), windows))'.dependencies]
9292
ctrlc = { version = "3.4.4", optional = true }
9393

9494
[target.'cfg(target_arch = "wasm32")'.dependencies]

crates/bevy_app/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ mod plugin_group;
3131
mod schedule_runner;
3232
mod sub_app;
3333
mod task_pool_plugin;
34-
#[cfg(all(any(unix, windows), feature = "std"))]
34+
#[cfg(all(any(all(unix, not(target_os = "horizon")), windows), feature = "std"))]
3535
mod terminal_ctrl_c_handler;
3636

3737
pub use app::*;
@@ -42,7 +42,7 @@ pub use plugin_group::*;
4242
pub use schedule_runner::*;
4343
pub use sub_app::*;
4444
pub use task_pool_plugin::*;
45-
#[cfg(all(any(unix, windows), feature = "std"))]
45+
#[cfg(all(any(all(unix, not(target_os = "horizon")), windows), feature = "std"))]
4646
pub use terminal_ctrl_c_handler::*;
4747

4848
/// The app prelude.

crates/bevy_ecs/src/archetype.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,10 @@ impl Archetypes {
874874
}
875875

876876
/// Gets the archetype id matching the given inputs or inserts a new one if it doesn't exist.
877+
///
878+
/// Specifically, it returns a tuple where the first element
879+
/// is the [`ArchetypeId`] that the given inputs belong to, and the second element is a boolean indicating whether a new archetype was created.
880+
///
877881
/// `table_components` and `sparse_set_components` must be sorted
878882
///
879883
/// # Safety

crates/bevy_ecs/src/bundle.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,7 @@ mod tests {
23122312
}
23132313

23142314
#[test]
2315-
fn new_archetype_creadted() {
2315+
fn new_archetype_created() {
23162316
let mut world = World::new();
23172317
#[derive(Resource, Default)]
23182318
struct Count(u32);

crates/bevy_ecs/src/relationship/mod.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use crate::{
1414
component::{Component, HookContext, Mutable},
1515
entity::{ComponentCloneCtx, Entity, SourceComponent},
1616
error::{ignore, CommandWithEntity, HandleError},
17-
system::entity_command::{self},
1817
world::{DeferredWorld, EntityWorldMut},
1918
};
2019
use log::warn;
@@ -223,50 +222,24 @@ pub trait RelationshipTarget: Component<Mutability = Mutable> + Sized {
223222

224223
/// The `on_replace` component hook that maintains the [`Relationship`] / [`RelationshipTarget`] connection.
225224
// note: think of this as "on_drop"
226-
fn on_replace(mut world: DeferredWorld, HookContext { entity, caller, .. }: HookContext) {
225+
fn on_replace(mut world: DeferredWorld, HookContext { entity, .. }: HookContext) {
227226
let (entities, mut commands) = world.entities_and_commands();
228227
let relationship_target = entities.get(entity).unwrap().get::<Self>().unwrap();
229228
for source_entity in relationship_target.iter() {
230-
if entities.get(source_entity).is_ok() {
231-
commands.queue(
232-
entity_command::remove::<Self::Relationship>()
233-
.with_entity(source_entity)
234-
.handle_error_with(ignore),
235-
);
236-
} else {
237-
warn!(
238-
"{}Tried to despawn non-existent entity {}",
239-
caller
240-
.map(|location| format!("{location}: "))
241-
.unwrap_or_default(),
242-
source_entity
243-
);
244-
}
229+
commands
230+
.entity(source_entity)
231+
.remove::<Self::Relationship>();
245232
}
246233
}
247234

248235
/// The `on_despawn` component hook that despawns entities stored in an entity's [`RelationshipTarget`] when
249236
/// that entity is despawned.
250237
// note: think of this as "on_drop"
251-
fn on_despawn(mut world: DeferredWorld, HookContext { entity, caller, .. }: HookContext) {
238+
fn on_despawn(mut world: DeferredWorld, HookContext { entity, .. }: HookContext) {
252239
let (entities, mut commands) = world.entities_and_commands();
253240
let relationship_target = entities.get(entity).unwrap().get::<Self>().unwrap();
254241
for source_entity in relationship_target.iter() {
255-
if entities.get(source_entity).is_ok() {
256-
commands.queue(
257-
entity_command::despawn()
258-
.with_entity(source_entity)
259-
.handle_error_with(ignore),
260-
);
261-
} else {
262-
warn!(
263-
"{}Tried to despawn non-existent entity {}",
264-
caller
265-
.map(|location| format!("{location}: "))
266-
.unwrap_or_default(),
267-
source_entity
268-
);
269-
}
242+
commands.entity(source_entity).despawn();
270243
}
271244
}
272245

crates/bevy_ecs/src/system/query.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,6 +2627,36 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Populated<'w, 's, D, F> {
26272627
}
26282628
}
26292629

2630+
impl<'w, 's, D: QueryData, F: QueryFilter> IntoIterator for Populated<'w, 's, D, F> {
2631+
type Item = <Query<'w, 's, D, F> as IntoIterator>::Item;
2632+
2633+
type IntoIter = <Query<'w, 's, D, F> as IntoIterator>::IntoIter;
2634+
2635+
fn into_iter(self) -> Self::IntoIter {
2636+
self.0.into_iter()
2637+
}
2638+
}
2639+
2640+
impl<'a, 'w, 's, D: QueryData, F: QueryFilter> IntoIterator for &'a Populated<'w, 's, D, F> {
2641+
type Item = <&'a Query<'w, 's, D, F> as IntoIterator>::Item;
2642+
2643+
type IntoIter = <&'a Query<'w, 's, D, F> as IntoIterator>::IntoIter;
2644+
2645+
fn into_iter(self) -> Self::IntoIter {
2646+
self.deref().into_iter()
2647+
}
2648+
}
2649+
2650+
impl<'a, 'w, 's, D: QueryData, F: QueryFilter> IntoIterator for &'a mut Populated<'w, 's, D, F> {
2651+
type Item = <&'a mut Query<'w, 's, D, F> as IntoIterator>::Item;
2652+
2653+
type IntoIter = <&'a mut Query<'w, 's, D, F> as IntoIterator>::IntoIter;
2654+
2655+
fn into_iter(self) -> Self::IntoIter {
2656+
self.deref_mut().into_iter()
2657+
}
2658+
}
2659+
26302660
#[cfg(test)]
26312661
mod tests {
26322662
use crate::{prelude::*, query::QueryEntityError};

0 commit comments

Comments
 (0)