break loop early on 0 curr strain

This commit is contained in:
MaxOhn
2023-02-09 14:04:28 +01:00
parent 68050f7848
commit 7cc3a4644b
11 changed files with 58 additions and 28 deletions
+1 -3
View File
@@ -89,11 +89,9 @@ impl<'map> ManiaStars<'map> {
/// Adjust the clock rate used in the calculation.
/// If none is specified, it will take the clock rate based on the mods
/// i.e. 1.5 for DT, 0.75 for HT and 1.0 otherwise.
///
/// The value cannot go below 0.001.
#[inline]
pub fn clock_rate(mut self, clock_rate: f64) -> Self {
self.clock_rate = Some(clock_rate.max(0.001));
self.clock_rate = Some(clock_rate);
self
}
+1 -3
View File
@@ -120,11 +120,9 @@ impl<'map> ManiaPP<'map> {
/// Adjust the clock rate used in the calculation.
/// If none is specified, it will take the clock rate based on the mods
/// i.e. 1.5 for DT, 0.75 for HT and 1.0 otherwise.
///
/// The value cannot go below 0.001.
#[inline]
pub fn clock_rate(mut self, clock_rate: f64) -> Self {
self.clock_rate = Some(clock_rate.max(0.001));
self.clock_rate = Some(clock_rate);
self
}
+12
View File
@@ -30,6 +30,18 @@ pub(crate) trait StrainSkill: Sized + Skill {
self.save_curr_peak();
self.start_new_section_from(self.curr_section_end(), curr, diff_objects);
*self.curr_section_end_mut() += SECTION_LEN;
// Optimization to finish the loop early if
// the current peak is 0.0 i.e. it can't decay further.
// If final values don't coincide perfectly anymore,
// this should be looked at and maybe adjusted.
if self.curr_section_peak().abs() <= f64::EPSILON
&& curr.start_time > self.curr_section_end()
{
let remaining = curr.start_time - self.curr_section_end();
let skip_iter_count = (remaining / SECTION_LEN).ceil();
*self.curr_section_end_mut() += skip_iter_count * SECTION_LEN;
}
}
*self.curr_section_peak_mut() = self.strain_value_at(curr).max(self.curr_section_peak());