# Objective - Contributes to #11478 ## Solution - Made `bevy_utils::tracing` `doc(hidden)` - Re-exported `tracing` from `bevy_log` for end-users - Added `tracing` directly to crates that need it. ## Testing - CI --- ## Migration Guide If you were importing `tracing` via `bevy::utils::tracing`, instead use `bevy::log::tracing`. Note that many items within `tracing` are also directly re-exported from `bevy::log` as well, so you may only need `bevy::log` for the most common items (e.g., `warn!`, `trace!`, etc.). This also applies to the `log_once!` family of macros. ## Notes - While this doesn't reduce the line-count in `bevy_utils`, it further decouples the internal crates from `bevy_utils`, making its eventual removal more feasible in the future. - I have just imported `tracing` as we do for all dependencies. However, a workspace dependency may be more appropriate for version management.
40 lines
1.4 KiB
Rust
40 lines
1.4 KiB
Rust
use super::config::*;
|
|
use bevy_app::AppExit;
|
|
use bevy_ecs::prelude::*;
|
|
use bevy_render::view::screenshot::{save_to_disk, Screenshot};
|
|
use tracing::{debug, info};
|
|
|
|
pub(crate) fn send_events(world: &mut World, mut current_frame: Local<u32>) {
|
|
let mut config = world.resource_mut::<CiTestingConfig>();
|
|
|
|
// Take all events for the current frame, leaving all the remaining alone.
|
|
let events = core::mem::take(&mut config.events);
|
|
let (to_run, remaining): (Vec<_>, _) = events
|
|
.into_iter()
|
|
.partition(|event| event.0 == *current_frame);
|
|
config.events = remaining;
|
|
|
|
for CiTestingEventOnFrame(_, event) in to_run {
|
|
debug!("Handling event: {:?}", event);
|
|
match event {
|
|
CiTestingEvent::AppExit => {
|
|
world.send_event(AppExit::Success);
|
|
info!("Exiting after {} frames. Test successful!", *current_frame);
|
|
}
|
|
CiTestingEvent::Screenshot => {
|
|
let path = format!("./screenshot-{}.png", *current_frame);
|
|
world
|
|
.spawn(Screenshot::primary_window())
|
|
.observe(save_to_disk(path));
|
|
info!("Took a screenshot at frame {}.", *current_frame);
|
|
}
|
|
// Custom events are forwarded to the world.
|
|
CiTestingEvent::Custom(event_string) => {
|
|
world.send_event(CiTestingCustomEvent(event_string));
|
|
}
|
|
}
|
|
}
|
|
|
|
*current_frame += 1;
|
|
}
|