Improved physics timings
parent
e59aca3536
commit
d0c26d6891
|
@ -35,14 +35,7 @@ impl FpsIndicator {
|
||||||
|
|
||||||
self.buffer.set_text(
|
self.buffer.set_text(
|
||||||
&mut state.text_font_system,
|
&mut state.text_font_system,
|
||||||
&format!(
|
&input.timing.get_string(),
|
||||||
"Frame: {:#?} ({:05.00})\nShips: {:05.02}%\nPhys: {:05.02}%\n",
|
|
||||||
input.timing.frame,
|
|
||||||
1.0 / input.timing.frame.as_secs_f32(),
|
|
||||||
100.0 * (input.timing.physics_sim.as_secs_f32() / input.timing.frame.as_secs_f32()),
|
|
||||||
100.0
|
|
||||||
* (input.timing.physics_ship.as_secs_f32() / input.timing.frame.as_secs_f32()),
|
|
||||||
),
|
|
||||||
Attrs::new().family(Family::Monospace),
|
Attrs::new().family(Family::Monospace),
|
||||||
Shaping::Basic,
|
Shaping::Basic,
|
||||||
);
|
);
|
||||||
|
|
|
@ -257,6 +257,7 @@ impl PhysSim {
|
||||||
res.timing.start_physics_sim();
|
res.timing.start_physics_sim();
|
||||||
|
|
||||||
// Update physics
|
// Update physics
|
||||||
|
res.timing.start_physics_step();
|
||||||
self.wrapper.step(res.t);
|
self.wrapper.step(res.t);
|
||||||
|
|
||||||
// Handle collision events
|
// Handle collision events
|
||||||
|
@ -281,12 +282,15 @@ impl PhysSim {
|
||||||
self.collide_projectile_ship(&mut res, a, b);
|
self.collide_projectile_ship(&mut res, a, b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
res.timing.mark_physics_step();
|
||||||
|
|
||||||
|
res.timing.start_physics_proj();
|
||||||
// Step and garbage-collect projectiles
|
// Step and garbage-collect projectiles
|
||||||
self.projectiles.retain(|_, proj| {
|
self.projectiles.retain(|_, proj| {
|
||||||
proj.step(&mut res, &mut self.new, &mut self.wrapper);
|
proj.step(&mut res, &mut self.new, &mut self.wrapper);
|
||||||
!proj.should_remove()
|
!proj.should_remove()
|
||||||
});
|
});
|
||||||
|
res.timing.mark_physics_proj();
|
||||||
|
|
||||||
// Step and garbage-collect ships
|
// Step and garbage-collect ships
|
||||||
res.timing.start_physics_ships();
|
res.timing.start_physics_ships();
|
||||||
|
@ -296,11 +300,13 @@ impl PhysSim {
|
||||||
});
|
});
|
||||||
res.timing.mark_physics_ships();
|
res.timing.mark_physics_ships();
|
||||||
|
|
||||||
|
res.timing.start_physics_effects();
|
||||||
// Step and garbage-collect effects
|
// Step and garbage-collect effects
|
||||||
self.effects.retain_mut(|x| {
|
self.effects.retain_mut(|x| {
|
||||||
x.step(&res, &mut self.wrapper);
|
x.step(&res, &mut self.wrapper);
|
||||||
!x.is_destroyed()
|
!x.is_destroyed()
|
||||||
});
|
});
|
||||||
|
res.timing.mark_physics_effects();
|
||||||
|
|
||||||
// Process new objects
|
// Process new objects
|
||||||
for p in self.new.projectiles.iter() {
|
for p in self.new.projectiles.iter() {
|
||||||
|
|
|
@ -9,13 +9,25 @@ pub struct Timing {
|
||||||
pub frame: Duration,
|
pub frame: Duration,
|
||||||
frame_timer: Instant,
|
frame_timer: Instant,
|
||||||
|
|
||||||
/// The time we spent simulating physics
|
/// The total time we spent simulating physics
|
||||||
pub physics_sim: Duration,
|
pub physics_sim: Duration,
|
||||||
physics_sim_timer: Instant,
|
physics_sim_timer: Instant,
|
||||||
|
|
||||||
|
/// The time we spent updating physics state
|
||||||
|
pub physics_step: Duration,
|
||||||
|
physics_step_timer: Instant,
|
||||||
|
|
||||||
/// The time we spent updating physics ships
|
/// The time we spent updating physics ships
|
||||||
pub physics_ship: Duration,
|
pub physics_ship: Duration,
|
||||||
physics_ship_timer: Instant,
|
physics_ship_timer: Instant,
|
||||||
|
|
||||||
|
/// The time we spent updating physics projectiles
|
||||||
|
pub physics_proj: Duration,
|
||||||
|
physics_proj_timer: Instant,
|
||||||
|
|
||||||
|
/// The time we spent updating effects
|
||||||
|
pub physics_effect: Duration,
|
||||||
|
physics_effect_timer: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: document each duration
|
// TODO: document each duration
|
||||||
|
@ -27,6 +39,12 @@ impl Timing {
|
||||||
frame: Duration::ZERO,
|
frame: Duration::ZERO,
|
||||||
physics_sim: Duration::ZERO,
|
physics_sim: Duration::ZERO,
|
||||||
physics_ship: Duration::ZERO,
|
physics_ship: Duration::ZERO,
|
||||||
|
physics_effect: Duration::ZERO,
|
||||||
|
physics_proj: Duration::ZERO,
|
||||||
|
physics_step: Duration::ZERO,
|
||||||
|
physics_effect_timer: Instant::now(),
|
||||||
|
physics_proj_timer: Instant::now(),
|
||||||
|
physics_step_timer: Instant::now(),
|
||||||
physics_sim_timer: Instant::now(),
|
physics_sim_timer: Instant::now(),
|
||||||
physics_ship_timer: Instant::now(),
|
physics_ship_timer: Instant::now(),
|
||||||
frame_timer: Instant::now(),
|
frame_timer: Instant::now(),
|
||||||
|
@ -38,28 +56,88 @@ impl Timing {
|
||||||
self.frame_timer = Instant::now();
|
self.frame_timer = Instant::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start physics sim timer
|
|
||||||
pub fn start_physics_sim(&mut self) {
|
|
||||||
self.physics_sim_timer = Instant::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start physics ship timer
|
|
||||||
pub fn start_physics_ships(&mut self) {
|
|
||||||
self.physics_ship_timer = Instant::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Record total frame compute time
|
/// Record total frame compute time
|
||||||
pub fn mark_frame(&mut self) {
|
pub fn mark_frame(&mut self) {
|
||||||
self.frame = self.frame_timer.elapsed();
|
self.frame = self.frame_timer.elapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start physics sim timer
|
||||||
|
pub fn start_physics_sim(&mut self) {
|
||||||
|
self.physics_sim_timer = Instant::now();
|
||||||
|
}
|
||||||
|
|
||||||
/// Record physics simulation time
|
/// Record physics simulation time
|
||||||
pub fn mark_physics_sim(&mut self) {
|
pub fn mark_physics_sim(&mut self) {
|
||||||
self.physics_sim = self.physics_sim_timer.elapsed();
|
self.physics_sim = self.physics_sim_timer.elapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start physics ship timer
|
||||||
|
pub fn start_physics_ships(&mut self) {
|
||||||
|
self.physics_ship_timer = Instant::now();
|
||||||
|
}
|
||||||
|
|
||||||
/// Record physics ship update time
|
/// Record physics ship update time
|
||||||
pub fn mark_physics_ships(&mut self) {
|
pub fn mark_physics_ships(&mut self) {
|
||||||
self.physics_ship = self.physics_ship_timer.elapsed();
|
self.physics_ship = self.physics_ship_timer.elapsed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Start physics step timer
|
||||||
|
pub fn start_physics_step(&mut self) {
|
||||||
|
self.physics_step_timer = Instant::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Record physics ship update time
|
||||||
|
pub fn mark_physics_step(&mut self) {
|
||||||
|
self.physics_step = self.physics_step_timer.elapsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start physics ship timer
|
||||||
|
pub fn start_physics_proj(&mut self) {
|
||||||
|
self.physics_proj_timer = Instant::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Record physics ship update time
|
||||||
|
pub fn mark_physics_proj(&mut self) {
|
||||||
|
self.physics_proj = self.physics_proj_timer.elapsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start physics ship timer
|
||||||
|
pub fn start_physics_effects(&mut self) {
|
||||||
|
self.physics_effect_timer = Instant::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Record physics ship update time
|
||||||
|
pub fn mark_physics_effects(&mut self) {
|
||||||
|
self.physics_effect = self.physics_effect_timer.elapsed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get current timing values as a pretty string
|
||||||
|
pub fn get_string(&self) -> String {
|
||||||
|
let mut s = String::new();
|
||||||
|
//s.push_str(&format!(
|
||||||
|
// "Overall {:6.00} fps\n\n",
|
||||||
|
// 1.0 / self.frame.as_secs_f32()
|
||||||
|
//));
|
||||||
|
|
||||||
|
let f = self.physics_sim.as_secs_f32();
|
||||||
|
s.push_str(&format!("Phys {:6.00} fps\n", 1.0 / f));
|
||||||
|
s.push_str(&format!(
|
||||||
|
"Step {:6.02}%\n",
|
||||||
|
100.0 * self.physics_step.as_secs_f32() / f
|
||||||
|
));
|
||||||
|
s.push_str(&format!(
|
||||||
|
"Proj {:05.02}%\n",
|
||||||
|
100.0 * self.physics_proj.as_secs_f32() / f
|
||||||
|
));
|
||||||
|
s.push_str(&format!(
|
||||||
|
"Ships {:05.02}%\n",
|
||||||
|
100.0 * self.physics_ship.as_secs_f32() / f
|
||||||
|
));
|
||||||
|
s.push_str(&format!(
|
||||||
|
"Efcts {:05.02}%",
|
||||||
|
100.0 * self.physics_effect.as_secs_f32() / f
|
||||||
|
));
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue