More DefaultUiCamera fixes (#17120)

# 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>
This commit is contained in:
ickshonpe 2025-01-06 19:11:04 +00:00 committed by GitHub
parent f61de1101c
commit d220eccbb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 4 deletions

View File

@ -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.
@ -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(),

View File

@ -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())
@ -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;
};
@ -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;
};

View File

@ -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;
};