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
+11 -3
View File
@@ -84,11 +84,9 @@ impl<'map> CatchStars<'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
}
@@ -218,6 +216,16 @@ fn calculate_movement(params: CatchStars<'_>) -> (Movement, CatchDifficultyAttri
movement.save_current_peak();
movement.start_new_section_from(curr_section_end);
curr_section_end += SECTION_LENGTH;
// 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 movement.curr_section_peak.abs() <= f64::EPSILON && base_time > curr_section_end {
let remaining = base_time - curr_section_end;
let skip_iter_count = (remaining / SECTION_LENGTH).ceil();
curr_section_end += skip_iter_count * SECTION_LENGTH;
}
}
movement.process(&h);
+1 -3
View File
@@ -152,11 +152,9 @@ impl<'map> CatchPP<'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
@@ -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());
+1 -3
View File
@@ -102,11 +102,9 @@ impl<'map> OsuStars<'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
@@ -172,11 +172,9 @@ impl<'map> OsuPP<'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
@@ -47,6 +47,18 @@ pub(crate) trait StrainSkill: Skill + Sized {
}
*self.curr_section_end() += 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() += skip_iter_count * SECTION_LEN;
}
}
*self.curr_section_peak() = self
+3 -5
View File
@@ -24,7 +24,7 @@ use self::{
skills::{Peaks, PeaksDifficultyValues, PeaksRaw, Skill},
};
const SECTION_LEN: usize = 400;
const SECTION_LEN: f64 = 400.0;
const DIFFICULTY_MULTIPLIER: f64 = 1.35;
@@ -96,11 +96,9 @@ impl<'map> TaikoStars<'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
}
@@ -182,7 +180,7 @@ impl<'map> TaikoStars<'map> {
} = peaks.into_raw();
TaikoStrains {
section_len: SECTION_LEN as f64,
section_len: SECTION_LEN,
color: colour,
rhythm,
stamina,
+1 -3
View File
@@ -162,11 +162,9 @@ impl<'map> TaikoPP<'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
}
+14 -2
View File
@@ -24,7 +24,7 @@ pub(crate) trait StrainSkill: Skill {
fn process(&mut self, curr: &TaikoDifficultyObject, hit_objects: &ObjectLists) {
// * The first object doesn't generate a strain, so we begin with an incremented section end
if curr.idx == 0 {
let section_len = SECTION_LEN as f64;
let section_len = SECTION_LEN;
*self.curr_section_end() = (curr.start_time / section_len).ceil() * section_len;
}
@@ -36,7 +36,19 @@ pub(crate) trait StrainSkill: Skill {
self.start_new_section_from(section_end, curr);
}
*self.curr_section_end() += SECTION_LEN as f64;
*self.curr_section_end() += 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() += skip_iter_count * SECTION_LEN;
}
}
*self.curr_section_peak() = self