Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show time spent in Debug::draw in debug view #26

Merged
merged 1 commit into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/debug/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub struct Debug {
update_durations: TimeBuffer,
draw_start: time::Instant,
draw_durations: TimeBuffer,
debug_start: time::Instant,
debug_durations: TimeBuffer,
text: Vec<graphics::Text>,
draw_rate: u16,
frames_until_refresh: u16,
Expand All @@ -52,6 +54,8 @@ impl Debug {
update_durations: TimeBuffer::new(200),
draw_start: now,
draw_durations: TimeBuffer::new(200),
debug_start: now,
debug_durations: TimeBuffer::new(200),
text: Vec::new(),
draw_rate,
frames_until_refresh: 0,
Expand Down Expand Up @@ -144,6 +148,22 @@ impl Debug {
self.frames_until_refresh = 0;
}

pub(crate) fn debug_started(&mut self) {
self.debug_start = time::Instant::now();
}

pub(crate) fn debug_finished(&mut self) {
self.debug_durations
.push(time::Instant::now() - self.debug_start);
}

/// Get the average time spent running [`Game::debug`].
///
/// [`Game::debug`]: trait.Game.html#tymethod.debug
pub fn debug_duration(&self) -> time::Duration {
self.draw_durations.average()
}

pub(crate) fn is_enabled(&self) -> bool {
self.enabled
}
Expand Down Expand Up @@ -182,6 +202,7 @@ impl Debug {
("Interact:", self.interact_duration, None),
("Update:", self.update_durations.average(), None),
("Draw:", self.draw_durations.average(), None),
("Debug:", self.debug_durations.average(), None),
("Frame:", frame_duration, Some(fps.to_string() + " fps")),
];

Expand Down
11 changes: 3 additions & 8 deletions src/debug/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,19 @@ impl Debug {
}

pub(crate) fn loading_started(&mut self) {}

pub(crate) fn loading_finished(&mut self) {}

pub(crate) fn frame_started(&mut self) {}
pub(crate) fn frame_finished(&mut self) {}

pub(crate) fn interact_started(&mut self) {}

pub(crate) fn interact_finished(&mut self) {}

pub(crate) fn update_started(&mut self) {}

pub(crate) fn update_finished(&mut self) {}

pub(crate) fn draw_started(&mut self) {}

pub(crate) fn draw_finished(&mut self) {}
pub(crate) fn debug_started(&mut self) {}
pub(crate) fn debug_finished(&mut self) {}

#[allow(dead_code)]
pub(crate) fn toggle(&mut self) {}

pub(crate) fn is_enabled(&self) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ pub trait Game {
debug.draw_finished();

if debug.is_enabled() {
debug.debug_started();
game.debug(input, view, window, &mut debug);
debug.debug_finished();
}

window.swap_buffers();
Expand Down