-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(profiler): Re-add puffin profiler (F10) (#908)
Re add puffin profiler. Haven't added any new scopes / fleshed anything out, but got it handy at least for now.
- Loading branch information
1 parent
3ffeaf0
commit 1fb348f
Showing
5 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Game plugin for performance profiling tools. | ||
use crate::prelude::*; | ||
|
||
/// Installs profiler ui plugins | ||
pub fn game_plugin(game: &mut Game) { | ||
game.systems.add_before_system(mark_new_frame); | ||
game.sessions | ||
.create(SessionNames::PROFILER) | ||
.install_plugin(session_plugin); | ||
} | ||
|
||
/// Install the profiler UI to profiler session. | ||
fn session_plugin(session: &mut Session) { | ||
session | ||
.stages | ||
.add_system_to_stage(CoreStage::First, profiler); | ||
} | ||
|
||
#[derive(HasSchema, Clone, Debug, Default)] | ||
struct ProfilerState { | ||
pub show_window: bool, | ||
} | ||
|
||
fn profiler( | ||
ctx: ResMut<EguiCtx>, | ||
localization: Localization<GameMeta>, | ||
mut state: ResMutInit<ProfilerState>, | ||
keyboard_inputs: Res<KeyboardInputs>, | ||
) { | ||
puffin::set_scopes_on(true); | ||
|
||
let toggle_window = keyboard_inputs | ||
.key_events | ||
.iter() | ||
.any(|x| x.key_code.option() == Some(KeyCode::F10) && !x.button_state.pressed()); | ||
|
||
let show_window = &mut state.show_window; | ||
if toggle_window { | ||
*show_window = !*show_window; | ||
} | ||
|
||
egui::Window::new(localization.get("profiler")) | ||
.id(egui::Id::new("profiler")) | ||
.open(show_window) | ||
.show(&ctx, |ui| { | ||
puffin_egui::profiler_ui(ui); | ||
}); | ||
} | ||
|
||
/// Notify profilers we are at frame boundary | ||
pub fn mark_new_frame(_game: &mut Game) { | ||
puffin::GlobalProfiler::lock().new_frame(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters