Skip to content

Commit

Permalink
More DefaultUiCamera fixes (#17120)
Browse files Browse the repository at this point in the history
# Objective

Found more excessive `DefaultUiCamera` queries outside of extraction.
The default UI camera lookup only needs to be done once. Do it first,
not per node.

---------

Co-authored-by: MichiRecRoom <1008889+LikeLakers2@users.noreply.github.com>
  • Loading branch information
ickshonpe and LikeLakers2 authored Jan 6, 2025
1 parent f61de11 commit d220ecc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion crates/bevy_ui/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ pub fn ui_focus_system(
})
.collect();

let default_camera_entity = default_ui_camera.get();

// prepare an iterator that contains all the nodes that have the cursor in their rect,
// from the top node to the bottom one. this will also reset the interaction to `None`
// for all nodes encountered that are no longer hovered.
Expand All @@ -239,7 +241,7 @@ pub fn ui_focus_system(
let camera_entity = node
.target_camera
.map(TargetCamera::entity)
.or(default_ui_camera.get())?;
.or(default_camera_entity)?;

let node_rect = Rect::from_center_size(
node.global_transform.translation().truncate(),
Expand Down
6 changes: 4 additions & 2 deletions crates/bevy_ui/src/picking_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub fn ui_picking(
// For each camera, the pointer and its position
let mut pointer_pos_by_camera = HashMap::<Entity, HashMap<PointerId, Vec2>>::default();

let default_camera_entity = default_ui_camera.get();

for (pointer_id, pointer_location) in
pointers.iter().filter_map(|(pointer, pointer_location)| {
Some(*pointer).zip(pointer_location.location().cloned())
Expand Down Expand Up @@ -133,7 +135,7 @@ pub fn ui_picking(
let Some(camera_entity) = node
.target_camera
.map(TargetCamera::entity)
.or(default_ui_camera.get())
.or(default_camera_entity)
else {
continue;
};
Expand Down Expand Up @@ -189,7 +191,7 @@ pub fn ui_picking(
let Some(camera_entity) = node
.target_camera
.map(TargetCamera::entity)
.or(default_ui_camera.get())
.or(default_camera_entity)
else {
continue;
};
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_ui/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ pub fn measure_text_system(
) {
scale_factors_buffer.clear();

let default_camera_entity = default_ui_camera.get();

for (entity, block, content_size, text_flags, computed, maybe_camera) in &mut text_query {
let Some(camera_entity) = maybe_camera
.map(TargetCamera::entity)
.or(default_ui_camera.get())
.or(default_camera_entity)
else {
continue;
};
Expand Down

0 comments on commit d220ecc

Please sign in to comment.