Skip to content

Commit

Permalink
improved tracing
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Mertz <git@jeanmertz.com>
  • Loading branch information
JeanMertz committed Apr 24, 2024
1 parent ae923a5 commit 01c0517
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 80 deletions.
12 changes: 8 additions & 4 deletions crates/butter/src/plugins/canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn update_text_computed_size(
for (entity, mut size, layout) in sizes.iter_mut() {
// The logical size of a text node can be zero, which we interpret as "unknown".
if layout.logical_size == Vec2::ZERO {
if size.as_ref() == &ComputedSize::Inherit {
if !matches!(size.as_ref(), &ComputedSize::Static(_)) {
continue;
}
}
Expand All @@ -150,14 +150,18 @@ fn update_transformed_computed_size(
mut sizes: Query<(Entity, &mut ComputedSize, &Transform), Changed<Transform>>,
) {
for (entity, mut size, transform) in sizes.iter_mut() {
let _span = trace_span!("Checking if entity needs computed size update", ?entity).entered();

let old = *size.as_ref();
if size.set_if_neq(old.transformed(*transform)) {
let new = size.as_ref();
debug!(
?entity,
trace!(?old, ?new, "Updated transformed ComputedSize component");
} else {
let new = size.as_ref();
trace!(
?old,
?new,
"Updated transformed ComputedSize component"
"ComputedSize matches new Transform, nothing to update"
);
}
}
Expand Down
103 changes: 47 additions & 56 deletions crates/butter/src/plugins/canvas/place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ impl Plugin for PlacePlugin {
position_body.run_if(run_position_body),
)
.chain(),
position_place.map(err),
position_relative_place
// position_place.map(err),
position_place
.map(err)
.run_if(any_with_component::<RequiresRelativePlacement>),
.run_if(any_with_component::<RequiresPositioning>),
toggle_numbering.run_if(resource_changed::<ShowNumbers>),
focus_next.run_if(input_just_pressed(KeyCode::ArrowRight)),
focus_last.run_if(input_just_pressed(KeyCode::ArrowLeft)),
Expand All @@ -68,7 +68,7 @@ pub(super) struct Place;

/// A place that requires placement relative to another place.
#[derive(Component)]
struct RequiresRelativePlacement {
struct RequiresPositioning {
x: Coordinate,
y: Coordinate,
}
Expand Down Expand Up @@ -160,10 +160,8 @@ fn create(
.map(|pos| (pos.x, pos.y))
.unwrap_or_else(|| (Coordinate::Absolute(0), Coordinate::Absolute(0)));

error!(?x, ?y, "Positions");

cmd.entity(place)
.insert((RequiresRelativePlacement { x, y }, Visibility::Hidden));
.insert((RequiresPositioning { x, y }, Visibility::Hidden));

let header = create_header(
&mut cmd,
Expand Down Expand Up @@ -378,21 +376,21 @@ fn redraw_underline(
.ok()
})
.for_each(
|(underline, mut sprite, mut translation, size)| match size {
Ok(Some(size)) => {
|(underline, mut sprite, mut translation, title_size)| match title_size {
Ok(Some(title_size)) => {
if let Some(custom_size) = sprite.custom_size.as_mut() {
custom_size.x = size.x * (1. + UNDERLINE_STRETCH);
custom_size.x = title_size.x * (1. + UNDERLINE_STRETCH);
}

translation.y = -size.y;
translation.y = -title_size.y;
info!(
?underline,
?translation,
"Repositioned place title underline."
);
}
Ok(None) => {
debug!(?underline, "Waiting on pending size.")
debug!(?underline, "Waiting on pending title size.")
}
Err(error) => error!(?underline, %error, "Unexpected error."),
},
Expand Down Expand Up @@ -474,50 +472,50 @@ fn run_position_body(
.any(|b| headers.iter().any(|h| h.get() == b.get()))
}

fn position_place(
mut events: EventReader<ComputedSizeUpdatedEvent>,
places: Query<Entity, With<Place>>,
sizes: ComputedSizeParam<()>,
) -> Result<(), Error> {
// Find any place for which any of its children has an updated computed size.
let mut places: Vec<_> = events
.read()
.map(|event| places.iter().filter(|place| event.contains(*place)))
.flatten()
.collect();

places.sort();
places.dedup();

for place in places {
let Some(size) = sizes.size_of(place)? else {
continue;
};

error!(?size);
}

Ok(())
}
// fn position_place(
// mut events: EventReader<ComputedSizeUpdatedEvent>,
// places: Query<Entity, With<Place>>,
// sizes: ComputedSizeParam<()>,
// ) -> Result<(), Error> {
// // Find any place for which any of its children has an updated computed size.
// let mut places: Vec<_> = events
// .read()
// .map(|event| places.iter().filter(|place| event.contains(*place)))
// .flatten()
// .collect();
//
// places.sort();
// places.dedup();
//
// for place in places {
// let Some(size) = sizes.size_of(place)? else {
// continue;
// };
//
// error!(?size);
// }
//
// Ok(())
// }

#[instrument(skip_all)]
fn position_relative_place(
fn position_place(
mut cmd: Commands,
positioning: Query<(Entity, &RequiresRelativePlacement)>,
positioning: Query<(Entity, &RequiresPositioning)>,
names: Query<(Entity, &Name)>,
places: Query<
Entity,
(
With<Place>,
With<ComputedSize>,
Without<RequiresRelativePlacement>,
Without<RequiresPositioning>,
),
>,
sizes: ComputedSizeParam<()>,
parent: Query<&Parent>,
) -> Result<(), Error> {
for (place, RequiresRelativePlacement { x, y }) in &positioning {
error!(?x, ?y);
for (place, RequiresPositioning { x, y }) in &positioning {
debug!(?place, ?x, ?y, "Positioning place.");

let position = match (x, y) {
(Coordinate::Absolute(x), Coordinate::Absolute(y)) => Vec2::new(*x as f32, *y as f32),
Expand Down Expand Up @@ -547,7 +545,6 @@ fn position_relative_place(
continue;
};

error!("Doing it y!");
pos.y = pos.y + *offset as f32 + 200.;

Vec2::new(*x as f32, pos.y)
Expand Down Expand Up @@ -578,7 +575,6 @@ fn position_relative_place(
continue;
};

error!("Doing it x!");
pos.x = pos.x + *offset as f32;

Vec2::new(pos.x, *y as f32)
Expand Down Expand Up @@ -626,23 +622,18 @@ fn position_relative_place(

let x = pos.x + offset_x + size.x;
let y = pos.y + *offset_y as f32;
error!(?x, ?y, "Doing it x/y!");

Vec2::new(x, y)
}
};

error!(?position, "Positioning?");

cmd.entity(place)
.remove::<RequiresRelativePlacement>()
.insert((
Transform {
translation: position.extend(0.0),
..default()
},
Visibility::Visible,
));
cmd.entity(place).remove::<RequiresPositioning>().insert((
Transform {
translation: position.extend(0.0),
..default()
},
Visibility::Visible,
));
}

Ok(())
Expand Down
4 changes: 3 additions & 1 deletion crates/butter/src/plugins/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ impl DebugPlugin {
.add_directive("wgpu_hal=error".parse().unwrap())
.add_directive("bevy_time::virt=error".parse().unwrap())
.add_directive("bevy_mod_raycast=error".parse().unwrap())
.add_directive("bevy_egui=error".parse().unwrap())
.add_directive("naga=error".parse().unwrap());

tracing_subscriber::fmt()
.with_env_filter(filter)
.with_span_events(FmtSpan::ENTER)
.with_span_events(FmtSpan::ENTER | FmtSpan::EXIT)
.with_target(true)
.without_time()
.with_line_number(true)
.init();
}
Expand Down
4 changes: 3 additions & 1 deletion crates/butter/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ pub(crate) use bevy_text::{Text2dBounds, TextLayoutInfo};
pub(crate) use bevy_transform::prelude::*;
pub(crate) use bevy_turborand::{DelegatedRng as _, RngComponent};
pub(crate) use bevy_utils::prelude::*;
pub(crate) use tracing::{debug, error, field, info, info_span, instrument, trace, warn};
pub(crate) use tracing::{
debug, debug_span, error, field, info, info_span, instrument, trace, trace_span, warn,
};
Loading

0 comments on commit 01c0517

Please sign in to comment.